Translations update
[openttd/fttd.git] / src / map / common.h
blobe138bc2a31c4f199fb46c6dc46c3004174702758
1 /*
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/>.
6 */
8 /** @file map/common.h Map tile accessors common to several tile types. */
10 #ifndef MAP_COMMON_H
11 #define MAP_COMMON_H
13 #include "../stdafx.h"
14 #include "../tile/common.h"
15 #include "../tile/misc.h"
16 #include "map.h"
17 #include "coord.h"
18 #include "class.h"
19 #include "../company_type.h"
20 #include "../direction_type.h"
22 /**
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]);
40 /**
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);
57 /**
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
72 /**
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
86 /**
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));
95 if (set) {
96 SetBit(_mc[t].m3, 4);
97 } else {
98 ClrBit(_mc[t].m3, 4);
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
133 * @param t the tile
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
144 * @param t the tile
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);
153 #endif /* MAP_COMMON_H */