clear_map.h

Go to the documentation of this file.
00001 /* $Id: clear_map.h 11776 2008-01-07 14:02:26Z rubidium $ */
00002 
00005 #ifndef CLEAR_MAP_H
00006 #define CLEAR_MAP_H
00007 
00008 #include "bridge_map.h"
00009 #include "industry_type.h"
00010 
00014 enum ClearGround {
00015   CLEAR_GRASS  = 0, 
00016   CLEAR_ROUGH  = 1, 
00017   CLEAR_ROCKS  = 2, 
00018   CLEAR_FIELDS = 3, 
00019   CLEAR_SNOW   = 4, 
00020   CLEAR_DESERT = 5  
00021 };
00022 
00023 
00030 static inline ClearGround GetClearGround(TileIndex t)
00031 {
00032   assert(IsTileType(t, MP_CLEAR));
00033   return (ClearGround)GB(_m[t].m5, 2, 3);
00034 }
00035 
00042 static inline bool IsClearGround(TileIndex t, ClearGround ct)
00043 {
00044   return GetClearGround(t) == ct;
00045 }
00046 
00047 
00054 static inline uint GetClearDensity(TileIndex t)
00055 {
00056   assert(IsTileType(t, MP_CLEAR));
00057   return GB(_m[t].m5, 0, 2);
00058 }
00059 
00066 static inline void AddClearDensity(TileIndex t, int d)
00067 {
00068   assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
00069   _m[t].m5 += d;
00070 }
00071 
00072 
00079 static inline uint GetClearCounter(TileIndex t)
00080 {
00081   assert(IsTileType(t, MP_CLEAR));
00082   return GB(_m[t].m5, 5, 3);
00083 }
00084 
00091 static inline void AddClearCounter(TileIndex t, int c)
00092 {
00093   assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
00094   _m[t].m5 += c << 5;
00095 }
00096 
00103 static inline void SetClearCounter(TileIndex t, uint c)
00104 {
00105   assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
00106   SB(_m[t].m5, 5, 3, c);
00107 }
00108 
00109 
00117 static inline void SetClearGroundDensity(TileIndex t, ClearGround type, uint density)
00118 {
00119   assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
00120   _m[t].m5 = 0 << 5 | type << 2 | density;
00121 }
00122 
00123 
00130 static inline uint GetFieldType(TileIndex t)
00131 {
00132   assert(GetClearGround(t) == CLEAR_FIELDS);
00133   return GB(_m[t].m3, 0, 4);
00134 }
00135 
00142 static inline void SetFieldType(TileIndex t, uint f)
00143 {
00144   assert(GetClearGround(t) == CLEAR_FIELDS); // XXX incomplete
00145   SB(_m[t].m3, 0, 4, f);
00146 }
00147 
00154 static inline IndustryID GetIndustryIndexOfField(TileIndex t)
00155 {
00156   assert(GetClearGround(t) == CLEAR_FIELDS);
00157   return(IndustryID) _m[t].m2;
00158 }
00159 
00166 static inline void SetIndustryIndexOfField(TileIndex t, IndustryID i)
00167 {
00168   assert(GetClearGround(t) == CLEAR_FIELDS);
00169   _m[t].m2 = i;
00170 }
00171 
00172 
00179 static inline uint GetFenceSE(TileIndex t)
00180 {
00181   assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES));
00182   return GB(_m[t].m4, 2, 3);
00183 }
00184 
00192 static inline void SetFenceSE(TileIndex t, uint h)
00193 {
00194   assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)); // XXX incomplete
00195   SB(_m[t].m4, 2, 3, h);
00196 }
00197 
00204 static inline uint GetFenceSW(TileIndex t)
00205 {
00206   assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES));
00207   return GB(_m[t].m4, 5, 3);
00208 }
00209 
00217 static inline void SetFenceSW(TileIndex t, uint h)
00218 {
00219   assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)); // XXX incomplete
00220   SB(_m[t].m4, 5, 3, h);
00221 }
00222 
00223 
00230 static inline void MakeClear(TileIndex t, ClearGround g, uint density)
00231 {
00232   /* If this is a non-bridgeable tile, clear the bridge bits while the rest
00233    * of the tile information is still here. */
00234   if (!MayHaveBridgeAbove(t)) SB(_m[t].m6, 6, 2, 0);
00235 
00236   SetTileType(t, MP_CLEAR);
00237   SetTileOwner(t, OWNER_NONE);
00238   _m[t].m2 = 0;
00239   _m[t].m3 = 0;
00240   _m[t].m4 = 0 << 5 | 0 << 2;
00241   SetClearGroundDensity(t, g, density);
00242   SB(_m[t].m6, 2, 4, 0); // Clear the rest of m6, bits 2 to 5
00243 }
00244 
00245 
00252 static inline void MakeField(TileIndex t, uint field_type, IndustryID industry)
00253 {
00254   SetTileType(t, MP_CLEAR);
00255   SetTileOwner(t, OWNER_NONE);
00256   _m[t].m2 = industry;
00257   _m[t].m3 = field_type;
00258   _m[t].m4 = 0 << 5 | 0 << 2;
00259   SetClearGroundDensity(t, CLEAR_FIELDS, 3);
00260 }
00261 
00262 #endif /* CLEAR_MAP_H */

Generated on Wed Oct 1 17:03:20 2008 for openttd by  doxygen 1.5.6