tron@3154: /* $Id$ */ tron@3154: glx@9574: /** @file tunnel_map.h */ glx@9574: tron@3154: #ifndef TUNNEL_MAP_H tron@3154: #define TUNNEL_MAP_H tron@3154: tron@3154: #include "direction.h" tron@3154: #include "macros.h" tron@3154: #include "map.h" tron@3154: #include "rail.h" glx@9624: #include "road.h" tron@3154: rubidium@9620: /** rubidium@9620: * Is this a tunnel (entrance)? rubidium@9620: * @param t the tile that might be a tunnel rubidium@9620: * @pre IsTileType(t, MP_TUNNELBRIDGE) rubidium@9620: * @return true if and only if this tile is a tunnel (entrance) rubidium@9620: */ tron@3184: static inline bool IsTunnel(TileIndex t) tron@3184: { tron@3369: assert(IsTileType(t, MP_TUNNELBRIDGE)); tron@3184: return !HASBIT(_m[t].m5, 7); tron@3184: } tron@3184: tron@3184: rubidium@9620: /** rubidium@9620: * Is this a tunnel (entrance)? rubidium@9620: * @param t the tile that might be a tunnel rubidium@9620: * @return true if and only if this tile is a tunnel (entrance) rubidium@9620: */ tron@3184: static inline bool IsTunnelTile(TileIndex t) tron@3184: { tron@3184: return IsTileType(t, MP_TUNNELBRIDGE) && IsTunnel(t); tron@3184: } tron@3184: rubidium@9620: /** rubidium@9620: * Gets the direction facing out of the tunnel rubidium@9620: * @param t the tile to get the tunnel facing direction of rubidium@9620: * @pre IsTunnelTile(t) rubidium@9620: * @return the direction the tunnel is facing rubidium@9620: */ tron@3154: static inline DiagDirection GetTunnelDirection(TileIndex t) tron@3154: { tron@3369: assert(IsTunnelTile(t)); tron@3154: return (DiagDirection)GB(_m[t].m5, 0, 2); tron@3154: } tron@3154: rubidium@9620: /** rubidium@9620: * Gets the transport type of the tunnel (road or rail) rubidium@9620: * @param t the tunnel entrance tile to get the type of rubidium@9620: * @pre IsTunnelTile(t) rubidium@9620: * @return the transport type in the tunnel rubidium@9620: */ tron@3154: static inline TransportType GetTunnelTransportType(TileIndex t) tron@3154: { tron@3369: assert(IsTunnelTile(t)); tron@3154: return (TransportType)GB(_m[t].m5, 2, 2); tron@3154: } tron@3154: rubidium@9620: /** rubidium@9620: * Is this tunnel entrance in a snowy or desert area? rubidium@9620: * @param t the tunnel entrance tile rubidium@9620: * @pre IsTunnelTile(t) rubidium@9620: * @return true if and only if the tunnel entrance is in a snowy/desert area rubidium@9620: */ rubidium@5661: static inline bool HasTunnelSnowOrDesert(TileIndex t) rubidium@5661: { rubidium@5661: assert(IsTunnelTile(t)); rubidium@5661: return HASBIT(_m[t].m4, 7); rubidium@5661: } rubidium@5661: rubidium@9620: /** rubidium@9620: * Places this tunnel entrance in a snowy or desert area, rubidium@9620: * or takes it out of there. rubidium@9620: * @param t the tunnel entrance tile rubidium@9620: * @param snow_or_desert is the entrance in snow or desert (true), when rubidium@9620: * not in snow and not in desert false rubidium@9620: * @pre IsTunnelTile(t) rubidium@9620: */ rubidium@5661: static inline void SetTunnelSnowOrDesert(TileIndex t, bool snow_or_desert) rubidium@5661: { rubidium@5661: assert(IsTunnelTile(t)); rubidium@5661: SB(_m[t].m4, 7, 1, snow_or_desert); rubidium@5661: } rubidium@5661: tron@3154: tron@3154: TileIndex GetOtherTunnelEnd(TileIndex); tron@3156: bool IsTunnelInWay(TileIndex, uint z); glx@9629: bool IsTunnelInWayDir(TileIndex tile, uint z, DiagDirection dir); tron@3154: tron@3154: rubidium@9620: /** rubidium@9620: * Makes a road tunnel entrance rubidium@9620: * @param t the entrance of the tunnel rubidium@9620: * @param o the owner of the entrance rubidium@9620: * @param d the direction facing out of the tunnel glx@9624: * @param r the road type used in the tunnel rubidium@9620: */ glx@9624: static inline void MakeRoadTunnel(TileIndex t, Owner o, DiagDirection d, RoadTypes r) tron@3154: { tron@3154: SetTileType(t, MP_TUNNELBRIDGE); tron@3154: SetTileOwner(t, o); tron@3154: _m[t].m2 = 0; glx@9624: _m[t].m3 = r; tron@3154: _m[t].m4 = 0; tron@3154: _m[t].m5 = TRANSPORT_ROAD << 2 | d; tron@3154: } tron@3154: rubidium@9620: /** rubidium@9620: * Makes a rail tunnel entrance rubidium@9620: * @param t the entrance of the tunnel rubidium@9620: * @param o the owner of the entrance rubidium@9620: * @param d the direction facing out of the tunnel rubidium@9620: * @param r the rail type used in the tunnel rubidium@9620: */ tron@3154: static inline void MakeRailTunnel(TileIndex t, Owner o, DiagDirection d, RailType r) tron@3154: { tron@3154: SetTileType(t, MP_TUNNELBRIDGE); tron@3154: SetTileOwner(t, o); tron@3154: _m[t].m2 = 0; tron@3154: _m[t].m3 = r; tron@3154: _m[t].m4 = 0; tron@3154: _m[t].m5 = TRANSPORT_RAIL << 2 | d; tron@3154: } tron@3154: peter1138@4666: #endif /* TUNNEL_MAP_H */