# clear_map.h

Go to the documentation of this file.

    00001 /* $Id$ */
    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(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES));
    00225   return GB(_m[t].m4, 2, 3);
    00226 }
    00227
    00235 static inline void SetFenceSE(TileIndex t, uint h)
    00236 {
    00237   assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)); // XXX incomplete
    00238   SB(_m[t].m4, 2, 3, h);
    00239 }
    00240
    00247 static inline uint GetFenceSW(TileIndex t)
    00248 {
    00249   assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES));
    00250   return GB(_m[t].m4, 5, 3);
    00251 }
    00252
    00260 static inline void SetFenceSW(TileIndex t, uint h)
    00261 {
    00262   assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)); // XXX incomplete
    00263   SB(_m[t].m4, 5, 3, h);
    00264 }
    00265
    00266
    00273 static inline void MakeClear(TileIndex t, ClearGround g, uint density)
    00274 {
    00275   /* If this is a non-bridgeable tile, clear the bridge bits while the rest
    00276    * of the tile information is still here. */
    00277   if (!MayHaveBridgeAbove(t)) SB(_m[t].m6, 6, 2, 0);
    00278
    00279   SetTileType(t, MP_CLEAR);
    00280   _m[t].m1 = 0;
    00281   SetTileOwner(t, OWNER_NONE);
    00282   _m[t].m2 = 0;
    00283   _m[t].m3 = 0;
    00284   _m[t].m4 = 0 << 5 | 0 << 2;
    00285   SetClearGroundDensity(t, g, density); // Sets m5
    00286   SB(_m[t].m6, 2, 4, 0); // Other bits are "tropic zone" and "bridge above"
    00287   _me[t].m7 = 0;
    00288 }
    00289
    00290
    00297 static inline void MakeField(TileIndex t, uint field_type, IndustryID industry)
    00298 {
    00299   SetTileType(t, MP_CLEAR);
    00300   _m[t].m1 = 0;
    00301   SetTileOwner(t, OWNER_NONE);
    00302   _m[t].m2 = industry;
    00303   _m[t].m3 = field_type;
    00304   _m[t].m4 = 0 << 5 | 0 << 2;
    00305   SetClearGroundDensity(t, CLEAR_FIELDS, 3);
    00306   SB(_m[t].m6, 2, 4, 0);
    00307   _me[t].m7 = 0;
    00308 }
    00309
    00315 static inline void MakeSnow(TileIndex t, uint density = 0)
    00316 {
    00317   assert(GetClearGround(t) != CLEAR_SNOW);
    00318   SetBit(_m[t].m3, 4);
    00319   if (GetRawClearGround(t) == CLEAR_FIELDS) {
    00320     SetClearGroundDensity(t, CLEAR_GRASS, density);
    00321   } else {
    00322     SetClearDensity(t, density);
    00323   }
    00324 }
    00325
    00331 static inline void ClearSnow(TileIndex t)
    00332 {
    00333   assert(GetClearGround(t) == CLEAR_SNOW);
    00334   ClrBit(_m[t].m3, 4);
    00335   SetClearDensity(t, 3);
    00336 }
    00337
    00338 #endif /* CLEAR_MAP_H */