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 
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 
129 static inline void MakeBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, TransportType tt, uint rt)
130 {
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 
179 {
180  MakeBridgeRamp(t, o, 0, d, TRANSPORT_WATER, 0);
181 }
182 
183 #endif /* BRIDGE_MAP_H */
static void ClearBridgeMiddle(TileIndex t)
Removes bridges from the given, that is bridges along the X and Y axis.
Definition: bridge_map.h:103
static void SetTileOwner(TileIndex tile, Owner owner)
Sets the owner of a tile.
Definition: tile_map.h:191
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:29
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
static bool IsBridgeTile(TileIndex t)
checks if there is a bridge on this tile
Definition: bridge_map.h:35
Basic road type.
Definition: road_type.h:24
byte m7
Primarily used for newgrf support.
Definition: map_type.h:37
Map accessors for roads.
uint16 m2
Primarily used for indices to towns, industries and stations.
Definition: map_type.h:22
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Tile * _m
Tiles of the map.
Definition: map.cpp:32
TileIndex GetSouthernBridgeEnd(TileIndex t)
Finds the southern end of a bridge starting at a middle tile.
Definition: bridge_map.cpp:51
Transport over water.
TileIndex GetOtherBridgeEnd(TileIndex t)
Starting at one bridge end finds the other bridge end.
Definition: bridge_map.cpp:61
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
static void ClearSingleBridgeMiddle(TileIndex t, Axis a)
Remove the bridge over the given axis.
Definition: bridge_map.h:94
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.
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
Definition: bridge_map.h:45
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
Definition: tile_map.h:143
The y axis.
TileIndex GetNorthernBridgeEnd(TileIndex t)
Finds the northern end of a bridge starting at a middle tile.
Definition: bridge_map.cpp:41
static void SetRoadOwner(TileIndex t, RoadType rt, Owner o)
Set the owner of a specific road type.
Definition: road_map.h:220
Trams.
Definition: road_type.h:25
TileExtended * _me
Extended Tiles of the map.
Definition: map.cpp:33
byte m5
General purpose.
Definition: map_type.h:26
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
int GetBridgeHeight(TileIndex tile)
Get the height (&#39;z&#39;) of a bridge.
Definition: bridge_map.cpp:72
DiagDirection
Enumeration for diagonal directions.
static void MakeRailBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RailType r)
Make a bridge ramp for rails.
Definition: bridge_map.h:167
static void SetBridgeMiddle(TileIndex t, Axis a)
Set that there is a bridge over the given axis.
Definition: bridge_map.h:114
RoadTypes
The different roadtypes we support, but then a bitmask of them.
Definition: road_type.h:36
static Axis GetBridgeAxis(TileIndex t)
Get the axis of the bridge that goes over the tile.
Definition: bridge_map.h:68
static BridgeType GetBridgeType(TileIndex t)
Determines the type of bridge on a tile.
Definition: bridge_map.h:56
The X axis.
Transport by train.
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:52
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
A town owns the tile, or a town is expanding.
Definition: company_type.h:26
static int GetBridgePixelHeight(TileIndex tile)
Get the height (&#39;z&#39;) of a bridge in pixels.
Definition: bridge_map.h:84
TransportType
Available types of transport.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
static void SetTileType(TileIndex tile, TileType type)
Set the type of a tile.
Definition: tile_map.h:124
Transport by road vehicle.
uint BridgeType
Bridge spec number.
Definition: bridge.h:38
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static void MakeAqueductBridgeRamp(TileIndex t, Owner o, DiagDirection d)
Make a bridge ramp for aqueducts.
Definition: bridge_map.h:178
Owner
Enum for all companies/owners.
Definition: company_type.h:20
static void SetRoadTypes(TileIndex t, RoadTypes rt)
Set the present road types of a tile.
Definition: road_map.h:176
Header file for bridges.
byte m3
General purpose.
Definition: map_type.h:24
Axis
Allow incrementing of DiagDirDiff variables.
static bool IsBridge(TileIndex t)
Checks if this is a bridge, instead of a tunnel.
Definition: bridge_map.h:24
byte m4
General purpose.
Definition: map_type.h:25