(svn r27724) -Cleanup: Remove pointless usage of IsOpenTTDBaseGRF. System GRFs are...
[openttd.git] / src / bridge_map.h
blob74c6974db25c9c1106acf2f620f945778dde0d9a
1 /* $Id$ */
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 */
10 /** @file bridge_map.h Map accessor functions for bridges. */
12 #ifndef BRIDGE_MAP_H
13 #define BRIDGE_MAP_H
15 #include "road_map.h"
16 #include "bridge.h"
18 /**
19 * Checks if this is a bridge, instead of a tunnel
20 * @param t The tile to analyze
21 * @pre IsTileType(t, MP_TUNNELBRIDGE)
22 * @return true if the structure is a bridge one
24 static inline bool IsBridge(TileIndex t)
26 assert(IsTileType(t, MP_TUNNELBRIDGE));
27 return HasBit(_m[t].m5, 7);
30 /**
31 * checks if there is a bridge on this tile
32 * @param t The tile to analyze
33 * @return true if a bridge is present
35 static inline bool IsBridgeTile(TileIndex t)
37 return IsTileType(t, MP_TUNNELBRIDGE) && IsBridge(t);
40 /**
41 * checks if a bridge is set above the ground of this tile
42 * @param t The tile to analyze
43 * @return true if a bridge is detected above
45 static inline bool IsBridgeAbove(TileIndex t)
47 return GB(_m[t].type, 2, 2) != 0;
50 /**
51 * Determines the type of bridge on a tile
52 * @param t The tile to analyze
53 * @pre IsBridgeTile(t)
54 * @return The bridge type
56 static inline BridgeType GetBridgeType(TileIndex t)
58 assert(IsBridgeTile(t));
59 return GB(_me[t].m6, 2, 4);
62 /**
63 * Get the axis of the bridge that goes over the tile. Not the axis or the ramp.
64 * @param t The tile to analyze
65 * @pre IsBridgeAbove(t)
66 * @return the above mentioned axis
68 static inline Axis GetBridgeAxis(TileIndex t)
70 assert(IsBridgeAbove(t));
71 return (Axis)(GB(_m[t].type, 2, 2) - 1);
74 TileIndex GetNorthernBridgeEnd(TileIndex t);
75 TileIndex GetSouthernBridgeEnd(TileIndex t);
76 TileIndex GetOtherBridgeEnd(TileIndex t);
78 int GetBridgeHeight(TileIndex tile);
79 /**
80 * Get the height ('z') of a bridge in pixels.
81 * @param tile the bridge ramp tile to get the bridge height from
82 * @return the height of the bridge in pixels
84 static inline int GetBridgePixelHeight(TileIndex tile)
86 return GetBridgeHeight(tile) * TILE_HEIGHT;
89 /**
90 * Remove the bridge over the given axis.
91 * @param t the tile to remove the bridge from
92 * @param a the axis of the bridge to remove
94 static inline void ClearSingleBridgeMiddle(TileIndex t, Axis a)
96 ClrBit(_m[t].type, 2 + a);
99 /**
100 * Removes bridges from the given, that is bridges along the X and Y axis.
101 * @param t the tile to remove the bridge from
103 static inline void ClearBridgeMiddle(TileIndex t)
105 ClearSingleBridgeMiddle(t, AXIS_X);
106 ClearSingleBridgeMiddle(t, AXIS_Y);
110 * Set that there is a bridge over the given axis.
111 * @param t the tile to add the bridge to
112 * @param a the axis of the bridge to add
114 static inline void SetBridgeMiddle(TileIndex t, Axis a)
116 SetBit(_m[t].type, 2 + a);
120 * Generic part to make a bridge ramp for both roads and rails.
121 * @param t the tile to make a bridge ramp
122 * @param o the new owner of the bridge ramp
123 * @param bridgetype the type of bridge this bridge ramp belongs to
124 * @param d the direction this ramp must be facing
125 * @param tt the transport type of the bridge
126 * @param rt the road or rail type
127 * @note this function should not be called directly.
129 static inline void MakeBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, TransportType tt, uint rt)
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;
142 * Make a bridge ramp for roads.
143 * @param t the tile to make a bridge ramp
144 * @param o the new owner of the bridge ramp
145 * @param owner_road the new owner of the road on the bridge
146 * @param owner_tram the new owner of the tram on the bridge
147 * @param bridgetype the type of bridge this bridge ramp belongs to
148 * @param d the direction this ramp must be facing
149 * @param r the road type of the bridge
151 static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, Owner owner_road, Owner owner_tram, BridgeType bridgetype, DiagDirection d, RoadTypes r)
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);
160 * Make a bridge ramp for rails.
161 * @param t the tile to make a bridge ramp
162 * @param o the new owner of the bridge ramp
163 * @param bridgetype the type of bridge this bridge ramp belongs to
164 * @param d the direction this ramp must be facing
165 * @param r the rail type of the bridge
167 static inline void MakeRailBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RailType r)
169 MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_RAIL, r);
173 * Make a bridge ramp for aqueducts.
174 * @param t the tile to make a bridge ramp
175 * @param o the new owner of the bridge ramp
176 * @param d the direction this ramp must be facing
178 static inline void MakeAqueductBridgeRamp(TileIndex t, Owner o, DiagDirection d)
180 MakeBridgeRamp(t, o, 0, d, TRANSPORT_WATER, 0);
183 #endif /* BRIDGE_MAP_H */