OpenTTD Source  14.0-beta3
waypoint_cmd.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * 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.
4  * 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.
5  * 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/>.
6  */
7 
10 #include "stdafx.h"
11 
12 #include "command_func.h"
13 #include "landscape.h"
14 #include "bridge_map.h"
15 #include "town.h"
16 #include "waypoint_base.h"
19 #include "strings_func.h"
20 #include "viewport_func.h"
21 #include "viewport_kdtree.h"
22 #include "window_func.h"
24 #include "vehicle_func.h"
25 #include "string_func.h"
26 #include "company_func.h"
27 #include "newgrf_station.h"
28 #include "company_base.h"
29 #include "water.h"
30 #include "company_gui.h"
31 #include "waypoint_cmd.h"
32 #include "landscape_cmd.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  if (this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeWaypoint(this->index));
45 
46  SetDParam(0, this->index);
47  this->sign.UpdatePosition(pt.x, pt.y - 32 * ZOOM_LVL_BASE, STR_VIEWPORT_WAYPOINT);
48 
49  _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeWaypoint(this->index));
50 
51  /* Recenter viewport */
53 }
54 
60 {
61  if (this->xy == new_xy) return;
62 
63  this->BaseStation::MoveSign(new_xy);
64 }
65 
74 {
75  Waypoint *best = nullptr;
76  uint thres = 8;
77 
78  for (Waypoint *wp : Waypoint::Iterate()) {
79  if (!wp->IsInUse() && wp->string_id == str && wp->owner == cid) {
80  uint cur_dist = DistanceManhattan(tile, wp->xy);
81 
82  if (cur_dist < thres) {
83  thres = cur_dist;
84  best = wp;
85  }
86  }
87  }
88 
89  return best;
90 }
91 
100 {
101  /* The axis for rail waypoints is easy. */
102  if (IsRailWaypointTile(tile)) return GetRailStationAxis(tile);
103 
104  /* Non-plain rail type, no valid axis for waypoints. */
105  if (!IsTileType(tile, MP_RAILWAY) || GetRailTileType(tile) != RAIL_TILE_NORMAL) return INVALID_AXIS;
106 
107  switch (GetTrackBits(tile)) {
108  case TRACK_BIT_X: return AXIS_X;
109  case TRACK_BIT_Y: return AXIS_Y;
110  default: return INVALID_AXIS;
111  }
112 }
113 
115 
122 static CommandCost IsValidTileForWaypoint(TileIndex tile, Axis axis, StationID *waypoint)
123 {
124  /* if waypoint is set, then we have special handling to allow building on top of already existing waypoints.
125  * so waypoint points to INVALID_STATION if we can build on any waypoint.
126  * Or it points to a waypoint if we're only allowed to build on exactly that waypoint. */
127  if (waypoint != nullptr && IsTileType(tile, MP_STATION)) {
128  if (!IsRailWaypoint(tile)) {
129  return ClearTile_Station(tile, DC_AUTO); // get error message
130  } else {
131  StationID wp = GetStationIndex(tile);
132  if (*waypoint == INVALID_STATION) {
133  *waypoint = wp;
134  } else if (*waypoint != wp) {
135  return_cmd_error(STR_ERROR_WAYPOINT_ADJOINS_MORE_THAN_ONE_EXISTING);
136  }
137  }
138  }
139 
140  if (GetAxisForNewWaypoint(tile) != axis) return_cmd_error(STR_ERROR_NO_SUITABLE_RAILROAD_TRACK);
141 
142  Owner owner = GetTileOwner(tile);
143  CommandCost ret = CheckOwnership(owner);
144  if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile);
145  if (ret.Failed()) return ret;
146 
147  Slope tileh = GetTileSlope(tile);
148  if (tileh != SLOPE_FLAT &&
149  (!_settings_game.construction.build_on_slopes || IsSteepSlope(tileh) || !(tileh & (0x3 << axis)) || !(tileh & ~(0x3 << axis)))) {
150  return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
151  }
152 
153  if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
154 
155  return CommandCost();
156 }
157 
158 extern void GetStationLayout(byte *layout, uint numtracks, uint plat_len, const StationSpec *statspec);
159 extern CommandCost FindJoiningWaypoint(StationID existing_station, StationID station_to_join, bool adjacent, TileArea ta, Waypoint **wp);
160 extern CommandCost CanExpandRailStation(const BaseStation *st, TileArea &new_ta);
161 
176 CommandCost CmdBuildRailWaypoint(DoCommandFlag flags, TileIndex start_tile, Axis axis, byte width, byte height, StationClassID spec_class, uint16_t spec_index, StationID station_to_join, bool adjacent)
177 {
178  if (!IsValidAxis(axis)) return CMD_ERROR;
179  /* Check if the given station class is valid */
180  if (spec_class != STAT_CLASS_WAYP) return CMD_ERROR;
181  if (spec_index >= StationClass::Get(spec_class)->GetSpecCount()) return CMD_ERROR;
182 
183  /* The number of parts to build */
184  byte count = axis == AXIS_X ? height : width;
185 
186  if ((axis == AXIS_X ? width : height) != 1) return CMD_ERROR;
187  if (count == 0 || count > _settings_game.station.station_spread) return CMD_ERROR;
188 
189  bool reuse = (station_to_join != NEW_STATION);
190  if (!reuse) station_to_join = INVALID_STATION;
191  bool distant_join = (station_to_join != INVALID_STATION);
192 
193  if (distant_join && (!_settings_game.station.distant_join_stations || !Waypoint::IsValidID(station_to_join))) return CMD_ERROR;
194 
195  TileArea new_location(start_tile, width, height);
196 
197  /* only AddCost for non-existing waypoints */
199  for (TileIndex cur_tile : new_location) {
200  if (!IsRailWaypointTile(cur_tile)) cost.AddCost(_price[PR_BUILD_WAYPOINT_RAIL]);
201  }
202 
203  /* Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) */
204  StationID est = INVALID_STATION;
205 
206  /* Check whether the tiles we're building on are valid rail or not. */
208  for (int i = 0; i < count; i++) {
209  TileIndex tile = start_tile + i * offset;
210  CommandCost ret = IsValidTileForWaypoint(tile, axis, &est);
211  if (ret.Failed()) return ret;
212  }
213 
214  Waypoint *wp = nullptr;
215  CommandCost ret = FindJoiningWaypoint(est, station_to_join, adjacent, new_location, &wp);
216  if (ret.Failed()) return ret;
217 
218  /* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */
219  TileIndex center_tile = start_tile + (count / 2) * offset;
220  if (wp == nullptr && reuse) wp = FindDeletedWaypointCloseTo(center_tile, STR_SV_STNAME_WAYPOINT, _current_company);
221 
222  if (wp != nullptr) {
223  /* Reuse an existing waypoint. */
224  if (wp->owner != _current_company) return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_WAYPOINT);
225 
226  /* check if we want to expand an already existing waypoint? */
227  if (wp->train_station.tile != INVALID_TILE) {
228  ret = CanExpandRailStation(wp, new_location);
229  if (ret.Failed()) return ret;
230  }
231 
232  ret = wp->rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TEST);
233  if (ret.Failed()) return ret;
234  } else {
235  /* allocate and initialize new waypoint */
236  if (!Waypoint::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING);
237  }
238 
239  if (flags & DC_EXEC) {
240  if (wp == nullptr) {
241  wp = new Waypoint(start_tile);
242  } else if (!wp->IsInUse()) {
243  /* Move existing (recently deleted) waypoint to the new location */
244  wp->xy = start_tile;
245  }
246  wp->owner = GetTileOwner(start_tile);
247 
248  wp->rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TRY);
249 
250  wp->delete_ctr = 0;
251  wp->facilities |= FACIL_TRAIN;
253  wp->string_id = STR_SV_STNAME_WAYPOINT;
254  wp->train_station = new_location;
255 
256  if (wp->town == nullptr) MakeDefaultName(wp);
257 
258  wp->UpdateVirtCoord();
259 
260  const StationSpec *spec = StationClass::Get(spec_class)->GetSpec(spec_index);
261  byte *layout_ptr = new byte[count];
262  if (spec == nullptr) {
263  /* The layout must be 0 for the 'normal' waypoints by design. */
264  memset(layout_ptr, 0, count);
265  } else {
266  /* But for NewGRF waypoints we like to have their style. */
267  GetStationLayout(layout_ptr, count, 1, spec);
268  }
269  byte map_spec_index = AllocateSpecToStation(spec, wp, true);
270 
271  Company *c = Company::Get(wp->owner);
272  for (int i = 0; i < count; i++) {
273  TileIndex tile = start_tile + i * offset;
274  byte old_specindex = HasStationTileRail(tile) ? GetCustomStationSpecIndex(tile) : 0;
275  if (!HasStationTileRail(tile)) c->infrastructure.station++;
276  bool reserved = IsTileType(tile, MP_RAILWAY) ?
278  HasStationReservation(tile);
279  MakeRailWaypoint(tile, wp->owner, wp->index, axis, layout_ptr[i], GetRailType(tile));
280  SetCustomStationSpecIndex(tile, map_spec_index);
281 
282  /* Should be the same as layout but axis component could be wrong... */
283  StationGfx gfx = GetStationGfx(tile);
284  bool blocked = spec != nullptr && HasBit(spec->blocked, gfx);
285  /* Default stations do not draw pylons under roofs (gfx >= 4) */
286  bool pylons = spec != nullptr ? HasBit(spec->pylons, gfx) : gfx < 4;
287  bool wires = spec == nullptr || !HasBit(spec->wires, gfx);
288 
289  SetStationTileBlocked(tile, blocked);
290  SetStationTileHavePylons(tile, pylons);
291  SetStationTileHaveWires(tile, wires);
292 
293  SetRailStationReservation(tile, reserved);
294  MarkTileDirtyByTile(tile);
295 
296  DeallocateSpecFromStation(wp, old_specindex);
298  }
300  delete[] layout_ptr;
301  }
302 
303  return cost;
304 }
305 
313 {
314  if (tile == 0 || !HasTileWaterGround(tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
315  if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
316 
317  if (!IsTileFlat(tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
318 
319  /* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */
320  Waypoint *wp = FindDeletedWaypointCloseTo(tile, STR_SV_STNAME_BUOY, OWNER_NONE);
321  if (wp == nullptr && !Waypoint::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING);
322 
323  CommandCost cost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_WAYPOINT_BUOY]);
324  if (!IsWaterTile(tile)) {
326  if (ret.Failed()) return ret;
327  cost.AddCost(ret);
328  }
329 
330  if (flags & DC_EXEC) {
331  if (wp == nullptr) {
332  wp = new Waypoint(tile);
333  } else {
334  /* Move existing (recently deleted) buoy to the new location */
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 
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();
355  }
356 
357  return cost;
358 }
359 
368 {
369  /* XXX: strange stuff, allow clearing as invalid company when clearing landscape */
371 
372  Waypoint *wp = Waypoint::GetByTile(tile);
373 
374  if (HasStationInUse(wp->index, false, _current_company)) return_cmd_error(STR_ERROR_BUOY_IS_IN_USE);
375  /* remove the buoy if there is a ship on tile when company goes bankrupt... */
376  if (!(flags & DC_BANKRUPT)) {
378  if (ret.Failed()) return ret;
379  }
380 
381  if (flags & DC_EXEC) {
382  wp->facilities &= ~FACIL_DOCK;
383 
385 
386  /* We have to set the water tile's state to the same state as before the
387  * buoy was placed. Otherwise one could plant a buoy on a canal edge,
388  * remove it and flood the land (if the canal edge is at level 0) */
389  MakeWaterKeepingClass(tile, GetTileOwner(tile));
390 
391  wp->rect.AfterRemoveTile(wp, tile);
392 
393  wp->UpdateVirtCoord();
394  wp->delete_ctr = 0;
395  }
396 
397  return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_WAYPOINT_BUOY]);
398 }
399 
405 static bool IsUniqueWaypointName(const std::string &name)
406 {
407  for (const Waypoint *wp : Waypoint::Iterate()) {
408  if (!wp->name.empty() && wp->name == name) return false;
409  }
410 
411  return true;
412 }
413 
421 CommandCost CmdRenameWaypoint(DoCommandFlag flags, StationID waypoint_id, const std::string &text)
422 {
423  Waypoint *wp = Waypoint::GetIfValid(waypoint_id);
424  if (wp == nullptr) return CMD_ERROR;
425 
426  if (wp->owner != OWNER_NONE) {
427  CommandCost ret = CheckOwnership(wp->owner);
428  if (ret.Failed()) return ret;
429  }
430 
431  bool reset = text.empty();
432 
433  if (!reset) {
435  if (!IsUniqueWaypointName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
436  }
437 
438  if (flags & DC_EXEC) {
439  if (reset) {
440  wp->name.clear();
441  } else {
442  wp->name = text;
443  }
444 
445  wp->UpdateVirtCoord();
446  }
447  return CommandCost();
448 }
AllocateSpecToStation
int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec)
Allocate a StationSpec to a Station.
Definition: newgrf_station.cpp:689
TileY
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:437
IsTileFlat
bool IsTileFlat(TileIndex tile, int *h)
Check if a given tile is flat.
Definition: tile_map.cpp:100
ClearTile_Station
CommandCost ClearTile_Station(TileIndex tile, DoCommandFlag flags)
Clear a single tile of a station.
Definition: station_cmd.cpp:4463
IsValidTileForWaypoint
static CommandCost IsValidTileForWaypoint(TileIndex tile, Axis axis, StationID *waypoint)
Check whether the given tile is suitable for a waypoint.
Definition: waypoint_cmd.cpp:122
BaseStation::facilities
StationFacility facilities
The facilities that this station has.
Definition: base_station_base.h:75
CmdBuildRailWaypoint
CommandCost CmdBuildRailWaypoint(DoCommandFlag flags, TileIndex start_tile, Axis axis, byte width, byte height, StationClassID spec_class, uint16_t spec_index, StationID station_to_join, bool adjacent)
Convert existing rail to waypoint.
Definition: waypoint_cmd.cpp:176
InvalidateWindowData
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:3200
Waypoint::MoveSign
void MoveSign(TileIndex new_xy) override
Move the waypoint main coordinate somewhere else.
Definition: waypoint_cmd.cpp:59
AXIS_Y
@ AXIS_Y
The y axis.
Definition: direction_type.h:118
MakeRailWaypoint
void MakeRailWaypoint(Tile t, Owner o, StationID sid, Axis a, byte section, RailType rt)
Make the given tile a rail waypoint tile.
Definition: station_map.h:665
StationGfx
byte StationGfx
Copy from station_map.h.
Definition: newgrf_airport.h:22
newgrf_station.h
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:335
MakeBuoy
void MakeBuoy(Tile t, StationID sid, WaterClass wc)
Make the given tile a buoy tile.
Definition: station_map.h:729
GameSettings::station
StationSettings station
settings related to station management
Definition: settings_type.h:630
water.h
command_func.h
YapfNotifyTrackLayoutChange
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
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:28
GetWaterClass
WaterClass GetWaterClass(Tile t)
Get the water class at a tile.
Definition: water_map.h:115
company_base.h
BaseStation::town
Town * town
The town this station is associated with.
Definition: base_station_base.h:73
timer_game_calendar.h
GetAxisForNewWaypoint
Axis GetAxisForNewWaypoint(TileIndex tile)
Get the axis for a new waypoint.
Definition: waypoint_cmd.cpp:99
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition: direction_type.h:116
company_gui.h
waypoint_cmd.h
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
Pool::PoolItem<&_station_pool >::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:234
FindDeletedWaypointCloseTo
static Waypoint * FindDeletedWaypointCloseTo(TileIndex tile, StringID str, CompanyID cid)
Find a deleted waypoint close to a tile.
Definition: waypoint_cmd.cpp:73
CmdBuildBuoy
CommandCost CmdBuildBuoy(DoCommandFlag flags, TileIndex tile)
Build a buoy.
Definition: waypoint_cmd.cpp:312
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:95
FindJoiningWaypoint
CommandCost FindJoiningWaypoint(StationID existing_station, StationID station_to_join, bool adjacent, TileArea ta, Waypoint **wp)
Find a nearby waypoint that joins this waypoint.
Definition: station_cmd.cpp:1221
SetStationTileHaveWires
void SetStationTileHaveWires(Tile t, bool b)
Set the catenary wires state of the rail station.
Definition: station_map.h:374
Waypoint
Representation of a waypoint.
Definition: waypoint_base.h:16
MP_RAILWAY
@ MP_RAILWAY
A railway.
Definition: tile_type.h:49
SetStationTileHavePylons
void SetStationTileHavePylons(Tile t, bool b)
Set the catenary pylon state of the rail station.
Definition: station_map.h:398
IsSteepSlope
static constexpr bool IsSteepSlope(Slope s)
Checks if a slope is steep.
Definition: slope_func.h:36
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:15
SpecializedStation< Waypoint, true >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index is a valid index for station of this type.
Definition: base_station_base.h:250
town.h
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
GetStationLayout
void GetStationLayout(byte *layout, uint numtracks, uint plat_len, const StationSpec *statspec)
Create the station layout for the given number of tracks and platform length.
Definition: station_cmd.cpp:1126
Company::infrastructure
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
Definition: company_base.h:129
IsWaterTile
bool IsWaterTile(Tile t)
Is it a water tile with plain water?
Definition: water_map.h:193
GetRailType
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
Definition: rail_map.h:115
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:371
DeallocateSpecFromStation
void DeallocateSpecFromStation(BaseStation *st, byte specindex)
Deallocate a StationSpec from a Station.
Definition: newgrf_station.cpp:731
BaseStation::owner
Owner owner
The owner of this station.
Definition: base_station_base.h:74
IsRailWaypointTile
bool IsRailWaypointTile(Tile t)
Is this tile a station tile and a rail waypoint?
Definition: station_map.h:123
GetRailStationAxis
Axis GetRailStationAxis(Tile t)
Get the rail direction of a rail station.
Definition: station_map.h:410
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:369
EnsureNoVehicleOnGround
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
Definition: vehicle.cpp:546
CompanyInfrastructure::station
uint32_t station
Count of company owned station tiles.
Definition: company_base.h:37
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:162
Kdtree::Remove
void Remove(const T &element)
Remove a single element from the tree, if it exists.
Definition: kdtree.hpp:417
BaseStation::string_id
StringID string_id
Default name (town area) of station.
Definition: base_station_base.h:70
SpecializedStation< Waypoint, true >::Iterate
static Pool::IterateWrapper< Waypoint > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
Definition: base_station_base.h:310
Waypoint::UpdateVirtCoord
void UpdateVirtCoord() override
Update the virtual coords needed to draw the waypoint sign.
Definition: waypoint_cmd.cpp:41
Utf8StringLength
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:378
Slope
Slope
Enumeration for the slope-type.
Definition: slope_type.h:48
DistanceManhattan
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Definition: map.cpp:159
CheckForDockingTile
void CheckForDockingTile(TileIndex t)
Mark the supplied tile as a docking tile if it is suitable for docking.
Definition: water_cmd.cpp:184
landscape_cmd.h
CheckOwnership
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
Definition: company_cmd.cpp:360
GetStationGfx
StationGfx GetStationGfx(Tile t)
Get the station graphics of this tile.
Definition: station_map.h:68
return_cmd_error
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:38
SetCustomStationSpecIndex
void SetCustomStationSpecIndex(Tile t, byte specindex)
Set the custom station spec for this tile.
Definition: station_map.h:537
EXPENSES_CONSTRUCTION
@ EXPENSES_CONSTRUCTION
Construction costs.
Definition: economy_type.h:173
BaseStation::sign
TrackedViewportSign sign
NOSAVE: Dimensions of sign.
Definition: base_station_base.h:66
STAT_CLASS_WAYP
@ STAT_CLASS_WAYP
Waypoint class.
Definition: newgrf_station.h:86
CommandCost
Common return value for all commands.
Definition: command_type.h:23
BaseStation::train_station
TileArea train_station
Tile area the train 'station' part covers.
Definition: base_station_base.h:89
DirtyCompanyInfrastructureWindows
void DirtyCompanyInfrastructureWindows(CompanyID company)
Redraw all windows with company infrastructure counts.
Definition: company_gui.cpp:2651
BaseStation::rect
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
Definition: base_station_base.h:90
StationSpec::pylons
byte pylons
Bitmask of base tiles (0 - 7) which should contain elrail pylons.
Definition: newgrf_station.h:161
Kdtree::Insert
void Insert(const T &element)
Insert a single element in the tree.
Definition: kdtree.hpp:398
GetRailReservationTrackBits
TrackBits GetRailReservationTrackBits(Tile t)
Returns the reserved track bits of the tile.
Definition: rail_map.h:194
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:171
OrthogonalTileArea
Represents the covered area of e.g.
Definition: tilearea_type.h:18
AxisToDiagDir
DiagDirection AxisToDiagDir(Axis a)
Converts an Axis to a DiagDirection.
Definition: direction_func.h:232
CanExpandRailStation
CommandCost CanExpandRailStation(const BaseStation *st, TileArea &new_ta)
Check whether we can expand the rail part of the given station.
Definition: station_cmd.cpp:1081
HasStationTileRail
bool HasStationTileRail(Tile t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
Definition: station_map.h:146
water_regions.h
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:55
TRACK_BIT_X
@ TRACK_BIT_X
X-axis track.
Definition: track_type.h:37
safeguards.h
WC_WAYPOINT_VIEW
@ WC_WAYPOINT_VIEW
Waypoint view; Window numbers:
Definition: window_type.h:357
GetTileSlope
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
Definition: tile_map.cpp:59
BaseStation::name
std::string name
Custom name.
Definition: base_station_base.h:69
GetTileOwner
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition: tile_map.h:178
RemoveBuoy
CommandCost RemoveBuoy(TileIndex tile, DoCommandFlag flags)
Remove a buoy.
Definition: waypoint_cmd.cpp:367
TileIndexDiff
int32_t TileIndexDiff
An offset value between two tiles.
Definition: map_func.h:376
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
GetRailTileType
static debug_inline RailTileType GetRailTileType(Tile t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
Definition: rail_map.h:36
FACIL_DOCK
@ FACIL_DOCK
Station with a dock.
Definition: station_type.h:56
StationSettings::station_spread
byte station_spread
amount a station may spread
Definition: settings_type.h:595
SetRailStationReservation
void SetRailStationReservation(Tile t, bool b)
Set the reservation state of the rail station.
Definition: station_map.h:478
CommandCost::AddCost
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Definition: command_type.h:63
IsValidAxis
bool IsValidAxis(Axis d)
Checks if an integer value is a valid Axis.
Definition: direction_func.h:43
stdafx.h
landscape.h
SetStationTileBlocked
void SetStationTileBlocked(Tile t, bool b)
Set the blocked state of the rail station.
Definition: station_map.h:350
DC_BANKRUPT
@ DC_BANKRUPT
company bankrupts, skip money check, skip vehicle on tile check in some cases
Definition: command_type.h:377
viewport_func.h
bridge_map.h
yapf_cache.h
GetTrackBits
TrackBits GetTrackBits(Tile tile)
Gets the track bits of the given tile.
Definition: rail_map.h:136
TileOffsByDiagDir
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:563
MAX_LENGTH_STATION_NAME_CHARS
static const uint MAX_LENGTH_STATION_NAME_CHARS
The maximum length of a station name in characters including '\0'.
Definition: station_type.h:87
string_func.h
MakeDefaultName
void MakeDefaultName(T *obj)
Set the default name for a depot/waypoint.
Definition: town.h:249
RemapCoords2
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:98
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:50
vehicle_func.h
strings_func.h
StationSpec
Station specification.
Definition: newgrf_station.h:112
INVALID_AXIS
@ INVALID_AXIS
Flag for an invalid Axis.
Definition: direction_type.h:120
FACIL_TRAIN
@ FACIL_TRAIN
Station with train station.
Definition: station_type.h:52
TrackedViewportSign::UpdatePosition
void UpdatePosition(int center, int top, StringID str, StringID str_small=STR_NULL)
Update the position of the viewport sign.
Definition: viewport_type.h:56
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
GetStationIndex
StationID GetStationIndex(Tile t)
Get StationID from a tile.
Definition: station_map.h:28
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
HasStationReservation
bool HasStationReservation(Tile t)
Get the reservation state of the rail station.
Definition: station_map.h:466
ConstructionSettings::build_on_slopes
bool build_on_slopes
allow building on slopes
Definition: settings_type.h:371
MarkTileDirtyByTile
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:2051
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
IsUniqueWaypointName
static bool IsUniqueWaypointName(const std::string &name)
Check whether the name is unique amongst the waypoints.
Definition: waypoint_cmd.cpp:405
MP_STATION
@ MP_STATION
A tile of a station.
Definition: tile_type.h:53
SpecializedStation< Waypoint, true >::GetByTile
static Waypoint * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
Definition: base_station_base.h:278
waypoint_base.h
StationClassID
StationClassID
Definition: newgrf_station.h:83
TrackedViewportSign::kdtree_valid
bool kdtree_valid
Are the sign data valid for use with the _viewport_sign_kdtree?
Definition: viewport_type.h:50
RAIL_TILE_NORMAL
@ RAIL_TILE_NORMAL
Normal rail tile without signals.
Definition: rail_map.h:24
Pool::PoolItem<&_station_pool >::CanAllocateItem
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
Definition: pool_type.hpp:305
IsBridgeAbove
bool IsBridgeAbove(Tile t)
checks if a bridge is set above the ground of this tile
Definition: bridge_map.h:45
DC_AUTO
@ DC_AUTO
don't allow building on structures
Definition: command_type.h:372
BaseStation::xy
TileIndex xy
Base tile of the station.
Definition: base_station_base.h:65
BaseStation
Base class for all station-ish types.
Definition: base_station_base.h:64
HasStationInUse
bool HasStationInUse(StationID station, bool include_company, CompanyID company)
Tests whether the company's vehicles have this station in orders.
Definition: station_cmd.cpp:2619
company_func.h
AxisToTrack
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:66
BaseStation::delete_ctr
byte delete_ctr
Delete counter. If greater than 0 then it is decremented until it reaches 0; the waypoint is then is ...
Definition: base_station_base.h:67
AXIS_X
@ AXIS_X
The X axis.
Definition: direction_type.h:117
StationSettings::distant_join_stations
bool distant_join_stations
allow to join non-adjacent stations
Definition: settings_type.h:593
CmdRenameWaypoint
CommandCost CmdRenameWaypoint(DoCommandFlag flags, StationID waypoint_id, const std::string &text)
Rename a waypoint.
Definition: waypoint_cmd.cpp:421
CommandHelper
Definition: command_func.h:93
window_func.h
NewGRFClass::Get
static NewGRFClass * Get(Tid cls_id)
Get a particular class.
Definition: newgrf_class_func.h:98
SpecializedStation< Waypoint, true >::GetIfValid
static Waypoint * GetIfValid(size_t index)
Returns station if the index is a valid index for this station type.
Definition: base_station_base.h:268
BaseStation::IsInUse
bool IsInUse() const
Check whether the base station currently is in use; in use means that it is not scheduled for deletio...
Definition: base_station_base.h:182
TRACK_BIT_Y
@ TRACK_BIT_Y
Y-axis track.
Definition: track_type.h:38
TimerGameCalendar::date
static Date date
Current date in days (day counter).
Definition: timer_game_calendar.h:34
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:620
IsTileType
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
IsRailWaypoint
bool IsRailWaypoint(Tile t)
Is this station tile a rail waypoint?
Definition: station_map.h:113
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:324
TileX
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:427
SLOPE_FLAT
@ SLOPE_FLAT
a flat tile
Definition: slope_type.h:49
Company
Definition: company_base.h:116
OtherAxis
Axis OtherAxis(Axis a)
Select the other axis as provided.
Definition: direction_func.h:197
HasTileWaterGround
bool HasTileWaterGround(Tile t)
Checks whether the tile has water at the ground.
Definition: water_map.h:353
StationSpec::wires
byte wires
Bitmask of base tiles (0 - 7) which should contain elrail wires.
Definition: newgrf_station.h:162
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
StationSpec::blocked
byte blocked
Bitmask of base tiles (0 - 7) which are blocked to trains.
Definition: newgrf_station.h:163
BaseStation::build_date
TimerGameCalendar::Date build_date
Date of construction.
Definition: base_station_base.h:80
GetCustomStationSpecIndex
uint GetCustomStationSpecIndex(Tile t)
Get the custom station spec for this tile.
Definition: station_map.h:549
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103