src/tunnelbridge_map.h
changeset 8083 ad22eade501f
child 8100 6bc08f98ec16
equal deleted inserted replaced
8082:63240e1bd6cc 8083:ad22eade501f
       
     1 /* $Id$ */
       
     2 
       
     3 /** @file tunnelbridge_map.h Functions that have tunnels and bridges in common */
       
     4 
       
     5 #ifndef TUNNELBRIDGE_MAP_H
       
     6 #define TUNNELBRIDGE_MAP_H
       
     7 
       
     8 #include "direction.h"            /* DiagDirection */
       
     9 #include "core/bitmath_func.hpp"  /* GB, HasBit, SB */
       
    10 #include "map.h"                  /* Tile, TileIndex */
       
    11 #include "tile.h"                 /* TileType, IsTileType */
       
    12 #include "openttd.h"              /* TransportType */
       
    13 
       
    14 
       
    15 /**
       
    16  * Tunnel: Get the direction facing out of the tunnel
       
    17  * Bridge: Get the direction pointing onto the bridge
       
    18  * @param t The tile to analyze
       
    19  * @pre IsTileType(t, MP_TUNNELBRIDGE)
       
    20  * @return the above mentionned direction
       
    21  */
       
    22 static inline DiagDirection GetTunnelBridgeDirection(TileIndex t)
       
    23 {
       
    24 	assert(IsTileType(t, MP_TUNNELBRIDGE));
       
    25 	return (DiagDirection)GB(_m[t].m5, 0, 2);
       
    26 }
       
    27 
       
    28 /**
       
    29  * Tunnel: Get the transport type of the tunnel (road or rail)
       
    30  * Bridge: Get the transport type of the bridge's ramp
       
    31  * @param t The tile to analyze
       
    32  * @pre IsTileType(t, MP_TUNNELBRIDGE)
       
    33  * @return the transport type in the tunnel/bridge
       
    34  */
       
    35 static inline TransportType GetTunnelBridgeTransportType(TileIndex t)
       
    36 {
       
    37 	assert(IsTileType(t, MP_TUNNELBRIDGE));
       
    38 	return (TransportType)GB(_m[t].m5, 2, 2);
       
    39 }
       
    40 
       
    41 /**
       
    42  * Tunnel: Is this tunnel entrance in a snowy or desert area?
       
    43  * Bridge: Does the bridge ramp lie in a snow or desert area?
       
    44  * @param t The tile to analyze
       
    45  * @pre IsTileType(t, MP_TUNNELBRIDGE)
       
    46  * @return true if and only if the tile is in a snowy/desert area
       
    47  */
       
    48 static inline bool HasTunnelBridgeSnowOrDesert(TileIndex t)
       
    49 {
       
    50 	assert(IsTileType(t, MP_TUNNELBRIDGE));
       
    51 	return HasBit(_m[t].m4, 7);
       
    52 }
       
    53 
       
    54 /**
       
    55  * Tunnel: Places this tunnel entrance in a snowy or desert area, or takes it out of there.
       
    56  * Bridge: Sets whether the bridge ramp lies in a snow or desert area.
       
    57  * @param t the tunnel entrance / bridge ramp tile
       
    58  * @param snow_or_desert is the entrance/ramp in snow or desert (true), when
       
    59  *                       not in snow and not in desert false
       
    60  * @pre IsTileType(t, MP_TUNNELBRIDGE)
       
    61  */
       
    62 static inline void SetTunnelBridgeSnowOrDesert(TileIndex t, bool snow_or_desert)
       
    63 {
       
    64 	assert(IsTileType(t, MP_TUNNELBRIDGE));
       
    65 	SB(_m[t].m4, 7, 1, snow_or_desert);
       
    66 }
       
    67 
       
    68 #endif /* TUNNELBRIDGE_MAP_H */