OpenTTD

bridge_map.h
Go to the documentation of this file.
1 /* $Id: bridge_map.h 26879 2014-09-21 11:24:51Z rubidium $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
12 #ifndef BRIDGE_MAP_H
13 #define BRIDGE_MAP_H
14
15 #include "road_map.h"
16 #include "bridge.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
56 static inline BridgeType GetBridgeType(TileIndex t)
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
74 TileIndex GetNorthernBridgeEnd(TileIndex t);
75 TileIndex GetSouthernBridgeEnd(TileIndex t);
76 TileIndex GetOtherBridgeEnd(TileIndex t);
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 {
105 ClearSingleBridgeMiddle(t, AXIS_X);
106 ClearSingleBridgeMiddle(t, AXIS_Y);
107 }
108
114 static inline void SetBridgeMiddle(TileIndex t, Axis a)
115 {
116 SetBit(_m[t].type, 2 + a);
117 }
118
129 static inline void MakeBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, TransportType tt, uint rt)
130 {
131 SetTileType(t, MP_TUNNELBRIDGE);
132 SetTileOwner(t, o);
133 _m[t].m2 = 0;
134 _m[t].m3 = rt;
135 _m[t].m4 = 0;
136 _m[t].m5 = 1 << 7 | tt << 2 | d;
137 SB(_me[t].m6, 2, 4, bridgetype);
138 _me[t].m7 = 0;
139 }
140
151 static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, Owner owner_road, Owner owner_tram, BridgeType bridgetype, DiagDirection d, RoadTypes r)
152 {
153 MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_ROAD, 0);
154 SetRoadOwner(t, ROADTYPE_ROAD, owner_road);
155 if (owner_tram != OWNER_TOWN) SetRoadOwner(t, ROADTYPE_TRAM, owner_tram);
156 SetRoadTypes(t, r);
157 }
158
167 static inline void MakeRailBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RailType r)
168 {
169 MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_RAIL, r);
170 }
171
178 static inline void MakeAqueductBridgeRamp(TileIndex t, Owner o, DiagDirection d)
179 {
180 MakeBridgeRamp(t, o, 0, d, TRANSPORT_WATER, 0);
181 }
182
183 #endif /* BRIDGE_MAP_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
SetTileOwner
static void SetTileOwner(TileIndex tile, Owner owner)
Sets the owner of a tile.
Definition: tile_map.h:191
RailType
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:29
MakeBridgeRamp
static void MakeBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, TransportType tt, uint rt)
Generic part to make a bridge ramp for both roads and rails.
Definition: bridge_map.h:129
IsBridgeTile
static bool IsBridgeTile(TileIndex t)
checks if there is a bridge on this tile
Definition: bridge_map.h:35
ROADTYPE_ROAD
Basic road type.
Definition: road_type.h:24
TileExtended::m7
byte m7
Primarily used for newgrf support.
Definition: map_type.h:37
road_map.h
Map accessors for roads.
Tile::m2
uint16 m2
Primarily used for indices to towns, industries and stations.
Definition: map_type.h:22
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:123
_m
Tile * _m
Tiles of the map.
Definition: map.cpp:32
GetSouthernBridgeEnd
TileIndex GetSouthernBridgeEnd(TileIndex t)
Finds the southern end of a bridge starting at a middle tile.
Definition: bridge_map.cpp:51
TRANSPORT_WATER
Transport over water.
Definition: transport_type.h:31
GetOtherBridgeEnd
TileIndex GetOtherBridgeEnd(TileIndex t)
Starting at one bridge end finds the other bridge end.
Definition: bridge_map.cpp:61
MakeRoadBridgeRamp
static void MakeRoadBridgeRamp(TileIndex t, Owner o, Owner owner_road, Owner owner_tram, BridgeType bridgetype, DiagDirection d, RoadTypes r)
Make a bridge ramp for roads.
Definition: bridge_map.h:151
ClearSingleBridgeMiddle
static void ClearSingleBridgeMiddle(TileIndex t, Axis a)
Remove the bridge over the given axis.
Definition: bridge_map.h:94
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:60
IsBridgeAbove
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
Definition: bridge_map.h:45
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
Definition: tile_map.h:143
AXIS_Y
The y axis.
Definition: direction_type.h:129
GetNorthernBridgeEnd
TileIndex GetNorthernBridgeEnd(TileIndex t)
Finds the northern end of a bridge starting at a middle tile.
Definition: bridge_map.cpp:41
SetRoadOwner
static void SetRoadOwner(TileIndex t, RoadType rt, Owner o)
Set the owner of a specific road type.
Definition: road_map.h:220
ROADTYPE_TRAM
Trams.
Definition: road_type.h:25
_me
TileExtended * _me
Extended Tiles of the map.
Definition: map.cpp:33
Tile::m5
byte m5
General purpose.
Definition: map_type.h:26
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:18
GetBridgeHeight
int GetBridgeHeight(TileIndex tile)
Get the height (&#39;z&#39;) of a bridge.
Definition: bridge_map.cpp:72
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:80
MakeRailBridgeRamp
static void MakeRailBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RailType r)
Make a bridge ramp for rails.
Definition: bridge_map.h:167
SetBridgeMiddle
static void SetBridgeMiddle(TileIndex t, Axis a)
Set that there is a bridge over the given axis.
Definition: bridge_map.h:114
RoadTypes
RoadTypes
The different roadtypes we support, but then a bitmask of them.
Definition: road_type.h:36
GetBridgeAxis
static Axis GetBridgeAxis(TileIndex t)
Get the axis of the bridge that goes over the tile.
Definition: bridge_map.h:68
GetBridgeType
static BridgeType GetBridgeType(TileIndex t)
Determines the type of bridge on a tile.
Definition: bridge_map.h:56
AXIS_X
The X axis.
Definition: direction_type.h:128
TRANSPORT_RAIL
Transport by train.
Definition: transport_type.h:29
ClrBit
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
Definition: bitmath_func.hpp:153
MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:52
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
OWNER_TOWN
A town owns the tile, or a town is expanding.
Definition: company_type.h:26
GetBridgePixelHeight
static int GetBridgePixelHeight(TileIndex tile)
Get the height (&#39;z&#39;) of a bridge in pixels.
Definition: bridge_map.h:84
TransportType
TransportType
Available types of transport.
Definition: transport_type.h:21
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:34
SetTileType
static void SetTileType(TileIndex tile, TileType type)
Set the type of a tile.
Definition: tile_map.h:124
TRANSPORT_ROAD
Transport by road vehicle.
Definition: transport_type.h:30
BridgeType
uint BridgeType
Bridge spec number.
Definition: bridge.h:38
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:105
MakeAqueductBridgeRamp
static void MakeAqueductBridgeRamp(TileIndex t, Owner o, DiagDirection d)
Make a bridge ramp for aqueducts.
Definition: bridge_map.h:178
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:20
SetRoadTypes
static void SetRoadTypes(TileIndex t, RoadTypes rt)
Set the present road types of a tile.
Definition: road_map.h:176
bridge.h
Header file for bridges.
Tile::m3
byte m3
General purpose.
Definition: map_type.h:24
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition: direction_type.h:127
IsBridge
static bool IsBridge(TileIndex t)
Checks if this is a bridge, instead of a tunnel.
Definition: bridge_map.h:24
Tile::m4
byte m4
General purpose.
Definition: map_type.h:25