OpenTTD

tunnel_map.h
Go to the documentation of this file.
1 /* $Id: tunnel_map.h 26878 2014-09-21 11:23:33Z rubidium $ */
2
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 */
9
12 #ifndef TUNNEL_MAP_H
13 #define TUNNEL_MAP_H
14
15 #include "road_map.h"
16
17
24 static inline bool IsTunnel(TileIndex t)
25 {
26 assert(IsTileType(t, MP_TUNNELBRIDGE));
27 return !HasBit(_m[t].m5, 7);
28 }
29
35 static inline bool IsTunnelTile(TileIndex t)
36 {
37 return IsTileType(t, MP_TUNNELBRIDGE) && IsTunnel(t);
38 }
39
40 TileIndex GetOtherTunnelEnd(TileIndex);
41 bool IsTunnelInWay(TileIndex, int z);
42 bool IsTunnelInWayDir(TileIndex tile, int z, DiagDirection dir);
43
51 static inline void MakeRoadTunnel(TileIndex t, Owner o, DiagDirection d, RoadTypes r)
52 {
53 SetTileType(t, MP_TUNNELBRIDGE);
54 SetTileOwner(t, o);
55 _m[t].m2 = 0;
56 _m[t].m3 = 0;
57 _m[t].m4 = 0;
58 _m[t].m5 = TRANSPORT_ROAD << 2 | d;
59 SB(_me[t].m6, 2, 4, 0);
60 _me[t].m7 = 0;
61 SetRoadOwner(t, ROADTYPE_ROAD, o);
62 if (o != OWNER_TOWN) SetRoadOwner(t, ROADTYPE_TRAM, o);
63 SetRoadTypes(t, r);
64 }
65
73 static inline void MakeRailTunnel(TileIndex t, Owner o, DiagDirection d, RailType r)
74 {
75 SetTileType(t, MP_TUNNELBRIDGE);
76 SetTileOwner(t, o);
77 _m[t].m2 = 0;
78 _m[t].m3 = r;
79 _m[t].m4 = 0;
80 _m[t].m5 = TRANSPORT_RAIL << 2 | d;
81 SB(_me[t].m6, 2, 4, 0);
82 _me[t].m7 = 0;
83 }
84
85 #endif /* TUNNEL_MAP_H */
SetTileOwner
static void SetTileOwner(TileIndex tile, Owner owner)
Sets the owner of a tile.
Definition: tile_map.h:191
RailType
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:29
ROADTYPE_ROAD
Basic road type.
Definition: road_type.h:24
TileExtended::m7
byte m7
Primarily used for newgrf support.
Definition: map_type.h:37
road_map.h
Map accessors for roads.
Tile::m2
uint16 m2
Primarily used for indices to towns, industries and stations.
Definition: map_type.h:22
_m
Tile * _m
Tiles of the map.
Definition: map.cpp:32
MakeRailTunnel
static void MakeRailTunnel(TileIndex t, Owner o, DiagDirection d, RailType r)
Makes a rail tunnel entrance.
Definition: tunnel_map.h:73
SB
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.
Definition: bitmath_func.hpp:60
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
Definition: tile_map.h:143
SetRoadOwner
static void SetRoadOwner(TileIndex t, RoadType rt, Owner o)
Set the owner of a specific road type.
Definition: road_map.h:220
ROADTYPE_TRAM
Trams.
Definition: road_type.h:25
_me
TileExtended * _me
Extended Tiles of the map.
Definition: map.cpp:33
Tile::m5
byte m5
General purpose.
Definition: map_type.h:26
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:80
IsTunnelInWay
bool IsTunnelInWay(TileIndex, int z)
Is there a tunnel in the way in any direction?
Definition: tunnel_map.cpp:70
RoadTypes
RoadTypes
The different roadtypes we support, but then a bitmask of them.
Definition: road_type.h:36
TRANSPORT_RAIL
Transport by train.
Definition: transport_type.h:29
IsTunnelInWayDir
bool IsTunnelInWayDir(TileIndex tile, int z, DiagDirection dir)
Is there a tunnel in the way in the given direction?
Definition: tunnel_map.cpp:50
MakeRoadTunnel
static void MakeRoadTunnel(TileIndex t, Owner o, DiagDirection d, RoadTypes r)
Makes a road tunnel entrance.
Definition: tunnel_map.h:51
MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:52
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
OWNER_TOWN
A town owns the tile, or a town is expanding.
Definition: company_type.h:26
SetTileType
static void SetTileType(TileIndex tile, TileType type)
Set the type of a tile.
Definition: tile_map.h:124
TRANSPORT_ROAD
Transport by road vehicle.
Definition: transport_type.h:30
IsTunnelTile
static bool IsTunnelTile(TileIndex t)
Is this a tunnel (entrance)?
Definition: tunnel_map.h:35
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:105
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:20
GetOtherTunnelEnd
TileIndex GetOtherTunnelEnd(TileIndex)
Gets the other end of the tunnel.
Definition: tunnel_map.cpp:24
SetRoadTypes
static void SetRoadTypes(TileIndex t, RoadTypes rt)
Set the present road types of a tile.
Definition: road_map.h:176
Tile::m3
byte m3
General purpose.
Definition: map_type.h:24
IsTunnel
static bool IsTunnel(TileIndex t)
Is this a tunnel (entrance)?
Definition: tunnel_map.h:24
Tile::m4
byte m4
General purpose.
Definition: map_type.h:25