tron@3069: /* $Id$ */ tron@3069: tron@3145: #ifndef ROAD_MAP_H tron@3145: #define ROAD_MAP_H tron@3069: tron@3069: #include "macros.h" tron@3099: #include "rail.h" tron@3099: #include "tile.h" tron@3069: tron@3069: typedef enum RoadBits { tron@3069: ROAD_NW = 1, tron@3069: ROAD_SW = 2, tron@3069: ROAD_SE = 4, tron@3069: ROAD_NE = 8, tron@3069: ROAD_X = ROAD_SW | ROAD_NE, tron@3069: ROAD_Y = ROAD_NW | ROAD_SE, tron@3069: ROAD_ALL = ROAD_X | ROAD_Y tron@3069: } RoadBits; tron@3069: tron@3103: static inline RoadBits ComplementRoadBits(RoadBits r) tron@3103: { tron@3103: return ROAD_ALL ^ r; tron@3103: } tron@3103: tron@3146: static inline RoadBits DiagDirToRoadBits(DiagDirection d) tron@3146: { tron@3146: return 1 << (3 ^ d); tron@3146: } tron@3146: tron@3146: tron@3369: typedef enum RoadType { tron@3369: ROAD_NORMAL, tron@3369: ROAD_CROSSING, tron@3369: ROAD_DEPOT tron@3369: } RoadType; tron@3369: tron@3369: static inline RoadType GetRoadType(TileIndex t) tron@3069: { tron@3369: assert(IsTileType(t, MP_STREET)); tron@3369: return GB(_m[t].m5, 4, 4); tron@3150: } tron@3150: tron@3150: tron@3369: static inline RoadBits GetRoadBits(TileIndex t) tron@3272: { tron@3369: assert(GetRoadType(t) == ROAD_NORMAL); tron@3369: return GB(_m[t].m5, 0, 4); tron@3369: } tron@3369: tron@3369: static inline void SetRoadBits(TileIndex t, RoadBits r) tron@3369: { tron@3369: assert(GetRoadType(t) == ROAD_NORMAL); // XXX incomplete tron@3369: SB(_m[t].m5, 0, 4, r); tron@3369: } tron@3369: tron@3369: tron@3369: static inline Axis GetCrossingRoadAxis(TileIndex t) tron@3369: { tron@3369: assert(GetRoadType(t) == ROAD_CROSSING); tron@3369: return (Axis)GB(_m[t].m5, 3, 1); tron@3272: } tron@3272: tron@3070: static inline RoadBits GetCrossingRoadBits(TileIndex tile) tron@3070: { tron@3272: return GetCrossingRoadAxis(tile) == AXIS_X ? ROAD_X : ROAD_Y; tron@3070: } tron@3070: tron@3103: static inline TrackBits GetCrossingRailBits(TileIndex tile) tron@3103: { tron@3272: return GetCrossingRoadAxis(tile) == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X; tron@3103: } tron@3103: tron@3103: tron@3274: // TODO swap owner of road and rail tron@3274: static inline Owner GetCrossingRoadOwner(TileIndex t) tron@3274: { tron@3369: assert(GetRoadType(t) == ROAD_CROSSING); tron@3274: return (Owner)_m[t].m3; tron@3274: } tron@3274: tron@3274: static inline void SetCrossingRoadOwner(TileIndex t, Owner o) tron@3274: { tron@3369: assert(GetRoadType(t) == ROAD_CROSSING); tron@3274: _m[t].m3 = o; tron@3274: } tron@3274: celestar@3322: static inline void UnbarCrossing(TileIndex t) celestar@3322: { tron@3369: assert(GetRoadType(t) == ROAD_CROSSING); celestar@3322: CLRBIT(_m[t].m5, 2); celestar@3322: } celestar@3322: celestar@3322: static inline void BarCrossing(TileIndex t) celestar@3322: { tron@3369: assert(GetRoadType(t) == ROAD_CROSSING); celestar@3322: SETBIT(_m[t].m5, 2); celestar@3322: } celestar@3322: celestar@3322: static inline bool IsCrossingBarred(TileIndex t) celestar@3322: { tron@3369: assert(GetRoadType(t) == ROAD_CROSSING); celestar@3322: return HASBIT(_m[t].m5, 2); celestar@3322: } tron@3274: tron@3069: tron@3369: static inline DiagDirection GetRoadDepotDirection(TileIndex t) tron@3069: { tron@3369: assert(GetRoadType(t) == ROAD_DEPOT); tron@3369: return (DiagDirection)GB(_m[t].m5, 0, 2); tron@3167: } tron@3167: tron@3167: tron@3146: /** tron@3146: * Returns the RoadBits on an arbitrary tile tron@3146: * Special behavior: tron@3146: * - road depots: entrance is treated as road piece tron@3146: * - road tunnels: entrance is treated as road piece tron@3196: * - bridge ramps: start of the ramp is treated as road piece tron@3146: * - bridge middle parts: bridge itself is ignored tron@3146: */ tron@3146: RoadBits GetAnyRoadBits(TileIndex); tron@3146: tron@3146: tron@3150: TrackBits GetAnyRoadTrackBits(TileIndex tile); tron@3150: tron@3150: tron@3099: static inline void MakeRoadNormal(TileIndex t, Owner owner, RoadBits bits, uint town) tron@3099: { tron@3099: SetTileType(t, MP_STREET); tron@3099: SetTileOwner(t, owner); tron@3099: _m[t].m2 = town; tron@3099: _m[t].m3 = 0; tron@3099: _m[t].m4 = 0 << 7 | 0 << 4 | 0; tron@3099: _m[t].m5 = ROAD_NORMAL << 4 | bits; tron@3099: } tron@3099: tron@3099: tron@3099: static inline void MakeRoadCrossing(TileIndex t, Owner road, Owner rail, Axis roaddir, RailType rt, uint town) tron@3099: { tron@3099: SetTileType(t, MP_STREET); tron@3099: SetTileOwner(t, rail); tron@3099: _m[t].m2 = town; tron@3099: _m[t].m3 = road; tron@3099: _m[t].m4 = 0 << 7 | 0 << 4 | rt; tron@3099: _m[t].m5 = ROAD_CROSSING << 4 | roaddir << 3 | 0 << 2; tron@3099: } tron@3099: tron@3099: tron@3099: static inline void MakeRoadDepot(TileIndex t, Owner owner, DiagDirection dir) tron@3099: { tron@3099: SetTileType(t, MP_STREET); tron@3099: SetTileOwner(t, owner); tron@3099: _m[t].m2 = 0; tron@3099: _m[t].m3 = 0; tron@3099: _m[t].m4 = 0; tron@3099: _m[t].m5 = ROAD_DEPOT << 4 | dir; tron@3099: } tron@3099: tron@3069: #endif