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 map/common.h Map tile accessors common to several tile types. */
13 #include "../stdafx.h"
14 #include "../tile/common.h"
15 #include "../tile/misc.h"
19 #include "../company_type.h"
20 #include "../direction_type.h"
23 * Returns the owner of a tile
25 * This function returns the owner of a tile. This cannot used
26 * for tiles whose type is one of void, house or industry,
27 * as no company owned any of these buildings.
29 * @param tile The tile to check
30 * @return The owner of the tile
31 * @pre IsValidTile(tile)
32 * @pre The tile must not be a house, an industry or void
34 static inline Owner
GetTileOwner(TileIndex tile
)
36 assert(IsValidTile(tile
));
37 return tile_get_owner(&_mc
[tile
]);
41 * Sets the owner of a tile
43 * This function sets the owner status of a tile. Note that you cannot
44 * set a owner for tiles of type house, void or industry.
46 * @param tile The tile to change the owner status.
47 * @param owner The new owner.
48 * @pre IsValidTile(tile)
49 * @pre The tile must not be a house, an industry or void
51 static inline void SetTileOwner(TileIndex tile
, Owner owner
)
53 assert(IsValidTile(tile
));
54 tile_set_owner(&_mc
[tile
], owner
);
58 * Checks if a tile belongs to the given owner
60 * @param tile The tile to check
61 * @param owner The owner to check against
62 * @return True if a tile belongs the the given owner
64 static inline bool IsTileOwner(TileIndex tile
, Owner owner
)
66 return tile_is_owner(&_mc
[tile
], owner
);
70 /** Check if a tile has snow/desert. */
71 #define IsOnDesert IsOnSnow
73 * Check if a tile has snow/desert.
74 * @param t The tile to query.
75 * @return True if the tile has snow/desert.
77 static inline bool IsOnSnow(TileIndex t
)
79 assert((IsRailwayTile(t
) && !IsTileSubtype(t
, TT_TRACK
)) ||
80 IsRoadTile(t
) || IsTileType(t
, TT_MISC
));
81 return HasBit(_mc
[t
].m3
, 4);
84 /** Set whether a tile has snow/desert. */
85 #define SetDesert SetSnow
87 * Set whether a tile has snow/desert.
88 * @param t The tile to set.
89 * @param set Whether to set snow/desert.
91 static inline void SetSnow(TileIndex t
, bool set
)
93 assert((IsRailwayTile(t
) && !IsTileSubtype(t
, TT_TRACK
)) ||
94 IsRoadTile(t
) || IsTileType(t
, TT_MISC
));
102 /** Toggle the snow/desert state of a tile. */
103 #define ToggleDesert ToggleSnow
105 * Toggle the snow/desert state of a tile.
106 * @param t The tile to change.
108 static inline void ToggleSnow(TileIndex t
)
110 assert((IsRailwayTile(t
) && !IsTileSubtype(t
, TT_TRACK
)) ||
111 IsRoadTile(t
) || IsTileType(t
, TT_MISC
));
112 ToggleBit(_mc
[t
].m3
, 4);
117 * Get the direction pointing to the other end.
119 * Tunnel: Get the direction facing into the tunnel
120 * Bridge: Get the direction pointing onto the bridge
121 * @param t The tile to analyze
122 * @pre IsTunnelTile(t) || IsBridgeHeadTile(t)
123 * @return the above mentioned direction
125 static inline DiagDirection
GetTunnelBridgeDirection(TileIndex t
)
127 return tile_get_tunnelbridge_direction(&_mc
[t
]);
132 * Get the current animation frame
134 * @pre IsHouseTile(t) || IsObjectTile(t) || IsIndustryTile(t) || IsStationTile(t)
135 * @return frame number
137 static inline byte
GetAnimationFrame(TileIndex t
)
139 return tile_get_frame(&_mc
[t
]);
143 * Set a new animation frame
145 * @param frame the new frame number
146 * @pre IsHouseTile(t) || IsObjectTile(t) || IsIndustryTile(t) || IsStationTile(t)
148 static inline void SetAnimationFrame(TileIndex t
, byte frame
)
150 tile_set_frame(&_mc
[t
], frame
);
155 * checks for the possibility that a bridge may be on this tile
156 * These are in fact all the tile types on which a bridge can be found
157 * @param t The tile to analyze
158 * @return true if a bridge might be present
160 static inline bool MayHaveBridgeAbove(TileIndex t
)
162 return tile_is_bridgeable(&_mc
[t
]);
166 * checks if a bridge is set above the ground of this tile
167 * @param t The tile to analyze
168 * @pre MayHaveBridgeAbove(t)
169 * @return true if a bridge is detected above
171 static inline bool IsBridgeAbove(TileIndex t
)
173 return tile_bridgeable_has_bridge(&_mc
[t
]);
177 * Checks if there is a bridge over this tile
178 * @param t The tile to check
179 * @return Whether there is a bridge over the tile
181 static inline bool HasBridgeAbove(TileIndex t
)
183 return tile_has_bridge_above(&_mc
[t
]);
187 * Get the axis of the bridge that goes over the tile. Not the axis or the ramp.
188 * @param t The tile to analyze
189 * @pre IsBridgeAbove(t)
190 * @return the above mentioned axis
192 static inline Axis
GetBridgeAxis(TileIndex t
)
194 return tile_get_bridge_axis(&_mc
[t
]);
198 * Removes bridges from the given, that is bridges along the X and Y axis.
199 * @param t the tile to remove the bridge from
200 * @pre MayHaveBridgeAbove(t)
202 static inline void ClearBridgeMiddle(TileIndex t
)
204 tile_clear_bridge_above(&_mc
[t
]);
208 * Set that there is a bridge over the given axis.
209 * @param t the tile to add the bridge to
210 * @param a the axis of the bridge to add
211 * @pre MayHaveBridgeAbove(t)
213 static inline void SetBridgeMiddle(TileIndex t
, Axis a
)
215 tile_set_bridge_above(&_mc
[t
], a
);
218 #endif /* MAP_COMMON_H */