src/tile.h
branchnoai
changeset 9694 e72987579514
parent 9574 698395509d12
equal deleted inserted replaced
9693:31fcaa5375a1 9694:e72987579514
     8 #include "macros.h"
     8 #include "macros.h"
     9 #include "openttd.h"
     9 #include "openttd.h"
    10 #include "map.h"
    10 #include "map.h"
    11 #include "slope.h"
    11 #include "slope.h"
    12 
    12 
       
    13 /** Maximum allowed tile height */
       
    14 #define MAX_TILE_HEIGHT 15
       
    15 
       
    16 /** Maximum allowed snowline height */
       
    17 #define MAX_SNOWLINE_HEIGHT (MAX_TILE_HEIGHT - 2)
       
    18 
       
    19 /**
       
    20  * The different type of a tile.
       
    21  *
       
    22  * Each tile belongs to one type, according whatever is build on it.
       
    23  *
       
    24  * @note A railway with a crossing street is marked as MP_ROAD.
       
    25  */
    13 enum TileType {
    26 enum TileType {
    14 	MP_CLEAR,
    27 	MP_CLEAR,               ///< A tile without any structures, i.e. grass, rocks, farm fields etc.
    15 	MP_RAILWAY,
    28 	MP_RAILWAY,             ///< A railway
    16 	MP_STREET,
    29 	MP_ROAD,                ///< A tile with road (or tram tracks)
    17 	MP_HOUSE,
    30 	MP_HOUSE,               ///< A house by a town
    18 	MP_TREES,
    31 	MP_TREES,               ///< Tile got trees
    19 	MP_STATION,
    32 	MP_STATION,             ///< A tile of a station
    20 	MP_WATER,
    33 	MP_WATER,               ///< Water tile
    21 	MP_VOID, // invisible tiles at the SW and SE border
    34 	MP_VOID,                ///< Invisible tiles at the SW and SE border
    22 	MP_INDUSTRY,
    35 	MP_INDUSTRY,            ///< Part of an industry
    23 	MP_TUNNELBRIDGE,
    36 	MP_TUNNELBRIDGE,        ///< Tunnel entry/exit and bridge heads
    24 	MP_UNMOVABLE,
    37 	MP_UNMOVABLE,           ///< Contains an object with cannot be removed like transmitters
    25 };
    38 };
    26 
    39 
       
    40 /**
       
    41  * Additional infos of a tile on a tropic game.
       
    42  *
       
    43  * Each non-water tile in a tropic game is either a rainforest tile or a
       
    44  * desert one.
       
    45  */
    27 enum TropicZone {
    46 enum TropicZone {
    28 	TROPICZONE_INVALID    = 0,
    47 	TROPICZONE_INVALID    = 0,      ///< Invalid tropiczone-type
    29 	TROPICZONE_DESERT     = 1,
    48 	TROPICZONE_DESERT     = 1,      ///< Tile is desert
    30 	TROPICZONE_RAINFOREST = 2,
    49 	TROPICZONE_RAINFOREST = 2,      ///< Rainforest tile
    31 };
    50 };
    32 
    51 
    33 Slope GetTileSlope(TileIndex tile, uint *h);
    52 Slope GetTileSlope(TileIndex tile, uint *h);
    34 uint GetTileZ(TileIndex tile);
    53 uint GetTileZ(TileIndex tile);
    35 uint GetTileMaxZ(TileIndex tile);
    54 uint GetTileMaxZ(TileIndex tile);
    36 
    55 
       
    56 /**
       
    57  * Returns the height of a tile
       
    58  *
       
    59  * This function returns the height of the northern corner of a tile.
       
    60  * This is saved in the global map-array. It does not take affect by
       
    61  * any slope-data of the tile.
       
    62  *
       
    63  * @param tile The tile to get the height from
       
    64  * @return the height of the tile
       
    65  * @pre tile < MapSize()
       
    66  */
    37 static inline uint TileHeight(TileIndex tile)
    67 static inline uint TileHeight(TileIndex tile)
    38 {
    68 {
    39 	assert(tile < MapSize());
    69 	assert(tile < MapSize());
    40 	return GB(_m[tile].type_height, 0, 4);
    70 	return GB(_m[tile].type_height, 0, 4);
    41 }
    71 }
    42 
    72 
       
    73 /**
       
    74  * Sets the height of a tile.
       
    75  *
       
    76  * This function sets the height of the northern corner of a tile.
       
    77  *
       
    78  * @param tile The tile to change the height
       
    79  * @param height The new height value of the tile
       
    80  * @pre tile < MapSize()
       
    81  * @pre heigth <= MAX_TILE_HEIGHT
       
    82  */
    43 static inline void SetTileHeight(TileIndex tile, uint height)
    83 static inline void SetTileHeight(TileIndex tile, uint height)
    44 {
    84 {
    45 	assert(tile < MapSize());
    85 	assert(tile < MapSize());
    46 	assert(height < 16);
    86 	assert(height <= MAX_TILE_HEIGHT);
    47 	SB(_m[tile].type_height, 0, 4, height);
    87 	SB(_m[tile].type_height, 0, 4, height);
    48 }
    88 }
    49 
    89 
       
    90 /**
       
    91  * Returns the height of a tile in pixels.
       
    92  *
       
    93  * This function returns the height of the northern corner of a tile in pixels.
       
    94  *
       
    95  * @param tile The tile to get the height
       
    96  * @return The height of the tile in pixel
       
    97  */
    50 static inline uint TilePixelHeight(TileIndex tile)
    98 static inline uint TilePixelHeight(TileIndex tile)
    51 {
    99 {
    52 	return TileHeight(tile) * TILE_HEIGHT;
   100 	return TileHeight(tile) * TILE_HEIGHT;
    53 }
   101 }
    54 
   102 
       
   103 /**
       
   104  * Get the tiletype of a given tile.
       
   105  *
       
   106  * @param tile The tile to get the TileType
       
   107  * @return The tiletype of the tile
       
   108  * @pre tile < MapSize()
       
   109  */
    55 static inline TileType GetTileType(TileIndex tile)
   110 static inline TileType GetTileType(TileIndex tile)
    56 {
   111 {
    57 	assert(tile < MapSize());
   112 	assert(tile < MapSize());
    58 	return (TileType)GB(_m[tile].type_height, 4, 4);
   113 	return (TileType)GB(_m[tile].type_height, 4, 4);
    59 }
   114 }
    60 
   115 
       
   116 /**
       
   117  * Set the type of a tile
       
   118  *
       
   119  * This functions sets the type of a tile. If the type
       
   120  * MP_VOID is selected the tile must be at the south-west or
       
   121  * south-east edges of the map and vice versa.
       
   122  *
       
   123  * @param tile The tile to save the new type
       
   124  * @param type The type to save
       
   125  * @pre tile < MapSize()
       
   126  * @pre type MP_VOID <=> tile is on the south-east or south-west edge.
       
   127  */
    61 static inline void SetTileType(TileIndex tile, TileType type)
   128 static inline void SetTileType(TileIndex tile, TileType type)
    62 {
   129 {
    63 	assert(tile < MapSize());
   130 	assert(tile < MapSize());
    64 	/* VOID tiles (and no others) are exactly allowed at the lower left and right
   131 	/* VOID tiles (and no others) are exactly allowed at the lower left and right
    65 	 * edges of the map */
   132 	 * edges of the map */
    66 	assert((TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) == (type == MP_VOID));
   133 	assert((TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) == (type == MP_VOID));
    67 	SB(_m[tile].type_height, 4, 4, type);
   134 	SB(_m[tile].type_height, 4, 4, type);
    68 }
   135 }
    69 
   136 
       
   137 /**
       
   138  * Checks if a tile is a give tiletype.
       
   139  *
       
   140  * This function checks if a tile got the given tiletype.
       
   141  *
       
   142  * @param tile The tile to check
       
   143  * @param type The type to check agains
       
   144  * @return true If the type matches agains the type of the tile
       
   145  */
    70 static inline bool IsTileType(TileIndex tile, TileType type)
   146 static inline bool IsTileType(TileIndex tile, TileType type)
    71 {
   147 {
    72 	return GetTileType(tile) == type;
   148 	return GetTileType(tile) == type;
    73 }
   149 }
    74 
   150 
    75 
   151 /**
       
   152  * Returns the owner of a tile
       
   153  *
       
   154  * This function returns the owner of a tile. This cannot used
       
   155  * for tiles which type is one of MP_HOUSE, MP_VOID and MP_INDUSTRY
       
   156  * as no player owned any of these buildings.
       
   157  *
       
   158  * @param tile The tile to check
       
   159  * @return The owner of the tile
       
   160  * @pre tile < MapSize()
       
   161  * @pre The type of the tile must not be MP_HOUSE, MP_VOID and MP_INDUSTRY
       
   162  */
    76 static inline Owner GetTileOwner(TileIndex tile)
   163 static inline Owner GetTileOwner(TileIndex tile)
    77 {
   164 {
    78 	assert(tile < MapSize());
   165 	assert(tile < MapSize());
    79 	assert(!IsTileType(tile, MP_HOUSE));
   166 	assert(!IsTileType(tile, MP_HOUSE));
    80 	assert(!IsTileType(tile, MP_VOID));
   167 	assert(!IsTileType(tile, MP_VOID));
    81 	assert(!IsTileType(tile, MP_INDUSTRY));
   168 	assert(!IsTileType(tile, MP_INDUSTRY));
    82 
   169 
    83 	return (Owner)_m[tile].m1;
   170 	return (Owner)_m[tile].m1;
    84 }
   171 }
    85 
   172 
       
   173 /**
       
   174  * Sets the owner of a tile
       
   175  *
       
   176  * This function sets the owner status of a tile. Note that you cannot
       
   177  * set a owner for tiles of type MP_HOUSE, MP_VOID and MP_INDUSTRY.
       
   178  *
       
   179  * @param tile The tile to change the owner status.
       
   180  * @param owner The new owner.
       
   181  * @pre tile < MapSize()
       
   182  * @pre The type of the tile must not be MP_HOUSE, MP_VOID and MP_INDUSTRY
       
   183  */
    86 static inline void SetTileOwner(TileIndex tile, Owner owner)
   184 static inline void SetTileOwner(TileIndex tile, Owner owner)
    87 {
   185 {
    88 	assert(tile < MapSize());
   186 	assert(tile < MapSize());
    89 	assert(!IsTileType(tile, MP_HOUSE));
   187 	assert(!IsTileType(tile, MP_HOUSE));
    90 	assert(!IsTileType(tile, MP_VOID));
   188 	assert(!IsTileType(tile, MP_VOID));
    91 	assert(!IsTileType(tile, MP_INDUSTRY));
   189 	assert(!IsTileType(tile, MP_INDUSTRY));
    92 
   190 
    93 	_m[tile].m1 = owner;
   191 	_m[tile].m1 = owner;
    94 }
   192 }
    95 
   193 
       
   194 /**
       
   195  * Checks if a tile belongs to the given owner
       
   196  *
       
   197  * @param tile The tile to check
       
   198  * @param owner The owner to check agains
       
   199  * @return True if a tile belongs the the given owner
       
   200  */
    96 static inline bool IsTileOwner(TileIndex tile, Owner owner)
   201 static inline bool IsTileOwner(TileIndex tile, Owner owner)
    97 {
   202 {
    98 	return GetTileOwner(tile) == owner;
   203 	return GetTileOwner(tile) == owner;
    99 }
   204 }
   100 
   205