# tree_map.h

Go to the documentation of this file.

    00001 /* $Id: tree_map.h 18809 2010-01-15 16:41:15Z rubidium $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #ifndef TREE_MAP_H
    00013 #define TREE_MAP_H
    00014
    00015 #include "tile_map.h"
    00016
    00028 enum TreeType {
    00029   TREE_INVALID      = -1,
    00030   TREE_TEMPERATE    = 0x00,
    00031   TREE_SUB_ARCTIC   = 0x0C,
    00032   TREE_RAINFOREST   = 0x14,
    00033   TREE_CACTUS       = 0x1B,
    00034   TREE_SUB_TROPICAL = 0x1C,
    00035   TREE_TOYLAND      = 0x20,
    00036 };
    00037
    00045 enum {
    00046   TREE_COUNT_TEMPERATE    = TREE_SUB_ARCTIC   - TREE_TEMPERATE,
    00047   TREE_COUNT_SUB_ARCTIC   = TREE_RAINFOREST   - TREE_SUB_ARCTIC,
    00048   TREE_COUNT_RAINFOREST   = TREE_CACTUS       - TREE_RAINFOREST,
    00049   TREE_COUNT_SUB_TROPICAL = TREE_SUB_TROPICAL - TREE_CACTUS,
    00050   TREE_COUNT_TOYLAND      = 9
    00051 };
    00052
    00058 enum TreeGround {
    00059   TREE_GROUND_GRASS       = 0,
    00060   TREE_GROUND_ROUGH       = 1,
    00061   TREE_GROUND_SNOW_DESERT = 2,
    00062   TREE_GROUND_SHORE       = 3,
    00063   TREE_GROUND_ROUGH_SNOW  = 4,
    00064 };
    00065
    00066
    00079 static inline TreeType GetTreeType(TileIndex t)
    00080 {
    00081   assert(IsTileType(t, MP_TREES));
    00082   return (TreeType)_m[t].m3;
    00083 }
    00084
    00094 static inline TreeGround GetTreeGround(TileIndex t)
    00095 {
    00096   assert(IsTileType(t, MP_TREES));
    00097   return (TreeGround)GB(_m[t].m2, 6, 3);
    00098 }
    00099
    00119 static inline uint GetTreeDensity(TileIndex t)
    00120 {
    00121   assert(IsTileType(t, MP_TREES));
    00122   return GB(_m[t].m2, 4, 2);
    00123 }
    00124
    00136 static inline void SetTreeGroundDensity(TileIndex t, TreeGround g, uint d)
    00137 {
    00138   assert(IsTileType(t, MP_TREES)); // XXX incomplete
    00139   SB(_m[t].m2, 4, 2, d);
    00140   SB(_m[t].m2, 6, 3, g);
    00141 }
    00142
    00154 static inline uint GetTreeCount(TileIndex t)
    00155 {
    00156   assert(IsTileType(t, MP_TREES));
    00157   return GB(_m[t].m5, 6, 2) + 1;
    00158 }
    00159
    00171 static inline void AddTreeCount(TileIndex t, int c)
    00172 {
    00173   assert(IsTileType(t, MP_TREES)); // XXX incomplete
    00174   _m[t].m5 += c << 6;
    00175 }
    00176
    00186 static inline uint GetTreeGrowth(TileIndex t)
    00187 {
    00188   assert(IsTileType(t, MP_TREES));
    00189   return GB(_m[t].m5, 0, 3);
    00190 }
    00191
    00201 static inline void AddTreeGrowth(TileIndex t, int a)
    00202 {
    00203   assert(IsTileType(t, MP_TREES)); // XXX incomplete
    00204   _m[t].m5 += a;
    00205 }
    00206
    00217 static inline void SetTreeGrowth(TileIndex t, uint g)
    00218 {
    00219   assert(IsTileType(t, MP_TREES)); // XXX incomplete
    00220   SB(_m[t].m5, 0, 3, g);
    00221 }
    00222
    00231 static inline uint GetTreeCounter(TileIndex t)
    00232 {
    00233   assert(IsTileType(t, MP_TREES));
    00234   return GB(_m[t].m2, 0, 4);
    00235 }
    00236
    00246 static inline void AddTreeCounter(TileIndex t, int a)
    00247 {
    00248   assert(IsTileType(t, MP_TREES)); // XXX incomplete
    00249   _m[t].m2 += a;
    00250 }
    00251
    00261 static inline void SetTreeCounter(TileIndex t, uint c)
    00262 {
    00263   assert(IsTileType(t, MP_TREES)); // XXX incomplete
    00264   SB(_m[t].m2, 0, 4, c);
    00265 }
    00266
    00279 static inline void MakeTree(TileIndex t, TreeType type, uint count, uint growth, TreeGround ground, uint density)
    00280 {
    00281   SetTileType(t, MP_TREES);
    00282   SetTileOwner(t, OWNER_NONE);
    00283   _m[t].m2 = ground << 6 | density << 4 | 0;
    00284   _m[t].m3 = type;
    00285   _m[t].m4 = 0 << 5 | 0 << 2;
    00286   _m[t].m5 = count << 6 | growth;
    00287   SB(_m[t].m6, 2, 4, 0);
    00288   _me[t].m7 = 0;
    00289 }
    00290
    00291 #endif /* TREE_MAP_H */