OpenTTD Source  13.2.1
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"
18 #include "strings_func.h"
19 #include "viewport_func.h"
20 #include "viewport_kdtree.h"
21 #include "window_func.h"
22 #include "date_func.h"
23 #include "vehicle_func.h"
24 #include "string_func.h"
25 #include "company_func.h"
26 #include "newgrf_station.h"
27 #include "company_base.h"
28 #include "water.h"
29 #include "company_gui.h"
30 #include "waypoint_cmd.h"
31 #include "landscape_cmd.h"
32 
33 #include "table/strings.h"
34 
35 #include "safeguards.h"
36 
41 {
42  Point pt = RemapCoords2(TileX(this->xy) * TILE_SIZE, TileY(this->xy) * TILE_SIZE);
43  if (this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeWaypoint(this->index));
44 
45  SetDParam(0, this->index);
46  this->sign.UpdatePosition(pt.x, pt.y - 32 * ZOOM_LVL_BASE, STR_VIEWPORT_WAYPOINT);
47 
48  _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeWaypoint(this->index));
49 
50  /* Recenter viewport */
52 }
53 
59 {
60  if (this->xy == new_xy) return;
61 
62  this->BaseStation::MoveSign(new_xy);
63 }
64 
73 {
74  Waypoint *best = nullptr;
75  uint thres = 8;
76 
77  for (Waypoint *wp : Waypoint::Iterate()) {
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, uint numtracks, uint 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 
175 CommandCost CmdBuildRailWaypoint(DoCommandFlag flags, TileIndex start_tile, Axis axis, byte width, byte height, StationClassID spec_class, byte spec_index, StationID station_to_join, bool adjacent)
176 {
177  if (!IsValidAxis(axis)) return CMD_ERROR;
178  /* Check if the given station class is valid */
179  if (spec_class != STAT_CLASS_WAYP) return CMD_ERROR;
180  if (spec_index >= StationClass::Get(spec_class)->GetSpecCount()) return CMD_ERROR;
181 
182  /* The number of parts to build */
183  byte count = axis == AXIS_X ? height : width;
184 
185  if ((axis == AXIS_X ? width : height) != 1) return CMD_ERROR;
186  if (count == 0 || count > _settings_game.station.station_spread) return CMD_ERROR;
187 
188  bool reuse = (station_to_join != NEW_STATION);
189  if (!reuse) station_to_join = INVALID_STATION;
190  bool distant_join = (station_to_join != INVALID_STATION);
191 
192  if (distant_join && (!_settings_game.station.distant_join_stations || !Waypoint::IsValidID(station_to_join))) return CMD_ERROR;
193 
194  /* Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) */
195  StationID est = INVALID_STATION;
196 
197  /* Check whether the tiles we're building on are valid rail or not. */
199  for (int i = 0; i < count; i++) {
200  TileIndex tile = start_tile + i * offset;
201  CommandCost ret = IsValidTileForWaypoint(tile, axis, &est);
202  if (ret.Failed()) return ret;
203  }
204 
205  Waypoint *wp = nullptr;
206  TileArea new_location(start_tile, width, height);
207  CommandCost ret = FindJoiningWaypoint(est, station_to_join, adjacent, new_location, &wp);
208  if (ret.Failed()) return ret;
209 
210  /* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */
211  TileIndex center_tile = start_tile + (count / 2) * offset;
212  if (wp == nullptr && reuse) wp = FindDeletedWaypointCloseTo(center_tile, STR_SV_STNAME_WAYPOINT, _current_company);
213 
214  if (wp != nullptr) {
215  /* Reuse an existing waypoint. */
216  if (wp->owner != _current_company) return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_WAYPOINT);
217 
218  /* check if we want to expand an already existing waypoint? */
219  if (wp->train_station.tile != INVALID_TILE) {
220  CommandCost ret = CanExpandRailStation(wp, new_location, axis);
221  if (ret.Failed()) return ret;
222  }
223 
224  CommandCost ret = wp->rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TEST);
225  if (ret.Failed()) return ret;
226  } else {
227  /* allocate and initialize new waypoint */
228  if (!Waypoint::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING);
229  }
230 
231  if (flags & DC_EXEC) {
232  if (wp == nullptr) {
233  wp = new Waypoint(start_tile);
234  } else if (!wp->IsInUse()) {
235  /* Move existing (recently deleted) waypoint to the new location */
236  wp->xy = start_tile;
237  }
238  wp->owner = GetTileOwner(start_tile);
239 
240  wp->rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TRY);
241 
242  wp->delete_ctr = 0;
243  wp->facilities |= FACIL_TRAIN;
244  wp->build_date = _date;
245  wp->string_id = STR_SV_STNAME_WAYPOINT;
246  wp->train_station = new_location;
247 
248  if (wp->town == nullptr) MakeDefaultName(wp);
249 
250  wp->UpdateVirtCoord();
251 
252  const StationSpec *spec = StationClass::Get(spec_class)->GetSpec(spec_index);
253  byte *layout_ptr = AllocaM(byte, count);
254  if (spec == nullptr) {
255  /* The layout must be 0 for the 'normal' waypoints by design. */
256  memset(layout_ptr, 0, count);
257  } else {
258  /* But for NewGRF waypoints we like to have their style. */
259  GetStationLayout(layout_ptr, count, 1, spec);
260  }
261  byte map_spec_index = AllocateSpecToStation(spec, wp, true);
262 
263  Company *c = Company::Get(wp->owner);
264  for (int i = 0; i < count; i++) {
265  TileIndex tile = start_tile + i * offset;
266  byte old_specindex = HasStationTileRail(tile) ? GetCustomStationSpecIndex(tile) : 0;
267  if (!HasStationTileRail(tile)) c->infrastructure.station++;
268  bool reserved = IsTileType(tile, MP_RAILWAY) ?
270  HasStationReservation(tile);
271  MakeRailWaypoint(tile, wp->owner, wp->index, axis, layout_ptr[i], GetRailType(tile));
272  SetCustomStationSpecIndex(tile, map_spec_index);
273  SetRailStationReservation(tile, reserved);
274  MarkTileDirtyByTile(tile);
275 
276  DeallocateSpecFromStation(wp, old_specindex);
278  }
280  }
281 
282  return CommandCost(EXPENSES_CONSTRUCTION, count * _price[PR_BUILD_WAYPOINT_RAIL]);
283 }
284 
292 {
293  if (tile == 0 || !HasTileWaterGround(tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
294  if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
295 
296  if (!IsTileFlat(tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
297 
298  /* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */
299  Waypoint *wp = FindDeletedWaypointCloseTo(tile, STR_SV_STNAME_BUOY, OWNER_NONE);
300  if (wp == nullptr && !Waypoint::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING);
301 
302  CommandCost cost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_WAYPOINT_BUOY]);
303  if (!IsWaterTile(tile)) {
305  if (ret.Failed()) return ret;
306  cost.AddCost(ret);
307  }
308 
309  if (flags & DC_EXEC) {
310  if (wp == nullptr) {
311  wp = new Waypoint(tile);
312  } else {
313  /* Move existing (recently deleted) buoy to the new location */
314  wp->xy = tile;
316  }
317  wp->rect.BeforeAddTile(tile, StationRect::ADD_TRY);
318 
319  wp->string_id = STR_SV_STNAME_BUOY;
320 
321  wp->facilities |= FACIL_DOCK;
322  wp->owner = OWNER_NONE;
323 
324  wp->build_date = _date;
325 
326  if (wp->town == nullptr) MakeDefaultName(wp);
327 
328  MakeBuoy(tile, wp->index, GetWaterClass(tile));
329  CheckForDockingTile(tile);
330  MarkTileDirtyByTile(tile);
331 
332  wp->UpdateVirtCoord();
334  }
335 
336  return cost;
337 }
338 
347 {
348  /* XXX: strange stuff, allow clearing as invalid company when clearing landscape */
350 
351  Waypoint *wp = Waypoint::GetByTile(tile);
352 
353  if (HasStationInUse(wp->index, false, _current_company)) return_cmd_error(STR_ERROR_BUOY_IS_IN_USE);
354  /* remove the buoy if there is a ship on tile when company goes bankrupt... */
355  if (!(flags & DC_BANKRUPT)) {
357  if (ret.Failed()) return ret;
358  }
359 
360  if (flags & DC_EXEC) {
361  wp->facilities &= ~FACIL_DOCK;
362 
364 
365  /* We have to set the water tile's state to the same state as before the
366  * buoy was placed. Otherwise one could plant a buoy on a canal edge,
367  * remove it and flood the land (if the canal edge is at level 0) */
368  MakeWaterKeepingClass(tile, GetTileOwner(tile));
369 
370  wp->rect.AfterRemoveTile(wp, tile);
371 
372  wp->UpdateVirtCoord();
373  wp->delete_ctr = 0;
374  }
375 
376  return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_WAYPOINT_BUOY]);
377 }
378 
384 static bool IsUniqueWaypointName(const std::string &name)
385 {
386  for (const Waypoint *wp : Waypoint::Iterate()) {
387  if (!wp->name.empty() && wp->name == name) return false;
388  }
389 
390  return true;
391 }
392 
400 CommandCost CmdRenameWaypoint(DoCommandFlag flags, StationID waypoint_id, const std::string &text)
401 {
402  Waypoint *wp = Waypoint::GetIfValid(waypoint_id);
403  if (wp == nullptr) return CMD_ERROR;
404 
405  if (wp->owner != OWNER_NONE) {
406  CommandCost ret = CheckOwnership(wp->owner);
407  if (ret.Failed()) return ret;
408  }
409 
410  bool reset = text.empty();
411 
412  if (!reset) {
414  if (!IsUniqueWaypointName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
415  }
416 
417  if (flags & DC_EXEC) {
418  if (reset) {
419  wp->name.clear();
420  } else {
421  wp->name = text;
422  }
423 
424  wp->UpdateVirtCoord();
425  }
426  return CommandCost();
427 }
AllocateSpecToStation
int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec)
Allocate a StationSpec to a Station.
Definition: newgrf_station.cpp:680
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:4254
IsValidTileForWaypoint
static CommandCost IsValidTileForWaypoint(TileIndex tile, Axis axis, StationID *waypoint)
Check whether the given tile is suitable for a waypoint.
Definition: waypoint_cmd.cpp:121
BaseStation::facilities
StationFacility facilities
The facilities that this station has.
Definition: base_station_base.h:63
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:3254
Waypoint::MoveSign
void MoveSign(TileIndex new_xy) override
Move the waypoint main coordinate somewhere else.
Definition: waypoint_cmd.cpp:58
AXIS_Y
@ AXIS_Y
The y axis.
Definition: direction_type.h:127
newgrf_station.h
CmdBuildRailWaypoint
CommandCost CmdBuildRailWaypoint(DoCommandFlag flags, TileIndex start_tile, Axis axis, byte width, byte height, StationClassID spec_class, byte spec_index, StationID station_to_join, bool adjacent)
Convert existing rail to waypoint.
Definition: waypoint_cmd.cpp:175
IsValidAxis
static bool IsValidAxis(Axis d)
Checks if an integer value is a valid Axis.
Definition: direction_func.h:43
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
TileOffsByDiagDir
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:341
GameSettings::station
StationSettings station
settings related to station management
Definition: settings_type.h:598
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
IsRailWaypointTile
static bool IsRailWaypointTile(TileIndex t)
Is this tile a station tile and a rail waypoint?
Definition: station_map.h:123
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:28
CanExpandRailStation
CommandCost CanExpandRailStation(const BaseStation *st, TileArea &new_ta, Axis axis)
Check whether we can expand the rail part of the given station.
Definition: station_cmd.cpp:1077
company_base.h
BaseStation::town
Town * town
The town this station is associated with.
Definition: base_station_base.h:61
SetCustomStationSpecIndex
static void SetCustomStationSpecIndex(TileIndex t, byte specindex)
Set the custom station spec for this tile.
Definition: station_map.h:481
GetAxisForNewWaypoint
Axis GetAxisForNewWaypoint(TileIndex tile)
Get the axis for a new waypoint.
Definition: waypoint_cmd.cpp:98
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition: direction_type.h:125
company_gui.h
OtherAxis
static Axis OtherAxis(Axis a)
Select the other axis as provided.
Definition: direction_func.h:197
waypoint_cmd.h
SetRailStationReservation
static void SetRailStationReservation(TileIndex t, bool b)
Set the reservation state of the rail station.
Definition: station_map.h:405
Pool::PoolItem<&_station_pool >::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:235
FindDeletedWaypointCloseTo
static Waypoint * FindDeletedWaypointCloseTo(TileIndex tile, StringID str, CompanyID cid)
Find a deleted waypoint close to a tile.
Definition: waypoint_cmd.cpp:72
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
CmdBuildBuoy
CommandCost CmdBuildBuoy(DoCommandFlag flags, TileIndex tile)
Build a buoy.
Definition: waypoint_cmd.cpp:291
INVALID_TILE
static constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:108
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:1217
CompanyInfrastructure::station
uint32 station
Count of company owned station tiles.
Definition: company_base.h:36
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
Waypoint
Representation of a waypoint.
Definition: waypoint_base.h:16
MP_RAILWAY
@ MP_RAILWAY
A railway.
Definition: tile_type.h:49
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:15
GetTrackBits
static TrackBits GetTrackBits(TileIndex tile)
Gets the track bits of the given tile.
Definition: rail_map.h:136
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:209
town.h
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:215
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:1122
Company::infrastructure
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
Definition: company_base.h:130
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:357
DeallocateSpecFromStation
void DeallocateSpecFromStation(BaseStation *st, byte specindex)
Deallocate a StationSpec from a Station.
Definition: newgrf_station.cpp:722
BaseStation::owner
Owner owner
The owner of this station.
Definition: base_station_base.h:62
SetDParam
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:196
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:355
EnsureNoVehicleOnGround
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
Definition: vehicle.cpp:539
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:151
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:205
GetRailReservationTrackBits
static TrackBits GetRailReservationTrackBits(TileIndex t)
Returns the reserved track bits of the tile.
Definition: rail_map.h:194
Kdtree::Remove
void Remove(const T &element)
Remove a single element from the tree, if it exists.
Definition: kdtree.hpp:419
BaseStation::string_id
StringID string_id
Default name (town area) of station.
Definition: base_station_base.h:58
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:269
MakeRailWaypoint
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:573
MakeBuoy
static void MakeBuoy(TileIndex t, StationID sid, WaterClass wc)
Make the given tile a buoy tile.
Definition: station_map.h:637
Waypoint::UpdateVirtCoord
void UpdateVirtCoord() override
Update the virtual coords needed to draw the waypoint sign.
Definition: waypoint_cmd.cpp:40
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:435
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:157
CheckForDockingTile
void CheckForDockingTile(TileIndex t)
Mark the supplied tile as a docking tile if it is suitable for docking.
Definition: water_cmd.cpp:183
landscape_cmd.h
CheckOwnership
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
Definition: company_cmd.cpp:316
return_cmd_error
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:38
EXPENSES_CONSTRUCTION
@ EXPENSES_CONSTRUCTION
Construction costs.
Definition: economy_type.h:158
BaseStation::sign
TrackedViewportSign sign
NOSAVE: Dimensions of sign.
Definition: base_station_base.h:54
STAT_CLASS_WAYP
@ STAT_CLASS_WAYP
Waypoint class.
Definition: newgrf_station.h:86
IsSteepSlope
static bool IsSteepSlope(Slope s)
Checks if a slope is steep.
Definition: slope_func.h:36
CommandCost
Common return value for all commands.
Definition: command_type.h:24
GetCustomStationSpecIndex
static uint GetCustomStationSpecIndex(TileIndex t)
Get the custom station spec for this tile.
Definition: station_map.h:493
HasTileWaterGround
static bool HasTileWaterGround(TileIndex t)
Checks whether the tile has water at the ground.
Definition: water_map.h:355
_date
Date _date
Current date in days (day counter)
Definition: date.cpp:28
AxisToTrack
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:65
BaseStation::train_station
TileArea train_station
Tile area the train 'station' part covers.
Definition: base_station_base.h:74
DirtyCompanyInfrastructureWindows
void DirtyCompanyInfrastructureWindows(CompanyID company)
Redraw all windows with company infrastructure counts.
Definition: company_gui.cpp:2774
BaseStation::rect
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
Definition: base_station_base.h:75
GetRailTileType
static RailTileType GetRailTileType(TileIndex t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
Definition: rail_map.h:36
TileIndexDiff
int32 TileIndexDiff
An offset value between two tiles.
Definition: map_func.h:154
Kdtree::Insert
void Insert(const T &element)
Insert a single element in the tree.
Definition: kdtree.hpp:400
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:160
OrthogonalTileArea
Represents the covered area of e.g.
Definition: tilearea_type.h:18
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:54
TRACK_BIT_X
@ TRACK_BIT_X
X-axis track.
Definition: track_type.h:40
HasStationTileRail
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:146
safeguards.h
WC_WAYPOINT_VIEW
@ WC_WAYPOINT_VIEW
Waypoint view; Window numbers:
Definition: window_type.h:350
GetTileSlope
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
Definition: tile_map.cpp:59
HasStationReservation
static bool HasStationReservation(TileIndex t)
Get the reservation state of the rail station.
Definition: station_map.h:393
BaseStation::name
std::string name
Custom name.
Definition: base_station_base.h:57
RemoveBuoy
CommandCost RemoveBuoy(TileIndex tile, DoCommandFlag flags)
Remove a buoy.
Definition: waypoint_cmd.cpp:346
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
FACIL_DOCK
@ FACIL_DOCK
Station with a dock.
Definition: station_type.h:57
StationSettings::station_spread
byte station_spread
amount a station may spread
Definition: settings_type.h:563
date_func.h
CommandCost::AddCost
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Definition: command_type.h:63
stdafx.h
landscape.h
DC_BANKRUPT
@ DC_BANKRUPT
company bankrupts, skip money check, skip vehicle on tile check in some cases
Definition: command_type.h:363
viewport_func.h
AxisToDiagDir
static DiagDirection AxisToDiagDir(Axis a)
Converts an Axis to a DiagDirection.
Definition: direction_func.h:232
bridge_map.h
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
GetTileOwner
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:178
yapf_cache.h
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:88
string_func.h
MakeDefaultName
void MakeDefaultName(T *obj)
Set the default name for a depot/waypoint.
Definition: town.h:245
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
vehicle_func.h
strings_func.h
StationSpec
Station specification.
Definition: newgrf_station.h:113
GetWaterClass
static WaterClass GetWaterClass(TileIndex t)
Get the water class at a tile.
Definition: water_map.h:117
IsRailWaypoint
static bool IsRailWaypoint(TileIndex t)
Is this station tile a rail waypoint?
Definition: station_map.h:113
INVALID_AXIS
@ INVALID_AXIS
Flag for an invalid Axis.
Definition: direction_type.h:129
FACIL_TRAIN
@ FACIL_TRAIN
Station with train station.
Definition: station_type.h:53
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
GetRailStationAxis
static Axis GetRailStationAxis(TileIndex t)
Get the rail direction of a rail station.
Definition: station_map.h:337
IsWaterTile
static bool IsWaterTile(TileIndex t)
Is it a water tile with plain water?
Definition: water_map.h:195
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
ConstructionSettings::build_on_slopes
bool build_on_slopes
allow building on slopes
Definition: settings_type.h:343
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:1998
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
GetRailType
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
Definition: rail_map.h:115
IsUniqueWaypointName
static bool IsUniqueWaypointName(const std::string &name)
Check whether the name is unique amongst the waypoints.
Definition: waypoint_cmd.cpp:384
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:237
GetStationIndex
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
Definition: station_map.h:28
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:307
DC_AUTO
@ DC_AUTO
don't allow building on structures
Definition: command_type.h:358
BaseStation::xy
TileIndex xy
Base tile of the station.
Definition: base_station_base.h:53
BaseStation
Base class for all station-ish types.
Definition: base_station_base.h:52
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:2445
company_func.h
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:55
AXIS_X
@ AXIS_X
The X axis.
Definition: direction_type.h:126
StationSettings::distant_join_stations
bool distant_join_stations
allow to join non-adjacent stations
Definition: settings_type.h:561
CmdRenameWaypoint
CommandCost CmdRenameWaypoint(DoCommandFlag flags, StationID waypoint_id, const std::string &text)
Rename a waypoint.
Definition: waypoint_cmd.cpp:400
CommandHelper
Definition: command_func.h:94
window_func.h
NewGRFClass::Get
static NewGRFClass * Get(Tid cls_id)
Get a particular class.
Definition: newgrf_class_func.h:103
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:227
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:165
TRACK_BIT_Y
@ TRACK_BIT_Y
Y-axis track.
Definition: track_type.h:41
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:588
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:326
SLOPE_FLAT
@ SLOPE_FLAT
a flat tile
Definition: slope_type.h:49
RemapCoords2
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:98
Company
Definition: company_base.h:117
BaseStation::build_date
Date build_date
Date of construction.
Definition: base_station_base.h:67
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
IsBridgeAbove
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
Definition: bridge_map.h:45
AllocaM
#define AllocaM(T, num_elements)
alloca() has to be called in the parent function, so define AllocaM() as a macro
Definition: alloc_func.hpp:132