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/>.
8 /** @file bridge_map.h Map accessor functions for bridges. */
16 #include "water_map.h"
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);
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
);
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;
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);
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
);
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
;
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
);
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 * @note this function should not be called directly.
128 static inline void MakeBridgeRamp(TileIndex t
, Owner o
, BridgeType bridgetype
, DiagDirection d
, TransportType tt
)
130 SetTileType(t
, MP_TUNNELBRIDGE
);
132 SetDockingTile(t
, false);
135 _m
[t
].m4
= INVALID_ROADTYPE
;
136 _m
[t
].m5
= 1 << 7 | tt
<< 2 | d
;
137 SB(_me
[t
].m6
, 2, 4, bridgetype
);
139 _me
[t
].m8
= INVALID_ROADTYPE
<< 6;
143 * Make a bridge ramp for roads.
144 * @param t the tile to make a bridge ramp
145 * @param o the new owner of the bridge ramp
146 * @param owner_road the new owner of the road on the bridge
147 * @param owner_tram the new owner of the tram on the bridge
148 * @param bridgetype the type of bridge this bridge ramp belongs to
149 * @param d the direction this ramp must be facing
150 * @param road_rt the road type of the bridge
151 * @param tram_rt the tram type of the bridge
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
)
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
);
162 * Make a bridge ramp for rails.
163 * @param t the tile to make a bridge ramp
164 * @param o the new owner of the bridge ramp
165 * @param bridgetype the type of bridge this bridge ramp belongs to
166 * @param d the direction this ramp must be facing
167 * @param rt the rail type of the bridge
169 static inline void MakeRailBridgeRamp(TileIndex t
, Owner o
, BridgeType bridgetype
, DiagDirection d
, RailType rt
)
171 MakeBridgeRamp(t
, o
, bridgetype
, d
, TRANSPORT_RAIL
);
176 * Make a bridge ramp for aqueducts.
177 * @param t the tile to make a bridge ramp
178 * @param o the new owner of the bridge ramp
179 * @param d the direction this ramp must be facing
181 static inline void MakeAqueductBridgeRamp(TileIndex t
, Owner o
, DiagDirection d
)
183 MakeBridgeRamp(t
, o
, 0, d
, TRANSPORT_WATER
);
186 #endif /* BRIDGE_MAP_H */