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/>.
8 /** @file map/station.h Map tile accessors for station tiles. */
13 #include "../stdafx.h"
14 #include "../tile/station.h"
19 #include "../direction_type.h"
20 #include "../track_type.h"
21 #include "../track_func.h"
22 #include "../rail_type.h"
23 #include "../road_type.h"
24 #include "../station_type.h"
25 #include "../company_type.h"
28 * Get the station type of this tile
29 * @param t the tile to query
30 * @pre IsStationTile(t)
31 * @return the station type
33 static inline StationType
GetStationType(TileIndex t
)
35 return tile_get_station_type(&_mc
[t
]);
40 * Is this station tile a rail station?
41 * @param t the tile to get the information from
42 * @pre IsStationTile(t)
43 * @return true if and only if the tile is a rail station
45 static inline bool IsRailStation(TileIndex t
)
47 return tile_station_is_rail(&_mc
[t
]);
51 * Is this tile a station tile and a rail station?
52 * @param t the tile to get the information from
53 * @return true if and only if the tile is a rail station
55 static inline bool IsRailStationTile(TileIndex t
)
57 return tile_is_rail_station(&_mc
[t
]);
61 * Is this station tile a rail waypoint?
62 * @param t the tile to get the information from
63 * @pre IsStationTile(t)
64 * @return true if and only if the tile is a rail waypoint
66 static inline bool IsRailWaypoint(TileIndex t
)
68 return tile_station_is_waypoint(&_mc
[t
]);
72 * Is this tile a station tile and a rail waypoint?
73 * @param t the tile to get the information from
74 * @return true if and only if the tile is a rail waypoint
76 static inline bool IsRailWaypointTile(TileIndex t
)
78 return tile_is_waypoint(&_mc
[t
]);
82 * Has this station tile a rail? In other words, is this station
83 * tile a rail station or rail waypoint?
84 * @param t the tile to check
85 * @pre IsStationTile(t)
86 * @return true if and only if the tile has rail
88 static inline bool HasStationRail(TileIndex t
)
90 return tile_station_has_rail(&_mc
[t
]);
94 * Has this station tile a rail? In other words, is this station
95 * tile a rail station or rail waypoint?
96 * @param t the tile to check
97 * @return true if and only if the tile is a station tile and has rail
99 static inline bool HasStationTileRail(TileIndex t
)
101 return tile_has_rail_station(&_mc
[t
]);
105 * Is the station at \a t a truck stop?
106 * @param t Tile to check
107 * @pre IsStationTile(t)
108 * @return \c true if station is a truck stop, \c false otherwise
110 static inline bool IsTruckStop(TileIndex t
)
112 return tile_station_is_truck(&_mc
[t
]);
116 * Is the station at \a t a bus stop?
117 * @param t Tile to check
118 * @pre IsStationTile(t)
119 * @return \c true if station is a bus stop, \c false otherwise
121 static inline bool IsBusStop(TileIndex t
)
123 return tile_station_is_bus(&_mc
[t
]);
127 * Is the station at \a t a road station?
128 * @param t Tile to check
129 * @pre IsStationTile(t)
130 * @return \c true if station at the tile is a bus top or a truck stop, \c false otherwise
132 static inline bool IsRoadStop(TileIndex t
)
134 return tile_station_is_road(&_mc
[t
]);
138 * Is tile \a t a road stop station?
139 * @param t Tile to check
140 * @return \c true if the tile is a station tile and a road stop
142 static inline bool IsRoadStopTile(TileIndex t
)
144 return tile_is_road_station(&_mc
[t
]);
148 * Is tile \a t part of an oilrig?
149 * @param t Tile to check
150 * @pre IsStationTile(t)
151 * @return \c true if the tile is an oilrig tile
153 static inline bool IsOilRig(TileIndex t
)
155 return tile_station_is_oilrig(&_mc
[t
]);
159 * Is tile \a t a dock tile?
160 * @param t Tile to check
161 * @pre IsStationTile(t)
162 * @return \c true if the tile is a dock
164 static inline bool IsDock(TileIndex t
)
166 return tile_station_is_dock(&_mc
[t
]);
170 * Is tile \a t a dock tile?
171 * @param t Tile to check
172 * @return \c true if the tile is a dock
174 static inline bool IsDockTile(TileIndex t
)
176 return tile_is_dock(&_mc
[t
]);
180 * Is tile \a t a buoy tile?
181 * @param t Tile to check
182 * @pre IsStationTile(t)
183 * @return \c true if the tile is a buoy
185 static inline bool IsBuoy(TileIndex t
)
187 return tile_station_is_buoy(&_mc
[t
]);
191 * Is tile \a t a buoy tile?
192 * @param t Tile to check
193 * @return \c true if the tile is a buoy
195 static inline bool IsBuoyTile(TileIndex t
)
197 return tile_is_buoy(&_mc
[t
]);
201 * Is this station tile an airport?
202 * @param t the tile to get the information from
203 * @pre IsStationTile(t)
204 * @return true if and only if the tile is an airport
206 static inline bool IsAirport(TileIndex t
)
208 return tile_station_is_airport(&_mc
[t
]);
212 * Is this tile a station tile and an airport tile?
213 * @param t the tile to get the information from
214 * @return true if and only if the tile is an airport
216 static inline bool IsAirportTile(TileIndex t
)
218 return tile_is_airport(&_mc
[t
]);
223 * Get StationID from a tile
224 * @param t Tile to query station ID from
225 * @pre IsStationTile(t)
226 * @return Station ID of the station at \a t
228 static inline uint
GetStationIndex(TileIndex t
)
230 return tile_get_station_index(&_mc
[t
]);
234 * Get the station graphics of this tile
235 * @param t the tile to query
236 * @pre IsStationTile(t)
237 * @return the station graphics
239 static inline StationGfx
GetStationGfx(TileIndex t
)
241 return tile_get_station_gfx(&_mc
[t
]);
245 * Set the station graphics of this tile
246 * @param t the tile to update
247 * @param gfx the new graphics
248 * @pre IsStationTile(t)
250 static inline void SetStationGfx(TileIndex t
, StationGfx gfx
)
252 tile_set_station_gfx(&_mc
[t
], gfx
);
257 * Get the random bits of a station tile.
258 * @param t Tile to query
259 * @pre IsStationTile(t)
260 * @return The random bits for this station tile.
262 static inline byte
GetStationTileRandomBits(TileIndex t
)
264 return tile_get_station_random_bits(&_mc
[t
]);
268 * Set the random bits for a station tile.
269 * @param t Tile to set random bits for.
270 * @param random_bits The random bits.
271 * @pre IsStationTile(t)
273 static inline void SetStationTileRandomBits(TileIndex t
, byte random_bits
)
275 tile_set_station_random_bits(&_mc
[t
], random_bits
);
280 * Get the rail direction of a rail station.
281 * @param t Tile to query
282 * @pre HasStationRail(t)
283 * @return The direction of the rails on tile \a t.
285 static inline Axis
GetRailStationAxis(TileIndex t
)
287 return tile_get_station_axis(&_mc
[t
]);
291 * Get the rail track of a rail station tile.
292 * @param t Tile to query
293 * @pre HasStationRail(t)
294 * @return The rail track of the rails on tile \a t.
296 static inline Track
GetRailStationTrack(TileIndex t
)
298 return tile_get_station_track(&_mc
[t
]);
302 * Get the trackbits of a rail station tile.
303 * @param t Tile to query
304 * @pre HasStationRail(t)
305 * @return The trackbits of the rails on tile \a t.
307 static inline TrackBits
GetRailStationTrackBits(TileIndex t
)
309 return tile_get_station_trackbits(&_mc
[t
]);
313 * Get the reservation state of the rail station
314 * @pre HasStationRail(t)
315 * @param t the station tile
316 * @return reservation state
318 static inline bool HasStationReservation(TileIndex t
)
320 return tile_station_is_reserved(&_mc
[t
]);
324 * Set the reservation state of the rail station
325 * @pre HasStationRail(t)
326 * @param t the station tile
327 * @param b the reservation state
329 static inline void SetRailStationReservation(TileIndex t
, bool b
)
331 tile_station_set_reserved(&_mc
[t
], b
);
335 * Get the reserved track bits for a waypoint
336 * @pre HasStationRail(t)
338 * @return reserved track bits
340 static inline TrackBits
GetStationReservationTrackBits(TileIndex t
)
342 return tile_station_get_reserved_trackbits(&_mc
[t
]);
346 * Get the custom station spec for this tile.
347 * @param t Tile to query
348 * @pre HasStationTileRail(t)
349 * @return The custom station spec of this tile.
351 static inline uint
GetCustomStationSpecIndex(TileIndex t
)
353 return tile_get_station_spec(&_mc
[t
]);
357 * Set the custom station spec for this tile.
358 * @param t Tile to set the stationspec of.
359 * @param specindex The new spec.
360 * @pre HasStationTileRail(t)
362 static inline void SetCustomStationSpecIndex(TileIndex t
, byte specindex
)
364 tile_set_station_spec(&_mc
[t
], specindex
);
368 * Is there a custom rail station spec on this tile?
369 * @param t Tile to query
370 * @pre HasStationTileRail(t)
371 * @return True if this station is part of a newgrf station.
373 static inline bool IsCustomStationSpecIndex(TileIndex t
)
375 return tile_has_custom_station_spec(&_mc
[t
]);
380 * Is tile \a t a standard (non-drive through) road stop station?
381 * @param t Tile to check
382 * @return \c true if the tile is a station tile and a standard road stop
384 static inline bool IsStandardRoadStopTile(TileIndex t
)
386 return tile_is_standard_road_station(&_mc
[t
]);
390 * Is tile \a t a drive through road stop station?
391 * @param t Tile to check
392 * @return \c true if the tile is a station tile and a drive through road stop
394 static inline bool IsDriveThroughStopTile(TileIndex t
)
396 return tile_is_drive_through_road_station(&_mc
[t
]);
400 * Gets the direction the road stop entrance points towards.
401 * @param t the tile of the road stop
402 * @pre IsRoadStopTile(t)
403 * @return the direction of the entrance
405 static inline DiagDirection
GetRoadStopDir(TileIndex t
)
407 return tile_get_road_station_dir(&_mc
[t
]);
411 * Gets the axis of the road stop.
412 * @param t the tile of the road stop
413 * @pre IsDriveThroughRoadStopTile(t)
414 * @return the axis of the road stop
416 static inline Axis
GetRoadStopAxis(TileIndex t
)
418 return tile_get_road_station_axis(&_mc
[t
]);
422 * Get the road stop type of this tile
423 * @param t the tile to query
425 * @return the road stop type
427 static inline RoadStopType
GetRoadStopType(TileIndex t
)
429 assert(IsRoadStop(t
));
430 return GetStationType(t
) == STATION_TRUCK
? ROADSTOP_TRUCK
: ROADSTOP_BUS
;
435 * Get the direction of a dock.
436 * @param t Tile to query
438 * @pre \a t is the land part of the dock
439 * @return The direction of the dock on tile \a t.
441 static inline DiagDirection
GetDockDirection(TileIndex t
)
443 return tile_get_dock_direction(&_mc
[t
]);
447 * Get the tileoffset from this tile a ship should target to get to this dock.
448 * @param t Tile to query
449 * @pre IsStationTile(t)
450 * @pre IsBuoy(t) || IsOilRig(t) || IsDock(t)
451 * @return The offset from this tile that should be used as destination for ships.
453 static inline TileIndexDiff
GetDockOffset(TileIndex t
)
455 assert(IsStationTile(t
));
457 if (IsBuoy(t
)) return TileDiffXY(0, 0);
458 if (IsOilRig(t
)) return TileDiffXY(2, 0);
461 return 2 * TileOffsByDiagDir(GetDockDirection(t
));
465 * Get the docking tile for a dock.
466 * @param t Tile to query
467 * @pre IsStationTile(t)
468 * @pre IsBuoy(t) || IsOilRig(t) || IsDock(t)
469 * @return The tile that should be used as destination for ships.
471 static inline TileIndex
GetDockingTile(TileIndex t
)
473 return TILE_ADD(t
, GetDockOffset(t
));
478 * Make the given tile a rail station tile.
479 * @param t the tile to make a rail station tile
480 * @param o the owner of the station
481 * @param sid the station to which this tile belongs
482 * @param a the axis of this tile
483 * @param section the StationGfx to be used for this tile
484 * @param rt the railtype of this tile
486 static inline void MakeRailStation(TileIndex t
, Owner o
, StationID sid
, Axis a
, byte section
, RailType rt
)
488 tile_make_rail_station(&_mc
[t
], o
, sid
, a
, section
, rt
);
492 * Make the given tile a rail waypoint tile.
493 * @param t the tile to make a rail waypoint
494 * @param o the owner of the waypoint
495 * @param sid the waypoint to which this tile belongs
496 * @param a the axis of this tile
497 * @param section the StationGfx to be used for this tile
498 * @param rt the railtype of this tile
500 static inline void MakeRailWaypoint(TileIndex t
, Owner o
, StationID sid
, Axis a
, byte section
, RailType rt
)
502 tile_make_rail_station(&_mc
[t
], o
, sid
, a
, section
, rt
, true);
506 * Make the given tile a roadstop tile.
507 * @param t the tile to make a roadstop
508 * @param o the owner of the roadstop
509 * @param sid the station to which this tile belongs
510 * @param rst the type of roadstop to make this tile
511 * @param rt the roadtypes on this tile
512 * @param d the direction of the roadstop
514 static inline void MakeRoadStop(TileIndex t
, Owner o
, StationID sid
, RoadStopType rst
, RoadTypes rt
, DiagDirection d
)
516 tile_make_road_stop(&_mc
[t
], o
, sid
, d
, rt
, rst
== ROADSTOP_BUS
, o
, o
);
520 * Make the given tile a drivethrough roadstop tile.
521 * @param t the tile to make a roadstop
522 * @param station the owner of the roadstop
523 * @param road the owner of the road
524 * @param tram the owner of the tram
525 * @param sid the station to which this tile belongs
526 * @param rst the type of roadstop to make this tile
527 * @param rt the roadtypes on this tile
528 * @param a the direction of the roadstop
530 static inline void MakeDriveThroughRoadStop(TileIndex t
, Owner station
, Owner road
, Owner tram
, StationID sid
, RoadStopType rst
, RoadTypes rt
, Axis a
)
532 tile_make_road_stop(&_mc
[t
], station
, sid
, GFX_ROAD_DT_OFFSET
+ a
, rt
, rst
== ROADSTOP_BUS
, road
, tram
);
536 * Make the given tile an oilrig tile.
537 * @param t the tile to make an oilrig
538 * @param sid the station to which this tile belongs
539 * @param wc the type of water on this tile
541 static inline void MakeOilrig(TileIndex t
, StationID sid
, WaterClass wc
)
543 tile_make_oilrig(&_mc
[t
], sid
, wc
);
547 * Make the given tile a dock tile.
548 * @param t the tile to make a dock
549 * @param o the owner of the dock
550 * @param sid the station to which this tile belongs
551 * @param d the direction of the dock
552 * @param wc the type of water on this tile
554 static inline void MakeDock(TileIndex t
, Owner o
, StationID sid
, DiagDirection d
, WaterClass wc
)
556 tile_make_dock(&_mc
[t
], o
, sid
, d
);
557 tile_make_dock(&_mc
[t
+ TileOffsByDiagDir(d
)], o
, sid
, GFX_DOCK_BASE_WATER_PART
+ DiagDirToAxis(d
), wc
);
561 * Make the given tile a buoy tile.
562 * @param t the tile to make a buoy
563 * @param sid the station to which this tile belongs
564 * @param wc the type of water on this tile
566 static inline void MakeBuoy(TileIndex t
, StationID sid
, WaterClass wc
)
568 /* Make the owner of the buoy tile the same as the current owner of the
569 * water tile. In this way, we can reset the owner of the water to its
570 * original state when the buoy gets removed. */
571 tile_make_buoy(&_mc
[t
], GetTileOwner(t
), sid
, wc
);
575 * Make the given tile an airport tile.
576 * @param t the tile to make a airport
577 * @param o the owner of the airport
578 * @param sid the station to which this tile belongs
579 * @param section the StationGfx to be used for this tile
580 * @param wc the type of water on this tile
582 static inline void MakeAirport(TileIndex t
, Owner o
, StationID sid
, byte section
, WaterClass wc
)
584 tile_make_airport(&_mc
[t
], o
, sid
, section
, wc
);
587 #endif /* MAP_STATION_H */