Rework the way the ReinitSeparation command is called. The old way was way too danger...
[openttd-joker.git] / src / tunnel_map.h
blob6e60e9a0fef7228f756f8f3623ff7ef3d4444d38
1 /* $Id: tunnel_map.h 23167 2011-11-08 19:44:41Z rubidium $ */
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
10 /** @file tunnel_map.h Map accessors for tunnels. */
12 #ifndef TUNNEL_MAP_H
13 #define TUNNEL_MAP_H
15 #include "road_map.h"
17 typedef uint32 TunnelID; ///< Type for the unique identifier of tunnels.
19 static const TunnelID TUNNEL_ID_MAP_LOOKUP = 0xFFFF; ///< Sentinel ID value to store in m2 to indiciate that the ID should be looked up instead
22 /**
23 * Is this a tunnel (entrance)?
24 * @param t the tile that might be a tunnel
25 * @pre IsTileType(t, MP_TUNNELBRIDGE)
26 * @return true if and only if this tile is a tunnel (entrance)
28 static inline bool IsTunnel(TileIndex t)
30 assert(IsTileType(t, MP_TUNNELBRIDGE));
31 return !HasBit(_m[t].m5, 7);
34 /**
35 * Is this a tunnel (entrance)?
36 * @param t the tile that might be a tunnel
37 * @return true if and only if this tile is a tunnel (entrance)
39 static inline bool IsTunnelTile(TileIndex t)
41 return IsTileType(t, MP_TUNNELBRIDGE) && IsTunnel(t);
44 /**
45 * Get the index of tunnel tile.
46 * @param t the tile
47 * @pre IsTunnelTile(t)
48 * @return TunnelID
50 static inline TunnelID GetTunnelIndex(TileIndex t)
52 extern TunnelID GetTunnelIndexByLookup(TileIndex t);
54 assert(IsTunnelTile(t));
55 TunnelID map_id = _m[t].m2;
56 return map_id == TUNNEL_ID_MAP_LOOKUP ? GetTunnelIndexByLookup(t) : map_id;
59 TileIndex GetOtherTunnelEnd(TileIndex);
61 /** Flags for miscellaneous industry tile specialities */
62 enum IsTunnelInWayFlags {
63 ITIWF_NONE = 0,
64 ITIWF_IGNORE_CHUNNEL = 1 << 0, ///< Chunnel mid-parts are ignored, used when terraforming.
65 ITIWF_CHUNNEL_ONLY = 1 << 1, ///< Only check for chunnels
67 DECLARE_ENUM_AS_BIT_SET(IsTunnelInWayFlags)
69 bool IsTunnelInWay(TileIndex, int z, IsTunnelInWayFlags flags = ITIWF_NONE);
71 /**
72 * Set the index of tunnel tile.
73 * @param t the tile
74 * @param id the tunnel ID
75 * @pre IsTunnelTile(t)
77 static inline void SetTunnelIndex(TileIndex t, TunnelID id)
79 assert(IsTunnelTile(t));
80 _m[t].m2 = (id >= TUNNEL_ID_MAP_LOOKUP) ? TUNNEL_ID_MAP_LOOKUP : id;
83 /**
84 * Makes a road tunnel entrance
85 * @param t the entrance of the tunnel
86 * @param o the owner of the entrance
87 * @param id the tunnel ID
88 * @param d the direction facing out of the tunnel
89 * @param r the road type used in the tunnel
91 static inline void MakeRoadTunnel(TileIndex t, Owner o, TunnelID id, DiagDirection d, RoadTypes r)
93 SetTileType(t, MP_TUNNELBRIDGE);
94 SetTileOwner(t, o);
95 _m[t].m3 = 0;
96 _m[t].m4 = 0;
97 _m[t].m5 = TRANSPORT_ROAD << 2 | d;
98 SB(_me[t].m6, 2, 4, 0);
99 _me[t].m7 = 0;
100 SetTunnelIndex(t, id);
101 SetRoadOwner(t, ROADTYPE_ROAD, o);
102 if (o != OWNER_TOWN) SetRoadOwner(t, ROADTYPE_TRAM, o);
103 SetRoadTypes(t, r);
107 * Makes a rail tunnel entrance
108 * @param t the entrance of the tunnel
109 * @param o the owner of the entrance
110 * @param id the tunnel ID
111 * @param d the direction facing out of the tunnel
112 * @param r the rail type used in the tunnel
114 static inline void MakeRailTunnel(TileIndex t, Owner o, TunnelID id, DiagDirection d, RailType r)
116 SetTileType(t, MP_TUNNELBRIDGE);
117 SetTileOwner(t, o);
118 SB(_m[t].m1, 7, 1, GB(r, 4, 1));
119 SB(_m[t].m3, 0, 4, GB(r, 0, 4));
120 _m[t].m4 = 0;
121 _m[t].m5 = TRANSPORT_RAIL << 2 | d;
122 SB(_me[t].m6, 2, 4, 0);
123 _me[t].m7 = 0;
124 SetTunnelIndex(t, id);
127 #endif /* TUNNEL_MAP_H */