OpenTTD
waypoint_cmd.cpp
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8  */
9 
12 #include "stdafx.h"
13 
14 #include "cmd_helper.h"
15 #include "command_func.h"
16 #include "landscape.h"
17 #include "bridge_map.h"
18 #include "town.h"
19 #include "waypoint_base.h"
21 #include "strings_func.h"
22 #include "viewport_func.h"
23 #include "viewport_kdtree.h"
24 #include "window_func.h"
25 #include "date_func.h"
26 #include "vehicle_func.h"
27 #include "string_func.h"
28 #include "company_func.h"
29 #include "newgrf_station.h"
30 #include "company_base.h"
31 #include "water.h"
32 #include "company_gui.h"
33 
34 #include "table/strings.h"
35 
36 #include "safeguards.h"
37 
42 {
43  Point pt = RemapCoords2(TileX(this->xy) * TILE_SIZE, TileY(this->xy) * TILE_SIZE);
44  SetDParam(0, this->index);
45  this->sign.UpdatePosition(pt.x, pt.y - 32 * ZOOM_LVL_BASE, STR_VIEWPORT_WAYPOINT);
46  /* Recenter viewport */
48 }
49 
55 {
56  if (this->xy == new_xy) return;
57 
58  _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeWaypoint(this->index));
59 
60  this->BaseStation::MoveSign(new_xy);
61 
62  _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeWaypoint(this->index));
63 }
64 
73 {
74  Waypoint *wp, *best = nullptr;
75  uint thres = 8;
76 
77  FOR_ALL_WAYPOINTS(wp) {
78  if (!wp->IsInUse() && wp->string_id == str && wp->owner == cid) {
79  uint cur_dist = DistanceManhattan(tile, wp->xy);
80 
81  if (cur_dist < thres) {
82  thres = cur_dist;
83  best = wp;
84  }
85  }
86  }
87 
88  return best;
89 }
90 
99 {
100  /* The axis for rail waypoints is easy. */
101  if (IsRailWaypointTile(tile)) return GetRailStationAxis(tile);
102 
103  /* Non-plain rail type, no valid axis for waypoints. */
104  if (!IsTileType(tile, MP_RAILWAY) || GetRailTileType(tile) != RAIL_TILE_NORMAL) return INVALID_AXIS;
105 
106  switch (GetTrackBits(tile)) {
107  case TRACK_BIT_X: return AXIS_X;
108  case TRACK_BIT_Y: return AXIS_Y;
109  default: return INVALID_AXIS;
110  }
111 }
112 
114 
121 static CommandCost IsValidTileForWaypoint(TileIndex tile, Axis axis, StationID *waypoint)
122 {
123  /* if waypoint is set, then we have special handling to allow building on top of already existing waypoints.
124  * so waypoint points to INVALID_STATION if we can build on any waypoint.
125  * Or it points to a waypoint if we're only allowed to build on exactly that waypoint. */
126  if (waypoint != nullptr && IsTileType(tile, MP_STATION)) {
127  if (!IsRailWaypoint(tile)) {
128  return ClearTile_Station(tile, DC_AUTO); // get error message
129  } else {
130  StationID wp = GetStationIndex(tile);
131  if (*waypoint == INVALID_STATION) {
132  *waypoint = wp;
133  } else if (*waypoint != wp) {
134  return_cmd_error(STR_ERROR_WAYPOINT_ADJOINS_MORE_THAN_ONE_EXISTING);
135  }
136  }
137  }
138 
139  if (GetAxisForNewWaypoint(tile) != axis) return_cmd_error(STR_ERROR_NO_SUITABLE_RAILROAD_TRACK);
140 
141  Owner owner = GetTileOwner(tile);
142  CommandCost ret = CheckOwnership(owner);
143  if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile);
144  if (ret.Failed()) return ret;
145 
146  Slope tileh = GetTileSlope(tile);
147  if (tileh != SLOPE_FLAT &&
148  (!_settings_game.construction.build_on_slopes || IsSteepSlope(tileh) || !(tileh & (0x3 << axis)) || !(tileh & ~(0x3 << axis)))) {
149  return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
150  }
151 
152  if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
153 
154  return CommandCost();
155 }
156 
157 extern void GetStationLayout(byte *layout, int numtracks, int plat_len, const StationSpec *statspec);
158 extern CommandCost FindJoiningWaypoint(StationID existing_station, StationID station_to_join, bool adjacent, TileArea ta, Waypoint **wp);
159 extern CommandCost CanExpandRailStation(const BaseStation *st, TileArea &new_ta, Axis axis);
160 
178 CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
179 {
180  /* Unpack parameters */
181  Axis axis = Extract<Axis, 6, 1>(p1);
182  byte width = GB(p1, 8, 8);
183  byte height = GB(p1, 16, 8);
184  bool adjacent = HasBit(p1, 24);
185 
186  StationClassID spec_class = Extract<StationClassID, 0, 8>(p2);
187  byte spec_index = GB(p2, 8, 8);
188  StationID station_to_join = GB(p2, 16, 16);
189 
190  /* Check if the given station class is valid */
191  if (spec_class != STAT_CLASS_WAYP) return CMD_ERROR;
192  if (spec_index >= StationClass::Get(spec_class)->GetSpecCount()) return CMD_ERROR;
193 
194  /* The number of parts to build */
195  byte count = axis == AXIS_X ? height : width;
196 
197  if ((axis == AXIS_X ? width : height) != 1) return CMD_ERROR;
198  if (count == 0 || count > _settings_game.station.station_spread) return CMD_ERROR;
199 
200  bool reuse = (station_to_join != NEW_STATION);
201  if (!reuse) station_to_join = INVALID_STATION;
202  bool distant_join = (station_to_join != INVALID_STATION);
203 
204  if (distant_join && (!_settings_game.station.distant_join_stations || !Waypoint::IsValidID(station_to_join))) return CMD_ERROR;
205 
206  /* Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) */
207  StationID est = INVALID_STATION;
208 
209  /* Check whether the tiles we're building on are valid rail or not. */
211  for (int i = 0; i < count; i++) {
212  TileIndex tile = start_tile + i * offset;
213  CommandCost ret = IsValidTileForWaypoint(tile, axis, &est);
214  if (ret.Failed()) return ret;
215  }
216 
217  Waypoint *wp = nullptr;
218  TileArea new_location(start_tile, width, height);
219  CommandCost ret = FindJoiningWaypoint(est, station_to_join, adjacent, new_location, &wp);
220  if (ret.Failed()) return ret;
221 
222  /* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */
223  TileIndex center_tile = start_tile + (count / 2) * offset;
224  if (wp == nullptr && reuse) wp = FindDeletedWaypointCloseTo(center_tile, STR_SV_STNAME_WAYPOINT, _current_company);
225 
226  if (wp != nullptr) {
227  /* Reuse an existing waypoint. */
228  if (wp->owner != _current_company) return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_WAYPOINT);
229 
230  /* check if we want to expand an already existing waypoint? */
231  if (wp->train_station.tile != INVALID_TILE) {
232  CommandCost ret = CanExpandRailStation(wp, new_location, axis);
233  if (ret.Failed()) return ret;
234  }
235 
236  CommandCost ret = wp->rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TEST);
237  if (ret.Failed()) return ret;
238  } else {
239  /* allocate and initialize new waypoint */
240  if (!Waypoint::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING);
241  }
242 
243  if (flags & DC_EXEC) {
244  bool need_sign_update = false;
245  if (wp == nullptr) {
246  wp = new Waypoint(start_tile);
247  need_sign_update = true;
248  } else if (!wp->IsInUse()) {
249  /* Move existing (recently deleted) waypoint to the new location */
250  _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeWaypoint(wp->index));
251  wp->xy = start_tile;
252  need_sign_update = true;
253  }
254  wp->owner = GetTileOwner(start_tile);
255 
256  wp->rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TRY);
257 
258  wp->delete_ctr = 0;
259  wp->facilities |= FACIL_TRAIN;
260  wp->build_date = _date;
261  wp->string_id = STR_SV_STNAME_WAYPOINT;
262  wp->train_station = new_location;
263 
264  if (wp->town == nullptr) MakeDefaultName(wp);
265 
266  wp->UpdateVirtCoord();
267  if (need_sign_update) _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeWaypoint(wp->index));
268 
269  const StationSpec *spec = StationClass::Get(spec_class)->GetSpec(spec_index);
270  byte *layout_ptr = AllocaM(byte, count);
271  if (spec == nullptr) {
272  /* The layout must be 0 for the 'normal' waypoints by design. */
273  memset(layout_ptr, 0, count);
274  } else {
275  /* But for NewGRF waypoints we like to have their style. */
276  GetStationLayout(layout_ptr, count, 1, spec);
277  }
278  byte map_spec_index = AllocateSpecToStation(spec, wp, true);
279 
280  Company *c = Company::Get(wp->owner);
281  for (int i = 0; i < count; i++) {
282  TileIndex tile = start_tile + i * offset;
283  byte old_specindex = HasStationTileRail(tile) ? GetCustomStationSpecIndex(tile) : 0;
284  if (!HasStationTileRail(tile)) c->infrastructure.station++;
285  bool reserved = IsTileType(tile, MP_RAILWAY) ?
287  HasStationReservation(tile);
288  MakeRailWaypoint(tile, wp->owner, wp->index, axis, layout_ptr[i], GetRailType(tile));
289  SetCustomStationSpecIndex(tile, map_spec_index);
290  SetRailStationReservation(tile, reserved);
291  MarkTileDirtyByTile(tile);
292 
293  DeallocateSpecFromStation(wp, old_specindex);
295  }
297  }
298 
299  return CommandCost(EXPENSES_CONSTRUCTION, count * _price[PR_BUILD_WAYPOINT_RAIL]);
300 }
301 
311 CommandCost CmdBuildBuoy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
312 {
313  if (tile == 0 || !HasTileWaterGround(tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
314  if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
315 
316  if (!IsTileFlat(tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
317 
318  /* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */
319  Waypoint *wp = FindDeletedWaypointCloseTo(tile, STR_SV_STNAME_BUOY, OWNER_NONE);
320  if (wp == nullptr && !Waypoint::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING);
321 
322  CommandCost cost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_WAYPOINT_BUOY]);
323  if (!IsWaterTile(tile)) {
324  CommandCost ret = DoCommand(tile, 0, 0, flags | DC_AUTO, CMD_LANDSCAPE_CLEAR);
325  if (ret.Failed()) return ret;
326  cost.AddCost(ret);
327  }
328 
329  if (flags & DC_EXEC) {
330  if (wp == nullptr) {
331  wp = new Waypoint(tile);
332  } else {
333  /* Move existing (recently deleted) buoy to the new location */
334  _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeWaypoint(wp->index));
335  wp->xy = tile;
337  }
338  wp->rect.BeforeAddTile(tile, StationRect::ADD_TRY);
339 
340  wp->string_id = STR_SV_STNAME_BUOY;
341 
342  wp->facilities |= FACIL_DOCK;
343  wp->owner = OWNER_NONE;
344 
345  wp->build_date = _date;
346 
347  if (wp->town == nullptr) MakeDefaultName(wp);
348 
349  MakeBuoy(tile, wp->index, GetWaterClass(tile));
350  CheckForDockingTile(tile);
351  MarkTileDirtyByTile(tile);
352 
353  wp->UpdateVirtCoord();
354  _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeWaypoint(wp->index));
356  }
357 
358  return cost;
359 }
360 
369 {
370  /* XXX: strange stuff, allow clearing as invalid company when clearing landscape */
372 
373  Waypoint *wp = Waypoint::GetByTile(tile);
374 
375  if (HasStationInUse(wp->index, false, _current_company)) return_cmd_error(STR_ERROR_BUOY_IS_IN_USE);
376  /* remove the buoy if there is a ship on tile when company goes bankrupt... */
377  if (!(flags & DC_BANKRUPT)) {
379  if (ret.Failed()) return ret;
380  }
381 
382  if (flags & DC_EXEC) {
383  wp->facilities &= ~FACIL_DOCK;
384 
386 
387  /* We have to set the water tile's state to the same state as before the
388  * buoy was placed. Otherwise one could plant a buoy on a canal edge,
389  * remove it and flood the land (if the canal edge is at level 0) */
390  MakeWaterKeepingClass(tile, GetTileOwner(tile));
391 
392  wp->rect.AfterRemoveTile(wp, tile);
393 
394  wp->UpdateVirtCoord();
395  wp->delete_ctr = 0;
396  }
397 
398  return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_WAYPOINT_BUOY]);
399 }
400 
406 static bool IsUniqueWaypointName(const char *name)
407 {
408  const Waypoint *wp;
409 
410  FOR_ALL_WAYPOINTS(wp) {
411  if (wp->name != nullptr && strcmp(wp->name, name) == 0) return false;
412  }
413 
414  return true;
415 }
416 
426 CommandCost CmdRenameWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
427 {
428  Waypoint *wp = Waypoint::GetIfValid(p1);
429  if (wp == nullptr) return CMD_ERROR;
430 
431  if (wp->owner != OWNER_NONE) {
432  CommandCost ret = CheckOwnership(wp->owner);
433  if (ret.Failed()) return ret;
434  }
435 
436  bool reset = StrEmpty(text);
437 
438  if (!reset) {
440  if (!IsUniqueWaypointName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
441  }
442 
443  if (flags & DC_EXEC) {
444  free(wp->name);
445  wp->name = reset ? nullptr : stredup(text);
446 
447  wp->UpdateVirtCoord();
448  }
449  return CommandCost();
450 }
Functions related to OTTD&#39;s strings.
Owner
Enum for all companies/owners.
Definition: company_type.h:20
don&#39;t allow building on structures
Definition: command_type.h:347
StationFacility facilities
The facilities that this station has.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:81
Definition of stuff that is very close to a company, like the company struct itself.
static void SetCustomStationSpecIndex(TileIndex t, byte specindex)
Set the custom station spec for this tile.
Definition: station_map.h:483
void UpdateVirtCoord() override
Update the virtual coords needed to draw the waypoint sign.
Waypoint class.
void DeallocateSpecFromStation(BaseStation *st, byte specindex)
Deallocate a StationSpec from a Station.
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
Definition: vehicle.cpp:539
int32 TileIndexDiff
An offset value between to tiles.
Definition: map_func.h:156
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:246
Functions related to dates.
static WaterClass GetWaterClass(TileIndex t)
Get the water class at a tile.
Definition: water_map.h:108
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:25
bool distant_join_stations
allow to join non-adjacent stations
Station specification.
bool IsInUse() const
Check whether the base station currently is in use; in use means that it is not scheduled for deletio...
X-axis track.
Definition: track_type.h:42
Functions related to vehicles.
static bool HasTileWaterGround(TileIndex t)
Checks whether the tile has water at the ground.
Definition: water_map.h:346
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:207
TileArea train_station
Tile area the train &#39;station&#39; part covers.
byte station_spread
amount a station may spread
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
static bool IsUniqueWaypointName(const char *name)
Check whether the name is unique amongst the waypoints.
demolish a tile
Definition: command_type.h:182
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
static bool IsSteepSlope(Slope s)
Checks if a slope is steep.
Definition: slope_func.h:38
Helper functions to extract data from command parameters.
static bool IsRailWaypointTile(TileIndex t)
Is this tile a station tile and a rail waypoint?
Definition: station_map.h:125
Representation of a waypoint.
Definition: waypoint_base.h:18
static void SetRailStationReservation(TileIndex t, bool b)
Set the reservation state of the rail station.
Definition: station_map.h:407
A railway.
Definition: tile_type.h:44
static Track AxisToTrack(Axis a)
Convert an Axis to the corresponding Track AXIS_X -> TRACK_X AXIS_Y -> TRACK_Y Uses the fact that the...
Definition: track_func.h:76
static void MakeBuoy(TileIndex t, StationID sid, WaterClass wc)
Make the given tile a buoy tile.
Definition: station_map.h:639
Construction costs.
Definition: economy_type.h:151
uint32 station
Count of company owned station tiles.
Definition: company_base.h:36
#define AllocaM(T, num_elements)
alloca() has to be called in the parent function, so define AllocaM() as a macro
Definition: alloc_func.hpp:134
Common return value for all commands.
Definition: command_type.h:25
void UpdatePosition(int center, int top, StringID str, StringID str_small=STR_NULL)
Update the position of the viewport sign.
Definition: viewport.cpp:1444
Town * town
The town this station is associated with.
bool IsTileFlat(TileIndex tile, int *h)
Check if a given tile is flat.
Definition: tile_map.cpp:102
a flat tile
Definition: slope_type.h:51
void MoveSign(TileIndex new_xy) override
Move the waypoint main coordinate somewhere else.
StationSettings station
settings related to station management
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:15
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Definition: command_type.h:64
static uint GetCustomStationSpecIndex(TileIndex t)
Get the custom station spec for this tile.
Definition: station_map.h:495
void YapfNotifyTrackLayoutChange(TileIndex tile, Track track)
Use this function to notify YAPF that track layout (or signal configuration) has change.
Definition: yapf_rail.cpp:644
byte delete_ctr
Delete counter. If greater than 0 then it is decremented until it reaches 0; the waypoint is then is ...
company bankrupts, skip money check, skip vehicle on tile check in some cases
Definition: command_type.h:352
Functions related to (drawing on) viewports.
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
Definition: tile_map.cpp:61
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
Definition: bridge_map.h:47
ViewportSign sign
NOSAVE: Dimensions of sign.
Functions related to low-level strings.
The tile has no ownership.
Definition: company_type.h:27
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:343
Waypoint view; Window numbers:
Definition: window_type.h:352
Axis GetAxisForNewWaypoint(TileIndex tile)
Get the axis for a new waypoint.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:152
void MakeDefaultName(T *obj)
Set the default name for a depot/waypoint.
Definition: town.h:241
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
Definition: command.cpp:443
The y axis.
static void MakeRailWaypoint(TileIndex t, Owner o, StationID sid, Axis a, byte section, RailType rt)
Make the given tile a rail waypoint tile.
Definition: station_map.h:575
static bool HasStationReservation(TileIndex t)
Get the reservation state of the rail station.
Definition: station_map.h:395
void DirtyCompanyInfrastructureWindows(CompanyID company)
Redraw all windows with company infrastructure counts.
static Waypoint * FindDeletedWaypointCloseTo(TileIndex tile, StringID str, CompanyID cid)
Find a deleted waypoint close to a tile.
Entry point for OpenTTD to YAPF&#39;s cache.
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:180
CommandCost FindJoiningWaypoint(StationID existing_station, StationID station_to_join, bool adjacent, TileArea ta, Waypoint **wp)
Find a nearby waypoint that joins this waypoint.
DoCommandFlag
List of flags for a command.
Definition: command_type.h:344
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:152
static bool HasStationTileRail(TileIndex t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint...
Definition: station_map.h:148
int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec)
Allocate a StationSpec to a Station.
Definition of base types and functions in a cross-platform compatible way.
static TrackBits GetRailReservationTrackBits(TileIndex t)
Returns the reserved track bits of the tile.
Definition: rail_map.h:196
A number of safeguards to prevent using unsafe methods.
Base of waypoints.
static Axis GetRailStationAxis(TileIndex t)
Get the rail direction of a rail station.
Definition: station_map.h:339
bool HasStationInUse(StationID station, bool include_company, CompanyID company)
Tests whether the company&#39;s vehicles have this station in orders.
Represents the covered area of e.g.
Definition: tilearea_type.h:18
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:138
GUI Functions related to companies.
Map accessor functions for bridges.
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Definition: viewport.cpp:1940
static bool IsWaterTile(TileIndex t)
Is it a water tile with plain water?
Definition: water_map.h:186
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
bool build_on_slopes
allow building on slopes
bool Failed() const
Did this command fail?
Definition: command_type.h:161
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:35
static RailTileType GetRailTileType(TileIndex t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
Definition: rail_map.h:38
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
static TrackBits GetTrackBits(TileIndex tile)
Gets the track bits of the given tile.
Definition: rail_map.h:138
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
Definition: company_base.h:133
The X axis.
execute the given command
Definition: command_type.h:346
Functions related to companies.
Station with a dock.
Definition: station_type.h:58
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
Definition: station_map.h:30
Header file for NewGRF stations.
StationClassID
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:59
size_t Utf8StringLength(const char *s)
Get the length of an UTF-8 encoded string in number of characters and thus not the number of bytes th...
Definition: string.cpp:312
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Definition: map.cpp:159
CommandCost CmdBuildBuoy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build a buoy.
void Remove(const T &element)
Remove a single element from the tree, if it exists.
Definition: kdtree.hpp:420
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:217
CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Convert existing rail to waypoint.
TileIndex xy
Base tile of the station.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Slope
Enumeration for the slope-type.
Definition: slope_type.h:50
A tile of a station.
Definition: tile_type.h:48
Normal rail tile without signals.
Definition: rail_map.h:26
static Waypoint * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
CommandCost ClearTile_Station(TileIndex tile, DoCommandFlag flags)
Clear a single tile of a station.
static NewGRFClass * Get(Tid cls_id)
Get a particular class.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() ...
Definition: pool_type.hpp:216
Functions related to OTTD&#39;s landscape.
static bool IsRailWaypoint(TileIndex t)
Is this station tile a rail waypoint?
Definition: station_map.h:115
void GetStationLayout(byte *layout, int numtracks, int plat_len, const StationSpec *statspec)
Create the station layout for the given number of tracks and platform length.
Functions related to commands.
static bool IsValidID(size_t index)
Tests whether given index is a valid index for station of this type.
Coordinates of a point in 2D.
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
Owner owner
The owner of this station.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:235
static Axis OtherAxis(Axis a)
Select the other axis as provided.
ConstructionSettings construction
construction of things in-game
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:19
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:131
CommandCost RemoveBuoy(TileIndex tile, DoCommandFlag flags)
Remove a buoy.
static const uint MAX_LENGTH_STATION_NAME_CHARS
The maximum length of a station name in characters including &#39;\0&#39;.
Definition: station_type.h:89
CommandCost CanExpandRailStation(const BaseStation *st, TileArea &new_ta, Axis axis)
Check whether we can expand the rail part of the given station.
CommandCost CmdRenameWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Rename a waypoint.
Waypoint(TileIndex tile=INVALID_TILE)
Create a waypoint at the given tile.
Definition: waypoint_base.h:25
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:85
Base of the town class.
Window functions not directly related to making/drawing windows.
Station with train station.
Definition: station_type.h:54
Functions related to water (management)
static DiagDirection AxisToDiagDir(Axis a)
Converts an Axis to a DiagDirection.
Flag for an invalid Axis.
Date _date
Current date in days (day counter)
Definition: date.cpp:28
char * name
Custom name.
void Insert(const T &element)
Insert a single element in the tree.
Definition: kdtree.hpp:401
static Point RemapCoords2(int x, int y)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap...
Definition: landscape.h:100
StringID string_id
Default name (town area) of station.
Y-axis track.
Definition: track_type.h:43
void CheckForDockingTile(TileIndex t)
Mark the supplied tile as a docking tile if it is suitable for docking.
Definition: water_cmd.cpp:184
static CommandCost IsValidTileForWaypoint(TileIndex tile, Axis axis, StationID *waypoint)
Check whether the given tile is suitable for a waypoint.
Base class for all station-ish types.
Axis
Allow incrementing of DiagDirDiff variables.
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
Definition: rail_map.h:117
#define FOR_ALL_WAYPOINTS(var)
Iterate over all waypoints.
Definition: waypoint_base.h:76
Date build_date
Date of construction.
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Definition: window.cpp:3300
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:201
static Waypoint * GetIfValid(size_t index)
Returns station if the index is a valid index for this station type.