OpenTTD Source: src/bridge_map.h Source File

OpenTTD Source 15.3

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
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
56 inline BridgeType GetBridgeType(Tile t)
57{
58 assert(IsBridgeTile(t));
59 return GB(t.m6(), 2, 4);
60}
61
68 inline Axis GetBridgeAxis(Tile t)
69{
70 assert(IsBridgeAbove(t));
71 return (Axis)(GB(t.type(), 2, 2) - 1);
72}
73
74 TileIndex GetNorthernBridgeEnd(TileIndex t);
75 TileIndex GetSouthernBridgeEnd(TileIndex t);
76 TileIndex GetOtherBridgeEnd(TileIndex t);
77
78int GetBridgeHeight(TileIndex tile);
84 inline int GetBridgePixelHeight(TileIndex tile)
85{
86 return GetBridgeHeight(tile) * TILE_HEIGHT;
87}
88
94 inline void ClearSingleBridgeMiddle(Tile t, Axis a)
95{
96 ClrBit(t.type(), 2 + a);
97}
98
103 inline void ClearBridgeMiddle(Tile t)
104{
105 ClearSingleBridgeMiddle(t, AXIS_X);
106 ClearSingleBridgeMiddle(t, AXIS_Y);
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{
130 SetTileType(t, MP_TUNNELBRIDGE);
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 | 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
154 inline 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, RTT_ROAD, owner_road);
158 if (owner_tram != OWNER_TOWN) SetRoadOwner(t, RTT_TRAM, owner_tram);
159 SetRoadTypes(t, road_rt, tram_rt);
160}
161
170 inline 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
182 inline void MakeAqueductBridgeRamp(Tile t, Owner o, DiagDirection d)
183{
184 MakeBridgeRamp(t, o, 0, d, TRANSPORT_WATER);
185}
186
187#endif /* BRIDGE_MAP_H */
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
GB
static constexpr 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
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition bitmath_func.hpp:121
HasBit
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition bitmath_func.hpp:103
ClrBit
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
Definition bitmath_func.hpp:139
bridge.h
Header file for bridges.
SetBridgeMiddle
void SetBridgeMiddle(Tile t, Axis a)
Set that there is a bridge over the given axis.
Definition bridge_map.h:114
MakeAqueductBridgeRamp
void MakeAqueductBridgeRamp(Tile t, Owner o, DiagDirection d)
Make a bridge ramp for aqueducts.
Definition bridge_map.h:182
IsBridgeTile
bool IsBridgeTile(Tile t)
checks if there is a bridge on this tile
Definition bridge_map.h:35
MakeRailBridgeRamp
void MakeRailBridgeRamp(Tile t, Owner o, BridgeType bridgetype, DiagDirection d, RailType rt)
Make a bridge ramp for rails.
Definition bridge_map.h:170
GetSouthernBridgeEnd
TileIndex GetSouthernBridgeEnd(TileIndex t)
Finds the southern end of a bridge starting at a middle tile.
Definition bridge_map.cpp:49
ClearSingleBridgeMiddle
void ClearSingleBridgeMiddle(Tile t, Axis a)
Remove the bridge over the given axis.
Definition bridge_map.h:94
GetBridgePixelHeight
int GetBridgePixelHeight(TileIndex tile)
Get the height ('z') of a bridge in pixels.
Definition bridge_map.h:84
ClearBridgeMiddle
void ClearBridgeMiddle(Tile t)
Removes bridges from the given, that is bridges along the X and Y axis.
Definition bridge_map.h:103
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:154
GetBridgeHeight
int GetBridgeHeight(TileIndex tile)
Get the height ('z') of a bridge.
Definition bridge_map.cpp:70
GetBridgeType
BridgeType GetBridgeType(Tile t)
Determines the type of bridge on a tile.
Definition bridge_map.h:56
GetOtherBridgeEnd
TileIndex GetOtherBridgeEnd(TileIndex t)
Starting at one bridge end finds the other bridge end.
Definition bridge_map.cpp:59
IsBridgeAbove
bool IsBridgeAbove(Tile t)
checks if a bridge is set above the ground of this tile
Definition bridge_map.h:45
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
GetNorthernBridgeEnd
TileIndex GetNorthernBridgeEnd(TileIndex t)
Finds the northern end of a bridge starting at a middle tile.
Definition bridge_map.cpp:39
GetBridgeAxis
Axis GetBridgeAxis(Tile t)
Get the axis of the bridge that goes over the tile.
Definition bridge_map.h:68
IsBridge
bool IsBridge(Tile t)
Checks if this is a bridge, instead of a tunnel.
Definition bridge_map.h:24
BridgeType
uint BridgeType
Bridge spec number.
Definition bridge_type.h:15
Tile
Wrapper class to abstract away the way the tiles are stored.
Definition map_func.h:25
Tile::m5
uint8_t & m5()
General purpose.
Definition map_func.h:161
Tile::m4
uint8_t & m4()
General purpose.
Definition map_func.h:149
Tile::m6
uint8_t & m6()
General purpose.
Definition map_func.h:173
Tile::type
uint8_t & type()
The type (bits 4..7), bridges (2..3), rainforest/desert (0..1)
Definition map_func.h:89
Tile::m7
uint8_t & m7()
Primarily used for newgrf support.
Definition map_func.h:185
Tile::m3
uint8_t & m3()
General purpose.
Definition map_func.h:137
Tile::m8
uint16_t & m8()
General purpose.
Definition map_func.h:197
Tile::m2
uint16_t & m2()
Primarily used for indices to towns, industries and stations.
Definition map_func.h:125
OWNER_TOWN
static constexpr Owner OWNER_TOWN
A town owns the tile, or a town is expanding.
Definition company_type.h:25
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition direction_type.h:123
AXIS_X
@ AXIS_X
The X axis.
Definition direction_type.h:124
AXIS_Y
@ AXIS_Y
The y axis.
Definition direction_type.h:125
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition direction_type.h:78
rail_map.h
Hides the direct accesses to the map array with map accessors.
SetRailType
void SetRailType(Tile t, RailType r)
Sets the rail type of the given tile.
Definition rail_map.h:125
RailType
RailType
Enumeration for all possible railtypes.
Definition rail_type.h:25
road_map.h
Map accessors for roads.
SetRoadOwner
void SetRoadOwner(Tile t, RoadTramType rtt, Owner o)
Set the owner of a specific road type.
Definition road_map.h:235
SetRoadTypes
void SetRoadTypes(Tile t, RoadType road_rt, RoadType tram_rt)
Set the present road types of a tile.
Definition road_map.h:604
RTT_ROAD
@ RTT_ROAD
Road road type.
Definition road_type.h:38
RTT_TRAM
@ RTT_TRAM
Tram road type.
Definition road_type.h:39
RoadType
RoadType
The different roadtypes we support.
Definition road_type.h:23
PoolID< uint8_t, struct CompanyIDTag, 0xF, 0xFF >
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
IsTileType
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
SetTileType
void SetTileType(Tile tile, TileType type)
Set the type of a tile.
Definition tile_map.h:131
SetTileOwner
void SetTileOwner(Tile tile, Owner owner)
Sets the owner of a tile.
Definition tile_map.h:198
TILE_HEIGHT
static constexpr uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in ZOOM_BASE.
Definition tile_type.h:18
MP_TUNNELBRIDGE
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition tile_type.h:57
TransportType
TransportType
Available types of transport.
Definition transport_type.h:17
TRANSPORT_RAIL
@ TRANSPORT_RAIL
Transport by train.
Definition transport_type.h:25
TRANSPORT_ROAD
@ TRANSPORT_ROAD
Transport by road vehicle.
Definition transport_type.h:26
TRANSPORT_WATER
@ TRANSPORT_WATER
Transport over water.
Definition transport_type.h:27
water_map.h
Map accessors for water tiles.
SetDockingTile
void SetDockingTile(Tile t, bool b)
Set the docking tile state of a tile.
Definition water_map.h:363