diff --git a/src/road_map.h b/src/road_map.h index ca233ad..e456466 100644 --- a/src/road_map.h +++ b/src/road_map.h @@ -159,38 +159,6 @@ static inline void SetRoadBits(TileIndex t, RoadBits r, RoadType rt) } /** - * Get the present road types of a tile. - * @param t The tile to query. - * @return Present road types. - */ -static inline RoadTypes GetRoadTypes(TileIndex t) -{ - return (RoadTypes)GB(_me[t].m7, 6, 2); -} - -/** - * Set the present road types of a tile. - * @param t The tile to change. - * @param rt The new road types. - */ -static inline void SetRoadTypes(TileIndex t, RoadTypes rt) -{ - assert(IsTileType(t, MP_ROAD) || IsTileType(t, MP_STATION) || IsTileType(t, MP_TUNNELBRIDGE)); - SB(_me[t].m7, 6, 2, rt); -} - -/** - * Check if a tile has a specific road type. - * @param t The tile to check. - * @param rt Road type to check. - * @return True if the tile has the specified road type. - */ -static inline bool HasTileRoadType(TileIndex t, RoadType rt) -{ - return HasBit(GetRoadTypes(t), rt); -} - -/** * Get the owner of a specific road type. * @param t The tile to query. * @param rt The road type to get the owner of. @@ -565,24 +533,8 @@ struct RoadTypeIdentifiers { assert(IsTileType(t, MP_ROAD) || IsTileType(t, MP_STATION) || IsTileType(t, MP_TUNNELBRIDGE)); RoadTypeIdentifiers rtids; - - switch (GetTileType(t)) { - default: NOT_REACHED(); - case MP_ROAD: - if (HasTileRoadType(t, ROADTYPE_ROAD)) { - rtids.road_identifier = GetRoadTypeRoad(t); - } - - if (HasTileRoadType(t, ROADTYPE_TRAM)) { - rtids.tram_identifier = GetRoadTypeTram(t); - } - break; - case MP_STATION: /* TODO */ - case MP_TUNNELBRIDGE: - rtids.road_identifier = GetRoadTypeRoad(t); - rtids.tram_identifier = GetRoadTypeTram(t); - break; - } + rtids.road_identifier = GetRoadTypeRoad(t); + rtids.tram_identifier = GetRoadTypeTram(t); return rtids; } @@ -714,15 +666,8 @@ static inline RoadTypeIdentifiers CombineTileRoadTypeIds(TileIndex tile, RoadTyp */ static inline void SetRoadTypes(TileIndex t, RoadTypeIdentifiers rtids) { - SetRoadTypes(t, rtids.PresentRoadTypes()); - - if (rtids.road_identifier.IsValid()) { - SB(_m[t].m4, 0, 4, rtids.road_identifier.subtype); - } - - if (rtids.tram_identifier.IsValid()) { - SB(_m[t].m4, 4, 4, rtids.tram_identifier.subtype); - } + SB(_m[t].m4, 0, 4, rtids.road_identifier.subtype); + SB(_m[t].m4, 4, 4, rtids.tram_identifier.subtype); } static inline bool HasRoadTypeRoad(TileIndex t) @@ -764,16 +709,17 @@ static inline bool HasRoadTypeTram(RoadTypeIdentifiers rtids) * @param road New owner of road. * @param tram New owner of tram tracks. */ -static inline void MakeRoadNormal(TileIndex t, RoadBits bits, RoadTypes rot, TownID town, Owner road, Owner tram) +static inline void MakeRoadNormal(TileIndex t, RoadBits bits, RoadTypeIdentifier rtid, TownID town, Owner road, Owner tram) { SetTileType(t, MP_ROAD); SetTileOwner(t, road); _m[t].m2 = town; - _m[t].m3 = (HasBit(rot, ROADTYPE_TRAM) ? bits : 0); + _m[t].m3 = rtid.IsTram() ? bits : 0); _m[t].m4 = 0; - _m[t].m5 = (HasBit(rot, ROADTYPE_ROAD) ? bits : 0) | ROAD_TILE_NORMAL << 6; + _m[t].m5 = (rtid.IsRoad() ? bits : 0) | ROAD_TILE_NORMAL << 6; SB(_me[t].m6, 2, 4, 0); - _me[t].m7 = rot << 6; + _me[t].m7 = 0; + SetRoadTypes(RoadTypeIdentifiers::FromRoadTypeIdentifier(rtid)); SetRoadOwner(t, ROADTYPE_TRAM, tram); } @@ -788,7 +734,7 @@ static inline void MakeRoadNormal(TileIndex t, RoadBits bits, RoadTypes rot, Tow * @param rot New present road types. * @param town Town ID if the road is a town-owned road. */ -static inline void MakeRoadCrossing(TileIndex t, Owner road, Owner tram, Owner rail, Axis roaddir, RailType rat, RoadTypes rot, uint town) +static inline void MakeRoadCrossing(TileIndex t, Owner road, Owner tram, Owner rail, Axis roaddir, RailType rat, RoadTypeIdentifier rtid, uint town) { SetTileType(t, MP_ROAD); SetTileOwner(t, rail); @@ -797,7 +743,8 @@ static inline void MakeRoadCrossing(TileIndex t, Owner road, Owner tram, Owner r _m[t].m4 = 0; _m[t].m5 = ROAD_TILE_CROSSING << 6 | roaddir; SB(_me[t].m6, 2, 4, 0); - _me[t].m7 = rot << 6 | road; + _me[t].m7 = road; + SetRoadTypes(RoadTypeIdentifiers::FromRoadTypeIdentifier(rtid)); SetRoadOwner(t, ROADTYPE_TRAM, tram); } @@ -818,7 +765,7 @@ static inline void MakeRoadDepot(TileIndex t, Owner owner, DepotID did, DiagDire _m[t].m4 = 0; _m[t].m5 = ROAD_TILE_DEPOT << 6 | dir; SB(_me[t].m6, 2, 4, 0); - _me[t].m7 = RoadTypeToRoadTypes(rtid.basetype) << 6 | owner; + _me[t].m7 = owner; SetRoadOwner(t, ROADTYPE_TRAM, owner); SetRoadTypes(t, RoadTypeIdentifiers::FromRoadTypeIdentifier(rtid)); } @@ -838,11 +785,11 @@ static inline void MakeRoadNormal(TileIndex t, RoadBits bits, RoadTypeIdentifier SetTileOwner(t, road); _m[t].m2 = town; _m[t].m3 = (rtid.basetype == ROADTYPE_TRAM ? bits : 0); - SetRoadTypes(t, RoadTypeIdentifiers::FromRoadTypeIdentifier(rtid)); _m[t].m5 = (rtid.basetype == ROADTYPE_ROAD ? bits : 0) | ROAD_TILE_NORMAL << 6; SB(_me[t].m6, 2, 4, 0); - _me[t].m7 = RoadTypeToRoadTypes(rtid.basetype) << 6; + _me[t].m7 = 0; SetRoadOwner(t, ROADTYPE_TRAM, tram); + SetRoadTypes(t, RoadTypeIdentifiers::FromRoadTypeIdentifier(rtid)); } #endif /* ROAD_MAP_H */