tree_map.h

Go to the documentation of this file.
00001 /* $Id: tree_map.h 20266 2010-07-31 21:02:56Z alberth $ */
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 
00036 /* Counts the number of tree types for each landscape.
00037  *
00038  * This list contains the counts of different tree types for each landscape. This list contains
00039  * 5 entries instead of 4 (as there are only 4 landscape types) as the sub tropic landscape
00040  * has two types of area, one for normal trees and one only for cacti.
00041  */
00042 static const uint TREE_COUNT_TEMPERATE    = TREE_SUB_ARCTIC - TREE_TEMPERATE;    
00043 static const uint TREE_COUNT_SUB_ARCTIC   = TREE_RAINFOREST - TREE_SUB_ARCTIC;   
00044 static const uint TREE_COUNT_RAINFOREST   = TREE_CACTUS     - TREE_RAINFOREST;   
00045 static const uint TREE_COUNT_SUB_TROPICAL = TREE_TOYLAND    - TREE_SUB_TROPICAL; 
00046 static const uint TREE_COUNT_TOYLAND      = 9;                                   
00047 
00053 enum TreeGround {
00054   TREE_GROUND_GRASS       = 0, 
00055   TREE_GROUND_ROUGH       = 1, 
00056   TREE_GROUND_SNOW_DESERT = 2, 
00057   TREE_GROUND_SHORE       = 3, 
00058   TREE_GROUND_ROUGH_SNOW  = 4, 
00059 };
00060 
00061 
00074 static inline TreeType GetTreeType(TileIndex t)
00075 {
00076   assert(IsTileType(t, MP_TREES));
00077   return (TreeType)_m[t].m3;
00078 }
00079 
00089 static inline TreeGround GetTreeGround(TileIndex t)
00090 {
00091   assert(IsTileType(t, MP_TREES));
00092   return (TreeGround)GB(_m[t].m2, 6, 3);
00093 }
00094 
00114 static inline uint GetTreeDensity(TileIndex t)
00115 {
00116   assert(IsTileType(t, MP_TREES));
00117   return GB(_m[t].m2, 4, 2);
00118 }
00119 
00131 static inline void SetTreeGroundDensity(TileIndex t, TreeGround g, uint d)
00132 {
00133   assert(IsTileType(t, MP_TREES)); // XXX incomplete
00134   SB(_m[t].m2, 4, 2, d);
00135   SB(_m[t].m2, 6, 3, g);
00136 }
00137 
00149 static inline uint GetTreeCount(TileIndex t)
00150 {
00151   assert(IsTileType(t, MP_TREES));
00152   return GB(_m[t].m5, 6, 2) + 1;
00153 }
00154 
00166 static inline void AddTreeCount(TileIndex t, int c)
00167 {
00168   assert(IsTileType(t, MP_TREES)); // XXX incomplete
00169   _m[t].m5 += c << 6;
00170 }
00171 
00181 static inline uint GetTreeGrowth(TileIndex t)
00182 {
00183   assert(IsTileType(t, MP_TREES));
00184   return GB(_m[t].m5, 0, 3);
00185 }
00186 
00196 static inline void AddTreeGrowth(TileIndex t, int a)
00197 {
00198   assert(IsTileType(t, MP_TREES)); // XXX incomplete
00199   _m[t].m5 += a;
00200 }
00201 
00212 static inline void SetTreeGrowth(TileIndex t, uint g)
00213 {
00214   assert(IsTileType(t, MP_TREES)); // XXX incomplete
00215   SB(_m[t].m5, 0, 3, g);
00216 }
00217 
00226 static inline uint GetTreeCounter(TileIndex t)
00227 {
00228   assert(IsTileType(t, MP_TREES));
00229   return GB(_m[t].m2, 0, 4);
00230 }
00231 
00241 static inline void AddTreeCounter(TileIndex t, int a)
00242 {
00243   assert(IsTileType(t, MP_TREES)); // XXX incomplete
00244   _m[t].m2 += a;
00245 }
00246 
00256 static inline void SetTreeCounter(TileIndex t, uint c)
00257 {
00258   assert(IsTileType(t, MP_TREES)); // XXX incomplete
00259   SB(_m[t].m2, 0, 4, c);
00260 }
00261 
00274 static inline void MakeTree(TileIndex t, TreeType type, uint count, uint growth, TreeGround ground, uint density)
00275 {
00276   SetTileType(t, MP_TREES);
00277   SetTileOwner(t, OWNER_NONE);
00278   _m[t].m2 = ground << 6 | density << 4 | 0;
00279   _m[t].m3 = type;
00280   _m[t].m4 = 0 << 5 | 0 << 2;
00281   _m[t].m5 = count << 6 | growth;
00282   SB(_m[t].m6, 2, 4, 0);
00283   _me[t].m7 = 0;
00284 }
00285 
00286 #endif /* TREE_MAP_H */

Generated on Fri Feb 4 20:53:49 2011 for OpenTTD by  doxygen 1.6.1