1 /* $Id: road_map.h 23595 2011-12-19 17:48:04Z rubidium $ */
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/>.
10 /** @file road_map.h Map accessors for roads. */
15 #include "track_func.h"
16 #include "depot_type.h"
17 #include "rail_type.h"
18 #include "road_func.h"
22 /** The different types of road tiles. */
24 ROAD_TILE_NORMAL
, ///< Normal road
25 ROAD_TILE_CROSSING
, ///< Level crossing
26 ROAD_TILE_DEPOT
, ///< Depot (one entrance)
30 * Test whether a tile can have road/tram subtypes.
31 * @param t Tile to query.
32 * @return true if tile can be queried about road/tram subtypes.
34 static inline bool MayHaveRoad(TileIndex t
)
36 switch (GetTileType(t
)) {
48 * Get the type of the road tile.
49 * @param t Tile to query.
50 * @pre IsTileType(t, MP_ROAD)
51 * @return The road tile type.
53 static inline RoadTileType
GetRoadTileType(TileIndex t
)
55 assert(IsTileType(t
, MP_ROAD
));
56 return (RoadTileType
)GB(_m
[t
].m5
, 6, 2);
60 * Return whether a tile is a normal road.
61 * @param t Tile to query.
62 * @pre IsTileType(t, MP_ROAD)
63 * @return True if normal road.
65 static inline bool IsNormalRoad(TileIndex t
)
67 return GetRoadTileType(t
) == ROAD_TILE_NORMAL
;
71 * Return whether a tile is a normal road tile.
72 * @param t Tile to query.
73 * @return True if normal road tile.
75 static inline bool IsNormalRoadTile(TileIndex t
)
77 return IsTileType(t
, MP_ROAD
) && IsNormalRoad(t
);
81 * Return whether a tile is a level crossing.
82 * @param t Tile to query.
83 * @pre IsTileType(t, MP_ROAD)
84 * @return True if level crossing.
86 static inline bool IsLevelCrossing(TileIndex t
)
88 return GetRoadTileType(t
) == ROAD_TILE_CROSSING
;
92 * Return whether a tile is a level crossing tile.
93 * @param t Tile to query.
94 * @return True if level crossing tile.
96 static inline bool IsLevelCrossingTile(TileIndex t
)
98 return IsTileType(t
, MP_ROAD
) && IsLevelCrossing(t
);
102 * Return whether a tile is a road depot.
103 * @param t Tile to query.
104 * @pre IsTileType(t, MP_ROAD)
105 * @return True if road depot.
107 static inline bool IsRoadDepot(TileIndex t
)
109 return GetRoadTileType(t
) == ROAD_TILE_DEPOT
;
113 * Return whether a tile is a road depot tile.
114 * @param t Tile to query.
115 * @return True if road depot tile.
117 static inline bool IsRoadDepotTile(TileIndex t
)
119 return IsTileType(t
, MP_ROAD
) && IsRoadDepot(t
);
123 * Get the present road bits for a specific road type.
124 * @param t The tile to query.
125 * @param rt Road type.
126 * @pre IsNormalRoad(t)
127 * @return The present road bits for the road type.
129 static inline RoadBits
GetRoadBits(TileIndex t
, RoadType rt
)
131 assert(IsNormalRoad(t
));
133 default: NOT_REACHED();
134 case ROADTYPE_ROAD
: return (RoadBits
)GB(_m
[t
].m5
, 0, 4);
135 case ROADTYPE_TRAM
: return (RoadBits
)GB(_m
[t
].m3
, 0, 4);
140 * Get all RoadBits set on a tile except from the given RoadType
142 * @param t The tile from which we want to get the RoadBits
143 * @param rt The RoadType which we exclude from the querry
144 * @return all set RoadBits of the tile which are not from the given RoadType
146 static inline RoadBits
GetOtherRoadBits(TileIndex t
, RoadType rt
)
148 return GetRoadBits(t
, rt
== ROADTYPE_ROAD
? ROADTYPE_TRAM
: ROADTYPE_ROAD
);
152 * Get all set RoadBits on the given tile
154 * @param tile The tile from which we want to get the RoadBits
155 * @return all set RoadBits of the tile
157 static inline RoadBits
GetAllRoadBits(TileIndex tile
)
159 return GetRoadBits(tile
, ROADTYPE_ROAD
) | GetRoadBits(tile
, ROADTYPE_TRAM
);
163 * Set the present road bits for a specific road type.
164 * @param t The tile to change.
165 * @param r The new road bits.
166 * @param rt Road type.
167 * @pre IsNormalRoad(t)
169 static inline void SetRoadBits(TileIndex t
, RoadBits r
, RoadType rt
)
171 assert(IsNormalRoad(t
)); // XXX incomplete
173 default: NOT_REACHED();
174 case ROADTYPE_ROAD
: SB(_m
[t
].m5
, 0, 4, r
); break;
175 case ROADTYPE_TRAM
: SB(_m
[t
].m3
, 0, 4, r
); break;
179 static inline RoadSubType
GetRoadSubTypeRoad(TileIndex t
)
181 assert(MayHaveRoad(t
));
183 return static_cast<RoadSubType
>((GB(_me
[t
].m7
, 6, 1) << 4) | GB(_m
[t
].m4
, 0, 4));
186 static inline RoadSubType
GetRoadSubTypeTram(TileIndex t
)
188 assert(MayHaveRoad(t
));
190 return static_cast<RoadSubType
>((GB(_me
[t
].m7
, 7, 1) << 4) | GB(_m
[t
].m4
, 4, 4));
193 static inline RoadSubType
GetRoadSubType(TileIndex t
, RoadType rt
)
196 default: NOT_REACHED();
197 case ROADTYPE_ROAD
: return GetRoadSubTypeRoad(t
);
198 case ROADTYPE_TRAM
: return GetRoadSubTypeTram(t
);
202 static inline RoadTypeIdentifier
GetRoadTypeRoad(TileIndex t
)
204 return RoadTypeIdentifier(ROADTYPE_ROAD
, GetRoadSubTypeRoad(t
));
207 static inline RoadTypeIdentifier
GetRoadTypeTram(TileIndex t
)
209 return RoadTypeIdentifier(ROADTYPE_TRAM
, GetRoadSubTypeTram(t
));
212 static inline RoadTypeIdentifier
GetRoadType(TileIndex t
, RoadType rt
)
214 return RoadTypeIdentifier(rt
, GetRoadSubType(t
, rt
));
218 * Get the present road types of a tile.
219 * @param t The tile to query.
220 * @return Present road types.
222 static inline RoadTypes
GetRoadTypes(TileIndex t
)
224 RoadTypes result
= ROADTYPES_NONE
;
225 if (MayHaveRoad(t
)) {
226 if (GetRoadSubTypeRoad(t
) != INVALID_ROADSUBTYPE
) result
|= ROADTYPES_ROAD
;
227 if (GetRoadSubTypeTram(t
) != INVALID_ROADSUBTYPE
) result
|= ROADTYPES_TRAM
;
232 static inline bool HasRoadTypeRoad(TileIndex t
)
234 return GetRoadSubTypeRoad(t
) != INVALID_ROADSUBTYPE
;
237 static inline bool HasRoadTypeTram(TileIndex t
)
239 return GetRoadSubTypeTram(t
) != INVALID_ROADSUBTYPE
;
243 * Check if a tile has a specific road type.
244 * @param t The tile to check.
245 * @param rt Road type to check.
246 * @return True if the tile has the specified road type.
248 static inline bool HasTileRoadType(TileIndex t
, RoadType rt
)
250 const RoadSubType sub_type
= GetRoadSubType(t
, rt
);
252 return sub_type
!= INVALID_ROADSUBTYPE
;
256 * Check if a tile has one of the specified road subtypes.
257 * @param t The tile to check.
258 * @param rt Road type to check.
259 * @param rst Allowed road subtypes.
260 * @return True if the tile has one of the specified road subtypes.
262 static inline bool HasTileAnyRoadSubType(TileIndex t
, RoadType rt
, RoadSubTypes rst
)
264 if (!MayHaveRoad(t
)) return false;
265 RoadSubType st
= GetRoadSubType(t
, rt
) ;
266 return st
!= INVALID_ROADSUBTYPE
&& HasBit(rst
, st
);
270 * Get the owner of a specific road type.
271 * @param t The tile to query.
272 * @param rt The road type to get the owner of.
273 * @return Owner of the given road type.
275 static inline Owner
GetRoadOwner(TileIndex t
, RoadType rt
)
277 assert(MayHaveRoad(t
));
279 default: NOT_REACHED();
280 case ROADTYPE_ROAD
: return (Owner
)GB(IsNormalRoadTile(t
) ? _m
[t
].m1
: _me
[t
].m7
, 0, 5);
281 case ROADTYPE_TRAM
: {
282 /* Trams don't need OWNER_TOWN, and remapping OWNER_NONE
283 * to OWNER_TOWN makes it use one bit less */
284 Owner o
= (Owner
)GB(_m
[t
].m3
, 4, 4);
285 return o
== OWNER_TOWN
? OWNER_NONE
: o
;
291 * Set the owner of a specific road type.
292 * @param t The tile to change.
293 * @param rt The road type to change the owner of.
294 * @param o New owner of the given road type.
296 static inline void SetRoadOwner(TileIndex t
, RoadType rt
, Owner o
)
299 default: NOT_REACHED();
300 case ROADTYPE_ROAD
: SB(IsNormalRoadTile(t
) ? _m
[t
].m1
: _me
[t
].m7
, 0, 5, o
); break;
301 case ROADTYPE_TRAM
: SB(_m
[t
].m3
, 4, 4, o
== OWNER_NONE
? OWNER_TOWN
: o
); break;
306 * Check if a specific road type is owned by an owner.
307 * @param t The tile to query.
308 * @param rt The road type to compare the owner of.
309 * @param o Owner to compare with.
310 * @pre HasTileRoadType(t, rt)
311 * @return True if the road type is owned by the given owner.
313 static inline bool IsRoadOwner(TileIndex t
, RoadType rt
, Owner o
)
315 assert(HasTileRoadType(t
, rt
));
316 return (GetRoadOwner(t
, rt
) == o
);
320 * Checks if given tile has town owned road
321 * @param t tile to check
322 * @pre IsTileType(t, MP_ROAD)
323 * @return true iff tile has road and the road is owned by a town
325 static inline bool HasTownOwnedRoad(TileIndex t
)
327 return HasTileRoadType(t
, ROADTYPE_ROAD
) && IsRoadOwner(t
, ROADTYPE_ROAD
, OWNER_TOWN
);
330 /** Which directions are disallowed ? */
331 enum DisallowedRoadDirections
{
332 DRD_NONE
, ///< None of the directions are disallowed
333 DRD_SOUTHBOUND
, ///< All southbound traffic is disallowed
334 DRD_NORTHBOUND
, ///< All northbound traffic is disallowed
335 DRD_BOTH
, ///< All directions are disallowed
336 DRD_END
, ///< Sentinel
338 DECLARE_ENUM_AS_BIT_SET(DisallowedRoadDirections
)
339 /** Helper information for extract tool. */
340 template <> struct EnumPropsT
<DisallowedRoadDirections
> : MakeEnumPropsT
<DisallowedRoadDirections
, byte
, DRD_NONE
, DRD_END
, DRD_END
, 2> {};
343 * Gets the disallowed directions
344 * @param t the tile to get the directions from
345 * @return the disallowed directions
347 static inline DisallowedRoadDirections
GetDisallowedRoadDirections(TileIndex t
)
349 assert(IsNormalRoad(t
));
350 return (DisallowedRoadDirections
)GB(_m
[t
].m5
, 4, 2);
354 * Sets the disallowed directions
355 * @param t the tile to set the directions for
356 * @param drd the disallowed directions
358 static inline void SetDisallowedRoadDirections(TileIndex t
, DisallowedRoadDirections drd
)
360 assert(IsNormalRoad(t
));
361 assert(drd
< DRD_END
);
362 SB(_m
[t
].m5
, 4, 2, drd
);
366 * Get the road axis of a level crossing.
367 * @param t The tile to query.
368 * @pre IsLevelCrossing(t)
369 * @return The axis of the road.
371 static inline Axis
GetCrossingRoadAxis(TileIndex t
)
373 assert(IsLevelCrossing(t
));
374 return (Axis
)GB(_m
[t
].m5
, 0, 1);
378 * Get the rail axis of a level crossing.
379 * @param t The tile to query.
380 * @pre IsLevelCrossing(t)
381 * @return The axis of the rail.
383 static inline Axis
GetCrossingRailAxis(TileIndex t
)
385 assert(IsLevelCrossing(t
));
386 return OtherAxis((Axis
)GetCrossingRoadAxis(t
));
390 * Get the road bits of a level crossing.
391 * @param tile The tile to query.
392 * @return The present road bits.
394 static inline RoadBits
GetCrossingRoadBits(TileIndex tile
)
396 return GetCrossingRoadAxis(tile
) == AXIS_X
? ROAD_X
: ROAD_Y
;
400 * Get the rail track of a level crossing.
401 * @param tile The tile to query.
402 * @return The rail track.
404 static inline Track
GetCrossingRailTrack(TileIndex tile
)
406 return AxisToTrack(GetCrossingRailAxis(tile
));
410 * Get the rail track bits of a level crossing.
411 * @param tile The tile to query.
412 * @return The rail track bits.
414 static inline TrackBits
GetCrossingRailBits(TileIndex tile
)
416 return AxisToTrackBits(GetCrossingRailAxis(tile
));
421 * Get the reservation state of the rail crossing
422 * @param t the crossing tile
423 * @return reservation state
424 * @pre IsLevelCrossingTile(t)
426 static inline bool HasCrossingReservation(TileIndex t
)
428 assert(IsLevelCrossingTile(t
));
429 return HasBit(_m
[t
].m5
, 4);
433 * Set the reservation state of the rail crossing
434 * @note Works for both waypoints and rail depots
435 * @param t the crossing tile
436 * @param b the reservation state
437 * @pre IsLevelCrossingTile(t)
439 static inline void SetCrossingReservation(TileIndex t
, bool b
)
441 assert(IsLevelCrossingTile(t
));
442 SB(_m
[t
].m5
, 4, 1, b
? 1 : 0);
446 * Get the reserved track bits for a rail crossing
448 * @pre IsLevelCrossingTile(t)
449 * @return reserved track bits
451 static inline TrackBits
GetCrossingReservationTrackBits(TileIndex t
)
453 return HasCrossingReservation(t
) ? GetCrossingRailBits(t
) : TRACK_BIT_NONE
;
457 * Check if the level crossing is barred.
458 * @param t The tile to query.
459 * @pre IsLevelCrossing(t)
460 * @return True if the level crossing is barred.
462 static inline bool IsCrossingBarred(TileIndex t
)
464 assert(IsLevelCrossing(t
));
465 return HasBit(_m
[t
].m5
, 5);
469 * Set the bar state of a level crossing.
470 * @param t The tile to modify.
471 * @param barred True if the crossing should be barred, false otherwise.
472 * @pre IsLevelCrossing(t)
474 static inline void SetCrossingBarred(TileIndex t
, bool barred
)
476 assert(IsLevelCrossing(t
));
477 SB(_m
[t
].m5
, 5, 1, barred
? 1 : 0);
481 * Unbar a level crossing.
482 * @param t The tile to change.
484 static inline void UnbarCrossing(TileIndex t
)
486 SetCrossingBarred(t
, false);
490 * Bar a level crossing.
491 * @param t The tile to change.
493 static inline void BarCrossing(TileIndex t
)
495 SetCrossingBarred(t
, true);
498 /** Check if a road tile has snow/desert. */
499 #define IsOnDesert IsOnSnow
501 * Check if a road tile has snow/desert.
502 * @param t The tile to query.
503 * @return True if the tile has snow/desert.
505 static inline bool IsOnSnow(TileIndex t
)
507 return HasBit(_me
[t
].m7
, 5);
510 /** Toggle the snow/desert state of a road tile. */
511 #define ToggleDesert ToggleSnow
513 * Toggle the snow/desert state of a road tile.
514 * @param t The tile to change.
516 static inline void ToggleSnow(TileIndex t
)
518 ToggleBit(_me
[t
].m7
, 5);
522 /** The possible road side decorations. */
524 ROADSIDE_BARREN
= 0, ///< Road on barren land
525 ROADSIDE_GRASS
= 1, ///< Road on grass
526 ROADSIDE_PAVED
= 2, ///< Road with paved sidewalks
527 ROADSIDE_STREET_LIGHTS
= 3, ///< Road with street lights on paved sidewalks
528 ROADSIDE_TREES
= 5, ///< Road with trees on paved sidewalks
529 ROADSIDE_GRASS_ROAD_WORKS
= 6, ///< Road on grass with road works
530 ROADSIDE_PAVED_ROAD_WORKS
= 7, ///< Road with sidewalks and road works
534 * Get the decorations of a road.
535 * @param tile The tile to query.
536 * @return The road decoration of the tile.
538 static inline Roadside
GetRoadside(TileIndex tile
)
540 return (Roadside
)GB(_me
[tile
].m6
, 3, 3);
544 * Set the decorations of a road.
545 * @param tile The tile to change.
546 * @param s The new road decoration of the tile.
548 static inline void SetRoadside(TileIndex tile
, Roadside s
)
550 SB(_me
[tile
].m6
, 3, 3, s
);
554 * Check if a tile has road works.
555 * @param t The tile to check.
556 * @return True if the tile has road works in progress.
558 static inline bool HasRoadWorks(TileIndex t
)
560 return GetRoadside(t
) >= ROADSIDE_GRASS_ROAD_WORKS
;
564 * Increase the progress counter of road works.
565 * @param t The tile to modify.
566 * @return True if the road works are in the last stage.
568 static inline bool IncreaseRoadWorksCounter(TileIndex t
)
570 AB(_me
[t
].m7
, 0, 4, 1);
572 return GB(_me
[t
].m7
, 0, 4) == 15;
576 * Start road works on a tile.
577 * @param t The tile to start the work on.
578 * @pre !HasRoadWorks(t)
580 static inline void StartRoadWorks(TileIndex t
)
582 assert(!HasRoadWorks(t
));
583 /* Remove any trees or lamps in case or roadwork */
584 switch (GetRoadside(t
)) {
585 case ROADSIDE_BARREN
:
586 case ROADSIDE_GRASS
: SetRoadside(t
, ROADSIDE_GRASS_ROAD_WORKS
); break;
587 default: SetRoadside(t
, ROADSIDE_PAVED_ROAD_WORKS
); break;
592 * Terminate road works on a tile.
593 * @param t Tile to stop the road works on.
594 * @pre HasRoadWorks(t)
596 static inline void TerminateRoadWorks(TileIndex t
)
598 assert(HasRoadWorks(t
));
599 SetRoadside(t
, (Roadside
)(GetRoadside(t
) - ROADSIDE_GRASS_ROAD_WORKS
+ ROADSIDE_GRASS
));
600 /* Stop the counter */
601 SB(_me
[t
].m7
, 0, 4, 0);
606 * Get the direction of the exit of a road depot.
607 * @param t The tile to query.
608 * @return Diagonal direction of the depot exit.
610 static inline DiagDirection
GetRoadDepotDirection(TileIndex t
)
612 assert(IsRoadDepot(t
));
613 return (DiagDirection
)GB(_m
[t
].m5
, 0, 2);
617 RoadBits
GetAnyRoadBits(TileIndex tile
, RoadType rt
, bool straight_tunnel_bridge_entrance
= false);
619 struct RoadTypeIdentifiers
{
620 RoadTypeIdentifier road_identifier
;
621 RoadTypeIdentifier tram_identifier
;
623 /** Creates an INVALID RoadTypeIdentifiers */
624 RoadTypeIdentifiers() {}
627 * Extracts the RoadTypeIdentifiers from the given tile
628 * @param tile The tile to read the informations from
630 static RoadTypeIdentifiers
FromTile(TileIndex t
)
632 assert(MayHaveRoad(t
));
634 RoadTypeIdentifiers rtids
;
635 rtids
.road_identifier
= GetRoadTypeRoad(t
);
636 rtids
.tram_identifier
= GetRoadTypeTram(t
);
642 * Converts a RoadTypeIdentifier into a RoadTypeIdentifiers
643 * @param rtid The RoadTypeIdentifier to convert
645 static RoadTypeIdentifiers
FromRoadTypeIdentifier(RoadTypeIdentifier rtid
)
647 RoadTypeIdentifiers rtids
;
649 switch (rtid
.basetype
) {
650 default: NOT_REACHED();
651 case ROADTYPE_ROAD
: rtids
.road_identifier
= rtid
; break;
652 case ROADTYPE_TRAM
: rtids
.tram_identifier
= rtid
; break;
659 * Creates a RoadTypeIdentifiers from two RoadTypeIdentifier
660 * The order of the identifier doesn't matter, but they must be of different
661 * base type (no ROAD + ROAD or TRAM + TRAM)
662 * @param rtid1 The first RoadTypeIdentifier
663 * @param rtid2 The second RoadTypeIdentifier
665 static RoadTypeIdentifiers
FromRoadTypeIdentifier(RoadTypeIdentifier rtid1
, RoadTypeIdentifier rtid2
)
667 assert(rtid1
.basetype
< ROADTYPE_END
);
668 assert(rtid2
.basetype
< ROADTYPE_END
);
670 /* We can't merge 2 road types of the same base type, not yet */
671 assert(rtid1
.basetype
!= rtid2
.basetype
);
673 RoadTypeIdentifiers rtids
;
675 /* As we are sure about the road types being different we can just check the first one */
676 switch (rtid1
.basetype
) {
677 default: NOT_REACHED();
679 rtids
.road_identifier
= rtid1
;
680 rtids
.tram_identifier
= rtid2
;
683 rtids
.road_identifier
= rtid2
;
684 rtids
.tram_identifier
= rtid1
;
692 * Returns the RoadTypes contained in the RoadTypeIdentifiers
693 * @return RoadTypes flags
695 RoadTypes
PresentRoadTypes() const
697 RoadTypes rot
= ROADTYPES_NONE
;
699 if (this->road_identifier
.IsValid()) {
700 rot
|= ROADTYPES_ROAD
;
703 if (this->tram_identifier
.IsValid()) {
704 rot
|= ROADTYPES_TRAM
;
710 RoadTypeIdentifier
GetType(RoadType rt
) const
713 default: NOT_REACHED();
714 case ROADTYPE_ROAD
: return this->road_identifier
;
715 case ROADTYPE_TRAM
: return this->tram_identifier
;
719 bool HasType(RoadType rt
) const
722 default: NOT_REACHED();
723 case ROADTYPE_ROAD
: return this->road_identifier
.IsValid();
724 case ROADTYPE_TRAM
: return this->tram_identifier
.IsValid();
730 return this->road_identifier
.IsValid();
735 return this->tram_identifier
.IsValid();
739 * Merge a new road type identifier into the current one.
740 * If the roadtype is already present, the new subtype replaces the old one.
741 * @param rtid The new RoadTypeIdentifier to merge into the current one
743 void MergeRoadType(RoadTypeIdentifier rtid
)
745 switch (rtid
.basetype
) {
746 default: NOT_REACHED();
747 case ROADTYPE_ROAD
: this->road_identifier
= rtid
; break;
748 case ROADTYPE_TRAM
: this->tram_identifier
= rtid
; break;
755 void ClearRoadType(RoadType rt
)
758 default: NOT_REACHED();
759 case ROADTYPE_ROAD
: this->road_identifier
= RoadTypeIdentifier(); break;
760 case ROADTYPE_TRAM
: this->tram_identifier
= RoadTypeIdentifier(); break;
765 #define FOR_EACH_SET_ROADTYPEIDENTIFIER(var, rtids) \
766 for (RoadType ___FESRTID = ROADTYPE_BEGIN; ___FESRTID < ROADTYPE_END; ___FESRTID++) \
767 if ((var = rtids.GetType(___FESRTID)).IsValid())
770 * Set the present road types of a tile.
771 * @param t The tile to change.
772 * @param rtids The new road types identifiers to set for the tile.
774 static inline void SetRoadTypes(TileIndex t
, RoadTypeIdentifiers rtids
)
776 assert(MayHaveRoad(t
));
778 SB(_m
[t
].m4
, 0, 4, GB(rtids
.road_identifier
.subtype
, 0, 4));
779 SB(_me
[t
].m7
, 6, 1, GB(rtids
.road_identifier
.subtype
, 4, 1));
781 SB(_m
[t
].m4
, 4, 4, GB(rtids
.tram_identifier
.subtype
, 0, 4));
782 SB(_me
[t
].m7
, 7, 1, GB(rtids
.tram_identifier
.subtype
, 4, 1));
786 * Make a normal road tile.
787 * @param t Tile to make a normal road.
788 * @param bits Road bits to set for all present road types.
789 * @param rtids New present road types.
790 * @param town Town ID if the road is a town-owned road.
791 * @param road New owner of road.
792 * @param tram New owner of tram tracks.
794 static inline void MakeRoadNormal(TileIndex t
, RoadBits bits
, RoadTypeIdentifiers rtids
, TownID town
, Owner road
, Owner tram
)
796 SetTileType(t
, MP_ROAD
);
797 SetTileOwner(t
, road
);
799 _m
[t
].m3
= (rtids
.HasTram() ? bits
: 0);
800 _m
[t
].m5
= (rtids
.HasRoad() ? bits
: 0) | ROAD_TILE_NORMAL
<< 6;
801 SB(_me
[t
].m6
, 2, 4, 0);
803 SetRoadTypes(t
, rtids
);
804 SetRoadOwner(t
, ROADTYPE_TRAM
, tram
);
808 * Make a level crossing.
809 * @param t Tile to make a level crossing.
810 * @param road New owner of road.
811 * @param tram New owner of tram tracks.
812 * @param rail New owner of the rail track.
813 * @param roaddir Axis of the road.
814 * @param rat New rail type.
815 * @param rtids New present road types.
816 * @param town Town ID if the road is a town-owned road.
818 static inline void MakeRoadCrossing(TileIndex t
, Owner road
, Owner tram
, Owner rail
, Axis roaddir
, RailType rat
, RoadTypeIdentifiers rtids
, uint town
)
820 SetTileType(t
, MP_ROAD
);
821 SetTileOwner(t
, rail
);
824 SB(_m
[t
].m1
, 7, 1, GB(rat
, 4, 1));
825 _m
[t
].m4
= INVALID_ROADTYPES
;
826 SB(_m
[t
].m3
, 0, 4, GB(rat
, 0, 4));
828 _m
[t
].m5
= ROAD_TILE_CROSSING
<< 6 | roaddir
;
829 SB(_me
[t
].m6
, 2, 4, 0);
831 SetRoadTypes(t
, rtids
);
832 SetRoadOwner(t
, ROADTYPE_TRAM
, tram
);
837 * @param t Tile to make a level crossing.
838 * @param owner New owner of the depot.
839 * @param did New depot ID.
840 * @param dir Direction of the depot exit.
841 * @param rtid Road type of the depot.
843 static inline void MakeRoadDepot(TileIndex t
, Owner owner
, DepotID did
, DiagDirection dir
, RoadTypeIdentifier rtid
)
845 SetTileType(t
, MP_ROAD
);
846 SetTileOwner(t
, owner
);
849 _m
[t
].m4
= INVALID_ROADTYPES
;
850 _m
[t
].m5
= ROAD_TILE_DEPOT
<< 6 | dir
;
851 SB(_me
[t
].m6
, 2, 4, 0);
853 SetRoadTypes(t
, RoadTypeIdentifiers::FromRoadTypeIdentifier(rtid
));
854 SetRoadOwner(t
, ROADTYPE_TRAM
, owner
);
857 #endif /* ROAD_MAP_H */