OpenTTD Source  1.11.2
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 static inline bool IsBridge(TileIndex t)
25 {
26  assert(IsTileType(t, MP_TUNNELBRIDGE));
27  return HasBit(_m[t].m5, 7);
28 }
29 
35 static inline bool IsBridgeTile(TileIndex t)
36 {
37  return IsTileType(t, MP_TUNNELBRIDGE) && IsBridge(t);
38 }
39 
45 static inline bool IsBridgeAbove(TileIndex t)
46 {
47  return GB(_m[t].type, 2, 2) != 0;
48 }
49 
57 {
58  assert(IsBridgeTile(t));
59  return GB(_me[t].m6, 2, 4);
60 }
61 
68 static inline Axis GetBridgeAxis(TileIndex t)
69 {
70  assert(IsBridgeAbove(t));
71  return (Axis)(GB(_m[t].type, 2, 2) - 1);
72 }
73 
77 
78 int GetBridgeHeight(TileIndex tile);
84 static inline int GetBridgePixelHeight(TileIndex tile)
85 {
86  return GetBridgeHeight(tile) * TILE_HEIGHT;
87 }
88 
94 static inline void ClearSingleBridgeMiddle(TileIndex t, Axis a)
95 {
96  ClrBit(_m[t].type, 2 + a);
97 }
98 
103 static inline void ClearBridgeMiddle(TileIndex t)
104 {
107 }
108 
114 static inline void SetBridgeMiddle(TileIndex t, Axis a)
115 {
116  SetBit(_m[t].type, 2 + a);
117 }
118 
128 static inline void MakeBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, TransportType tt)
129 {
131  SetTileOwner(t, o);
132  SetDockingTile(t, false);
133  _m[t].m2 = 0;
134  _m[t].m3 = 0;
135  _m[t].m4 = INVALID_ROADTYPE;
136  _m[t].m5 = 1 << 7 | tt << 2 | d;
137  SB(_me[t].m6, 2, 4, bridgetype);
138  _me[t].m7 = 0;
139  _me[t].m8 = INVALID_ROADTYPE << 6;
140 }
141 
153 static inline void MakeRoadBridgeRamp(TileIndex 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 static inline void MakeRailBridgeRamp(TileIndex 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 */
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:83
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
GetBridgeType
static BridgeType GetBridgeType(TileIndex t)
Determines the type of bridge on a tile.
Definition: bridge_map.h:56
SetTileType
static void SetTileType(TileIndex tile, TileType type)
Set the type of a tile.
Definition: tile_map.h:131
TRANSPORT_RAIL
@ TRANSPORT_RAIL
Transport by train.
Definition: transport_type.h:27
INVALID_ROADTYPE
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition: road_type.h:27
MakeAqueductBridgeRamp
static void MakeAqueductBridgeRamp(TileIndex t, Owner o, DiagDirection d)
Make a bridge ramp for aqueducts.
Definition: bridge_map.h:181
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
_me
TileExtended * _me
Extended Tiles of the map.
Definition: map.cpp:31
ClrBit
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
Definition: bitmath_func.hpp:151
Tile::m2
uint16 m2
Primarily used for indices to towns, industries and stations.
Definition: map_type.h:20
SetRoadOwner
static void SetRoadOwner(TileIndex t, RoadTramType rtt, Owner o)
Set the owner of a specific road type.
Definition: road_map.h:250
SetRoadTypes
static void SetRoadTypes(TileIndex t, RoadType road_rt, RoadType tram_rt)
Set the present road types of a tile.
Definition: road_map.h:619
TransportType
TransportType
Available types of transport.
Definition: transport_type.h:19
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
TRANSPORT_ROAD
@ TRANSPORT_ROAD
Transport by road vehicle.
Definition: transport_type.h:28
AXIS_Y
@ AXIS_Y
The y axis.
Definition: direction_type.h:125
RailType
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:27
IsBridgeTile
static bool IsBridgeTile(TileIndex t)
checks if there is a bridge on this tile
Definition: bridge_map.h:35
SetBridgeMiddle
static void SetBridgeMiddle(TileIndex t, Axis a)
Set that there is a bridge over the given axis.
Definition: bridge_map.h:114
GetBridgeHeight
int GetBridgeHeight(TileIndex tile)
Get the height ('z') of a bridge.
Definition: bridge_map.cpp:70
SB
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
Definition: bitmath_func.hpp:58
rail_map.h
SetDockingTile
static void SetDockingTile(TileIndex t, bool b)
Set the docking tile state of a tile.
Definition: water_map.h:355
GetNorthernBridgeEnd
TileIndex GetNorthernBridgeEnd(TileIndex t)
Finds the northern end of a bridge starting at a middle tile.
Definition: bridge_map.cpp:39
IsBridge
static bool IsBridge(TileIndex t)
Checks if this is a bridge, instead of a tunnel.
Definition: bridge_map.h:24
MP_TUNNELBRIDGE
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:55
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:77
BridgeType
uint BridgeType
Bridge spec number.
Definition: bridge.h:36
RoadType
RoadType
The different roadtypes we support.
Definition: road_type.h:22
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
road_map.h
GetBridgeAxis
static Axis GetBridgeAxis(TileIndex t)
Get the axis of the bridge that goes over the tile.
Definition: bridge_map.h:68
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
Tile::m5
byte m5
General purpose.
Definition: map_type.h:24
bridge.h
ClearBridgeMiddle
static void ClearBridgeMiddle(TileIndex t)
Removes bridges from the given, that is bridges along the X and Y axis.
Definition: bridge_map.h:103
TRANSPORT_WATER
@ TRANSPORT_WATER
Transport over water.
Definition: transport_type.h:29
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
GetBridgePixelHeight
static int GetBridgePixelHeight(TileIndex tile)
Get the height ('z') of a bridge in pixels.
Definition: bridge_map.h:84
TILE_HEIGHT
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
Definition: tile_type.h:16
TileExtended::m7
byte m7
Primarily used for newgrf support.
Definition: map_type.h:35
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition: direction_type.h:123
SetTileOwner
static void SetTileOwner(TileIndex tile, Owner owner)
Sets the owner of a tile.
Definition: tile_map.h:198
MakeRoadBridgeRamp
static void MakeRoadBridgeRamp(TileIndex 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
Tile::m3
byte m3
General purpose.
Definition: map_type.h:22
MakeRailBridgeRamp
static void MakeRailBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RailType rt)
Make a bridge ramp for rails.
Definition: bridge_map.h:169
TileExtended::m8
uint16 m8
General purpose.
Definition: map_type.h:36
SetRailType
static void SetRailType(TileIndex t, RailType r)
Sets the rail type of the given tile.
Definition: rail_map.h:125
Tile::m4
byte m4
General purpose.
Definition: map_type.h:23
_m
Tile * _m
Tiles of the map.
Definition: map.cpp:30
MakeBridgeRamp
static void MakeBridgeRamp(TileIndex 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
GetOtherBridgeEnd
TileIndex GetOtherBridgeEnd(TileIndex t)
Starting at one bridge end finds the other bridge end.
Definition: bridge_map.cpp:59
ClearSingleBridgeMiddle
static void ClearSingleBridgeMiddle(TileIndex t, Axis a)
Remove the bridge over the given axis.
Definition: bridge_map.h:94
OWNER_TOWN
@ OWNER_TOWN
A town owns the tile, or a town is expanding.
Definition: company_type.h:24
IsBridgeAbove
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
Definition: bridge_map.h:45
AXIS_X
@ AXIS_X
The X axis.
Definition: direction_type.h:124