OpenTTD Source  20241108-master-g80f628063a
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 */
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
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 T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
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.
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
Header file for bridges.
uint BridgeType
Bridge spec number.
Definition: bridge.h:37
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:181
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:169
TileIndex GetSouthernBridgeEnd(TileIndex t)
Finds the southern end of a bridge starting at a middle tile.
Definition: bridge_map.cpp:49
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:153
int GetBridgeHeight(TileIndex tile)
Get the height ('z') of a bridge.
Definition: bridge_map.cpp:70
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.
Definition: bridge_map.cpp:59
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.
Definition: bridge_map.cpp:39
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
Wrapper class to abstract away the way the tiles are stored.
Definition: map_func.h:25
debug_inline uint16_t & m8()
General purpose.
Definition: map_func.h:197
debug_inline uint8_t & m7()
Primarily used for newgrf support.
Definition: map_func.h:185
debug_inline uint8_t & type()
The type (bits 4..7), bridges (2..3), rainforest/desert (0..1)
Definition: map_func.h:89
debug_inline uint8_t & m5()
General purpose.
Definition: map_func.h:161
debug_inline uint8_t & m4()
General purpose.
Definition: map_func.h:149
debug_inline uint16_t & m2()
Primarily used for indices to towns, industries and stations.
Definition: map_func.h:125
debug_inline uint8_t & m6()
General purpose.
Definition: map_func.h:173
debug_inline uint8_t & m3()
General purpose.
Definition: map_func.h:137
Owner
Enum for all companies/owners.
Definition: company_type.h:18
@ OWNER_TOWN
A town owns the tile, or a town is expanding.
Definition: company_type.h:24
Axis
Allow incrementing of DiagDirDiff variables.
@ AXIS_X
The X axis.
@ AXIS_Y
The y axis.
DiagDirection
Enumeration for diagonal directions.
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:27
Map accessors for roads.
void SetRoadOwner(Tile t, RoadTramType rtt, Owner o)
Set the owner of a specific road type.
Definition: road_map.h:251
void SetRoadTypes(Tile t, RoadType road_rt, RoadType tram_rt)
Set the present road types of a tile.
Definition: road_map.h:619
RoadType
The different roadtypes we support.
Definition: road_type.h:25
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition: road_type.h:30
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
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_BASE.
Definition: tile_type.h:18
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:57
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:361