OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

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 */