tron@3189: /* $Id$ */ tron@3189: tron@3189: #ifndef BRIDGE_MAP_H tron@3189: #define BRIDGE_MAP_H tron@3189: tron@3196: #include "direction.h" tron@3189: #include "macros.h" tron@3189: #include "map.h" tron@3189: #include "rail.h" tron@3234: #include "road_map.h" tron@3189: #include "tile.h" tron@3189: tron@3189: tron@3234: static inline bool IsBridge(TileIndex t) tron@3234: { tron@3369: assert(IsTileType(t, MP_TUNNELBRIDGE)); tron@3234: return HASBIT(_m[t].m5, 7); tron@3234: } tron@3234: tron@3234: static inline bool IsBridgeTile(TileIndex t) tron@3234: { tron@3234: return IsTileType(t, MP_TUNNELBRIDGE) && IsBridge(t); tron@3234: } tron@3234: tron@3234: tron@3977: static inline bool IsBridgeRamp(TileIndex t) tron@3214: { tron@3977: assert(IsBridgeTile(t)); tron@3977: return !HASBIT(_m[t].m5, 6); tron@3977: } tron@3977: tron@3977: static inline bool IsBridgeMiddle(TileIndex t) tron@3977: { tron@3977: assert(IsBridgeTile(t)); tron@3977: return HASBIT(_m[t].m5, 6); tron@3225: } tron@3225: tron@3225: tron@3977: /** tron@3977: * Determines which piece of a bridge is contained in the current tile tron@3977: * @param tile The tile to analyze tron@3977: * @return the piece tron@3977: */ tron@3977: static inline uint GetBridgePiece(TileIndex t) celestar@3933: { tron@3977: assert(IsBridgeMiddle(t)); tron@3977: return GB(_m[t].m2, 0, 4); tron@3231: } tron@3231: tron@3231: tron@3231: /** tron@3231: * Determines the type of bridge on a tile tron@3231: * @param tile The tile to analyze tron@3231: * @return The bridge type tron@3231: */ tron@3369: static inline uint GetBridgeType(TileIndex t) tron@3231: { tron@3369: assert(IsBridgeTile(t)); tron@3369: return GB(_m[t].m2, 4, 4); tron@3231: } tron@3231: tron@3214: tron@3196: /** tron@3196: * Get the direction pointing onto the bridge tron@3196: */ tron@3196: static inline DiagDirection GetBridgeRampDirection(TileIndex t) tron@3196: { tron@3977: assert(IsBridgeRamp(t)); tron@3953: return ReverseDiagDir(XYNSToDiagDir((Axis)GB(_m[t].m5, 0, 1), GB(_m[t].m5, 5, 1))); tron@3196: } tron@3196: tron@3196: tron@3225: static inline Axis GetBridgeAxis(TileIndex t) tron@3225: { tron@3977: assert(IsBridgeMiddle(t)); tron@3977: return (Axis)GB(_m[t].m5, 0, 1); tron@3225: } tron@3225: tron@3225: tron@3234: static inline TransportType GetBridgeTransportType(TileIndex t) tron@3234: { tron@3369: assert(IsBridgeTile(t)); tron@3234: return (TransportType)GB(_m[t].m5, 1, 2); tron@3234: } tron@3234: tron@3234: tron@3977: static inline bool IsClearUnderBridge(TileIndex t) tron@3977: { tron@3977: assert(IsBridgeMiddle(t)); tron@3977: return GB(_m[t].m5, 3, 3) == 0; tron@3977: } tron@3977: tron@3977: static inline bool IsWaterUnderBridge(TileIndex t) tron@3977: { tron@3977: assert(IsBridgeMiddle(t)); tron@3977: return GB(_m[t].m5, 3, 3) == 1; tron@3977: } tron@3977: tron@3977: tron@3977: static inline bool IsTransportUnderBridge(TileIndex t) tron@3977: { tron@3977: assert(IsBridgeMiddle(t)); tron@3977: return HASBIT(_m[t].m5, 5); tron@3977: } tron@3977: tron@3977: static inline TransportType GetTransportTypeUnderBridge(TileIndex t) tron@3977: { tron@3977: assert(IsTransportUnderBridge(t)); tron@3977: return (TransportType)GB(_m[t].m5, 3, 2); tron@3977: } tron@3977: tron@3977: static inline RoadBits GetRoadBitsUnderBridge(TileIndex t) tron@3977: { tron@3977: assert(GetTransportTypeUnderBridge(t) == TRANSPORT_ROAD); tron@3977: return GetBridgeAxis(t) == AXIS_X ? ROAD_Y : ROAD_X; tron@3977: } tron@3977: tron@3977: static inline TrackBits GetRailBitsUnderBridge(TileIndex t) tron@3977: { tron@3977: assert(GetTransportTypeUnderBridge(t) == TRANSPORT_RAIL); tron@3977: return GetBridgeAxis(t) == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X; tron@3977: } tron@3977: tron@3977: tron@3214: /** tron@3225: * Finds the end of a bridge in the specified direction starting at a middle tile tron@3225: */ tron@3225: TileIndex GetBridgeEnd(TileIndex, DiagDirection); tron@3225: tron@3225: /** tron@3225: * Finds the southern end of a bridge starting at a middle tile tron@3225: */ tron@3225: TileIndex GetSouthernBridgeEnd(TileIndex t); tron@3225: tron@3225: tron@3225: /** tron@3214: * Starting at one bridge end finds the other bridge end tron@3214: */ tron@3214: TileIndex GetOtherBridgeEnd(TileIndex); tron@3214: tron@3977: uint GetBridgeHeight(TileIndex t); tron@3214: tron@3977: static inline void SetClearUnderBridge(TileIndex t) tron@3189: { tron@3977: assert(IsBridgeMiddle(t)); tron@3977: SetTileOwner(t, OWNER_NONE); tron@3977: SB(_m[t].m5, 3, 3, 0 << 2 | 0); tron@3977: SB(_m[t].m3, 0, 4, 0); tron@3189: } tron@3189: tron@3977: static inline void SetWaterUnderBridge(TileIndex t) tron@3189: { tron@3977: assert(IsBridgeMiddle(t)); tron@3977: SetTileOwner(t, OWNER_WATER); tron@3977: SB(_m[t].m5, 3, 3, 0 << 2 | 1); tron@3977: SB(_m[t].m3, 0, 4, 0); tron@3189: } tron@3189: tron@3977: static inline void SetCanalUnderBridge(TileIndex t, Owner o) tron@3189: { tron@3977: assert(IsBridgeMiddle(t)); tron@3977: SetTileOwner(t, o); tron@3977: SB(_m[t].m5, 3, 3, 0 << 2 | 1); tron@3977: SB(_m[t].m3, 0, 4, 0); tron@3977: } tron@3977: tron@3977: static inline void SetRailUnderBridge(TileIndex t, Owner o, RailType r) tron@3977: { tron@3977: assert(IsBridgeMiddle(t)); tron@3977: SetTileOwner(t, o); tron@3977: SB(_m[t].m5, 3, 3, 1 << 2 | TRANSPORT_RAIL); tron@3977: SB(_m[t].m3, 0, 4, r); tron@3977: } tron@3977: tron@3977: static inline void SetRoadUnderBridge(TileIndex t, Owner o) tron@3977: { tron@3977: assert(IsBridgeMiddle(t)); tron@3977: SetTileOwner(t, o); tron@3977: SB(_m[t].m5, 3, 3, 1 << 2 | TRANSPORT_ROAD); tron@3977: SB(_m[t].m3, 0, 4, 0); tron@3189: } tron@3189: tron@3209: tron@3209: static inline void MakeBridgeRamp(TileIndex t, Owner o, uint bridgetype, DiagDirection d, TransportType tt) tron@3209: { tron@3209: uint northsouth = (d == DIAGDIR_NE || d == DIAGDIR_NW); tron@3209: tron@3209: SetTileType(t, MP_TUNNELBRIDGE); tron@3209: SetTileOwner(t, o); tron@3209: _m[t].m2 = bridgetype << 4; tron@3209: _m[t].m4 = 0; tron@3209: _m[t].m5 = 1 << 7 | 0 << 6 | northsouth << 5 | tt << 1 | DiagDirToAxis(d); tron@3209: } tron@3209: tron@3209: static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, uint bridgetype, DiagDirection d) tron@3209: { tron@3209: MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_ROAD); tron@3209: _m[t].m3 = 0; tron@3209: } tron@3209: tron@3209: static inline void MakeRailBridgeRamp(TileIndex t, Owner o, uint bridgetype, DiagDirection d, RailType r) tron@3209: { tron@3209: MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_RAIL); tron@3209: _m[t].m3 = r; tron@3209: } tron@3209: tron@3209: tron@3977: static inline void MakeBridgeMiddle(TileIndex t, uint bridgetype, uint piece, Axis a, TransportType tt) tron@3977: { tron@3977: SetTileType(t, MP_TUNNELBRIDGE); tron@3977: SetTileOwner(t, OWNER_NONE); tron@3977: _m[t].m2 = bridgetype << 4 | piece; tron@3977: _m[t].m3 = 0; tron@3977: _m[t].m4 = 0; tron@3977: _m[t].m5 = 1 << 7 | 1 << 6 | 0 << 5 | 0 << 3 | tt << 1 | a; tron@3977: } tron@3977: tron@3977: static inline void MakeRoadBridgeMiddle(TileIndex t, uint bridgetype, uint piece, Axis a) tron@3977: { tron@3977: MakeBridgeMiddle(t, bridgetype, piece, a, TRANSPORT_ROAD); tron@3977: } tron@3977: tron@3977: static inline void MakeRailBridgeMiddle(TileIndex t, uint bridgetype, uint piece, Axis a, RailType r) tron@3977: { tron@3977: MakeBridgeMiddle(t, bridgetype, piece, a, TRANSPORT_RAIL); tron@3977: SB(_m[t].m3, 4, 4, r); tron@3977: } tron@3977: tron@3977: tron@3189: #endif