tron@3189: /* $Id$ */ tron@3189: rubidium@6914: /** @file bridge_map.h Map accessor functions for bridges. */ belugas@6449: tron@3189: #ifndef BRIDGE_MAP_H tron@3189: #define BRIDGE_MAP_H tron@3189: rubidium@8596: #include "direction_func.h" rubidium@8599: #include "rail_type.h" rubidium@10444: #include "transport_type.h" tron@3234: #include "road_map.h" belugas@9028: #include "bridge.h" tron@3189: belugas@6912: /** belugas@6912: * Checks if this is a bridge, instead of a tunnel belugas@6912: * @param t The tile to analyze belugas@6912: * @pre IsTileType(t, MP_TUNNELBRIDGE) belugas@6912: * @return true if the structure is a bridge one belugas@6912: */ tron@3234: static inline bool IsBridge(TileIndex t) tron@3234: { tron@3369: assert(IsTileType(t, MP_TUNNELBRIDGE)); skidd13@8424: return HasBit(_m[t].m5, 7); tron@3234: } tron@3234: belugas@6912: /** belugas@6912: * checks if there is a bridge on this tile belugas@6912: * @param t The tile to analyze belugas@6912: * @return true if a bridge is present belugas@6912: */ tron@3234: static inline bool IsBridgeTile(TileIndex t) tron@3234: { tron@3234: return IsTileType(t, MP_TUNNELBRIDGE) && IsBridge(t); tron@3234: } tron@3234: belugas@6912: /** belugas@6912: * checks for the possibility that a bridge may be on this tile belugas@6912: * These are in fact all the tile types on which a bridge can be found belugas@6912: * @param t The tile to analyze belugas@6912: * @return true if a bridge migh be present belugas@6912: */ 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) || rubidium@7866: IsTileType(t, MP_ROAD) || celestar@5573: IsTileType(t, MP_WATER) || celestar@5573: IsTileType(t, MP_TUNNELBRIDGE) || celestar@5573: IsTileType(t, MP_UNMOVABLE); tron@3225: } tron@3225: belugas@6912: /** belugas@6912: * checks if a bridge is set above the ground of this tile belugas@6912: * @param t The tile to analyze rubidium@6914: * @pre MayHaveBridgeAbove(t) belugas@6912: * @return true if a bridge is detected above belugas@6912: */ 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: * Determines the type of bridge on a tile belugas@6912: * @param t The tile to analyze rubidium@6914: * @pre IsBridgeTile(t) tron@3231: * @return The bridge type tron@3231: */ belugas@9028: static inline BridgeType GetBridgeType(TileIndex t) tron@3231: { tron@3369: assert(IsBridgeTile(t)); tron@3369: return GB(_m[t].m2, 4, 4); tron@3231: } tron@3231: rubidium@6914: /** rubidium@6914: * Get the axis of the bridge that goes over the tile. Not the axis or the ramp. rubidium@6914: * @param t The tile to analyze rubidium@6914: * @pre IsBridgeAbove(t) rubidium@6914: * @return the above mentioned axis rubidium@6914: */ 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@3214: /** tron@3225: * Finds the end of a bridge in the specified direction starting at a middle tile rubidium@6914: * @param t the bridge tile to find the bridge ramp for rubidium@6914: * @param d the direction to search in tron@3225: */ rubidium@6914: TileIndex GetBridgeEnd(TileIndex t, DiagDirection d); tron@3225: tron@3225: /** celestar@5573: * Finds the northern end of a bridge starting at a middle tile rubidium@6914: * @param t the bridge tile to find the bridge ramp for 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 rubidium@6914: * @param t the bridge tile to find the bridge ramp for 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 rubidium@6914: * @param t the bridge ramp tile to find the other bridge ramp for tron@3214: */ rubidium@6914: TileIndex GetOtherBridgeEnd(TileIndex t); tron@3214: rubidium@6914: /** rubidium@6914: * Get the height ('z') of a bridge in pixels. rubidium@6914: * @param tile the bridge ramp tile to get the bridge height from rubidium@6914: * @return the height of the bridge in pixels rubidium@6914: */ celestar@5573: uint GetBridgeHeight(TileIndex tile); tron@3214: rubidium@6914: /** rubidium@6914: * Remove the bridge over the given axis. rubidium@6914: * @param t the tile to remove the bridge from rubidium@6914: * @param a the axis of the bridge to remove rubidium@6914: * @pre MayHaveBridgeAbove(t) rubidium@6914: */ celestar@5573: static inline void ClearSingleBridgeMiddle(TileIndex t, Axis a) tron@3189: { celestar@5573: assert(MayHaveBridgeAbove(t)); skidd13@8425: ClrBit(_m[t].m6, 6 + a); tron@3189: } tron@3189: rubidium@6914: /** rubidium@6914: * Removes bridges from the given, that is bridges along the X and Y axis. rubidium@6914: * @param t the tile to remove the bridge from rubidium@6914: * @pre MayHaveBridgeAbove(t) rubidium@6914: */ 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: rubidium@6914: /** rubidium@6914: * Set that there is a bridge over the given axis. rubidium@6914: * @param t the tile to add the bridge to rubidium@6914: * @param a the axis of the bridge to add rubidium@6914: * @pre MayHaveBridgeAbove(t) rubidium@6914: */ celestar@5573: static inline void SetBridgeMiddle(TileIndex t, Axis a) tron@3977: { celestar@5573: assert(MayHaveBridgeAbove(t)); skidd13@8427: SetBit(_m[t].m6, 6 + a); tron@3189: } tron@3189: rubidium@6914: /** rubidium@6914: * Generic part to make a bridge ramp for both roads and rails. rubidium@6914: * @param t the tile to make a bridge ramp rubidium@6914: * @param o the new owner of the bridge ramp rubidium@6914: * @param bridgetype the type of bridge this bridge ramp belongs to rubidium@6914: * @param d the direction this ramp must be facing rubidium@6914: * @param tt the transport type of the bridge rubidium@7157: * @param rt the road or rail type rubidium@6914: * @note this function should not be called directly. rubidium@6914: */ belugas@9028: static inline void MakeBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, TransportType tt, uint rt) tron@3209: { tron@3209: SetTileType(t, MP_TUNNELBRIDGE); tron@3209: SetTileOwner(t, o); tron@3209: _m[t].m2 = bridgetype << 4; rubidium@7157: _m[t].m3 = rt; tron@3209: _m[t].m4 = 0; celestar@5573: _m[t].m5 = 1 << 7 | tt << 2 | d; tron@3209: } tron@3209: rubidium@6914: /** rubidium@6914: * Make a bridge ramp for roads. rubidium@6914: * @param t the tile to make a bridge ramp rubidium@6914: * @param o the new owner of the bridge ramp rubidium@6914: * @param bridgetype the type of bridge this bridge ramp belongs to rubidium@6914: * @param d the direction this ramp must be facing rubidium@7157: * @param r the road type of the bridge rubidium@6914: */ belugas@9028: static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RoadTypes r) tron@3209: { rubidium@7157: MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_ROAD, r); tron@3209: } tron@3209: rubidium@6914: /** rubidium@6914: * Make a bridge ramp for rails. rubidium@6914: * @param t the tile to make a bridge ramp rubidium@6914: * @param o the new owner of the bridge ramp rubidium@6914: * @param bridgetype the type of bridge this bridge ramp belongs to rubidium@6914: * @param d the direction this ramp must be facing rubidium@6914: * @param r the rail type of the bridge rubidium@6914: */ belugas@9028: static inline void MakeRailBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RailType r) tron@3209: { rubidium@7157: MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_RAIL, r); tron@3209: } tron@3209: rubidium@10913: /** rubidium@10913: * Make a bridge ramp for aqueducts. rubidium@10913: * @param t the tile to make a bridge ramp rubidium@10913: * @param o the new owner of the bridge ramp rubidium@10913: * @param d the direction this ramp must be facing rubidium@10913: */ rubidium@10913: static inline void MakeAqueductBridgeRamp(TileIndex t, Owner o, DiagDirection d) rubidium@10913: { rubidium@10913: MakeBridgeRamp(t, o, 0, d, TRANSPORT_WATER, 0); rubidium@10913: } tron@3209: peter1138@4666: #endif /* BRIDGE_MAP_H */