Fix ICU iterators on leading/trailing whitespace
[openttd/fttd.git] / src / map / road.h
blob4a4618b148ace57af3a4f0ff633ee8e45904f53e
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/road.h Map tile accessors for road tiles. */
10 #ifndef MAP_ROAD_H
11 #define MAP_ROAD_H
13 #include "../stdafx.h"
14 #include "../tile/road.h"
15 #include "map.h"
16 #include "coord.h"
17 #include "../direction_type.h"
18 #include "../road_type.h"
19 #include "../company_type.h"
21 /**
22 * Get the present road bits for a specific road type.
23 * @param t The tile to query.
24 * @param rt Road type.
25 * @pre IsRoadTile(t)
26 * @return The present road bits for the road type.
28 static inline RoadBits GetRoadBits(TileIndex t, RoadType rt)
30 return tile_get_roadbits(&_mc[t], rt);
33 /**
34 * Get all RoadBits set on a tile except from the given RoadType
36 * @param t The tile from which we want to get the RoadBits
37 * @param rt The RoadType which we exclude from the querry
38 * @return all set RoadBits of the tile which are not from the given RoadType
40 static inline RoadBits GetOtherRoadBits(TileIndex t, RoadType rt)
42 return GetRoadBits(t, rt == ROADTYPE_ROAD ? ROADTYPE_TRAM : ROADTYPE_ROAD);
45 /**
46 * Get all set RoadBits on the given tile
48 * @param tile The tile from which we want to get the RoadBits
49 * @return all set RoadBits of the tile
51 static inline RoadBits GetAllRoadBits(TileIndex tile)
53 return tile_get_all_roadbits(&_mc[tile]);
56 /**
57 * Set the present road bits for a specific road type.
58 * @param t The tile to change.
59 * @param r The new road bits.
60 * @param rt Road type.
61 * @pre IsRoadTile(t)
63 static inline void SetRoadBits(TileIndex t, RoadBits r, RoadType rt)
65 tile_set_roadbits(&_mc[t], rt, r);
69 RoadBits GetAnyRoadBits(TileIndex tile, RoadType rt, bool tunnel_bridge_entrance = false);
72 /**
73 * Get the present road types of a tile.
74 * @param t The tile to query.
75 * @return Present road types.
77 static inline RoadTypes GetRoadTypes(TileIndex t)
79 return tile_get_roadtypes(&_mc[t]);
82 /**
83 * Set the present road types of a tile.
84 * @param t The tile to change.
85 * @param rt The new road types.
87 static inline void SetRoadTypes(TileIndex t, RoadTypes rt)
89 tile_set_roadtypes(&_mc[t], rt);
92 /**
93 * Check if a tile has a specific road type.
94 * @param t The tile to check.
95 * @param rt Road type to check.
96 * @return True if the tile has the specified road type.
98 static inline bool HasTileRoadType(TileIndex t, RoadType rt)
100 return tile_has_roadtype(&_mc[t], rt);
105 * Get the owner of a specific road type.
106 * @param t The tile to query.
107 * @param rt The road type to get the owner of.
108 * @return Owner of the given road type.
110 static inline Owner GetRoadOwner(TileIndex t, RoadType rt)
112 return tile_get_road_owner(&_mc[t], rt);
116 * Set the owner of a specific road type.
117 * @param t The tile to change.
118 * @param rt The road type to change the owner of.
119 * @param o New owner of the given road type.
121 static inline void SetRoadOwner(TileIndex t, RoadType rt, Owner o)
123 tile_set_road_owner(&_mc[t], rt, o);
127 * Check if a specific road type is owned by an owner.
128 * @param t The tile to query.
129 * @param rt The road type to compare the owner of.
130 * @param o Owner to compare with.
131 * @pre HasTileRoadType(t, rt)
132 * @return True if the road type is owned by the given owner.
134 static inline bool IsRoadOwner(TileIndex t, RoadType rt, Owner o)
136 assert(HasTileRoadType(t, rt));
137 return (GetRoadOwner(t, rt) == o);
141 * Checks if given tile has town owned road
142 * @param t tile to check
143 * @pre IsRoadTile(t)
144 * @return true iff tile has road and the road is owned by a town
146 static inline bool HasTownOwnedRoad(TileIndex t)
148 return HasTileRoadType(t, ROADTYPE_ROAD) && IsRoadOwner(t, ROADTYPE_ROAD, OWNER_TOWN);
153 * Get the decorations of a road.
154 * @param tile The tile to query.
155 * @return The road decoration of the tile.
157 static inline Roadside GetRoadside(TileIndex tile)
159 return tile_get_roadside(&_mc[tile]);
163 * Set the decorations of a road.
164 * @param tile The tile to change.
165 * @param s The new road decoration of the tile.
167 static inline void SetRoadside(TileIndex tile, Roadside s)
169 tile_set_roadside(&_mc[tile], s);
173 * Check if a tile has road works.
174 * @param t The tile to check.
175 * @return True if the tile has road works in progress.
177 static inline bool HasRoadWorks(TileIndex t)
179 return tile_has_roadworks(&_mc[t]);
183 * Start road works on a tile.
184 * @param t The tile to start the work on.
185 * @pre IsNormalRoadTile(t)
187 static inline void StartRoadWorks(TileIndex t)
189 tile_init_roadworks(&_mc[t]);
193 * Decrease the road works counter.
194 * @param t The tile to modify.
195 * @return True if the road works are in the last stage.
197 static inline bool DecreaseRoadWorksCounter(TileIndex t)
199 return tile_dec_roadworks(&_mc[t]);
204 * Gets the disallowed directions
205 * @param t the tile to get the directions from
206 * @return the disallowed directions
208 static inline DisallowedRoadDirections GetDisallowedRoadDirections(TileIndex t)
210 return tile_get_disallowed_directions(&_mc[t]);
214 * Sets the disallowed directions
215 * @param t the tile to set the directions for
216 * @param drd the disallowed directions
218 static inline void SetDisallowedRoadDirections(TileIndex t, DisallowedRoadDirections drd)
220 tile_set_disallowed_directions(&_mc[t], drd);
225 * Determines the type of road bridge on a tile
226 * @param t The tile to analyze
227 * @pre IsRoadBridgeTile(t)
228 * @return The bridge type
230 static inline uint GetRoadBridgeType(TileIndex t)
232 return tile_get_road_bridge_type(&_mc[t]);
236 * Set the type of road bridge on a tile
237 * @param t The tile to set
238 * @param type The type to set
240 static inline void SetRoadBridgeType(TileIndex t, uint type)
242 tile_set_road_bridge_type(&_mc[t], type);
246 * Check if a road bridge is an extended bridge head
247 * @param t The tile to check
248 * @return Whether there are road bits set not in the axis of the bridge
250 static inline bool IsExtendedRoadBridge(TileIndex t)
252 return tile_is_road_custom_bridgehead(&_mc[t]);
257 * Make a normal road tile.
258 * @param t Tile to make a normal road.
259 * @param bits Road bits to set for all present road types.
260 * @param rot New present road types.
261 * @param town Town ID if the road is a town-owned road.
262 * @param road New owner of road.
263 * @param tram New owner of tram tracks.
265 static inline void MakeRoadNormal(TileIndex t, RoadBits bits, RoadTypes rot, TownID town, Owner road, Owner tram)
267 tile_make_road(&_mc[t], rot, bits, town, road, tram);
271 * Make a bridge ramp for roads.
272 * @param t the tile to make a bridge ramp
273 * @param owner_road the new owner of the road on the bridge
274 * @param owner_tram the new owner of the tram on the bridge
275 * @param bridgetype the type of bridge this bridge ramp belongs to
276 * @param d the direction this ramp must be facing
277 * @param r the road type of the bridge
278 * @param town owner/closest town ID
280 static inline void MakeRoadBridgeRamp(TileIndex t, Owner owner_road, Owner owner_tram, uint bridgetype, DiagDirection d, RoadTypes r, uint town)
282 tile_make_road_bridge(&_mc[t], bridgetype, d, r, town, owner_road, owner_tram);
286 * Make a normal road tile from a road bridge ramp.
287 * @param t the tile to make a normal road
288 * @note roadbits will have to be adjusted when this function is called
290 static inline void MakeNormalRoadFromBridge(TileIndex t)
292 tile_make_road_from_bridge(&_mc[t]);
296 * Make a road bridge tile from a normal road.
297 * @param t the tile to make a road bridge
298 * @param bridgetype the type of bridge this bridge ramp belongs to
299 * @param d the direction this ramp must be facing
300 * @note roadbits will have to be adjusted when this function is called
302 static inline void MakeRoadBridgeFromRoad(TileIndex t, uint bridgetype, DiagDirection d)
304 tile_make_bridge_from_road(&_mc[t], bridgetype, d);
309 * Get the road axis of a level crossing.
310 * @param t The tile to query.
311 * @pre IsLevelCrossingTile(t)
312 * @return The axis of the road.
314 static inline Axis GetCrossingRoadAxis(TileIndex t)
316 return tile_get_crossing_road_axis(&_mc[t]);
320 * Get the road bits of a level crossing.
321 * @param tile The tile to query.
322 * @return The present road bits.
324 static inline RoadBits GetCrossingRoadBits(TileIndex tile)
326 return tile_get_crossing_roadbits(&_mc[tile]);
330 * Get the rail axis of a level crossing.
331 * @param t The tile to query.
332 * @pre IsLevelCrossingTile(t)
333 * @return The axis of the rail.
335 static inline Axis GetCrossingRailAxis(TileIndex t)
337 return tile_get_crossing_rail_axis(&_mc[t]);
341 * Get the rail track of a level crossing.
342 * @param tile The tile to query.
343 * @return The rail track.
345 static inline Track GetCrossingRailTrack(TileIndex tile)
347 return tile_get_crossing_rail_track(&_mc[tile]);
351 * Get the rail track bits of a level crossing.
352 * @param tile The tile to query.
353 * @return The rail track bits.
355 static inline TrackBits GetCrossingRailBits(TileIndex tile)
357 return tile_get_crossing_rail_trackbits(&_mc[tile]);
362 * Get the reservation state of the rail crossing
363 * @param t the crossing tile
364 * @return reservation state
365 * @pre IsLevelCrossingTile(t)
367 static inline bool HasCrossingReservation(TileIndex t)
369 return tile_crossing_is_reserved(&_mc[t]);
373 * Set the reservation state of the rail crossing
374 * @param t the crossing tile
375 * @param b the reservation state
376 * @pre IsLevelCrossingTile(t)
378 static inline void SetCrossingReservation(TileIndex t, bool b)
380 tile_crossing_set_reserved(&_mc[t], b);
384 * Get the reserved track bits for a rail crossing
385 * @param t the tile
386 * @pre IsLevelCrossingTile(t)
387 * @return reserved track bits
389 static inline TrackBits GetCrossingReservationTrackBits(TileIndex t)
391 return tile_crossing_get_reserved_trackbits(&_mc[t]);
396 * Check if the level crossing is barred.
397 * @param t The tile to query.
398 * @pre IsLevelCrossingTile(t)
399 * @return True if the level crossing is barred.
401 static inline bool IsCrossingBarred(TileIndex t)
403 return tile_crossing_is_barred(&_mc[t]);
407 * Set the bar state of a level crossing.
408 * @param t The tile to modify.
409 * @param barred True if the crossing should be barred, false otherwise.
410 * @pre IsLevelCrossingTile(t)
412 static inline void SetCrossingBarred(TileIndex t, bool barred)
414 tile_crossing_set_barred(&_mc[t], barred);
418 * Unbar a level crossing.
419 * @param t The tile to change.
421 static inline void UnbarCrossing(TileIndex t)
423 SetCrossingBarred(t, false);
427 * Bar a level crossing.
428 * @param t The tile to change.
430 static inline void BarCrossing(TileIndex t)
432 SetCrossingBarred(t, true);
437 * Make a level crossing.
438 * @param t Tile to make a level crossing.
439 * @param road New owner of road.
440 * @param tram New owner of tram tracks.
441 * @param rail New owner of the rail track.
442 * @param roaddir Axis of the road.
443 * @param rat New rail type.
444 * @param rot New present road types.
445 * @param town Town ID if the road is a town-owned road.
447 static inline void MakeRoadCrossing(TileIndex t, Owner road, Owner tram, Owner rail, Axis roaddir, RailType rat, RoadTypes rot, uint town)
449 tile_make_crossing(&_mc[t], rail, road, tram, roaddir, rat, rot, town);
452 #endif /* MAP_ROAD_H */