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