tree_map.h
changeset 3144 33e42feae531
parent 3079 a26f87fba4c1
child 3145 e833d7a78887
equal deleted inserted replaced
3143:24e7291f7652 3144:33e42feae531
       
     1 /* $Id$ */
       
     2 
       
     3 #ifndef TREE_H
       
     4 #define TREE_H
       
     5 
       
     6 #include "macros.h"
       
     7 
       
     8 typedef enum TreeType {
       
     9 	TR_INVALID      = -1,
       
    10 	TR_TEMPERATE    = 0,
       
    11 	TR_SUB_ARCTIC   = 12,
       
    12 	TR_RAINFOREST   = 20,
       
    13 	TR_CACTUS       = 27,
       
    14 	TR_SUB_TROPICAL = 28,
       
    15 	TR_TOYLAND      = 32
       
    16 } TreeType;
       
    17 
       
    18 enum {
       
    19 	TR_COUNT_TEMPERATE    = TR_SUB_ARCTIC   - TR_TEMPERATE,
       
    20 	TR_COUNT_SUB_ARCTIC   = TR_RAINFOREST   - TR_SUB_ARCTIC,
       
    21 	TR_COUNT_RAINFOREST   = TR_CACTUS       - TR_RAINFOREST,
       
    22 	TR_COUNT_SUB_TROPICAL = TR_SUB_TROPICAL - TR_CACTUS,
       
    23 	TR_COUNT_TOYLAND      = 9
       
    24 };
       
    25 
       
    26 /* ground type, m2 bits 4...5
       
    27  * valid densities (bits 6...7) in comments after the enum */
       
    28 typedef enum TreeGround {
       
    29 	TR_GRASS       = 0, // 0
       
    30 	TR_ROUGH       = 1, // 0
       
    31 	TR_SNOW_DESERT = 2  // 0-3 for snow, 3 for desert
       
    32 } TreeGround;
       
    33 
       
    34 static inline TreeType GetTreeType(TileIndex t) { return _m[t].m3; }
       
    35 static inline void SetTreeType(TileIndex t, TreeType r) { _m[t].m3 = r; }
       
    36 
       
    37 static inline TreeGround GetTreeGround(TileIndex t) { return GB(_m[t].m2, 4, 2); }
       
    38 
       
    39 static inline uint GetTreeDensity(TileIndex t) { return GB(_m[t].m2, 6, 2); }
       
    40 
       
    41 static inline void SetTreeGroundDensity(TileIndex t, TreeGround g, uint d)
       
    42 {
       
    43 	SB(_m[t].m2, 4, 2, g);
       
    44 	SB(_m[t].m2, 6, 2, d);
       
    45 }
       
    46 
       
    47 static inline void AddTreeCount(TileIndex t, int c) { _m[t].m5 += c << 6; }
       
    48 static inline uint GetTreeCount(TileIndex t) { return GB(_m[t].m5, 6, 2); }
       
    49 static inline void SetTreeCount(TileIndex t, uint c) { SB(_m[t].m5, 6, 2, c); }
       
    50 
       
    51 static inline void AddTreeGrowth(TileIndex t, int a) { _m[t].m5 += a; }
       
    52 static inline uint GetTreeGrowth(TileIndex t) { return GB(_m[t].m5, 0, 3); }
       
    53 static inline void SetTreeGrowth(TileIndex t, uint g) { SB(_m[t].m5, 0, 3, g); }
       
    54 
       
    55 static inline void AddTreeCounter(TileIndex t, int a) { _m[t].m2 += a; }
       
    56 static inline uint GetTreeCounter(TileIndex t) { return GB(_m[t].m2, 0, 4); }
       
    57 static inline void SetTreeCounter(TileIndex t, uint c) { SB(_m[t].m2, 0, 4, c); }
       
    58 
       
    59 
       
    60 static inline void MakeTree(TileIndex t, TreeType type, uint count, uint growth, TreeGround ground, uint density)
       
    61 {
       
    62 	SetTileType(t, MP_TREES);
       
    63 	SetTileOwner(t, OWNER_NONE);
       
    64 	_m[t].m2 = density << 6 | ground << 4 | 0;
       
    65 	_m[t].m3 = type;
       
    66 	_m[t].m4 = 0 << 5 | 0 << 2;
       
    67 	_m[t].m5 = count << 6 | growth;
       
    68 }
       
    69 
       
    70 #endif