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