src/tile_map.h
branchnoai
changeset 9723 eee46cb39750
child 9724 b39bc69bb2f2
equal deleted inserted replaced
9722:ebf0ece7d8f6 9723:eee46cb39750
       
     1 /* $Id$ */
       
     2 
       
     3 /** @file tile_map.h Map writing/reading functions for tiles. */
       
     4 
       
     5 #ifndef TILE_MAP_H
       
     6 #define TILE_MAP_H
       
     7 
       
     8 #include "tile_type.h"
       
     9 #include "slope_type.h"
       
    10 #include "map_func.h"
       
    11 #include "core/bitmath_func.hpp"
       
    12 
       
    13 /**
       
    14  * Returns the height of a tile
       
    15  *
       
    16  * This function returns the height of the northern corner of a tile.
       
    17  * This is saved in the global map-array. It does not take affect by
       
    18  * any slope-data of the tile.
       
    19  *
       
    20  * @param tile The tile to get the height from
       
    21  * @return the height of the tile
       
    22  * @pre tile < MapSize()
       
    23  */
       
    24 static inline uint TileHeight(TileIndex tile)
       
    25 {
       
    26 	assert(tile < MapSize());
       
    27 	return GB(_m[tile].type_height, 0, 4);
       
    28 }
       
    29 
       
    30 /**
       
    31  * Sets the height of a tile.
       
    32  *
       
    33  * This function sets the height of the northern corner of a tile.
       
    34  *
       
    35  * @param tile The tile to change the height
       
    36  * @param height The new height value of the tile
       
    37  * @pre tile < MapSize()
       
    38  * @pre heigth <= MAX_TILE_HEIGHT
       
    39  */
       
    40 static inline void SetTileHeight(TileIndex tile, uint height)
       
    41 {
       
    42 	assert(tile < MapSize());
       
    43 	assert(height <= MAX_TILE_HEIGHT);
       
    44 	SB(_m[tile].type_height, 0, 4, height);
       
    45 }
       
    46 
       
    47 /**
       
    48  * Returns the height of a tile in pixels.
       
    49  *
       
    50  * This function returns the height of the northern corner of a tile in pixels.
       
    51  *
       
    52  * @param tile The tile to get the height
       
    53  * @return The height of the tile in pixel
       
    54  */
       
    55 static inline uint TilePixelHeight(TileIndex tile)
       
    56 {
       
    57 	return TileHeight(tile) * TILE_HEIGHT;
       
    58 }
       
    59 
       
    60 /**
       
    61  * Get the tiletype of a given tile.
       
    62  *
       
    63  * @param tile The tile to get the TileType
       
    64  * @return The tiletype of the tile
       
    65  * @pre tile < MapSize()
       
    66  */
       
    67 static inline TileType GetTileType(TileIndex tile)
       
    68 {
       
    69 	assert(tile < MapSize());
       
    70 	return (TileType)GB(_m[tile].type_height, 4, 4);
       
    71 }
       
    72 
       
    73 /**
       
    74  * Set the type of a tile
       
    75  *
       
    76  * This functions sets the type of a tile. If the type
       
    77  * MP_VOID is selected the tile must be at the south-west or
       
    78  * south-east edges of the map and vice versa.
       
    79  *
       
    80  * @param tile The tile to save the new type
       
    81  * @param type The type to save
       
    82  * @pre tile < MapSize()
       
    83  * @pre type MP_VOID <=> tile is on the south-east or south-west edge.
       
    84  */
       
    85 static inline void SetTileType(TileIndex tile, TileType type)
       
    86 {
       
    87 	assert(tile < MapSize());
       
    88 	/* VOID tiles (and no others) are exactly allowed at the lower left and right
       
    89 	 * edges of the map */
       
    90 	assert((TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) == (type == MP_VOID));
       
    91 	SB(_m[tile].type_height, 4, 4, type);
       
    92 }
       
    93 
       
    94 /**
       
    95  * Checks if a tile is a give tiletype.
       
    96  *
       
    97  * This function checks if a tile got the given tiletype.
       
    98  *
       
    99  * @param tile The tile to check
       
   100  * @param type The type to check agains
       
   101  * @return true If the type matches agains the type of the tile
       
   102  */
       
   103 static inline bool IsTileType(TileIndex tile, TileType type)
       
   104 {
       
   105 	return GetTileType(tile) == type;
       
   106 }
       
   107 
       
   108 /**
       
   109  * Returns the owner of a tile
       
   110  *
       
   111  * This function returns the owner of a tile. This cannot used
       
   112  * for tiles which type is one of MP_HOUSE, MP_VOID and MP_INDUSTRY
       
   113  * as no player owned any of these buildings.
       
   114  *
       
   115  * @param tile The tile to check
       
   116  * @return The owner of the tile
       
   117  * @pre tile < MapSize()
       
   118  * @pre The type of the tile must not be MP_HOUSE, MP_VOID and MP_INDUSTRY
       
   119  */
       
   120 static inline Owner GetTileOwner(TileIndex tile)
       
   121 {
       
   122 	assert(tile < MapSize());
       
   123 	assert(!IsTileType(tile, MP_HOUSE));
       
   124 	assert(!IsTileType(tile, MP_VOID));
       
   125 	assert(!IsTileType(tile, MP_INDUSTRY));
       
   126 
       
   127 	return (Owner)_m[tile].m1;
       
   128 }
       
   129 
       
   130 /**
       
   131  * Sets the owner of a tile
       
   132  *
       
   133  * This function sets the owner status of a tile. Note that you cannot
       
   134  * set a owner for tiles of type MP_HOUSE, MP_VOID and MP_INDUSTRY.
       
   135  *
       
   136  * @param tile The tile to change the owner status.
       
   137  * @param owner The new owner.
       
   138  * @pre tile < MapSize()
       
   139  * @pre The type of the tile must not be MP_HOUSE, MP_VOID and MP_INDUSTRY
       
   140  */
       
   141 static inline void SetTileOwner(TileIndex tile, Owner owner)
       
   142 {
       
   143 	assert(tile < MapSize());
       
   144 	assert(!IsTileType(tile, MP_HOUSE));
       
   145 	assert(!IsTileType(tile, MP_VOID));
       
   146 	assert(!IsTileType(tile, MP_INDUSTRY));
       
   147 
       
   148 	_m[tile].m1 = owner;
       
   149 }
       
   150 
       
   151 /**
       
   152  * Checks if a tile belongs to the given owner
       
   153  *
       
   154  * @param tile The tile to check
       
   155  * @param owner The owner to check agains
       
   156  * @return True if a tile belongs the the given owner
       
   157  */
       
   158 static inline bool IsTileOwner(TileIndex tile, Owner owner)
       
   159 {
       
   160 	return GetTileOwner(tile) == owner;
       
   161 }
       
   162 
       
   163 /**
       
   164  * Set the tropic zone
       
   165  * @param tile the tile to set the zone of
       
   166  * @param type the new type
       
   167  * @pre assert(tile < MapSize());
       
   168  */
       
   169 static inline void SetTropicZone(TileIndex tile, TropicZone type)
       
   170 {
       
   171 	assert(tile < MapSize());
       
   172 	SB(_m[tile].m6, 0, 2, type);
       
   173 }
       
   174 
       
   175 /**
       
   176  * Get the tropic zone
       
   177  * @param tile the tile to get the zone of
       
   178  * @pre assert(tile < MapSize());
       
   179  * @return the zone type
       
   180  */
       
   181 static inline TropicZone GetTropicZone(TileIndex tile)
       
   182 {
       
   183 	assert(tile < MapSize());
       
   184 	return (TropicZone)GB(_m[tile].m6, 0, 2);
       
   185 }
       
   186 
       
   187 Slope GetTileSlope(TileIndex tile, uint *h);
       
   188 uint GetTileZ(TileIndex tile);
       
   189 uint GetTileMaxZ(TileIndex tile);
       
   190 
       
   191 #endif /* TILE_TYPE_H */