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: celestar@5573: void DrawBridgeMiddle(const TileInfo* ti); // XXX celestar@5573: celestar@5573: 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: celestar@5573: static inline bool MayHaveBridgeAbove(TileIndex t) tron@3214: { celestar@5573: return celestar@5573: IsTileType(t, MP_CLEAR) || celestar@5573: IsTileType(t, MP_RAILWAY) || celestar@5573: IsTileType(t, MP_STREET) || celestar@5573: IsTileType(t, MP_WATER) || celestar@5573: IsTileType(t, MP_TUNNELBRIDGE) || celestar@5573: IsTileType(t, MP_UNMOVABLE); tron@3225: } tron@3225: tron@3225: celestar@5573: static inline bool IsBridgeAbove(TileIndex t) celestar@3933: { celestar@5573: assert(MayHaveBridgeAbove(t)); belugas@5847: return GB(_m[t].m6, 6, 2) != 0; 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: { celestar@5573: assert(IsBridgeTile(t)); celestar@5573: return (DiagDirection)GB(_m[t].m5, 0, 2); tron@3196: } tron@3196: tron@3196: tron@3225: static inline Axis GetBridgeAxis(TileIndex t) tron@3225: { celestar@5573: assert(IsBridgeAbove(t)); belugas@5847: return (Axis)(GB(_m[t].m6, 6, 2) - 1); tron@3225: } tron@3225: tron@3225: tron@3234: static inline TransportType GetBridgeTransportType(TileIndex t) tron@3234: { tron@3369: assert(IsBridgeTile(t)); celestar@5573: return (TransportType)GB(_m[t].m5, 2, 2); tron@3977: } tron@3977: tron@3977: rubidium@5661: static inline bool HasBridgeSnowOrDesert(TileIndex t) rubidium@5661: { rubidium@5661: assert(IsBridgeTile(t)); rubidium@5661: return HASBIT(_m[t].m4, 7); rubidium@5661: } rubidium@5661: rubidium@5661: rubidium@5661: static inline void SetBridgeSnowOrDesert(TileIndex t, bool snow_or_desert) rubidium@5661: { rubidium@5661: assert(IsBridgeTile(t)); rubidium@5661: SB(_m[t].m4, 7, 1, snow_or_desert); rubidium@5661: } rubidium@5661: 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: /** celestar@5573: * Finds the northern end of a bridge starting at a middle tile celestar@5573: */ celestar@5573: TileIndex GetNorthernBridgeEnd(TileIndex t); celestar@5573: celestar@5573: /** 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: celestar@5573: uint GetBridgeHeight(TileIndex tile); celestar@5573: uint GetBridgeFoundation(Slope tileh, Axis axis); tron@3214: celestar@5573: static inline void ClearSingleBridgeMiddle(TileIndex t, Axis a) tron@3189: { celestar@5573: assert(MayHaveBridgeAbove(t)); belugas@5847: CLRBIT(_m[t].m6, 6 + a); tron@3189: } tron@3189: celestar@5573: celestar@5573: static inline void ClearBridgeMiddle(TileIndex t) tron@3189: { celestar@5573: ClearSingleBridgeMiddle(t, AXIS_X); celestar@5573: ClearSingleBridgeMiddle(t, AXIS_Y); tron@3977: } tron@3977: celestar@5573: static inline void SetBridgeMiddle(TileIndex t, Axis a) tron@3977: { celestar@5573: assert(MayHaveBridgeAbove(t)); belugas@5847: SETBIT(_m[t].m6, 6 + a); 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: SetTileType(t, MP_TUNNELBRIDGE); tron@3209: SetTileOwner(t, o); tron@3209: _m[t].m2 = bridgetype << 4; tron@3209: _m[t].m4 = 0; celestar@5573: _m[t].m5 = 1 << 7 | tt << 2 | 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: peter1138@4666: #endif /* BRIDGE_MAP_H */