clear_map.h

Go to the documentation of this file.
00001 /* $Id: clear_map.h 23595 2011-12-19 17:48:04Z 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 CLEAR_MAP_H
00013 #define CLEAR_MAP_H
00014 
00015 #include "bridge_map.h"
00016 #include "industry_type.h"
00017 
00021 enum ClearGround {
00022   CLEAR_GRASS  = 0, 
00023   CLEAR_ROUGH  = 1, 
00024   CLEAR_ROCKS  = 2, 
00025   CLEAR_FIELDS = 3, 
00026   CLEAR_SNOW   = 4, 
00027   CLEAR_DESERT = 5, 
00028 };
00029 
00030 
00037 static inline bool IsSnowTile(TileIndex t)
00038 {
00039   assert(IsTileType(t, MP_CLEAR));
00040   return HasBit(_m[t].m3, 4);
00041 }
00042 
00049 static inline ClearGround GetRawClearGround(TileIndex t)
00050 {
00051   assert(IsTileType(t, MP_CLEAR));
00052   return (ClearGround)GB(_m[t].m5, 2, 3);
00053 }
00054 
00061 static inline ClearGround GetClearGround(TileIndex t)
00062 {
00063   if (IsSnowTile(t)) return CLEAR_SNOW;
00064   return GetRawClearGround(t);
00065 }
00066 
00073 static inline bool IsClearGround(TileIndex t, ClearGround ct)
00074 {
00075   return GetClearGround(t) == ct;
00076 }
00077 
00078 
00085 static inline uint GetClearDensity(TileIndex t)
00086 {
00087   assert(IsTileType(t, MP_CLEAR));
00088   return GB(_m[t].m5, 0, 2);
00089 }
00090 
00097 static inline void AddClearDensity(TileIndex t, int d)
00098 {
00099   assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
00100   _m[t].m5 += d;
00101 }
00102 
00109 static inline void SetClearDensity(TileIndex t, uint d)
00110 {
00111   assert(IsTileType(t, MP_CLEAR));
00112   SB(_m[t].m5, 0, 2, d);
00113 }
00114 
00115 
00122 static inline uint GetClearCounter(TileIndex t)
00123 {
00124   assert(IsTileType(t, MP_CLEAR));
00125   return GB(_m[t].m5, 5, 3);
00126 }
00127 
00134 static inline void AddClearCounter(TileIndex t, int c)
00135 {
00136   assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
00137   _m[t].m5 += c << 5;
00138 }
00139 
00146 static inline void SetClearCounter(TileIndex t, uint c)
00147 {
00148   assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
00149   SB(_m[t].m5, 5, 3, c);
00150 }
00151 
00152 
00160 static inline void SetClearGroundDensity(TileIndex t, ClearGround type, uint density)
00161 {
00162   assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
00163   _m[t].m5 = 0 << 5 | type << 2 | density;
00164 }
00165 
00166 
00173 static inline uint GetFieldType(TileIndex t)
00174 {
00175   assert(GetClearGround(t) == CLEAR_FIELDS);
00176   return GB(_m[t].m3, 0, 4);
00177 }
00178 
00185 static inline void SetFieldType(TileIndex t, uint f)
00186 {
00187   assert(GetClearGround(t) == CLEAR_FIELDS); // XXX incomplete
00188   SB(_m[t].m3, 0, 4, f);
00189 }
00190 
00197 static inline IndustryID GetIndustryIndexOfField(TileIndex t)
00198 {
00199   assert(GetClearGround(t) == CLEAR_FIELDS);
00200   return(IndustryID) _m[t].m2;
00201 }
00202 
00209 static inline void SetIndustryIndexOfField(TileIndex t, IndustryID i)
00210 {
00211   assert(GetClearGround(t) == CLEAR_FIELDS);
00212   _m[t].m2 = i;
00213 }
00214 
00215 
00222 static inline uint GetFenceSE(TileIndex t)
00223 {
00224   assert(IsClearGround(t, CLEAR_FIELDS));
00225   return GB(_m[t].m4, 2, 3);
00226 }
00227 
00235 static inline void SetFenceSE(TileIndex t, uint h)
00236 {
00237   assert(IsClearGround(t, CLEAR_FIELDS));
00238   SB(_m[t].m4, 2, 3, h);
00239 }
00240 
00247 static inline uint GetFenceSW(TileIndex t)
00248 {
00249   assert(IsClearGround(t, CLEAR_FIELDS));
00250   return GB(_m[t].m4, 5, 3);
00251 }
00252 
00260 static inline void SetFenceSW(TileIndex t, uint h)
00261 {
00262   assert(IsClearGround(t, CLEAR_FIELDS));
00263   SB(_m[t].m4, 5, 3, h);
00264 }
00265 
00272 static inline uint GetFenceNE(TileIndex t)
00273 {
00274   assert(IsClearGround(t, CLEAR_FIELDS));
00275   return GB(_m[t].m3, 5, 3);
00276 }
00277 
00285 static inline void SetFenceNE(TileIndex t, uint h)
00286 {
00287   assert(IsClearGround(t, CLEAR_FIELDS));
00288   SB(_m[t].m3, 5, 3, h);
00289 }
00290 
00297 static inline uint GetFenceNW(TileIndex t)
00298 {
00299   assert(IsClearGround(t, CLEAR_FIELDS));
00300   return GB(_m[t].m6, 2, 3);
00301 }
00302 
00310 static inline void SetFenceNW(TileIndex t, uint h)
00311 {
00312   assert(IsClearGround(t, CLEAR_FIELDS));
00313   SB(_m[t].m6, 2, 3, h);
00314 }
00315 
00316 
00323 static inline void MakeClear(TileIndex t, ClearGround g, uint density)
00324 {
00325   /* If this is a non-bridgeable tile, clear the bridge bits while the rest
00326    * of the tile information is still here. */
00327   if (!MayHaveBridgeAbove(t)) SB(_m[t].m6, 6, 2, 0);
00328 
00329   SetTileType(t, MP_CLEAR);
00330   _m[t].m1 = 0;
00331   SetTileOwner(t, OWNER_NONE);
00332   _m[t].m2 = 0;
00333   _m[t].m3 = 0;
00334   _m[t].m4 = 0 << 5 | 0 << 2;
00335   SetClearGroundDensity(t, g, density); // Sets m5
00336   SB(_m[t].m6, 2, 4, 0); // Other bits are "tropic zone" and "bridge above"
00337   _me[t].m7 = 0;
00338 }
00339 
00340 
00347 static inline void MakeField(TileIndex t, uint field_type, IndustryID industry)
00348 {
00349   SetTileType(t, MP_CLEAR);
00350   _m[t].m1 = 0;
00351   SetTileOwner(t, OWNER_NONE);
00352   _m[t].m2 = industry;
00353   _m[t].m3 = field_type;
00354   _m[t].m4 = 0 << 5 | 0 << 2;
00355   SetClearGroundDensity(t, CLEAR_FIELDS, 3);
00356   SB(_m[t].m6, 2, 4, 0);
00357   _me[t].m7 = 0;
00358 }
00359 
00366 static inline void MakeSnow(TileIndex t, uint density = 0)
00367 {
00368   assert(GetClearGround(t) != CLEAR_SNOW);
00369   SetBit(_m[t].m3, 4);
00370   if (GetRawClearGround(t) == CLEAR_FIELDS) {
00371     SetClearGroundDensity(t, CLEAR_GRASS, density);
00372   } else {
00373     SetClearDensity(t, density);
00374   }
00375 }
00376 
00382 static inline void ClearSnow(TileIndex t)
00383 {
00384   assert(GetClearGround(t) == CLEAR_SNOW);
00385   ClrBit(_m[t].m3, 4);
00386   SetClearDensity(t, 3);
00387 }
00388 
00389 #endif /* CLEAR_MAP_H */