2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2007-12-19 23:26:02 +00:00
|
|
|
/** @file tile_map.h Map writing/reading functions for tiles. */
|
2007-04-04 03:21:14 +00:00
|
|
|
|
2007-12-19 23:26:02 +00:00
|
|
|
#ifndef TILE_MAP_H
|
|
|
|
#define TILE_MAP_H
|
2005-01-29 12:19:05 +00:00
|
|
|
|
2007-12-19 23:26:02 +00:00
|
|
|
#include "tile_type.h"
|
|
|
|
#include "slope_type.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_type.h"
|
2007-12-26 11:45:43 +00:00
|
|
|
#include "map_func.h"
|
2007-12-21 19:21:21 +00:00
|
|
|
#include "core/bitmath_func.hpp"
|
2009-01-21 02:31:55 +00:00
|
|
|
#include "settings_type.h"
|
2005-01-29 13:33:48 +00:00
|
|
|
|
2007-07-29 21:43:49 +00:00
|
|
|
/**
|
|
|
|
* Returns the height of a tile
|
|
|
|
*
|
|
|
|
* This function returns the height of the northern corner of a tile.
|
|
|
|
* This is saved in the global map-array. It does not take affect by
|
|
|
|
* any slope-data of the tile.
|
|
|
|
*
|
|
|
|
* @param tile The tile to get the height from
|
|
|
|
* @return the height of the tile
|
|
|
|
* @pre tile < MapSize()
|
|
|
|
*/
|
2005-01-29 12:19:05 +00:00
|
|
|
static inline uint TileHeight(TileIndex tile)
|
|
|
|
{
|
|
|
|
assert(tile < MapSize());
|
2005-07-13 18:04:01 +00:00
|
|
|
return GB(_m[tile].type_height, 0, 4);
|
2005-01-29 12:19:05 +00:00
|
|
|
}
|
|
|
|
|
2007-07-29 21:43:49 +00:00
|
|
|
/**
|
|
|
|
* Sets the height of a tile.
|
|
|
|
*
|
|
|
|
* This function sets the height of the northern corner of a tile.
|
|
|
|
*
|
|
|
|
* @param tile The tile to change the height
|
|
|
|
* @param height The new height value of the tile
|
|
|
|
* @pre tile < MapSize()
|
|
|
|
* @pre heigth <= MAX_TILE_HEIGHT
|
|
|
|
*/
|
2005-01-29 12:19:05 +00:00
|
|
|
static inline void SetTileHeight(TileIndex tile, uint height)
|
|
|
|
{
|
|
|
|
assert(tile < MapSize());
|
2007-07-29 21:43:49 +00:00
|
|
|
assert(height <= MAX_TILE_HEIGHT);
|
2005-07-13 18:04:01 +00:00
|
|
|
SB(_m[tile].type_height, 0, 4, height);
|
2005-01-29 12:19:05 +00:00
|
|
|
}
|
|
|
|
|
2007-07-29 21:43:49 +00:00
|
|
|
/**
|
|
|
|
* Returns the height of a tile in pixels.
|
|
|
|
*
|
|
|
|
* This function returns the height of the northern corner of a tile in pixels.
|
|
|
|
*
|
|
|
|
* @param tile The tile to get the height
|
|
|
|
* @return The height of the tile in pixel
|
|
|
|
*/
|
2005-01-29 12:19:05 +00:00
|
|
|
static inline uint TilePixelHeight(TileIndex tile)
|
|
|
|
{
|
2006-06-27 21:25:53 +00:00
|
|
|
return TileHeight(tile) * TILE_HEIGHT;
|
2005-01-29 12:19:05 +00:00
|
|
|
}
|
|
|
|
|
2007-07-29 21:43:49 +00:00
|
|
|
/**
|
|
|
|
* Get the tiletype of a given tile.
|
|
|
|
*
|
|
|
|
* @param tile The tile to get the TileType
|
|
|
|
* @return The tiletype of the tile
|
|
|
|
* @pre tile < MapSize()
|
|
|
|
*/
|
2005-01-29 15:12:40 +00:00
|
|
|
static inline TileType GetTileType(TileIndex tile)
|
2005-01-29 12:19:05 +00:00
|
|
|
{
|
|
|
|
assert(tile < MapSize());
|
2006-05-27 16:12:16 +00:00
|
|
|
return (TileType)GB(_m[tile].type_height, 4, 4);
|
2005-01-29 12:19:05 +00:00
|
|
|
}
|
|
|
|
|
2007-07-29 21:43:49 +00:00
|
|
|
/**
|
|
|
|
* Set the type of a tile
|
|
|
|
*
|
|
|
|
* This functions sets the type of a tile. If the type
|
|
|
|
* MP_VOID is selected the tile must be at the south-west or
|
|
|
|
* south-east edges of the map and vice versa.
|
|
|
|
*
|
|
|
|
* @param tile The tile to save the new type
|
|
|
|
* @param type The type to save
|
|
|
|
* @pre tile < MapSize()
|
|
|
|
* @pre type MP_VOID <=> tile is on the south-east or south-west edge.
|
|
|
|
*/
|
2005-01-29 15:12:40 +00:00
|
|
|
static inline void SetTileType(TileIndex tile, TileType type)
|
2005-01-29 12:19:05 +00:00
|
|
|
{
|
|
|
|
assert(tile < MapSize());
|
2006-06-10 21:06:29 +00:00
|
|
|
/* VOID tiles (and no others) are exactly allowed at the lower left and right
|
2009-01-21 02:31:55 +00:00
|
|
|
* edges of the map. If _settings_game.construction.freeform_edges is true,
|
|
|
|
* the upper edges of the map are also VOID tiles. */
|
|
|
|
assert((TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY() || (_settings_game.construction.freeform_edges && (TileX(tile) == 0 || TileY(tile) == 0))) == (type == MP_VOID));
|
2005-07-13 18:04:01 +00:00
|
|
|
SB(_m[tile].type_height, 4, 4, type);
|
2005-01-29 12:19:05 +00:00
|
|
|
}
|
|
|
|
|
2007-07-29 21:43:49 +00:00
|
|
|
/**
|
|
|
|
* Checks if a tile is a give tiletype.
|
|
|
|
*
|
|
|
|
* This function checks if a tile got the given tiletype.
|
|
|
|
*
|
|
|
|
* @param tile The tile to check
|
|
|
|
* @param type The type to check agains
|
|
|
|
* @return true If the type matches agains the type of the tile
|
|
|
|
*/
|
2005-01-29 15:12:40 +00:00
|
|
|
static inline bool IsTileType(TileIndex tile, TileType type)
|
2005-01-29 12:19:05 +00:00
|
|
|
{
|
2005-01-29 15:12:40 +00:00
|
|
|
return GetTileType(tile) == type;
|
2005-01-29 12:19:05 +00:00
|
|
|
}
|
|
|
|
|
2008-02-28 00:10:08 +00:00
|
|
|
/**
|
|
|
|
* Checks if a tile is valid
|
|
|
|
*
|
|
|
|
* @param tile The tile to check
|
|
|
|
* @return True if the tile is on the map and not one of MP_VOID.
|
|
|
|
*/
|
|
|
|
static inline bool IsValidTile(TileIndex tile)
|
|
|
|
{
|
|
|
|
return tile < MapSize() && !IsTileType(tile, MP_VOID);
|
|
|
|
}
|
|
|
|
|
2007-07-29 21:43:49 +00:00
|
|
|
/**
|
|
|
|
* Returns the owner of a tile
|
|
|
|
*
|
|
|
|
* This function returns the owner of a tile. This cannot used
|
|
|
|
* for tiles which type is one of MP_HOUSE, MP_VOID and MP_INDUSTRY
|
2008-09-30 20:39:50 +00:00
|
|
|
* as no company owned any of these buildings.
|
2007-07-29 21:43:49 +00:00
|
|
|
*
|
|
|
|
* @param tile The tile to check
|
|
|
|
* @return The owner of the tile
|
2008-02-28 00:10:08 +00:00
|
|
|
* @pre IsValidTile(tile)
|
|
|
|
* @pre The type of the tile must not be MP_HOUSE and MP_INDUSTRY
|
2007-07-29 21:43:49 +00:00
|
|
|
*/
|
2005-02-07 10:09:28 +00:00
|
|
|
static inline Owner GetTileOwner(TileIndex tile)
|
2005-02-06 22:36:08 +00:00
|
|
|
{
|
2008-02-28 00:10:08 +00:00
|
|
|
assert(IsValidTile(tile));
|
2005-06-03 22:43:59 +00:00
|
|
|
assert(!IsTileType(tile, MP_HOUSE));
|
|
|
|
assert(!IsTileType(tile, MP_INDUSTRY));
|
|
|
|
|
2006-05-27 16:12:16 +00:00
|
|
|
return (Owner)_m[tile].m1;
|
2005-02-06 22:36:08 +00:00
|
|
|
}
|
|
|
|
|
2007-07-29 21:43:49 +00:00
|
|
|
/**
|
|
|
|
* Sets the owner of a tile
|
|
|
|
*
|
|
|
|
* This function sets the owner status of a tile. Note that you cannot
|
|
|
|
* set a owner for tiles of type MP_HOUSE, MP_VOID and MP_INDUSTRY.
|
|
|
|
*
|
|
|
|
* @param tile The tile to change the owner status.
|
|
|
|
* @param owner The new owner.
|
2008-02-28 00:10:08 +00:00
|
|
|
* @pre IsValidTile(tile)
|
|
|
|
* @pre The type of the tile must not be MP_HOUSE and MP_INDUSTRY
|
2007-07-29 21:43:49 +00:00
|
|
|
*/
|
2005-06-04 12:13:24 +00:00
|
|
|
static inline void SetTileOwner(TileIndex tile, Owner owner)
|
|
|
|
{
|
2008-02-28 00:10:08 +00:00
|
|
|
assert(IsValidTile(tile));
|
2005-06-04 12:13:24 +00:00
|
|
|
assert(!IsTileType(tile, MP_HOUSE));
|
|
|
|
assert(!IsTileType(tile, MP_INDUSTRY));
|
|
|
|
|
2005-08-23 18:47:04 +00:00
|
|
|
_m[tile].m1 = owner;
|
2005-06-04 12:13:24 +00:00
|
|
|
}
|
|
|
|
|
2007-07-29 21:43:49 +00:00
|
|
|
/**
|
|
|
|
* Checks if a tile belongs to the given owner
|
|
|
|
*
|
|
|
|
* @param tile The tile to check
|
|
|
|
* @param owner The owner to check agains
|
|
|
|
* @return True if a tile belongs the the given owner
|
|
|
|
*/
|
2005-02-06 22:36:08 +00:00
|
|
|
static inline bool IsTileOwner(TileIndex tile, Owner owner)
|
|
|
|
{
|
|
|
|
return GetTileOwner(tile) == owner;
|
|
|
|
}
|
|
|
|
|
2006-03-30 19:16:44 +00:00
|
|
|
/**
|
|
|
|
* Set the tropic zone
|
|
|
|
* @param tile the tile to set the zone of
|
|
|
|
* @param type the new type
|
2008-02-28 00:10:08 +00:00
|
|
|
* @pre tile < MapSize()
|
2006-03-30 19:16:44 +00:00
|
|
|
*/
|
|
|
|
static inline void SetTropicZone(TileIndex tile, TropicZone type)
|
|
|
|
{
|
|
|
|
assert(tile < MapSize());
|
2007-01-11 02:05:13 +00:00
|
|
|
SB(_m[tile].m6, 0, 2, type);
|
2006-03-30 19:16:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the tropic zone
|
|
|
|
* @param tile the tile to get the zone of
|
2008-02-28 00:10:08 +00:00
|
|
|
* @pre tile < MapSize()
|
2006-03-30 19:16:44 +00:00
|
|
|
* @return the zone type
|
|
|
|
*/
|
|
|
|
static inline TropicZone GetTropicZone(TileIndex tile)
|
|
|
|
{
|
|
|
|
assert(tile < MapSize());
|
2007-01-11 02:05:13 +00:00
|
|
|
return (TropicZone)GB(_m[tile].m6, 0, 2);
|
2006-03-30 19:16:44 +00:00
|
|
|
}
|
2007-12-19 23:26:02 +00:00
|
|
|
|
|
|
|
Slope GetTileSlope(TileIndex tile, uint *h);
|
|
|
|
uint GetTileZ(TileIndex tile);
|
|
|
|
uint GetTileMaxZ(TileIndex tile);
|
|
|
|
|
|
|
|
#endif /* TILE_TYPE_H */
|