OpenTTD Source 20260531-master-g0e951f3528
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef TUNNEL_MAP_H
11#define TUNNEL_MAP_H
12
13#include "rail_map.h"
14#include "road_map.h"
15
16
23inline bool IsTunnel(Tile t)
24{
26 return !HasBit(t.m5(), 7);
27}
28
34inline bool IsTunnelTile(Tile t)
35{
37}
38
40bool IsTunnelInWay(TileIndex, int z);
41bool IsTunnelInWayDir(TileIndex tile, int z, DiagDirection dir);
42
51inline void MakeRoadTunnel(Tile t, Owner o, DiagDirection d, RoadType road_rt, RoadType tram_rt)
52{
54 SetTileOwner(t, o);
55 t.m2() = 0;
56 t.m3() = 0;
57 t.m4() = 0;
58 t.m5() = TRANSPORT_ROAD << 2 | to_underlying(d);
59 SB(t.m6(), 2, 6, 0);
60 t.m7() = 0;
61 t.m8() = 0;
64 SetRoadTypes(t, road_rt, tram_rt);
65}
66
74inline void MakeRailTunnel(Tile t, Owner o, DiagDirection d, RailType r)
75{
77 SetTileOwner(t, o);
78 t.m2() = 0;
79 t.m3() = 0;
80 t.m4() = 0;
81 t.m5() = TRANSPORT_RAIL << 2 | to_underlying(d);
82 SB(t.m6(), 2, 6, 0);
83 t.m7() = 0;
84 t.m8() = 0;
85 SetRailType(t, r);
86}
87
88#endif /* TUNNEL_MAP_H */
constexpr T SB(T &x, const uint8_t s, const uint8_t n, const U d)
Set n bits in x starting at bit s to d.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Wrapper class to abstract away the way the tiles are stored.
Definition map_func.h:25
uint8_t & m5()
General purpose.
Definition map_func.h:156
uint8_t & m4()
General purpose.
Definition map_func.h:145
uint8_t & m6()
General purpose.
Definition map_func.h:167
uint8_t & m7()
Primarily used for newgrf support.
Definition map_func.h:178
uint8_t & m3()
General purpose.
Definition map_func.h:134
uint16_t & m8()
General purpose.
Definition map_func.h:189
uint16_t & m2()
Primarily used for indices to towns, industries and stations.
Definition map_func.h:123
static constexpr Owner OWNER_TOWN
A town owns the tile, or a town is expanding.
DiagDirection
Enumeration for diagonal directions.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
Definition enum_type.hpp:21
Hides the direct accesses to the map array with map accessors.
void SetRailType(Tile t, RailType r)
Sets the rail type of the given tile.
Definition rail_map.h:125
RailType
Enumeration for all possible railtypes.
Definition rail_type.h:25
Map accessors for roads.
void SetRoadOwner(Tile t, RoadTramType rtt, Owner o)
Set the owner of a specific road type.
Definition road_map.h:261
void SetRoadTypes(Tile t, RoadType road_rt, RoadType tram_rt)
Set the present road types of a tile.
Definition road_map.h:630
RoadType
The different roadtypes we support.
Definition road_type.h:23
@ Tram
Tram type.
Definition road_type.h:39
@ Road
Road type.
Definition road_type.h:38
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
void SetTileType(Tile tile, TileType type)
Set the type of a tile.
Definition tile_map.h:131
void SetTileOwner(Tile tile, Owner owner)
Sets the owner of a tile.
Definition tile_map.h:198
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
@ TunnelBridge
Tunnel entry/exit and bridge heads.
Definition tile_type.h:58
@ TRANSPORT_RAIL
Transport by train.
@ TRANSPORT_ROAD
Transport by road vehicle.
void MakeRailTunnel(Tile t, Owner o, DiagDirection d, RailType r)
Makes a rail tunnel entrance.
Definition tunnel_map.h:74
bool IsTunnelInWay(TileIndex, int z)
Is there a tunnel in the way in any direction?
bool IsTunnelTile(Tile t)
Is this a tunnel (entrance)?
Definition tunnel_map.h:34
bool IsTunnel(Tile t)
Is this a tunnel (entrance)?
Definition tunnel_map.h:23
void MakeRoadTunnel(Tile t, Owner o, DiagDirection d, RoadType road_rt, RoadType tram_rt)
Makes a road tunnel entrance.
Definition tunnel_map.h:51
TileIndex GetOtherTunnelEnd(TileIndex)
Gets the other end of the tunnel.
bool IsTunnelInWayDir(TileIndex tile, int z, DiagDirection dir)
Is there a tunnel in the way in the given direction?