OpenTTD Source  20240915-master-g3784a3d3d6
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 <http://www.gnu.org/licenses/>.
6  */
7 
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 
24 inline bool IsBridge(Tile t)
25 {
26  assert(IsTileType(t, MP_TUNNELBRIDGE));
27  return HasBit(t.m5(), 7);
28 }
29 
35 inline bool IsBridgeTile(Tile t)
36 {
37  return IsTileType(t, MP_TUNNELBRIDGE) && IsBridge(t);
38 }
39 
45 inline 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 (Axis)(GB(t.type(), 2, 2) - 1);
72 }
73 
77 
78 int GetBridgeHeight(TileIndex tile);
85 {
86  return GetBridgeHeight(tile) * TILE_HEIGHT;
87 }
88 
95 {
96  ClrBit(t.type(), 2 + a);
97 }
98 
103 inline void ClearBridgeMiddle(Tile t)
104 {
107 }
108 
114 inline void SetBridgeMiddle(Tile t, Axis a)
115 {
116  SetBit(t.type(), 2 + a);
117 }
118 
128 inline 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() = INVALID_ROADTYPE;
136  t.m5() = 1 << 7 | tt << 2 | d;
137  SB(t.m6(), 2, 4, bridgetype);
138  t.m7() = 0;
139  t.m8() = INVALID_ROADTYPE << 6;
140 }
141 
153 inline void MakeRoadBridgeRamp(Tile t, Owner o, Owner owner_road, Owner owner_tram, BridgeType bridgetype, DiagDirection d, RoadType road_rt, RoadType tram_rt)
154 {
155  MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_ROAD);
156  SetRoadOwner(t, RTT_ROAD, owner_road);
157  if (owner_tram != OWNER_TOWN) SetRoadOwner(t, RTT_TRAM, owner_tram);
158  SetRoadTypes(t, road_rt, tram_rt);
159 }
160 
169 inline void MakeRailBridgeRamp(Tile t, Owner o, BridgeType bridgetype, DiagDirection d, RailType rt)
170 {
171  MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_RAIL);
172  SetRailType(t, rt);
173 }
174 
182 {
183  MakeBridgeRamp(t, o, 0, d, TRANSPORT_WATER);
184 }
185 
186 #endif /* BRIDGE_MAP_H */
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
Tile::m5
debug_inline uint8_t & m5()
General purpose.
Definition: map_func.h:161
SetRoadTypes
void SetRoadTypes(Tile t, RoadType road_rt, RoadType tram_rt)
Set the present road types of a tile.
Definition: road_map.h:619
Tile::m3
debug_inline uint8_t & m3()
General purpose.
Definition: map_func.h:137
TRANSPORT_WATER
@ TRANSPORT_WATER
Transport over water.
Definition: transport_type.h:29
GB
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
RailType
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:27
Tile::m8
debug_inline uint16_t & m8()
General purpose.
Definition: map_func.h:197
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:73
Tile
Wrapper class to abstract away the way the tiles are stored.
Definition: map_func.h:25
ClearBridgeMiddle
void ClearBridgeMiddle(Tile t)
Removes bridges from the given, that is bridges along the X and Y axis.
Definition: bridge_map.h:103
MakeBridgeRamp
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
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
Tile::m4
debug_inline uint8_t & m4()
General purpose.
Definition: map_func.h:149
Tile::m7
debug_inline uint8_t & m7()
Primarily used for newgrf support.
Definition: map_func.h:185
TRANSPORT_ROAD
@ TRANSPORT_ROAD
Transport by road vehicle.
Definition: transport_type.h:28
MakeRailBridgeRamp
void MakeRailBridgeRamp(Tile t, Owner o, BridgeType bridgetype, DiagDirection d, RailType rt)
Make a bridge ramp for rails.
Definition: bridge_map.h:169
SetBridgeMiddle
void SetBridgeMiddle(Tile t, Axis a)
Set that there is a bridge over the given axis.
Definition: bridge_map.h:114
TransportType
TransportType
Available types of transport.
Definition: transport_type.h:19
Tile::m2
debug_inline uint16_t & m2()
Primarily used for indices to towns, industries and stations.
Definition: map_func.h:125
IsBridge
bool IsBridge(Tile t)
Checks if this is a bridge, instead of a tunnel.
Definition: bridge_map.h:24
GetBridgeHeight
int GetBridgeHeight(TileIndex tile)
Get the height ('z') of a bridge.
Definition: bridge_map.cpp:70
rail_map.h
IsBridgeTile
bool IsBridgeTile(Tile t)
checks if there is a bridge on this tile
Definition: bridge_map.h:35
RoadType
RoadType
The different roadtypes we support.
Definition: road_type.h:25
GetNorthernBridgeEnd
TileIndex GetNorthernBridgeEnd(TileIndex t)
Finds the northern end of a bridge starting at a middle tile.
Definition: bridge_map.cpp:39
MP_TUNNELBRIDGE
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:57
INVALID_ROADTYPE
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition: road_type.h:30
Tile::m6
debug_inline uint8_t & m6()
General purpose.
Definition: map_func.h:173
BridgeType
uint BridgeType
Bridge spec number.
Definition: bridge.h:37
SetTileOwner
void SetTileOwner(Tile tile, Owner owner)
Sets the owner of a tile.
Definition: tile_map.h:198
OWNER_TOWN
@ OWNER_TOWN
A town owns the tile, or a town is expanding.
Definition: company_type.h:24
road_map.h
AXIS_X
@ AXIS_X
The X axis.
Definition: direction_type.h:117
water_map.h
GetSouthernBridgeEnd
TileIndex GetSouthernBridgeEnd(TileIndex t)
Finds the southern end of a bridge starting at a middle tile.
Definition: bridge_map.cpp:49
bridge.h
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition: direction_type.h:116
TRANSPORT_RAIL
@ TRANSPORT_RAIL
Transport by train.
Definition: transport_type.h:27
SetDockingTile
void SetDockingTile(Tile t, bool b)
Set the docking tile state of a tile.
Definition: water_map.h:364
SetRailType
void SetRailType(Tile t, RailType r)
Sets the rail type of the given tile.
Definition: rail_map.h:125
SetTileType
void SetTileType(Tile tile, TileType type)
Set the type of a tile.
Definition: tile_map.h:131
IsBridgeAbove
bool IsBridgeAbove(Tile t)
checks if a bridge is set above the ground of this tile
Definition: bridge_map.h:45
SetRoadOwner
void SetRoadOwner(Tile t, RoadTramType rtt, Owner o)
Set the owner of a specific road type.
Definition: road_map.h:251
TILE_HEIGHT
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_BASE.
Definition: tile_type.h:18
MakeRoadBridgeRamp
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:153
SB
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.
Definition: bitmath_func.hpp:58
IsTileType
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
MakeAqueductBridgeRamp
void MakeAqueductBridgeRamp(Tile t, Owner o, DiagDirection d)
Make a bridge ramp for aqueducts.
Definition: bridge_map.h:181
GetBridgePixelHeight
int GetBridgePixelHeight(TileIndex tile)
Get the height ('z') of a bridge in pixels.
Definition: bridge_map.h:84
AXIS_Y
@ AXIS_Y
The y axis.
Definition: direction_type.h:118
GetBridgeAxis
Axis GetBridgeAxis(Tile t)
Get the axis of the bridge that goes over the tile.
Definition: bridge_map.h:68
ClrBit
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
Definition: bitmath_func.hpp:151
ClearSingleBridgeMiddle
void ClearSingleBridgeMiddle(Tile t, Axis a)
Remove the bridge over the given axis.
Definition: bridge_map.h:94
Tile::type
debug_inline uint8_t & type()
The type (bits 4..7), bridges (2..3), rainforest/desert (0..1)
Definition: map_func.h:89
GetOtherBridgeEnd
TileIndex GetOtherBridgeEnd(TileIndex t)
Starting at one bridge end finds the other bridge end.
Definition: bridge_map.cpp:59
GetBridgeType
BridgeType GetBridgeType(Tile t)
Determines the type of bridge on a tile.
Definition: bridge_map.h:56
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103