Codechange: Use unique_ptr throughout instead of new raw pointer for company news...
[openttd-github.git] / src / tunnel_map.h
blobcecdfcd2c1a41d0af4cd6efe995ed1d811f9d3c2
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
8 /** @file tunnel_map.h Map accessors for tunnels. */
10 #ifndef TUNNEL_MAP_H
11 #define TUNNEL_MAP_H
13 #include "rail_map.h"
14 #include "road_map.h"
17 /**
18 * Is this a tunnel (entrance)?
19 * @param t the tile that might be a tunnel
20 * @pre IsTileType(t, MP_TUNNELBRIDGE)
21 * @return true if and only if this tile is a tunnel (entrance)
23 inline bool IsTunnel(Tile t)
25 assert(IsTileType(t, MP_TUNNELBRIDGE));
26 return !HasBit(t.m5(), 7);
29 /**
30 * Is this a tunnel (entrance)?
31 * @param t the tile that might be a tunnel
32 * @return true if and only if this tile is a tunnel (entrance)
34 inline bool IsTunnelTile(Tile t)
36 return IsTileType(t, MP_TUNNELBRIDGE) && IsTunnel(t);
39 TileIndex GetOtherTunnelEnd(TileIndex);
40 bool IsTunnelInWay(TileIndex, int z);
41 bool IsTunnelInWayDir(TileIndex tile, int z, DiagDirection dir);
43 /**
44 * Makes a road tunnel entrance
45 * @param t the entrance of the tunnel
46 * @param o the owner of the entrance
47 * @param d the direction facing out of the tunnel
48 * @param r the road type used in the tunnel
50 inline void MakeRoadTunnel(Tile t, Owner o, DiagDirection d, RoadType road_rt, RoadType tram_rt)
52 SetTileType(t, MP_TUNNELBRIDGE);
53 SetTileOwner(t, o);
54 t.m2() = 0;
55 t.m3() = 0;
56 t.m4() = 0;
57 t.m5() = TRANSPORT_ROAD << 2 | d;
58 SB(t.m6(), 2, 4, 0);
59 t.m7() = 0;
60 t.m8() = 0;
61 SetRoadOwner(t, RTT_ROAD, o);
62 if (o != OWNER_TOWN) SetRoadOwner(t, RTT_TRAM, o);
63 SetRoadTypes(t, road_rt, tram_rt);
66 /**
67 * Makes a rail tunnel entrance
68 * @param t the entrance of the tunnel
69 * @param o the owner of the entrance
70 * @param d the direction facing out of the tunnel
71 * @param r the rail type used in the tunnel
73 inline void MakeRailTunnel(Tile t, Owner o, DiagDirection d, RailType r)
75 SetTileType(t, MP_TUNNELBRIDGE);
76 SetTileOwner(t, o);
77 t.m2() = 0;
78 t.m3() = 0;
79 t.m4() = 0;
80 t.m5() = TRANSPORT_RAIL << 2 | d;
81 SB(t.m6(), 2, 4, 0);
82 t.m7() = 0;
83 t.m8() = 0;
84 SetRailType(t, r);
85 SetRoadTypes(t, INVALID_ROADTYPE, INVALID_ROADTYPE);
88 #endif /* TUNNEL_MAP_H */