smatz@8083: /* $Id$ */ smatz@8083: smatz@8083: /** @file tunnelbridge_map.h Functions that have tunnels and bridges in common */ smatz@8083: smatz@8083: #ifndef TUNNELBRIDGE_MAP_H smatz@8083: #define TUNNELBRIDGE_MAP_H smatz@8083: rubidium@8100: #include "direction_func.h" rubidium@8139: #include "core/bitmath_func.hpp" rubidium@8139: #include "tile_map.h" smatz@8197: #include "bridge_map.h" smatz@8197: #include "tunnel_map.h" rubidium@9126: #include "transport_type.h" rubidium@9784: #include "track_func.h" smatz@8083: smatz@8083: smatz@8083: /** frosch@8481: * Get the direction pointing to the other end. frosch@8481: * frosch@8481: * Tunnel: Get the direction facing into the tunnel smatz@8083: * Bridge: Get the direction pointing onto the bridge smatz@8083: * @param t The tile to analyze smatz@8083: * @pre IsTileType(t, MP_TUNNELBRIDGE) smatz@8083: * @return the above mentionned direction smatz@8083: */ smatz@8083: static inline DiagDirection GetTunnelBridgeDirection(TileIndex t) smatz@8083: { smatz@8083: assert(IsTileType(t, MP_TUNNELBRIDGE)); smatz@8083: return (DiagDirection)GB(_m[t].m5, 0, 2); smatz@8083: } smatz@8083: smatz@8083: /** smatz@8083: * Tunnel: Get the transport type of the tunnel (road or rail) smatz@8083: * Bridge: Get the transport type of the bridge's ramp smatz@8083: * @param t The tile to analyze smatz@8083: * @pre IsTileType(t, MP_TUNNELBRIDGE) smatz@8083: * @return the transport type in the tunnel/bridge smatz@8083: */ smatz@8083: static inline TransportType GetTunnelBridgeTransportType(TileIndex t) smatz@8083: { smatz@8083: assert(IsTileType(t, MP_TUNNELBRIDGE)); smatz@8083: return (TransportType)GB(_m[t].m5, 2, 2); smatz@8083: } smatz@8083: smatz@8083: /** smatz@8083: * Tunnel: Is this tunnel entrance in a snowy or desert area? smatz@8083: * Bridge: Does the bridge ramp lie in a snow or desert area? smatz@8083: * @param t The tile to analyze smatz@8083: * @pre IsTileType(t, MP_TUNNELBRIDGE) smatz@8083: * @return true if and only if the tile is in a snowy/desert area smatz@8083: */ smatz@8083: static inline bool HasTunnelBridgeSnowOrDesert(TileIndex t) smatz@8083: { smatz@8083: assert(IsTileType(t, MP_TUNNELBRIDGE)); smatz@8083: return HasBit(_m[t].m4, 7); smatz@8083: } smatz@8083: smatz@8083: /** smatz@8083: * Tunnel: Places this tunnel entrance in a snowy or desert area, or takes it out of there. smatz@8083: * Bridge: Sets whether the bridge ramp lies in a snow or desert area. smatz@8083: * @param t the tunnel entrance / bridge ramp tile smatz@8083: * @param snow_or_desert is the entrance/ramp in snow or desert (true), when smatz@8083: * not in snow and not in desert false smatz@8083: * @pre IsTileType(t, MP_TUNNELBRIDGE) smatz@8083: */ smatz@8083: static inline void SetTunnelBridgeSnowOrDesert(TileIndex t, bool snow_or_desert) smatz@8083: { smatz@8083: assert(IsTileType(t, MP_TUNNELBRIDGE)); smatz@8083: SB(_m[t].m4, 7, 1, snow_or_desert); smatz@8083: } smatz@8083: smatz@8197: /** smatz@8197: * Determines type of the wormhole and returns its other end smatz@8197: * @param t one end smatz@8197: * @pre IsTileType(t, MP_TUNNELBRIDGE) smatz@8197: * @return other end smatz@8197: */ smatz@8197: static inline TileIndex GetOtherTunnelBridgeEnd(TileIndex t) smatz@8197: { smatz@8197: assert(IsTileType(t, MP_TUNNELBRIDGE)); smatz@8197: return IsTunnel(t) ? GetOtherTunnelEnd(t) : GetOtherBridgeEnd(t); smatz@8197: } smatz@8197: rubidium@9784: rubidium@9784: /** rubidium@9784: * Get the reservation state of the rail tunnel/bridge rubidium@9784: * @pre IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL rubidium@9784: * @param t the tile rubidium@9784: * @return reservation state rubidium@9784: */ rubidium@9784: static inline bool GetTunnelBridgeReservation(TileIndex t) rubidium@9784: { rubidium@9784: assert(IsTileType(t, MP_TUNNELBRIDGE)); rubidium@9784: assert(GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL); rubidium@9784: return HasBit(_m[t].m5, 4); rubidium@9784: } rubidium@9784: rubidium@9784: /** rubidium@9784: * Set the reservation state of the rail tunnel/bridge rubidium@9784: * @pre IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL rubidium@9784: * @param t the tile rubidium@9784: * @param b the reservation state rubidium@9784: */ rubidium@9784: static inline void SetTunnelBridgeReservation(TileIndex t, bool b) rubidium@9784: { rubidium@9784: assert(IsTileType(t, MP_TUNNELBRIDGE)); rubidium@9784: assert(GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL); rubidium@9784: SB(_m[t].m5, 4, 1, b ? 1 : 0); rubidium@9784: } rubidium@9784: rubidium@9784: /** rubidium@9784: * Get the reserved track bits for a rail tunnel/bridge rubidium@9784: * @pre IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL rubidium@9784: * @param t the tile rubidium@9784: * @return reserved track bits rubidium@9784: */ rubidium@9784: static inline TrackBits GetRailTunnelBridgeReservation(TileIndex t) rubidium@9784: { rubidium@9784: return GetTunnelBridgeReservation(t) ? DiagDirToDiagTrackBits(GetTunnelBridgeDirection(t)) : TRACK_BIT_NONE; rubidium@9784: } rubidium@9784: smatz@8083: #endif /* TUNNELBRIDGE_MAP_H */