2007-12-16 15:38:51 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
/** @file tunnelbridge_map.h Functions that have tunnels and bridges in common */
|
|
|
|
|
|
|
|
#ifndef TUNNELBRIDGE_MAP_H
|
|
|
|
#define TUNNELBRIDGE_MAP_H
|
|
|
|
|
2007-12-18 19:52:14 +00:00
|
|
|
#include "direction_func.h"
|
2007-12-26 11:45:43 +00:00
|
|
|
#include "core/bitmath_func.hpp"
|
|
|
|
#include "tile_map.h"
|
2008-01-04 19:45:29 +00:00
|
|
|
#include "bridge_map.h"
|
|
|
|
#include "tunnel_map.h"
|
2008-05-07 09:07:19 +00:00
|
|
|
#include "transport_type.h"
|
2008-08-02 22:47:20 +00:00
|
|
|
#include "track_func.h"
|
2007-12-16 15:38:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-02-04 15:26:35 +00:00
|
|
|
* Get the direction pointing to the other end.
|
|
|
|
*
|
|
|
|
* Tunnel: Get the direction facing into the tunnel
|
2007-12-16 15:38:51 +00:00
|
|
|
* Bridge: Get the direction pointing onto the bridge
|
|
|
|
* @param t The tile to analyze
|
|
|
|
* @pre IsTileType(t, MP_TUNNELBRIDGE)
|
|
|
|
* @return the above mentionned direction
|
|
|
|
*/
|
|
|
|
static inline DiagDirection GetTunnelBridgeDirection(TileIndex t)
|
|
|
|
{
|
|
|
|
assert(IsTileType(t, MP_TUNNELBRIDGE));
|
|
|
|
return (DiagDirection)GB(_m[t].m5, 0, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tunnel: Get the transport type of the tunnel (road or rail)
|
|
|
|
* Bridge: Get the transport type of the bridge's ramp
|
|
|
|
* @param t The tile to analyze
|
|
|
|
* @pre IsTileType(t, MP_TUNNELBRIDGE)
|
|
|
|
* @return the transport type in the tunnel/bridge
|
|
|
|
*/
|
|
|
|
static inline TransportType GetTunnelBridgeTransportType(TileIndex t)
|
|
|
|
{
|
|
|
|
assert(IsTileType(t, MP_TUNNELBRIDGE));
|
|
|
|
return (TransportType)GB(_m[t].m5, 2, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tunnel: Is this tunnel entrance in a snowy or desert area?
|
|
|
|
* Bridge: Does the bridge ramp lie in a snow or desert area?
|
|
|
|
* @param t The tile to analyze
|
|
|
|
* @pre IsTileType(t, MP_TUNNELBRIDGE)
|
|
|
|
* @return true if and only if the tile is in a snowy/desert area
|
|
|
|
*/
|
|
|
|
static inline bool HasTunnelBridgeSnowOrDesert(TileIndex t)
|
|
|
|
{
|
|
|
|
assert(IsTileType(t, MP_TUNNELBRIDGE));
|
|
|
|
return HasBit(_m[t].m4, 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tunnel: Places this tunnel entrance in a snowy or desert area, or takes it out of there.
|
|
|
|
* Bridge: Sets whether the bridge ramp lies in a snow or desert area.
|
|
|
|
* @param t the tunnel entrance / bridge ramp tile
|
|
|
|
* @param snow_or_desert is the entrance/ramp in snow or desert (true), when
|
|
|
|
* not in snow and not in desert false
|
|
|
|
* @pre IsTileType(t, MP_TUNNELBRIDGE)
|
|
|
|
*/
|
|
|
|
static inline void SetTunnelBridgeSnowOrDesert(TileIndex t, bool snow_or_desert)
|
|
|
|
{
|
|
|
|
assert(IsTileType(t, MP_TUNNELBRIDGE));
|
|
|
|
SB(_m[t].m4, 7, 1, snow_or_desert);
|
|
|
|
}
|
|
|
|
|
2008-01-04 19:45:29 +00:00
|
|
|
/**
|
|
|
|
* Determines type of the wormhole and returns its other end
|
|
|
|
* @param t one end
|
|
|
|
* @pre IsTileType(t, MP_TUNNELBRIDGE)
|
|
|
|
* @return other end
|
|
|
|
*/
|
|
|
|
static inline TileIndex GetOtherTunnelBridgeEnd(TileIndex t)
|
|
|
|
{
|
|
|
|
assert(IsTileType(t, MP_TUNNELBRIDGE));
|
|
|
|
return IsTunnel(t) ? GetOtherTunnelEnd(t) : GetOtherBridgeEnd(t);
|
|
|
|
}
|
|
|
|
|
2008-08-02 22:47:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the reservation state of the rail tunnel/bridge
|
|
|
|
* @pre IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL
|
|
|
|
* @param t the tile
|
|
|
|
* @return reservation state
|
|
|
|
*/
|
|
|
|
static inline bool GetTunnelBridgeReservation(TileIndex t)
|
|
|
|
{
|
|
|
|
assert(IsTileType(t, MP_TUNNELBRIDGE));
|
|
|
|
assert(GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL);
|
|
|
|
return HasBit(_m[t].m5, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the reservation state of the rail tunnel/bridge
|
|
|
|
* @pre IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL
|
|
|
|
* @param t the tile
|
|
|
|
* @param b the reservation state
|
|
|
|
*/
|
|
|
|
static inline void SetTunnelBridgeReservation(TileIndex t, bool b)
|
|
|
|
{
|
|
|
|
assert(IsTileType(t, MP_TUNNELBRIDGE));
|
|
|
|
assert(GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL);
|
|
|
|
SB(_m[t].m5, 4, 1, b ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the reserved track bits for a rail tunnel/bridge
|
|
|
|
* @pre IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL
|
|
|
|
* @param t the tile
|
|
|
|
* @return reserved track bits
|
|
|
|
*/
|
|
|
|
static inline TrackBits GetRailTunnelBridgeReservation(TileIndex t)
|
|
|
|
{
|
|
|
|
return GetTunnelBridgeReservation(t) ? DiagDirToDiagTrackBits(GetTunnelBridgeDirection(t)) : TRACK_BIT_NONE;
|
|
|
|
}
|
|
|
|
|
2007-12-16 15:38:51 +00:00
|
|
|
#endif /* TUNNELBRIDGE_MAP_H */
|