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
);
153 #endif /* MAP_COMMON_H */