2006-03-23 20:47:56 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file unmovable_map.h Map accessors for unmovable tiles. */
|
2007-04-04 04:08:47 +00:00
|
|
|
|
2006-09-28 18:42:35 +00:00
|
|
|
#ifndef UNMOVABLE_MAP_H
|
|
|
|
#define UNMOVABLE_MAP_H
|
|
|
|
|
2008-01-07 00:45:05 +00:00
|
|
|
#include "core/bitmath_func.hpp"
|
|
|
|
#include "tile_map.h"
|
|
|
|
|
2006-04-03 12:20:55 +00:00
|
|
|
enum {
|
2007-04-18 18:20:31 +00:00
|
|
|
HQ_NUM_TILE = 4, ///< Number of HQ tiles
|
|
|
|
HQ_NUM_SIZE = 5 ///< Number of stages of an HQ
|
2006-04-03 12:20:55 +00:00
|
|
|
};
|
|
|
|
|
2007-04-18 18:20:31 +00:00
|
|
|
/** Types of unmovable structure */
|
2007-03-07 12:11:48 +00:00
|
|
|
enum UnmovableType {
|
2007-04-18 18:20:31 +00:00
|
|
|
UNMOVABLE_TRANSMITTER = 0, ///< The large antenna
|
|
|
|
UNMOVABLE_LIGHTHOUSE = 1, ///< The nice lighthouse
|
|
|
|
UNMOVABLE_STATUE = 2, ///< Statue in towns
|
|
|
|
UNMOVABLE_OWNED_LAND = 3, ///< Owned land 'flag'
|
|
|
|
UNMOVABLE_HQ_NORTH = 0x80, ///< Offset for the northern HQ tile
|
|
|
|
UNMOVABLE_HQ_WEST = 0x81, ///< Offset for the western HQ tile
|
|
|
|
UNMOVABLE_HQ_EAST = 0x82, ///< Offset for the eastern HQ tile
|
|
|
|
UNMOVABLE_HQ_SOUTH = 0x83, ///< Offset for the southern HQ tile
|
|
|
|
|
2007-11-24 10:38:43 +00:00
|
|
|
/** End of the HQ (rather end + 1 for IsInside) */
|
2006-04-03 12:20:55 +00:00
|
|
|
UNMOVABLE_HQ_END = UNMOVABLE_HQ_NORTH + HQ_NUM_SIZE * HQ_NUM_TILE
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-03-23 20:47:56 +00:00
|
|
|
|
|
|
|
|
2006-04-03 12:20:55 +00:00
|
|
|
|
2007-04-18 18:20:31 +00:00
|
|
|
/**
|
|
|
|
* Gets the UnmovableType of the given unmovable tile
|
|
|
|
* @param t the tile to get the type from.
|
|
|
|
* @pre IsTileType(t, MP_UNMOVABLE)
|
|
|
|
* @return the type.
|
|
|
|
*/
|
2006-03-23 20:47:56 +00:00
|
|
|
static inline UnmovableType GetUnmovableType(TileIndex t)
|
|
|
|
{
|
2006-03-30 09:29:01 +00:00
|
|
|
assert(IsTileType(t, MP_UNMOVABLE));
|
2007-01-10 18:56:51 +00:00
|
|
|
return (UnmovableType)_m[t].m5;
|
2006-03-23 20:47:56 +00:00
|
|
|
}
|
|
|
|
|
2007-04-18 18:20:31 +00:00
|
|
|
/**
|
|
|
|
* Does the given tile have a transmitter?
|
|
|
|
* @param t the tile to inspect.
|
|
|
|
* @return true if and only if the tile has a transmitter.
|
|
|
|
*/
|
2006-03-23 20:47:56 +00:00
|
|
|
static inline bool IsTransmitterTile(TileIndex t)
|
|
|
|
{
|
2007-04-18 18:20:31 +00:00
|
|
|
return IsTileType(t, MP_UNMOVABLE) && GetUnmovableType(t) == UNMOVABLE_TRANSMITTER;
|
2006-03-23 20:47:56 +00:00
|
|
|
}
|
|
|
|
|
2007-04-18 18:20:31 +00:00
|
|
|
/**
|
|
|
|
* Is this unmovable tile an 'owned land' tile?
|
|
|
|
* @param t the tile to inspect.
|
|
|
|
* @pre IsTileType(t, MP_UNMOVABLE)
|
|
|
|
* @return true if and only if the tile is an 'owned land' tile.
|
|
|
|
*/
|
2006-03-23 20:47:56 +00:00
|
|
|
static inline bool IsOwnedLand(TileIndex t)
|
|
|
|
{
|
2006-03-30 09:29:01 +00:00
|
|
|
assert(IsTileType(t, MP_UNMOVABLE));
|
2006-03-23 20:47:56 +00:00
|
|
|
return GetUnmovableType(t) == UNMOVABLE_OWNED_LAND;
|
|
|
|
}
|
|
|
|
|
2007-04-18 18:20:31 +00:00
|
|
|
/**
|
|
|
|
* Is the given tile (pre-)owned by someone (the little flags)?
|
|
|
|
* @param t the tile to inspect.
|
|
|
|
* @return true if and only if the tile is an 'owned land' tile.
|
|
|
|
*/
|
2006-03-23 20:47:56 +00:00
|
|
|
static inline bool IsOwnedLandTile(TileIndex t)
|
|
|
|
{
|
|
|
|
return IsTileType(t, MP_UNMOVABLE) && IsOwnedLand(t);
|
|
|
|
}
|
|
|
|
|
2007-04-18 18:20:31 +00:00
|
|
|
/**
|
|
|
|
* Is this unmovable tile a HQ tile?
|
|
|
|
* @param t the tile to inspect.
|
|
|
|
* @pre IsTileType(t, MP_UNMOVABLE)
|
|
|
|
* @return true if and only if the tile is a HQ tile.
|
|
|
|
*/
|
2006-04-03 12:20:55 +00:00
|
|
|
static inline bool IsCompanyHQ(TileIndex t)
|
|
|
|
{
|
2007-04-18 18:20:31 +00:00
|
|
|
assert(IsTileType(t, MP_UNMOVABLE));
|
2008-08-25 16:41:00 +00:00
|
|
|
return HasBit(_m[t].m5, 7);
|
2006-04-03 12:20:55 +00:00
|
|
|
}
|
|
|
|
|
2007-04-18 18:20:31 +00:00
|
|
|
/**
|
|
|
|
* Is this unmovable tile a statue?
|
|
|
|
* @param t the tile to inspect.
|
|
|
|
* @pre IsTileType(t, MP_UNMOVABLE)
|
|
|
|
* @return true if and only if the tile is a statue.
|
|
|
|
*/
|
2007-03-08 14:34:32 +00:00
|
|
|
static inline bool IsStatue(TileIndex t)
|
|
|
|
{
|
|
|
|
assert(IsTileType(t, MP_UNMOVABLE));
|
|
|
|
return GetUnmovableType(t) == UNMOVABLE_STATUE;
|
|
|
|
}
|
|
|
|
|
2007-04-18 18:20:31 +00:00
|
|
|
/**
|
|
|
|
* Is the given tile a statue?
|
|
|
|
* @param t the tile to inspect.
|
|
|
|
* @return true if and only if the tile is a statue.
|
|
|
|
*/
|
2007-03-08 14:34:32 +00:00
|
|
|
static inline bool IsStatueTile(TileIndex t)
|
|
|
|
{
|
|
|
|
return IsTileType(t, MP_UNMOVABLE) && IsStatue(t);
|
|
|
|
}
|
|
|
|
|
2007-04-18 18:20:31 +00:00
|
|
|
/**
|
|
|
|
* Get the town of the given statue tile.
|
|
|
|
* @param t the tile of the statue.
|
|
|
|
* @pre IsStatueTile(t)
|
|
|
|
* @return the town the given statue is in.
|
|
|
|
*/
|
2007-03-08 14:34:32 +00:00
|
|
|
static inline TownID GetStatueTownID(TileIndex t)
|
|
|
|
{
|
2007-04-18 18:20:31 +00:00
|
|
|
assert(IsStatueTile(t));
|
2007-03-08 14:34:32 +00:00
|
|
|
return _m[t].m2;
|
|
|
|
}
|
|
|
|
|
2007-04-18 18:20:31 +00:00
|
|
|
/**
|
|
|
|
* Get the 'stage' of the HQ.
|
|
|
|
* @param t a tile of the HQ.
|
|
|
|
* @pre IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t)
|
|
|
|
* @return the 'stage' of the HQ.
|
|
|
|
*/
|
2006-04-03 12:20:55 +00:00
|
|
|
static inline byte GetCompanyHQSize(TileIndex t)
|
|
|
|
{
|
|
|
|
assert(IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t));
|
|
|
|
return GB(_m[t].m5, 2, 3);
|
|
|
|
}
|
|
|
|
|
2007-04-18 18:20:31 +00:00
|
|
|
/**
|
|
|
|
* Get the 'section' (including stage) of the HQ.
|
|
|
|
* @param t a tile of the HQ.
|
|
|
|
* @pre IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t)
|
|
|
|
* @return the 'section' of the HQ.
|
|
|
|
*/
|
2006-04-03 12:20:55 +00:00
|
|
|
static inline byte GetCompanyHQSection(TileIndex t)
|
|
|
|
{
|
|
|
|
assert(IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t));
|
|
|
|
return GB(_m[t].m5, 0, 5);
|
|
|
|
}
|
|
|
|
|
2007-04-18 18:20:31 +00:00
|
|
|
/**
|
|
|
|
* Enlarge the given HQ to the given size. If the new size
|
|
|
|
* is larger than the current size, nothing happens.
|
|
|
|
* @param t the tile of the HQ.
|
|
|
|
* @param size the new size of the HQ.
|
|
|
|
* @pre t is the northern tile of the HQ
|
|
|
|
*/
|
2006-03-31 09:09:26 +00:00
|
|
|
static inline void EnlargeCompanyHQ(TileIndex t, byte size)
|
|
|
|
{
|
2007-04-18 18:20:31 +00:00
|
|
|
assert(GB(GetCompanyHQSection(t), 0, 2) == 0);
|
|
|
|
|
2006-05-01 13:24:37 +00:00
|
|
|
size *= 4;
|
2006-03-31 09:09:26 +00:00
|
|
|
if (size <= _m[t].m5 - UNMOVABLE_HQ_NORTH) return;
|
|
|
|
|
2006-05-01 13:24:37 +00:00
|
|
|
_m[t + TileDiffXY(0, 0)].m5 = UNMOVABLE_HQ_NORTH + size;
|
|
|
|
_m[t + TileDiffXY(0, 1)].m5 = UNMOVABLE_HQ_WEST + size;
|
|
|
|
_m[t + TileDiffXY(1, 0)].m5 = UNMOVABLE_HQ_EAST + size;
|
|
|
|
_m[t + TileDiffXY(1, 1)].m5 = UNMOVABLE_HQ_SOUTH + size;
|
2006-03-31 09:09:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-18 18:20:31 +00:00
|
|
|
/**
|
|
|
|
* Make an Unmovable tile.
|
|
|
|
* @note do not use this function directly. Use one of the other Make* functions.
|
|
|
|
* @param t the tile to make unmovable.
|
|
|
|
* @param u the unmovable type of the tile.
|
|
|
|
* @param o the new owner of the tile.
|
|
|
|
*/
|
2006-03-23 20:47:56 +00:00
|
|
|
static inline void MakeUnmovable(TileIndex t, UnmovableType u, Owner o)
|
|
|
|
{
|
|
|
|
SetTileType(t, MP_UNMOVABLE);
|
|
|
|
SetTileOwner(t, o);
|
|
|
|
_m[t].m2 = 0;
|
|
|
|
_m[t].m3 = 0;
|
|
|
|
_m[t].m4 = 0;
|
|
|
|
_m[t].m5 = u;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-18 18:20:31 +00:00
|
|
|
/**
|
|
|
|
* Make a transmitter tile.
|
|
|
|
* @param t the tile to make a transmitter.
|
|
|
|
*/
|
2006-03-23 20:47:56 +00:00
|
|
|
static inline void MakeTransmitter(TileIndex t)
|
|
|
|
{
|
|
|
|
MakeUnmovable(t, UNMOVABLE_TRANSMITTER, OWNER_NONE);
|
|
|
|
}
|
|
|
|
|
2007-04-18 18:20:31 +00:00
|
|
|
/**
|
|
|
|
* Make a lighthouse tile.
|
|
|
|
* @param t the tile to make a transmitter.
|
|
|
|
*/
|
2006-03-23 20:47:56 +00:00
|
|
|
static inline void MakeLighthouse(TileIndex t)
|
|
|
|
{
|
|
|
|
MakeUnmovable(t, UNMOVABLE_LIGHTHOUSE, OWNER_NONE);
|
|
|
|
}
|
|
|
|
|
2007-04-18 18:20:31 +00:00
|
|
|
/**
|
|
|
|
* Make a statue tile.
|
|
|
|
* @param t the tile to make a statue.
|
|
|
|
* @param o the owner of the statue.
|
|
|
|
* @param town_id the town the statue was built in.
|
|
|
|
*/
|
2007-03-08 14:34:32 +00:00
|
|
|
static inline void MakeStatue(TileIndex t, Owner o, TownID town_id)
|
2006-03-23 20:47:56 +00:00
|
|
|
{
|
|
|
|
MakeUnmovable(t, UNMOVABLE_STATUE, o);
|
2007-03-08 14:34:32 +00:00
|
|
|
_m[t].m2 = town_id;
|
2006-03-23 20:47:56 +00:00
|
|
|
}
|
|
|
|
|
2007-04-18 18:20:31 +00:00
|
|
|
/**
|
|
|
|
* Make an 'owned land' tile.
|
|
|
|
* @param t the tile to make an 'owned land' tile.
|
|
|
|
* @param o the owner of the land.
|
|
|
|
*/
|
2006-03-23 20:47:56 +00:00
|
|
|
static inline void MakeOwnedLand(TileIndex t, Owner o)
|
|
|
|
{
|
|
|
|
MakeUnmovable(t, UNMOVABLE_OWNED_LAND, o);
|
|
|
|
}
|
2006-03-31 08:44:53 +00:00
|
|
|
|
2007-04-18 18:20:31 +00:00
|
|
|
/**
|
|
|
|
* Make an HQ with the give tile as it's northern tile.
|
|
|
|
* @param t the tile to make the northern tile of a HQ.
|
|
|
|
* @param o the owner of the HQ.
|
|
|
|
*/
|
2006-03-31 08:44:53 +00:00
|
|
|
static inline void MakeCompanyHQ(TileIndex t, Owner o)
|
|
|
|
{
|
|
|
|
MakeUnmovable(t + TileDiffXY(0, 0), UNMOVABLE_HQ_NORTH, o);
|
|
|
|
MakeUnmovable(t + TileDiffXY(0, 1), UNMOVABLE_HQ_WEST, o);
|
|
|
|
MakeUnmovable(t + TileDiffXY(1, 0), UNMOVABLE_HQ_EAST, o);
|
|
|
|
MakeUnmovable(t + TileDiffXY(1, 1), UNMOVABLE_HQ_SOUTH, o);
|
|
|
|
}
|
2006-09-28 18:42:35 +00:00
|
|
|
|
|
|
|
#endif /* UNMOVABLE_MAP_H */
|