src/tunnel_map.h
branchnoai
changeset 9620 31e38d28a0af
parent 9574 698395509d12
child 7157 270bc5b64e08
equal deleted inserted replaced
9619:6e81cec30a2b 9620:31e38d28a0af
     8 #include "direction.h"
     8 #include "direction.h"
     9 #include "macros.h"
     9 #include "macros.h"
    10 #include "map.h"
    10 #include "map.h"
    11 #include "rail.h"
    11 #include "rail.h"
    12 
    12 
    13 
    13 /**
       
    14  * Is this a tunnel (entrance)?
       
    15  * @param t the tile that might be a tunnel
       
    16  * @pre IsTileType(t, MP_TUNNELBRIDGE)
       
    17  * @return true if and only if this tile is a tunnel (entrance)
       
    18  */
    14 static inline bool IsTunnel(TileIndex t)
    19 static inline bool IsTunnel(TileIndex t)
    15 {
    20 {
    16 	assert(IsTileType(t, MP_TUNNELBRIDGE));
    21 	assert(IsTileType(t, MP_TUNNELBRIDGE));
    17 	return !HASBIT(_m[t].m5, 7);
    22 	return !HASBIT(_m[t].m5, 7);
    18 }
    23 }
    19 
    24 
    20 
    25 
       
    26 /**
       
    27  * Is this a tunnel (entrance)?
       
    28  * @param t the tile that might be a tunnel
       
    29  * @return true if and only if this tile is a tunnel (entrance)
       
    30  */
    21 static inline bool IsTunnelTile(TileIndex t)
    31 static inline bool IsTunnelTile(TileIndex t)
    22 {
    32 {
    23 	return IsTileType(t, MP_TUNNELBRIDGE) && IsTunnel(t);
    33 	return IsTileType(t, MP_TUNNELBRIDGE) && IsTunnel(t);
    24 }
    34 }
    25 
    35 
    26 
    36 /**
       
    37  * Gets the direction facing out of the tunnel
       
    38  * @param t the tile to get the tunnel facing direction of
       
    39  * @pre IsTunnelTile(t)
       
    40  * @return the direction the tunnel is facing
       
    41  */
    27 static inline DiagDirection GetTunnelDirection(TileIndex t)
    42 static inline DiagDirection GetTunnelDirection(TileIndex t)
    28 {
    43 {
    29 	assert(IsTunnelTile(t));
    44 	assert(IsTunnelTile(t));
    30 	return (DiagDirection)GB(_m[t].m5, 0, 2);
    45 	return (DiagDirection)GB(_m[t].m5, 0, 2);
    31 }
    46 }
    32 
    47 
    33 
    48 /**
       
    49  * Gets the transport type of the tunnel (road or rail)
       
    50  * @param t the tunnel entrance tile to get the type of
       
    51  * @pre IsTunnelTile(t)
       
    52  * @return the transport type in the tunnel
       
    53  */
    34 static inline TransportType GetTunnelTransportType(TileIndex t)
    54 static inline TransportType GetTunnelTransportType(TileIndex t)
    35 {
    55 {
    36 	assert(IsTunnelTile(t));
    56 	assert(IsTunnelTile(t));
    37 	return (TransportType)GB(_m[t].m5, 2, 2);
    57 	return (TransportType)GB(_m[t].m5, 2, 2);
    38 }
    58 }
    39 
    59 
       
    60 /**
       
    61  * Is this tunnel entrance in a snowy or desert area?
       
    62  * @param t the tunnel entrance tile
       
    63  * @pre IsTunnelTile(t)
       
    64  * @return true if and only if the tunnel entrance is in a snowy/desert area
       
    65  */
    40 static inline bool HasTunnelSnowOrDesert(TileIndex t)
    66 static inline bool HasTunnelSnowOrDesert(TileIndex t)
    41 {
    67 {
    42 	assert(IsTunnelTile(t));
    68 	assert(IsTunnelTile(t));
    43 	return HASBIT(_m[t].m4, 7);
    69 	return HASBIT(_m[t].m4, 7);
    44 }
    70 }
    45 
    71 
       
    72 /**
       
    73  * Places this tunnel entrance in a snowy or desert area,
       
    74  * or takes it out of there.
       
    75  * @param t the tunnel entrance tile
       
    76  * @param snow_or_desert is the entrance in snow or desert (true), when
       
    77  *                       not in snow and not in desert false
       
    78  * @pre IsTunnelTile(t)
       
    79  */
    46 static inline void SetTunnelSnowOrDesert(TileIndex t, bool snow_or_desert)
    80 static inline void SetTunnelSnowOrDesert(TileIndex t, bool snow_or_desert)
    47 {
    81 {
    48 	assert(IsTunnelTile(t));
    82 	assert(IsTunnelTile(t));
    49 	SB(_m[t].m4, 7, 1, snow_or_desert);
    83 	SB(_m[t].m4, 7, 1, snow_or_desert);
    50 }
    84 }
    52 
    86 
    53 TileIndex GetOtherTunnelEnd(TileIndex);
    87 TileIndex GetOtherTunnelEnd(TileIndex);
    54 bool IsTunnelInWay(TileIndex, uint z);
    88 bool IsTunnelInWay(TileIndex, uint z);
    55 
    89 
    56 
    90 
       
    91 /**
       
    92  * Makes a road tunnel entrance
       
    93  * @param t the entrance of the tunnel
       
    94  * @param o the owner of the entrance
       
    95  * @param d the direction facing out of the tunnel
       
    96  */
    57 static inline void MakeRoadTunnel(TileIndex t, Owner o, DiagDirection d)
    97 static inline void MakeRoadTunnel(TileIndex t, Owner o, DiagDirection d)
    58 {
    98 {
    59 	SetTileType(t, MP_TUNNELBRIDGE);
    99 	SetTileType(t, MP_TUNNELBRIDGE);
    60 	SetTileOwner(t, o);
   100 	SetTileOwner(t, o);
    61 	_m[t].m2 = 0;
   101 	_m[t].m2 = 0;
    62 	_m[t].m3 = 0;
   102 	_m[t].m3 = 0;
    63 	_m[t].m4 = 0;
   103 	_m[t].m4 = 0;
    64 	_m[t].m5 = TRANSPORT_ROAD << 2 | d;
   104 	_m[t].m5 = TRANSPORT_ROAD << 2 | d;
    65 }
   105 }
    66 
   106 
       
   107 /**
       
   108  * Makes a rail tunnel entrance
       
   109  * @param t the entrance of the tunnel
       
   110  * @param o the owner of the entrance
       
   111  * @param d the direction facing out of the tunnel
       
   112  * @param r the rail type used in the tunnel
       
   113  */
    67 static inline void MakeRailTunnel(TileIndex t, Owner o, DiagDirection d, RailType r)
   114 static inline void MakeRailTunnel(TileIndex t, Owner o, DiagDirection d, RailType r)
    68 {
   115 {
    69 	SetTileType(t, MP_TUNNELBRIDGE);
   116 	SetTileType(t, MP_TUNNELBRIDGE);
    70 	SetTileOwner(t, o);
   117 	SetTileOwner(t, o);
    71 	_m[t].m2 = 0;
   118 	_m[t].m2 = 0;