Translations update
[openttd/fttd.git] / src / map / station.h
blob90cd5dc8bce22a33b4c0f965e19145969f81e984
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 */
8 /** @file map/station.h Map tile accessors for station tiles. */
10 #ifndef MAP_STATION_H
11 #define MAP_STATION_H
13 #include "../stdafx.h"
14 #include "../tile/station.h"
15 #include "map.h"
16 #include "coord.h"
17 #include "class.h"
18 #include "common.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"
27 /**
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]);
39 /**
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]);
50 /**
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]);
60 /**
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]);
71 /**
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]);
81 /**
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]);
93 /**
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)
337 * @param t the tile
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);
369 * Is tile \a t a standard (non-drive through) road stop station?
370 * @param t Tile to check
371 * @return \c true if the tile is a station tile and a standard road stop
373 static inline bool IsStandardRoadStopTile(TileIndex t)
375 return tile_is_standard_road_station(&_mc[t]);
379 * Is tile \a t a drive through road stop station?
380 * @param t Tile to check
381 * @return \c true if the tile is a station tile and a drive through road stop
383 static inline bool IsDriveThroughStopTile(TileIndex t)
385 return tile_is_drive_through_road_station(&_mc[t]);
389 * Gets the direction the road stop entrance points towards.
390 * @param t the tile of the road stop
391 * @pre IsRoadStopTile(t)
392 * @return the direction of the entrance
394 static inline DiagDirection GetRoadStopDir(TileIndex t)
396 return tile_get_road_station_dir(&_mc[t]);
400 * Gets the axis of the road stop.
401 * @param t the tile of the road stop
402 * @pre IsDriveThroughRoadStopTile(t)
403 * @return the axis of the road stop
405 static inline Axis GetRoadStopAxis(TileIndex t)
407 return tile_get_road_station_axis(&_mc[t]);
411 * Get the road stop type of this tile
412 * @param t the tile to query
413 * @pre IsRoadStop(t)
414 * @return the road stop type
416 static inline RoadStopType GetRoadStopType(TileIndex t)
418 assert(IsRoadStop(t));
419 return GetStationType(t) == STATION_TRUCK ? ROADSTOP_TRUCK : ROADSTOP_BUS;
424 * Check if a dock is a 'buoy-like' dock
425 * @param t The tile to check
426 * @pre IsDockTile(t)
427 * @return Whether the dock tile is a 'buoy-like' dock
429 static inline bool IsDockBuoy (TileIndex t)
431 assert (IsDockTile (t));
432 return tile_dock_is_buoy (&_mc[t]);
436 * Get the direction of a dock.
437 * @param t Tile to query
438 * @pre IsDock(t)
439 * @pre \a t is the land part of the dock
440 * @return The direction of the dock on tile \a t.
442 static inline DiagDirection GetDockDirection(TileIndex t)
444 return tile_get_dock_direction(&_mc[t]);
448 * Get the secondary dock tile for a primary (usually sloped) dock tile.
449 * @param t Tile to query
450 * @pre IsDockTile(t)
451 * @pre GetStationGfx(t) < GFX_DOCK_BASE_WATER_PART || GetStationGfx(t) == GFX_DOCK_BUOY
452 * @return The secondary dock tile for standard docks, or INVALID_TILE for buoy docks.
454 static inline TileIndex GetOtherDockTile (TileIndex t)
456 assert (IsDockTile(t));
458 return IsDockBuoy(t) ? INVALID_TILE :
459 TileAddByDiagDir (t, GetDockDirection(t));
463 * Get the tileoffset from this tile a ship should target to get to this dock.
464 * @param t Tile to query
465 * @pre IsStationTile(t)
466 * @pre IsBuoy(t) || IsOilRig(t) || IsDock(t)
467 * @return The offset from this tile that should be used as destination for ships.
469 static inline TileIndexDiff GetDockOffset(TileIndex t)
471 assert(IsStationTile(t));
473 if (IsBuoy(t)) return TileDiffXY(0, 0);
474 if (IsOilRig(t)) return TileDiffXY(2, 0);
476 assert(IsDock(t));
477 return IsDockBuoy(t) ? TileDiffXY(0, 0) :
478 2 * TileOffsByDiagDir(GetDockDirection(t));
482 * Get the docking tile for a dock.
483 * @param t Tile to query
484 * @pre IsStationTile(t)
485 * @pre IsBuoy(t) || IsOilRig(t) || IsDock(t)
486 * @return The tile that should be used as destination for ships.
488 static inline TileIndex GetDockingTile(TileIndex t)
490 return TILE_ADD(t, GetDockOffset(t));
495 * Make the given tile a rail station tile.
496 * @param t the tile to make a rail station tile
497 * @param o the owner of the station
498 * @param sid the station to which this tile belongs
499 * @param a the axis of this tile
500 * @param section the StationGfx to be used for this tile
501 * @param rt the railtype of this tile
503 static inline void MakeRailStation(TileIndex t, Owner o, StationID sid, Axis a, byte section, RailType rt)
505 tile_make_rail_station(&_mc[t], o, sid, a, section, rt);
509 * Make the given tile a rail waypoint tile.
510 * @param t the tile to make a rail waypoint
511 * @param o the owner of the waypoint
512 * @param sid the waypoint to which this tile belongs
513 * @param a the axis of this tile
514 * @param section the StationGfx to be used for this tile
515 * @param rt the railtype of this tile
517 static inline void MakeRailWaypoint(TileIndex t, Owner o, StationID sid, Axis a, byte section, RailType rt)
519 tile_make_rail_station(&_mc[t], o, sid, a, section, rt, true);
523 * Make the given tile a roadstop tile.
524 * @param t the tile to make a roadstop
525 * @param o the owner of the roadstop
526 * @param sid the station to which this tile belongs
527 * @param rst the type of roadstop to make this tile
528 * @param rt the roadtypes on this tile
529 * @param d the direction of the roadstop
531 static inline void MakeRoadStop(TileIndex t, Owner o, StationID sid, RoadStopType rst, RoadTypes rt, DiagDirection d)
533 tile_make_road_stop(&_mc[t], o, sid, d, rt, rst == ROADSTOP_BUS, o, o);
537 * Make the given tile a drivethrough roadstop tile.
538 * @param t the tile to make a roadstop
539 * @param station the owner of the roadstop
540 * @param road the owner of the road
541 * @param tram the owner of the tram
542 * @param sid the station to which this tile belongs
543 * @param rst the type of roadstop to make this tile
544 * @param rt the roadtypes on this tile
545 * @param a the direction of the roadstop
547 static inline void MakeDriveThroughRoadStop(TileIndex t, Owner station, Owner road, Owner tram, StationID sid, RoadStopType rst, RoadTypes rt, Axis a)
549 tile_make_road_stop(&_mc[t], station, sid, GFX_ROAD_DT_OFFSET + a, rt, rst == ROADSTOP_BUS, road, tram);
553 * Make the given tile an oilrig tile.
554 * @param t the tile to make an oilrig
555 * @param sid the station to which this tile belongs
556 * @param wc the type of water on this tile
558 static inline void MakeOilrig(TileIndex t, StationID sid, WaterClass wc)
560 tile_make_oilrig(&_mc[t], sid, wc);
564 * Make the given tile a dock tile.
565 * @param t the tile to make a dock
566 * @param o the owner of the dock
567 * @param sid the station to which this tile belongs
568 * @param d the direction of the dock
569 * @param wc the type of water on this tile
571 static inline void MakeDock(TileIndex t, Owner o, StationID sid, DiagDirection d, WaterClass wc)
573 tile_make_dock(&_mc[t], o, sid, d);
574 tile_make_dock(&_mc[t + TileOffsByDiagDir(d)], o, sid, GFX_DOCK_BASE_WATER_PART + DiagDirToAxis(d), wc);
578 * Make the given tile a buoy-dock tile.
579 * @param t the tile to make a buoy-dock
580 * @param o the owner of the dock
581 * @param sid the station to which this tile belongs
582 * @param wc the type of water on this tile
584 static inline void MakeDockBuoy (TileIndex t, Owner o, StationID sid, WaterClass wc)
586 tile_make_dock (&_mc[t], o, sid, GFX_DOCK_BUOY, wc);
590 * Make the given tile a buoy tile.
591 * @param t the tile to make a buoy
592 * @param sid the station to which this tile belongs
593 * @param wc the type of water on this tile
595 static inline void MakeBuoy(TileIndex t, StationID sid, WaterClass wc)
597 /* Make the owner of the buoy tile the same as the current owner of the
598 * water tile. In this way, we can reset the owner of the water to its
599 * original state when the buoy gets removed. */
600 tile_make_buoy(&_mc[t], GetTileOwner(t), sid, wc);
604 * Make the given tile an airport tile.
605 * @param t the tile to make a airport
606 * @param o the owner of the airport
607 * @param sid the station to which this tile belongs
608 * @param section the StationGfx to be used for this tile
609 * @param wc the type of water on this tile
611 static inline void MakeAirport(TileIndex t, Owner o, StationID sid, byte section, WaterClass wc)
613 tile_make_airport(&_mc[t], o, sid, section, wc);
616 #endif /* MAP_STATION_H */