OpenTTD Source 20260531-master-g0e951f3528
bridge_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 BRIDGE_MAP_H
11#define BRIDGE_MAP_H
12
13#include "rail_map.h"
14#include "road_map.h"
15#include "bridge.h"
16#include "water_map.h"
17
24inline bool IsBridge(Tile t)
25{
27 return HasBit(t.m5(), 7);
28}
29
35inline bool IsBridgeTile(Tile t)
36{
38}
39
45inline bool IsBridgeAbove(Tile t)
46{
47 return GB(t.type(), 2, 2) != 0;
48}
49
57{
58 assert(IsBridgeTile(t));
59 return GB(t.m6(), 2, 4);
60}
61
69{
70 assert(IsBridgeAbove(t));
71 return static_cast<Axis>(GB(t.type(), 2, 2) - 1);
72}
73
77
85{
86 return GetBridgeHeight(tile) * TILE_HEIGHT;
87}
88
95{
96 ClrBit(t.type(), 2 + to_underlying(a));
97}
98
108
114inline void SetBridgeMiddle(Tile t, Axis a)
115{
116 SetBit(t.type(), 2 + to_underlying(a));
117}
118
128inline void MakeBridgeRamp(Tile t, Owner o, BridgeType bridgetype, DiagDirection d, TransportType tt)
129{
131 SetTileOwner(t, o);
132 SetDockingTile(t, false);
133 t.m2() = 0;
134 t.m3() = 0;
135 t.m4() = 0;
136 t.m5() = 1 << 7 | tt << 2 | to_underlying(d);
137 SB(t.m6(), 2, 4, bridgetype);
138 SB(t.m6(), 6, 2, 0);
139 t.m7() = 0;
140 t.m8() = 0;
141}
142
154inline void MakeRoadBridgeRamp(Tile t, Owner o, Owner owner_road, Owner owner_tram, BridgeType bridgetype, DiagDirection d, RoadType road_rt, RoadType tram_rt)
155{
156 MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_ROAD);
157 SetRoadOwner(t, RoadTramType::Road, owner_road);
158 if (owner_tram != OWNER_TOWN) SetRoadOwner(t, RoadTramType::Tram, owner_tram);
159 SetRoadTypes(t, road_rt, tram_rt);
160}
161
170inline void MakeRailBridgeRamp(Tile t, Owner o, BridgeType bridgetype, DiagDirection d, RailType rt)
171{
172 MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_RAIL);
173 SetRailType(t, rt);
174}
175
182inline void MakeAqueductBridgeRamp(Tile t, Owner o, DiagDirection d)
183{
184 MakeBridgeRamp(t, o, 0, d, TRANSPORT_WATER);
185}
186
187#endif /* BRIDGE_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.
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
Header file for bridges.
void SetBridgeMiddle(Tile t, Axis a)
Set that there is a bridge over the given axis.
Definition bridge_map.h:114
void MakeAqueductBridgeRamp(Tile t, Owner o, DiagDirection d)
Make a bridge ramp for aqueducts.
Definition bridge_map.h:182
bool IsBridgeTile(Tile t)
checks if there is a bridge on this tile
Definition bridge_map.h:35
void MakeRailBridgeRamp(Tile t, Owner o, BridgeType bridgetype, DiagDirection d, RailType rt)
Make a bridge ramp for rails.
Definition bridge_map.h:170
TileIndex GetSouthernBridgeEnd(TileIndex t)
Finds the southern end of a bridge starting at a middle tile.
void ClearSingleBridgeMiddle(Tile t, Axis a)
Remove the bridge over the given axis.
Definition bridge_map.h:94
int GetBridgePixelHeight(TileIndex tile)
Get the height ('z') of a bridge in pixels.
Definition bridge_map.h:84
void ClearBridgeMiddle(Tile t)
Removes bridges from the given, that is bridges along the X and Y axis.
Definition bridge_map.h:103
void MakeRoadBridgeRamp(Tile t, Owner o, Owner owner_road, Owner owner_tram, BridgeType bridgetype, DiagDirection d, RoadType road_rt, RoadType tram_rt)
Make a bridge ramp for roads.
Definition bridge_map.h:154
int GetBridgeHeight(TileIndex tile)
Get the height ('z') of a bridge.
BridgeType GetBridgeType(Tile t)
Determines the type of bridge on a tile.
Definition bridge_map.h:56
TileIndex GetOtherBridgeEnd(TileIndex t)
Starting at one bridge end finds the other bridge end.
bool IsBridgeAbove(Tile t)
checks if a bridge is set above the ground of this tile
Definition bridge_map.h:45
void MakeBridgeRamp(Tile t, Owner o, BridgeType bridgetype, DiagDirection d, TransportType tt)
Generic part to make a bridge ramp for both roads and rails.
Definition bridge_map.h:128
TileIndex GetNorthernBridgeEnd(TileIndex t)
Finds the northern end of a bridge starting at a middle tile.
Axis GetBridgeAxis(Tile t)
Get the axis of the bridge that goes over the tile.
Definition bridge_map.h:68
bool IsBridge(Tile t)
Checks if this is a bridge, instead of a tunnel.
Definition bridge_map.h:24
uint BridgeType
Bridge spec number.
Definition bridge_type.h:15
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 & type()
The type (bits 4..7), bridges (2..3), rainforest/desert (0..1).
Definition map_func.h:90
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.
Axis
Enumeration for the two axis X and Y.
@ X
The X axis.
@ Y
The y axis.
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
static constexpr uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in ZOOM_BASE.
Definition tile_type.h:18
@ TunnelBridge
Tunnel entry/exit and bridge heads.
Definition tile_type.h:58
TransportType
Available types of transport.
@ TRANSPORT_RAIL
Transport by train.
@ TRANSPORT_ROAD
Transport by road vehicle.
@ TRANSPORT_WATER
Transport over water.
Map accessors for water tiles.
void SetDockingTile(Tile t, bool b)
Set the docking tile state of a tile.
Definition water_map.h:364