OpenTTD

waypoint_cmd.cpp
Go to the documentation of this file.
1 /* $Id: waypoint_cmd.cpp 27785 2017-03-12 15:32:40Z peter1138 $ */
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"
20 #include "pathfinder/yapf/yapf_cache.h"
21 #include "strings_func.h"
22 #include "viewport_func.h"
23 #include "window_func.h"
24 #include "date_func.h"
25 #include "vehicle_func.h"
26 #include "string_func.h"
27 #include "company_func.h"
28 #include "newgrf_station.h"
29 #include "company_base.h"
30 #include "water.h"
31 #include "company_gui.h"
32
33 #include "table/strings.h"
34
35 #include "safeguards.h"
36
40 void Waypoint::UpdateVirtCoord()
41 {
42 Point pt = RemapCoords2(TileX(this->xy) * TILE_SIZE, TileY(this->xy) * TILE_SIZE);
43 SetDParam(0, this->index);
44 this->sign.UpdatePosition(pt.x, pt.y - 32 * ZOOM_LVL_BASE, STR_VIEWPORT_WAYPOINT);
45 /* Recenter viewport */
46 InvalidateWindowData(WC_WAYPOINT_VIEW, this->index);
47 }
48
56 static Waypoint *FindDeletedWaypointCloseTo(TileIndex tile, StringID str, CompanyID cid)
57 {
58 Waypoint *wp, *best = NULL;
59 uint thres = 8;
60
61 FOR_ALL_WAYPOINTS(wp) {
62 if (!wp->IsInUse() && wp->string_id == str && wp->owner == cid) {
63 uint cur_dist = DistanceManhattan(tile, wp->xy);
64
65 if (cur_dist < thres) {
66 thres = cur_dist;
67 best = wp;
68 }
69 }
70 }
71
72 return best;
73 }
74
82 Axis GetAxisForNewWaypoint(TileIndex tile)
83 {
84 /* The axis for rail waypoints is easy. */
85 if (IsRailWaypointTile(tile)) return GetRailStationAxis(tile);
86
87 /* Non-plain rail type, no valid axis for waypoints. */
88 if (!IsTileType(tile, MP_RAILWAY) || GetRailTileType(tile) != RAIL_TILE_NORMAL) return INVALID_AXIS;
89
90 switch (GetTrackBits(tile)) {
91 case TRACK_BIT_X: return AXIS_X;
92 case TRACK_BIT_Y: return AXIS_Y;
93 default: return INVALID_AXIS;
94 }
95 }
96
97 extern CommandCost ClearTile_Station(TileIndex tile, DoCommandFlag flags);
98
105 static CommandCost IsValidTileForWaypoint(TileIndex tile, Axis axis, StationID *waypoint)
106 {
107 /* if waypoint is set, then we have special handling to allow building on top of already existing waypoints.
108 * so waypoint points to INVALID_STATION if we can build on any waypoint.
109 * Or it points to a waypoint if we're only allowed to build on exactly that waypoint. */
110 if (waypoint != NULL && IsTileType(tile, MP_STATION)) {
111 if (!IsRailWaypoint(tile)) {
112 return ClearTile_Station(tile, DC_AUTO); // get error message
113 } else {
114 StationID wp = GetStationIndex(tile);
115 if (*waypoint == INVALID_STATION) {
116 *waypoint = wp;
117 } else if (*waypoint != wp) {
118 return_cmd_error(STR_ERROR_WAYPOINT_ADJOINS_MORE_THAN_ONE_EXISTING);
119 }
120 }
121 }
122
123 if (GetAxisForNewWaypoint(tile) != axis) return_cmd_error(STR_ERROR_NO_SUITABLE_RAILROAD_TRACK);
124
125 Owner owner = GetTileOwner(tile);
126 CommandCost ret = CheckOwnership(owner);
127 if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile);
128 if (ret.Failed()) return ret;
129
130 Slope tileh = GetTileSlope(tile);
131 if (tileh != SLOPE_FLAT &&
132 (!_settings_game.construction.build_on_slopes || IsSteepSlope(tileh) || !(tileh & (0x3 << axis)) || !(tileh & ~(0x3 << axis)))) {
133 return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
134 }
135
136 if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
137
138 return CommandCost();
139 }
140
141 extern void GetStationLayout(byte *layout, int numtracks, int plat_len, const StationSpec *statspec);
142 extern CommandCost FindJoiningWaypoint(StationID existing_station, StationID station_to_join, bool adjacent, TileArea ta, Waypoint **wp);
143 extern CommandCost CanExpandRailStation(const BaseStation *st, TileArea &new_ta, Axis axis);
144
161 CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
162 {
163 /* Unpack parameters */
164 Axis axis = Extract<Axis, 4, 1>(p1);
165 byte width = GB(p1, 8, 8);
166 byte height = GB(p1, 16, 8);
167 bool adjacent = HasBit(p1, 24);
168
169 StationClassID spec_class = Extract<StationClassID, 0, 8>(p2);
170 byte spec_index = GB(p2, 8, 8);
171 StationID station_to_join = GB(p2, 16, 16);
172
173 /* Check if the given station class is valid */
174 if (spec_class != STAT_CLASS_WAYP) return CMD_ERROR;
175 if (spec_index >= StationClass::Get(spec_class)->GetSpecCount()) return CMD_ERROR;
176
177 /* The number of parts to build */
178 byte count = axis == AXIS_X ? height : width;
179
180 if ((axis == AXIS_X ? width : height) != 1) return CMD_ERROR;
181 if (count == 0 || count > _settings_game.station.station_spread) return CMD_ERROR;
182
183 bool reuse = (station_to_join != NEW_STATION);
184 if (!reuse) station_to_join = INVALID_STATION;
185 bool distant_join = (station_to_join != INVALID_STATION);
186
187 if (distant_join && (!_settings_game.station.distant_join_stations || !Waypoint::IsValidID(station_to_join))) return CMD_ERROR;
188
189 /* Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) */
190 StationID est = INVALID_STATION;
191
192 /* Check whether the tiles we're building on are valid rail or not. */
193 TileIndexDiff offset = TileOffsByDiagDir(AxisToDiagDir(OtherAxis(axis)));
194 for (int i = 0; i < count; i++) {
195 TileIndex tile = start_tile + i * offset;
196 CommandCost ret = IsValidTileForWaypoint(tile, axis, &est);
197 if (ret.Failed()) return ret;
198 }
199
200 Waypoint *wp = NULL;
201 TileArea new_location(TileArea(start_tile, width, height));
202 CommandCost ret = FindJoiningWaypoint(est, station_to_join, adjacent, new_location, &wp);
203 if (ret.Failed()) return ret;
204
205 /* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */
206 TileIndex center_tile = start_tile + (count / 2) * offset;
207 if (wp == NULL && reuse) wp = FindDeletedWaypointCloseTo(center_tile, STR_SV_STNAME_WAYPOINT, _current_company);
208
209 if (wp != NULL) {
210 /* Reuse an existing waypoint. */
211 if (wp->owner != _current_company) return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_WAYPOINT);
212
213 /* check if we want to expand an already existing waypoint? */
214 if (wp->train_station.tile != INVALID_TILE) {
215 CommandCost ret = CanExpandRailStation(wp, new_location, axis);
216 if (ret.Failed()) return ret;
217 }
218
219 CommandCost ret = wp->rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TEST);
220 if (ret.Failed()) return ret;
221 } else {
222 /* allocate and initialize new waypoint */
223 if (!Waypoint::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING);
224 }
225
226 if (flags & DC_EXEC) {
227 if (wp == NULL) {
228 wp = new Waypoint(start_tile);
229 } else if (!wp->IsInUse()) {
230 /* Move existing (recently deleted) waypoint to the new location */
231 wp->xy = start_tile;
232 }
233 wp->owner = GetTileOwner(start_tile);
234
235 wp->rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TRY);
236
237 wp->delete_ctr = 0;
238 wp->facilities |= FACIL_TRAIN;
239 wp->build_date = _date;
240 wp->string_id = STR_SV_STNAME_WAYPOINT;
241 wp->train_station = new_location;
242
243 if (wp->town == NULL) MakeDefaultName(wp);
244
245 wp->UpdateVirtCoord();
246
247 const StationSpec *spec = StationClass::Get(spec_class)->GetSpec(spec_index);
248 byte *layout_ptr = AllocaM(byte, count);
249 if (spec == NULL) {
250 /* The layout must be 0 for the 'normal' waypoints by design. */
251 memset(layout_ptr, 0, count);
252 } else {
253 /* But for NewGRF waypoints we like to have their style. */
254 GetStationLayout(layout_ptr, count, 1, spec);
255 }
256 byte map_spec_index = AllocateSpecToStation(spec, wp, true);
257
258 Company *c = Company::Get(wp->owner);
259 for (int i = 0; i < count; i++) {
260 TileIndex tile = start_tile + i * offset;
261 byte old_specindex = HasStationTileRail(tile) ? GetCustomStationSpecIndex(tile) : 0;
262 if (!HasStationTileRail(tile)) c->infrastructure.station++;
263 bool reserved = IsTileType(tile, MP_RAILWAY) ?
264 HasBit(GetRailReservationTrackBits(tile), AxisToTrack(axis)) :
265 HasStationReservation(tile);
266 MakeRailWaypoint(tile, wp->owner, wp->index, axis, layout_ptr[i], GetRailType(tile));
267 SetCustomStationSpecIndex(tile, map_spec_index);
268 SetRailStationReservation(tile, reserved);
269 MarkTileDirtyByTile(tile);
270
271 DeallocateSpecFromStation(wp, old_specindex);
272 YapfNotifyTrackLayoutChange(tile, AxisToTrack(axis));
273 }
274 DirtyCompanyInfrastructureWindows(wp->owner);
275 }
276
277 return CommandCost(EXPENSES_CONSTRUCTION, count * _price[PR_BUILD_WAYPOINT_RAIL]);
278 }
279
289 CommandCost CmdBuildBuoy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
290 {
291 if (tile == 0 || !HasTileWaterGround(tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
292 if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
293
294 if (!IsTileFlat(tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
295
296 /* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */
297 Waypoint *wp = FindDeletedWaypointCloseTo(tile, STR_SV_STNAME_BUOY, OWNER_NONE);
298 if (wp == NULL && !Waypoint::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING);
299
300 CommandCost cost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_WAYPOINT_BUOY]);
301 if (!IsWaterTile(tile)) {
302 CommandCost ret = DoCommand(tile, 0, 0, flags | DC_AUTO, CMD_LANDSCAPE_CLEAR);
303 if (ret.Failed()) return ret;
304 cost.AddCost(ret);
305 }
306
307 if (flags & DC_EXEC) {
308 if (wp == NULL) {
309 wp = new Waypoint(tile);
310 } else {
311 /* Move existing (recently deleted) buoy to the new location */
312 wp->xy = tile;
313 InvalidateWindowData(WC_WAYPOINT_VIEW, wp->index);
314 }
315 wp->rect.BeforeAddTile(tile, StationRect::ADD_TRY);
316
317 wp->string_id = STR_SV_STNAME_BUOY;
318
319 wp->facilities |= FACIL_DOCK;
320 wp->owner = OWNER_NONE;
321
322 wp->build_date = _date;
323
324 if (wp->town == NULL) MakeDefaultName(wp);
325
326 MakeBuoy(tile, wp->index, GetWaterClass(tile));
327 MarkTileDirtyByTile(tile);
328
329 wp->UpdateVirtCoord();
330 InvalidateWindowData(WC_WAYPOINT_VIEW, wp->index);
331 }
332
333 return cost;
334 }
335
343 CommandCost RemoveBuoy(TileIndex tile, DoCommandFlag flags)
344 {
345 /* XXX: strange stuff, allow clearing as invalid company when clearing landscape */
346 if (!Company::IsValidID(_current_company) && !(flags & DC_BANKRUPT)) return_cmd_error(INVALID_STRING_ID);
347
348 Waypoint *wp = Waypoint::GetByTile(tile);
349
350 if (HasStationInUse(wp->index, false, _current_company)) return_cmd_error(STR_ERROR_BUOY_IS_IN_USE);
351 /* remove the buoy if there is a ship on tile when company goes bankrupt... */
352 if (!(flags & DC_BANKRUPT)) {
353 CommandCost ret = EnsureNoVehicleOnGround(tile);
354 if (ret.Failed()) return ret;
355 }
356
357 if (flags & DC_EXEC) {
358 wp->facilities &= ~FACIL_DOCK;
359
360 InvalidateWindowData(WC_WAYPOINT_VIEW, wp->index);
361
362 /* We have to set the water tile's state to the same state as before the
363 * buoy was placed. Otherwise one could plant a buoy on a canal edge,
364 * remove it and flood the land (if the canal edge is at level 0) */
365 MakeWaterKeepingClass(tile, GetTileOwner(tile));
366
367 wp->rect.AfterRemoveTile(wp, tile);
368
369 wp->UpdateVirtCoord();
370 wp->delete_ctr = 0;
371 }
372
373 return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_WAYPOINT_BUOY]);
374 }
375
381 static bool IsUniqueWaypointName(const char *name)
382 {
383 const Waypoint *wp;
384
385 FOR_ALL_WAYPOINTS(wp) {
386 if (wp->name != NULL && strcmp(wp->name, name) == 0) return false;
387 }
388
389 return true;
390 }
391
401 CommandCost CmdRenameWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
402 {
403 Waypoint *wp = Waypoint::GetIfValid(p1);
404 if (wp == NULL) return CMD_ERROR;
405
406 if (wp->owner != OWNER_NONE) {
407 CommandCost ret = CheckOwnership(wp->owner);
408 if (ret.Failed()) return ret;
409 }
410
411 bool reset = StrEmpty(text);
412
413 if (!reset) {
414 if (Utf8StringLength(text) >= MAX_LENGTH_STATION_NAME_CHARS) return CMD_ERROR;
415 if (!IsUniqueWaypointName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
416 }
417
418 if (flags & DC_EXEC) {
419 free(wp->name);
420 wp->name = reset ? NULL : stredup(text);
421
422 wp->UpdateVirtCoord();
423 }
424 return CommandCost();
425 }
strings_func.h
Functions related to OTTD&#39;s strings.
DC_AUTO
don&#39;t allow building on structures
Definition: command_type.h:343
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:77
company_base.h
Definition of stuff that is very close to a company, like the company struct itself.
SetCustomStationSpecIndex
static void SetCustomStationSpecIndex(TileIndex t, byte specindex)
Set the custom station spec for this tile.
Definition: station_map.h:482
DeallocateSpecFromStation
void DeallocateSpecFromStation(BaseStation *st, byte specindex)
Deallocate a StationSpec from a Station.
Definition: newgrf_station.cpp:716
EnsureNoVehicleOnGround
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
Definition: vehicle.cpp:538
TileIndexDiff
int32 TileIndexDiff
An offset value between to tiles.
Definition: map_func.h:156
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:246
date_func.h
Functions related to dates.
GetWaterClass
static WaterClass GetWaterClass(TileIndex t)
Get the water class at a tile.
Definition: water_map.h:106
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:25
StationSettings::distant_join_stations
bool distant_join_stations
allow to join non-adjacent stations
Definition: settings_type.h:518
StationSpec
Station specification.
Definition: newgrf_station.h:117
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:154
vehicle_func.h
Functions related to vehicles.
HasTileWaterGround
static bool HasTileWaterGround(TileIndex t)
Checks whether the tile has water at the ground.
Definition: water_map.h:344
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:207
BaseStation::train_station
TileArea train_station
Tile area the train &#39;station&#39; part covers.
Definition: base_station_base.h:76
StationSettings::station_spread
byte station_spread
amount a station may spread
Definition: settings_type.h:520
BaseStation::rect
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
Definition: base_station_base.h:77
IsUniqueWaypointName
static bool IsUniqueWaypointName(const char *name)
Check whether the name is unique amongst the waypoints.
Definition: waypoint_cmd.cpp:381
CMD_LANDSCAPE_CLEAR
demolish a tile
Definition: command_type.h:182
Pool::PoolItem<&_station_pool >::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
IsSteepSlope
static bool IsSteepSlope(Slope s)
Checks if a slope is steep.
Definition: slope_func.h:38
cmd_helper.h
Helper functions to extract data from command parameters.
IsRailWaypointTile
static bool IsRailWaypointTile(TileIndex t)
Is this tile a station tile and a rail waypoint?
Definition: station_map.h:124
Waypoint
Representation of a waypoint.
Definition: waypoint_base.h:18
SetRailStationReservation
static void SetRailStationReservation(TileIndex t, bool b)
Set the reservation state of the rail station.
Definition: station_map.h:406
MP_RAILWAY
A railway.
Definition: tile_type.h:44
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:76
MakeBuoy
static void MakeBuoy(TileIndex t, StationID sid, WaterClass wc)
Make the given tile a buoy tile.
Definition: station_map.h:634
CompanyInfrastructure::station
uint32 station
Count of company owned station tiles.
Definition: company_base.h:36
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:134
CommandCost
Common return value for all commands.
Definition: command_type.h:25
ViewportSign::UpdatePosition
void UpdatePosition(int center, int top, StringID str, StringID str_small=STR_NULL)
Update the position of the viewport sign.
Definition: viewport.cpp:1314
BaseStation::town
Town * town
The town this station is associated with.
Definition: base_station_base.h:62
IsTileFlat
bool IsTileFlat(TileIndex tile, int *h)
Check if a given tile is flat.
Definition: tile_map.cpp:159
STAT_CLASS_WAYP
Waypoint class.
Definition: newgrf_station.h:85
SLOPE_FLAT
a flat tile
Definition: slope_type.h:51
GameSettings::station
StationSettings station
settings related to station management
Definition: settings_type.h:555
TILE_SIZE
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:15
CommandCost::AddCost
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Definition: command_type.h:64
GetCustomStationSpecIndex
static uint GetCustomStationSpecIndex(TileIndex t)
Get the custom station spec for this tile.
Definition: station_map.h:494
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:642
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:57
DC_BANKRUPT
company bankrupts, skip money check, skip vehicle on tile check in some cases
Definition: command_type.h:348
viewport_func.h
Functions related to (drawing on) viewports.
GetTileSlope
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
Definition: tile_map.cpp:115
IsBridgeAbove
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
Definition: bridge_map.h:45
BaseStation::sign
ViewportSign sign
NOSAVE: Dimensions of sign.
Definition: base_station_base.h:56
string_func.h
Functions related to low-level strings.
TileOffsByDiagDir
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:343
WC_WAYPOINT_VIEW
Waypoint view; Window numbers:
Definition: window_type.h:352
TileArea
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Definition: tilearea_type.h:96
GetAxisForNewWaypoint
Axis GetAxisForNewWaypoint(TileIndex tile)
Get the axis for a new waypoint.
Definition: waypoint_cmd.cpp:82
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
Definition: tile_map.h:143
MakeDefaultName
void MakeDefaultName(T *obj)
Set the default name for a depot/waypoint.
Definition: town.h:229
DoCommand
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
Definition: command.cpp:436
AXIS_Y
The y axis.
Definition: direction_type.h:129
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:572
HasStationReservation
static bool HasStationReservation(TileIndex t)
Get the reservation state of the rail station.
Definition: station_map.h:394
TRACK_BIT_X
X-axis track.
Definition: track_type.h:43
DirtyCompanyInfrastructureWindows
void DirtyCompanyInfrastructureWindows(CompanyID company)
Redraw all windows with company infrastructure counts.
Definition: company_gui.cpp:2473
FindDeletedWaypointCloseTo
static Waypoint * FindDeletedWaypointCloseTo(TileIndex tile, StringID str, CompanyID cid)
Find a deleted waypoint close to a tile.
Definition: waypoint_cmd.cpp:56
yapf_cache.h
Entry point for OpenTTD to YAPF&#39;s cache.
GetTileOwner
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:171
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:1140
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:340
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:152
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:147
AllocateSpecToStation
int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec)
Allocate a StationSpec to a Station.
Definition: newgrf_station.cpp:663
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
GetRailReservationTrackBits
static TrackBits GetRailReservationTrackBits(TileIndex t)
Returns the reserved track bits of the tile.
Definition: rail_map.h:195
safeguards.h
A number of safeguards to prevent using unsafe methods.
waypoint_base.h
Base of waypoints.
GetRailStationAxis
static Axis GetRailStationAxis(TileIndex t)
Get the rail direction of a rail station.
Definition: station_map.h:338
HasStationInUse
bool HasStationInUse(StationID station, bool include_company, CompanyID company)
Tests whether the company&#39;s vehicles have this station in orders.
Definition: station_cmd.cpp:2434
OrthogonalTileArea
Represents the covered area of e.g.
Definition: tilearea_type.h:18
stredup
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:126
company_gui.h
GUI Functions related to companies.
bridge_map.h
Map accessor functions for bridges.
CheckOwnership
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
Definition: company_cmd.cpp:310
OWNER_NONE
The tile has no ownership.
Definition: company_type.h:27
BaseStation::facilities
StationFacilityByte facilities
The facilities that this station has.
Definition: base_station_base.h:64
IsWaterTile
static bool IsWaterTile(TileIndex t)
Is it a water tile with plain water?
Definition: water_map.h:184
FACIL_DOCK
Station with a dock.
Definition: station_type.h:59
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
ConstructionSettings::build_on_slopes
bool build_on_slopes
allow building on slopes
Definition: settings_type.h:301
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:161
return_cmd_error
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:35
GetRailTileType
static RailTileType GetRailTileType(TileIndex t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
Definition: rail_map.h:37
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
BaseStation::owner
OwnerByte owner
The owner of this station.
Definition: base_station_base.h:63
MarkTileDirtyByTile
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset)
Mark a tile given by its index dirty for repaint.
Definition: viewport.cpp:1904
Company
Definition: company_base.h:110
GetTrackBits
static TrackBits GetTrackBits(TileIndex tile)
Gets the track bits of the given tile.
Definition: rail_map.h:137
Company::infrastructure
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
Definition: company_base.h:125
AXIS_X
The X axis.
Definition: direction_type.h:128
EXPENSES_CONSTRUCTION
Construction costs.
Definition: economy_type.h:151
DC_EXEC
execute the given command
Definition: command_type.h:342
company_func.h
Functions related to companies.
GetStationIndex
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
Definition: station_map.h:29
newgrf_station.h
Header file for NewGRF stations.
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:59
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:300
_current_company
CompanyByte _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
DistanceManhattan
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Definition: map.cpp:159
CmdBuildBuoy
CommandCost CmdBuildBuoy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build a buoy.
Definition: waypoint_cmd.cpp:289
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:217
CmdBuildRailWaypoint
CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Convert existing rail to waypoint.
Definition: waypoint_cmd.cpp:161
BaseStation::xy
TileIndex xy
Base tile of the station.
Definition: base_station_base.h:55
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:34
Waypoint::UpdateVirtCoord
void UpdateVirtCoord()
Update the virtual coords needed to draw the waypoint sign.
Definition: waypoint_cmd.cpp:40
Slope
Slope
Enumeration for the slope-type.
Definition: slope_type.h:50
MP_STATION
A tile of a station.
Definition: tile_type.h:48
RAIL_TILE_NORMAL
Normal rail tile without signals.
Definition: rail_map.h:25
SpecializedStation< Waypoint, true >::GetByTile
static Waypoint * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
Definition: base_station_base.h:225
ClearTile_Station
CommandCost ClearTile_Station(TileIndex tile, DoCommandFlag flags)
Clear a single tile of a station.
Definition: station_cmd.cpp:4064
NewGRFClass::Get
static NewGRFClass * Get(Tid cls_id)
Get a particular class.
Definition: newgrf_class_func.h:105
FACIL_TRAIN
Station with train station.
Definition: station_type.h:55
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:216
landscape.h
Functions related to OTTD&#39;s landscape.
IsRailWaypoint
static bool IsRailWaypoint(TileIndex t)
Is this station tile a rail waypoint?
Definition: station_map.h:114
GetStationLayout
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.
Definition: station_cmd.cpp:1045
command_func.h
Functions related to commands.
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:197
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:28
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-NULL) Titem.
Definition: pool_type.hpp:235
OtherAxis
static Axis OtherAxis(Axis a)
Select the other axis as provided.
Definition: direction_func.h:199
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition: settings_type.h:545
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:19
StationClassID
StationClassID
Definition: newgrf_station.h:82
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:114
RemoveBuoy
CommandCost RemoveBuoy(TileIndex tile, DoCommandFlag flags)
Remove a buoy.
Definition: waypoint_cmd.cpp:343
MAX_LENGTH_STATION_NAME_CHARS
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:92
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:1000
CmdRenameWaypoint
CommandCost CmdRenameWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Rename a waypoint.
Definition: waypoint_cmd.cpp:401
Waypoint::Waypoint
Waypoint(TileIndex tile=INVALID_TILE)
Create a waypoint at the given tile.
Definition: waypoint_base.h:25
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:105
INVALID_TILE
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:85
town.h
Base of the town class.
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:20
window_func.h
Window functions not directly related to making/drawing windows.
water.h
Functions related to water (management)
AxisToDiagDir
static DiagDirection AxisToDiagDir(Axis a)
Converts an Axis to a DiagDirection.
Definition: direction_func.h:234
INVALID_AXIS
Flag for an invalid Axis.
Definition: direction_type.h:131
_date
Date _date
Current date in days (day counter)
Definition: date.cpp:28
BaseStation::name
char * name
Custom name.
Definition: base_station_base.h:59
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:99
BaseStation::string_id
StringID string_id
Default name (town area) of station.
Definition: base_station_base.h:60
IsValidTileForWaypoint
static CommandCost IsValidTileForWaypoint(TileIndex tile, Axis axis, StationID *waypoint)
Check whether the given tile is suitable for a waypoint.
Definition: waypoint_cmd.cpp:105
BaseStation
Base class for all station-ish types.
Definition: base_station_base.h:54
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition: direction_type.h:127
GetRailType
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
Definition: rail_map.h:116
TRACK_BIT_Y
Y-axis track.
Definition: track_type.h:44
FOR_ALL_WAYPOINTS
#define FOR_ALL_WAYPOINTS(var)
Iterate over all waypoints.
Definition: waypoint_base.h:74
BaseStation::build_date
Date build_date
Date of construction.
Definition: base_station_base.h:69
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:3220
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:201
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:215