OpenTTD
tunnel_map.h
Go to the documentation of this file.
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  */
7 
10 #ifndef TUNNEL_MAP_H
11 #define TUNNEL_MAP_H
12 
13 #include "road_map.h"
14 
15 
22 static inline bool IsTunnel(TileIndex t)
23 {
24  assert(IsTileType(t, MP_TUNNELBRIDGE));
25  return !HasBit(_m[t].m5, 7);
26 }
27 
33 static inline bool IsTunnelTile(TileIndex t)
34 {
35  return IsTileType(t, MP_TUNNELBRIDGE) && IsTunnel(t);
36 }
37 
39 bool IsTunnelInWay(TileIndex, int z);
40 bool IsTunnelInWayDir(TileIndex tile, int z, DiagDirection dir);
41 
49 static inline void MakeRoadTunnel(TileIndex t, Owner o, DiagDirection d, RoadType road_rt, RoadType tram_rt)
50 {
52  SetTileOwner(t, o);
53  _m[t].m2 = 0;
54  _m[t].m3 = 0;
55  _m[t].m4 = 0;
56  _m[t].m5 = TRANSPORT_ROAD << 2 | d;
57  SB(_me[t].m6, 2, 4, 0);
58  _me[t].m7 = 0;
59  _me[t].m8 = 0;
60  SetRoadOwner(t, RTT_ROAD, o);
61  if (o != OWNER_TOWN) SetRoadOwner(t, RTT_TRAM, o);
62  SetRoadTypes(t, road_rt, tram_rt);
63 }
64 
72 static inline void MakeRailTunnel(TileIndex t, Owner o, DiagDirection d, RailType r)
73 {
75  SetTileOwner(t, o);
76  _m[t].m2 = 0;
77  _m[t].m3 = 0;
78  _m[t].m4 = 0;
79  _m[t].m5 = TRANSPORT_RAIL << 2 | d;
80  SB(_me[t].m6, 2, 4, 0);
81  _me[t].m7 = 0;
82  _me[t].m8 = r;
83 }
84 
85 #endif /* TUNNEL_MAP_H */
Owner
Enum for all companies/owners.
Definition: company_type.h:18
static void SetTileOwner(TileIndex tile, Owner owner)
Sets the owner of a tile.
Definition: tile_map.h:198
byte m7
Primarily used for newgrf support.
Definition: map_type.h:35
Map accessors for roads.
uint16 m2
Primarily used for indices to towns, industries and stations.
Definition: map_type.h:20
A town owns the tile, or a town is expanding.
Definition: company_type.h:24
Tile * _m
Tiles of the map.
Definition: map.cpp:30
static void MakeRailTunnel(TileIndex t, Owner o, DiagDirection d, RailType r)
Makes a rail tunnel entrance.
Definition: tunnel_map.h:72
RoadType
The different roadtypes we support.
Definition: road_type.h:22
static void SetRoadTypes(TileIndex t, RoadType road_rt, RoadType tram_rt)
Set the present road types of a tile.
Definition: road_map.h:619
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
TileExtended * _me
Extended Tiles of the map.
Definition: map.cpp:31
byte m5
General purpose.
Definition: map_type.h:24
bool IsTunnelInWay(TileIndex, int z)
Is there a tunnel in the way in any direction?
Definition: tunnel_map.cpp:68
static void SetRoadOwner(TileIndex t, RoadTramType rtt, Owner o)
Set the owner of a specific road type.
Definition: road_map.h:250
Transport by train.
bool IsTunnelInWayDir(TileIndex tile, int z, DiagDirection dir)
Is there a tunnel in the way in the given direction?
Definition: tunnel_map.cpp:48
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:27
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:50
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
static void MakeRoadTunnel(TileIndex t, Owner o, DiagDirection d, RoadType road_rt, RoadType tram_rt)
Makes a road tunnel entrance.
Definition: tunnel_map.h:49
static void SetTileType(TileIndex tile, TileType type)
Set the type of a tile.
Definition: tile_map.h:131
Transport by road vehicle.
uint16 m8
General purpose.
Definition: map_type.h:36
static bool IsTunnelTile(TileIndex t)
Is this a tunnel (entrance)?
Definition: tunnel_map.h:33
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
DiagDirection
Enumeration for diagonal directions.
TileIndex GetOtherTunnelEnd(TileIndex)
Gets the other end of the tunnel.
Definition: tunnel_map.cpp:22
byte m3
General purpose.
Definition: map_type.h:22
static bool IsTunnel(TileIndex t)
Is this a tunnel (entrance)?
Definition: tunnel_map.h:22
byte m4
General purpose.
Definition: map_type.h:23