tron@2981: /* $Id$ */ tron@2981: rubidium@9111: /** @file tree_map.h Map accessors for tree tiles. */ belugas@6422: tron@3145: #ifndef TREE_MAP_H tron@3145: #define TREE_MAP_H tron@2981: rubidium@7597: /** rubidium@7597: * List of tree types along all landscape types. rubidium@7597: * rubidium@7597: * This enumeration contains a list of the different tree types along rubidium@7597: * all landscape types. The values for the enumerations may be used for rubidium@7597: * offsets from the grfs files. These points to the start of rubidium@7597: * the tree list for a landscape. See the TREE_COUNT_* enumerations rubidium@7597: * for the amount of different trees for a specific landscape. rubidium@7597: * rubidium@7597: * @note TREE_INVALID may be 0xFF according to the coding style, not -1 (Progman) rubidium@7597: */ rubidium@6248: enum TreeType { rubidium@7597: TREE_INVALID = -1, ///< An invalid tree rubidium@7597: TREE_TEMPERATE = 0x00, ///< temperate tree rubidium@7597: TREE_SUB_ARCTIC = 0x0C, ///< tree on a sub_arctic landscape rubidium@7597: TREE_RAINFOREST = 0x14, ///< tree on the 'green part' on a sub-tropical map rubidium@7597: TREE_CACTUS = 0x1B, ///< a catus for the 'desert part' on a sub-tropical map rubidium@7597: TREE_SUB_TROPICAL = 0x1C, ///< tree on a sub-tropical map, non-rainforest, non-desert rubidium@7597: TREE_TOYLAND = 0x20, ///< tree on a toyland map rubidium@6248: }; tron@2981: rubidium@7597: /** rubidium@7597: * Counts the number of treetypes for each landscape. rubidium@7597: * rubidium@7597: * This list contains the counts of different treetypes for each landscape. This list contains rubidium@7597: * 5 entries instead of 4 (as there are only 4 landscape types) as the sub tropic landscape rubidium@7597: * got two types of area, one for normal trees and one only for cacti. rubidium@7597: */ tron@2981: enum { rubidium@7597: TREE_COUNT_TEMPERATE = TREE_SUB_ARCTIC - TREE_TEMPERATE, ///< number of treetypes on a temperate map rubidium@7597: TREE_COUNT_SUB_ARCTIC = TREE_RAINFOREST - TREE_SUB_ARCTIC, ///< number of treetypes on a sub arctic map rubidium@7597: TREE_COUNT_RAINFOREST = TREE_CACTUS - TREE_RAINFOREST, ///< number of treetypes for the 'green part' of a sub tropic map rubidium@7597: TREE_COUNT_SUB_TROPICAL = TREE_SUB_TROPICAL - TREE_CACTUS, ///< number of treetypes for the 'desert part' of a sub tropic map rubidium@7597: TREE_COUNT_TOYLAND = 9 ///< number of treetypes on a toyland map tron@2981: }; tron@2981: rubidium@7597: /** rubidium@7597: * Enumeration for ground types of tiles with trees. rubidium@7597: * rubidium@7597: * This enumeration defines the ground types for tiles with trees on it. rubidium@7597: */ rubidium@6248: enum TreeGround { rubidium@7597: TREE_GROUND_GRASS = 0, ///< normal grass rubidium@7597: TREE_GROUND_ROUGH = 1, ///< some rough tile frosch@8459: TREE_GROUND_SNOW_DESERT = 2, ///< a desert or snow tile, depend on landscape frosch@8459: TREE_GROUND_SHORE = 3, ///< shore rubidium@6248: }; tron@2981: tron@2981: rubidium@7597: /** rubidium@7597: * Returns the treetype of a tile. rubidium@7597: * rubidium@7597: * This function returns the treetype of a given tile. As there are more rubidium@7597: * possible treetypes for a tile in a game as the enumeration #TreeType defines rubidium@7597: * this function may be return a value which isn't catch by an entry of the rubidium@7597: * enumeration #TreeType. But there is no problem known about it. rubidium@7597: * rubidium@7597: * @param t The tile to get the treetype from rubidium@7597: * @return The treetype of the given tile with trees rubidium@7597: * @pre Tile t must be of type MP_TREES rubidium@7597: */ tron@3369: static inline TreeType GetTreeType(TileIndex t) tron@3369: { tron@3369: assert(IsTileType(t, MP_TREES)); rubidium@5587: return (TreeType)_m[t].m3; tron@3369: } tron@2981: rubidium@7597: /** rubidium@7597: * Returns the groundtype for tree tiles. rubidium@7597: * rubidium@7597: * This function returns the groundtype of a tile with trees. rubidium@7597: * rubidium@7597: * @param t The tile to get the groundtype from rubidium@7597: * @return The groundtype of the tile rubidium@7597: * @pre Tile must be of type MP_TREES rubidium@7597: */ tron@3369: static inline TreeGround GetTreeGround(TileIndex t) tron@3369: { tron@3369: assert(IsTileType(t, MP_TREES)); rubidium@5587: return (TreeGround)GB(_m[t].m2, 4, 2); tron@3369: } tron@3369: rubidium@7597: /** rubidium@7597: * Returns the 'density' of a tile with trees. rubidium@7597: * rubidium@7597: * This function returns the density of a tile which got trees. Note rubidium@7597: * that this value doesn't count the number of trees on a tile, use rubidium@7597: * #GetTreeCount instead. This function instead returns some kind of rubidium@7597: * groundtype of the tile. As the map-array is finite in size and rubidium@7597: * the informations about the trees must be saved somehow other rubidium@7597: * informations about a tile must be saved somewhere encoded in the rubidium@7597: * tile. So this function returns the density of a tile for sub arctic rubidium@7597: * and sub tropical games. This means for sub arctic the type of snowline rubidium@7597: * (0 to 3 for all 4 types of snowtiles) and for sub tropical the value rubidium@7597: * 3 for a desert (and 0 for non-desert). The functionname is not read as rubidium@7597: * "get the tree density of a tile" but "get the density of a tile which got trees". rubidium@7597: * rubidium@7597: * @param t The tile to get the 'density' rubidium@7597: * @pre Tile must be of type MP_TREES rubidium@7597: * @see GetTreeCount rubidium@7597: */ tron@3369: static inline uint GetTreeDensity(TileIndex t) tron@3369: { tron@3369: assert(IsTileType(t, MP_TREES)); tron@3369: return GB(_m[t].m2, 6, 2); tron@3369: } tron@3369: rubidium@7597: /** rubidium@7597: * Set the density and ground type of a tile with trees. rubidium@7597: * rubidium@7597: * This functions saves the ground type and the density which belongs to it rubidium@7597: * for a given tile. rubidium@7597: * rubidium@7597: * @param t The tile to set the density and ground type rubidium@7597: * @param g The ground type to save rubidium@7597: * @param d The density to save with rubidium@7597: * @pre Tile must be of type MP_TREES rubidium@7597: */ tron@2981: static inline void SetTreeGroundDensity(TileIndex t, TreeGround g, uint d) tron@2981: { tron@3369: assert(IsTileType(t, MP_TREES)); // XXX incomplete tron@2981: SB(_m[t].m2, 4, 2, g); tron@2981: SB(_m[t].m2, 6, 2, d); tron@2981: } tron@2981: rubidium@7597: /** rubidium@7597: * Returns the number of trees on a tile. rubidium@7597: * rubidium@7597: * This function returns the number of trees of a tile (1-4). rubidium@7597: * The tile must be contains at least one tree or be more specific: it must be rubidium@7597: * of type MP_TREES. rubidium@7597: * rubidium@7597: * @param t The index to get the number of trees rubidium@7597: * @return The number of trees (1-4) rubidium@7597: * @pre Tile must be of type MP_TREES rubidium@7597: */ tron@3369: static inline uint GetTreeCount(TileIndex t) tron@3369: { tron@3369: assert(IsTileType(t, MP_TREES)); smatz@10363: return GB(_m[t].m5, 6, 2) + 1; tron@3369: } tron@2981: rubidium@7597: /** rubidium@7597: * Add a amount to the tree-count value of a tile with trees. rubidium@7597: * rubidium@7597: * This function add a value to the tree-count value of a tile. This rubidium@7597: * value may be negative to reduce the tree-counter. If the resulting rubidium@7597: * value reach 0 it doesn't get converted to a "normal" tile. rubidium@7597: * rubidium@7597: * @param t The tile to change the tree amount rubidium@7597: * @param c The value to add (or reduce) on the tree-count value rubidium@7597: * @pre Tile must be of type MP_TREES rubidium@7597: */ tron@3369: static inline void AddTreeCount(TileIndex t, int c) tron@3369: { tron@3369: assert(IsTileType(t, MP_TREES)); // XXX incomplete tron@3369: _m[t].m5 += c << 6; tron@3369: } tron@3369: rubidium@7597: /** rubidium@7597: * Returns the tree growth status. rubidium@7597: * rubidium@7597: * This function returns the tree growth status of a tile with trees. rubidium@7597: * rubidium@7597: * @param t The tile to get the tree growth status rubidium@7597: * @return The tree growth status rubidium@7597: * @pre Tile must be of type MP_TREES rubidium@7597: */ tron@3369: static inline uint GetTreeGrowth(TileIndex t) tron@3369: { tron@3369: assert(IsTileType(t, MP_TREES)); tron@3369: return GB(_m[t].m5, 0, 3); tron@3369: } tron@3369: rubidium@7597: /** rubidium@7597: * Add a value to the tree growth status. rubidium@7597: * rubidium@7597: * This function adds a value to the tree grow status of a tile. rubidium@7597: * rubidium@7597: * @param t The tile to add the value on rubidium@7597: * @param a The value to add on the tree growth status rubidium@7597: * @pre Tile must be of type MP_TREES rubidium@7597: */ tron@3369: static inline void AddTreeGrowth(TileIndex t, int a) tron@3369: { tron@3369: assert(IsTileType(t, MP_TREES)); // XXX incomplete tron@3369: _m[t].m5 += a; tron@3369: } tron@3369: rubidium@7597: /** rubidium@7597: * Sets the tree growth status of a tile. rubidium@7597: * rubidium@7597: * This function sets the tree growth status of a tile directly with rubidium@7597: * the given value. rubidium@7597: * rubidium@7597: * @param t The tile to change the tree growth status rubidium@7597: * @param g The new value rubidium@7597: * @pre Tile must be of type MP_TREES rubidium@7597: */ tron@3369: static inline void SetTreeGrowth(TileIndex t, uint g) tron@3369: { tron@3369: assert(IsTileType(t, MP_TREES)); // XXX incomplete tron@3369: SB(_m[t].m5, 0, 3, g); tron@3369: } tron@3369: rubidium@7597: /** rubidium@7597: * Get the tick counter of a tree tile. rubidium@7597: * rubidium@7597: * Returns the saved tick counter of a given tile. rubidium@7597: * rubidium@7597: * @param t The tile to get the counter value from rubidium@7597: * @pre Tile must be of type MP_TREES rubidium@7597: */ tron@3369: static inline uint GetTreeCounter(TileIndex t) tron@3369: { tron@3369: assert(IsTileType(t, MP_TREES)); tron@3369: return GB(_m[t].m2, 0, 4); tron@3369: } tron@3369: rubidium@7597: /** rubidium@7597: * Add a value on the tick counter of a tree-tile rubidium@7597: * rubidium@7597: * This function adds a value on the tick counter of a tree-tile. rubidium@7597: * rubidium@7597: * @param t The tile to add the value on rubidium@7597: * @param a The value to add on the tick counter rubidium@7597: * @pre Tile must be of type MP_TREES rubidium@7597: */ tron@3369: static inline void AddTreeCounter(TileIndex t, int a) tron@3369: { tron@3369: assert(IsTileType(t, MP_TREES)); // XXX incomplete tron@3369: _m[t].m2 += a; tron@3369: } tron@3369: rubidium@7597: /** rubidium@7597: * Set the tick counter for a tree-tile rubidium@7597: * rubidium@7597: * This function sets directly the tick counter for a tree-tile. rubidium@7597: * rubidium@7597: * @param t The tile to set the tick counter rubidium@7597: * @param c The new tick counter value rubidium@7597: * @pre Tile must be of type MP_TREES rubidium@7597: */ tron@3369: static inline void SetTreeCounter(TileIndex t, uint c) tron@3369: { tron@3369: assert(IsTileType(t, MP_TREES)); // XXX incomplete tron@3369: SB(_m[t].m2, 0, 4, c); tron@3369: } tron@2981: rubidium@7597: /** rubidium@7597: * Make a tree-tile. rubidium@7597: * rubidium@7597: * This functions change the tile to a tile with trees and all informations which belongs to it. rubidium@7597: * rubidium@7597: * @param t The tile to make a tree-tile from rubidium@7597: * @param type The type of the tree rubidium@7597: * @param set the number of trees rubidium@7597: * @param growth the growth status rubidium@7597: * @param ground the ground type rubidium@7597: * @param density the density (not the number of trees) rubidium@7597: */ tron@3079: static inline void MakeTree(TileIndex t, TreeType type, uint count, uint growth, TreeGround ground, uint density) tron@3079: { tron@3079: SetTileType(t, MP_TREES); tron@3079: SetTileOwner(t, OWNER_NONE); tron@3079: _m[t].m2 = density << 6 | ground << 4 | 0; tron@3079: _m[t].m3 = type; tron@3079: _m[t].m4 = 0 << 5 | 0 << 2; tron@3079: _m[t].m5 = count << 6 | growth; tron@3079: } tron@3079: peter1138@4666: #endif /* TREE_MAP_H */