# tree_map.h

Go to the documentation of this file.

    00001 /* $Id: tree_map.h 19741 2010-04-30 21:01:21Z 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
    00026 enum TreeType {
    00027   TREE_TEMPERATE    = 0x00,
    00028   TREE_SUB_ARCTIC   = 0x0C,
    00029   TREE_RAINFOREST   = 0x14,
    00030   TREE_CACTUS       = 0x1B,
    00031   TREE_SUB_TROPICAL = 0x1C,
    00032   TREE_TOYLAND      = 0x20,
    00033   TREE_INVALID      = 0xFF,
    00034 };
    00035
    00043 enum {
    00044   TREE_COUNT_TEMPERATE    = TREE_SUB_ARCTIC - TREE_TEMPERATE,
    00045   TREE_COUNT_SUB_ARCTIC   = TREE_RAINFOREST - TREE_SUB_ARCTIC,
    00046   TREE_COUNT_RAINFOREST   = TREE_CACTUS     - TREE_RAINFOREST,
    00047   TREE_COUNT_SUB_TROPICAL = TREE_TOYLAND    - TREE_SUB_TROPICAL,
    00048   TREE_COUNT_TOYLAND      = 9
    00049 };
    00050
    00056 enum TreeGround {
    00057   TREE_GROUND_GRASS       = 0,
    00058   TREE_GROUND_ROUGH       = 1,
    00059   TREE_GROUND_SNOW_DESERT = 2,
    00060   TREE_GROUND_SHORE       = 3,
    00061   TREE_GROUND_ROUGH_SNOW  = 4,
    00062 };
    00063
    00064
    00077 static inline TreeType GetTreeType(TileIndex t)
    00078 {
    00079   assert(IsTileType(t, MP_TREES));
    00080   return (TreeType)_m[t].m3;
    00081 }
    00082
    00092 static inline TreeGround GetTreeGround(TileIndex t)
    00093 {
    00094   assert(IsTileType(t, MP_TREES));
    00095   return (TreeGround)GB(_m[t].m2, 6, 3);
    00096 }
    00097
    00117 static inline uint GetTreeDensity(TileIndex t)
    00118 {
    00119   assert(IsTileType(t, MP_TREES));
    00120   return GB(_m[t].m2, 4, 2);
    00121 }
    00122
    00134 static inline void SetTreeGroundDensity(TileIndex t, TreeGround g, uint d)
    00135 {
    00136   assert(IsTileType(t, MP_TREES)); // XXX incomplete
    00137   SB(_m[t].m2, 4, 2, d);
    00138   SB(_m[t].m2, 6, 3, g);
    00139 }
    00140
    00152 static inline uint GetTreeCount(TileIndex t)
    00153 {
    00154   assert(IsTileType(t, MP_TREES));
    00155   return GB(_m[t].m5, 6, 2) + 1;
    00156 }
    00157
    00169 static inline void AddTreeCount(TileIndex t, int c)
    00170 {
    00171   assert(IsTileType(t, MP_TREES)); // XXX incomplete
    00172   _m[t].m5 += c << 6;
    00173 }
    00174
    00184 static inline uint GetTreeGrowth(TileIndex t)
    00185 {
    00186   assert(IsTileType(t, MP_TREES));
    00187   return GB(_m[t].m5, 0, 3);
    00188 }
    00189
    00199 static inline void AddTreeGrowth(TileIndex t, int a)
    00200 {
    00201   assert(IsTileType(t, MP_TREES)); // XXX incomplete
    00202   _m[t].m5 += a;
    00203 }
    00204
    00215 static inline void SetTreeGrowth(TileIndex t, uint g)
    00216 {
    00217   assert(IsTileType(t, MP_TREES)); // XXX incomplete
    00218   SB(_m[t].m5, 0, 3, g);
    00219 }
    00220
    00229 static inline uint GetTreeCounter(TileIndex t)
    00230 {
    00231   assert(IsTileType(t, MP_TREES));
    00232   return GB(_m[t].m2, 0, 4);
    00233 }
    00234
    00244 static inline void AddTreeCounter(TileIndex t, int a)
    00245 {
    00246   assert(IsTileType(t, MP_TREES)); // XXX incomplete
    00247   _m[t].m2 += a;
    00248 }
    00249
    00259 static inline void SetTreeCounter(TileIndex t, uint c)
    00260 {
    00261   assert(IsTileType(t, MP_TREES)); // XXX incomplete
    00262   SB(_m[t].m2, 0, 4, c);
    00263 }
    00264
    00277 static inline void MakeTree(TileIndex t, TreeType type, uint count, uint growth, TreeGround ground, uint density)
    00278 {
    00279   SetTileType(t, MP_TREES);
    00280   SetTileOwner(t, OWNER_NONE);
    00281   _m[t].m2 = ground << 6 | density << 4 | 0;
    00282   _m[t].m3 = type;
    00283   _m[t].m4 = 0 << 5 | 0 << 2;
    00284   _m[t].m5 = count << 6 | growth;
    00285   SB(_m[t].m6, 2, 4, 0);
    00286   _me[t].m7 = 0;
    00287 }
    00288
    00289 #endif /* TREE_MAP_H */