# clear_map.h

Go to the documentation of this file.

    00001 /* $Id: clear_map.h 17248 2009-08-21 20:21:05Z 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 ClearGround GetClearGround(TileIndex t)
    00038 {
    00039   assert(IsTileType(t, MP_CLEAR));
    00040   return (ClearGround)GB(_m[t].m5, 2, 3);
    00041 }
    00042
    00049 static inline bool IsClearGround(TileIndex t, ClearGround ct)
    00050 {
    00051   return GetClearGround(t) == ct;
    00052 }
    00053
    00054
    00061 static inline uint GetClearDensity(TileIndex t)
    00062 {
    00063   assert(IsTileType(t, MP_CLEAR));
    00064   return GB(_m[t].m5, 0, 2);
    00065 }
    00066
    00073 static inline void AddClearDensity(TileIndex t, int d)
    00074 {
    00075   assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
    00076   _m[t].m5 += d;
    00077 }
    00078
    00079
    00086 static inline uint GetClearCounter(TileIndex t)
    00087 {
    00088   assert(IsTileType(t, MP_CLEAR));
    00089   return GB(_m[t].m5, 5, 3);
    00090 }
    00091
    00098 static inline void AddClearCounter(TileIndex t, int c)
    00099 {
    00100   assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
    00101   _m[t].m5 += c << 5;
    00102 }
    00103
    00110 static inline void SetClearCounter(TileIndex t, uint c)
    00111 {
    00112   assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
    00113   SB(_m[t].m5, 5, 3, c);
    00114 }
    00115
    00116
    00124 static inline void SetClearGroundDensity(TileIndex t, ClearGround type, uint density)
    00125 {
    00126   assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
    00127   _m[t].m5 = 0 << 5 | type << 2 | density;
    00128 }
    00129
    00130
    00137 static inline uint GetFieldType(TileIndex t)
    00138 {
    00139   assert(GetClearGround(t) == CLEAR_FIELDS);
    00140   return GB(_m[t].m3, 0, 4);
    00141 }
    00142
    00149 static inline void SetFieldType(TileIndex t, uint f)
    00150 {
    00151   assert(GetClearGround(t) == CLEAR_FIELDS); // XXX incomplete
    00152   SB(_m[t].m3, 0, 4, f);
    00153 }
    00154
    00161 static inline IndustryID GetIndustryIndexOfField(TileIndex t)
    00162 {
    00163   assert(GetClearGround(t) == CLEAR_FIELDS);
    00164   return(IndustryID) _m[t].m2;
    00165 }
    00166
    00173 static inline void SetIndustryIndexOfField(TileIndex t, IndustryID i)
    00174 {
    00175   assert(GetClearGround(t) == CLEAR_FIELDS);
    00176   _m[t].m2 = i;
    00177 }
    00178
    00179
    00186 static inline uint GetFenceSE(TileIndex t)
    00187 {
    00188   assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES));
    00189   return GB(_m[t].m4, 2, 3);
    00190 }
    00191
    00199 static inline void SetFenceSE(TileIndex t, uint h)
    00200 {
    00201   assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)); // XXX incomplete
    00202   SB(_m[t].m4, 2, 3, h);
    00203 }
    00204
    00211 static inline uint GetFenceSW(TileIndex t)
    00212 {
    00213   assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES));
    00214   return GB(_m[t].m4, 5, 3);
    00215 }
    00216
    00224 static inline void SetFenceSW(TileIndex t, uint h)
    00225 {
    00226   assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)); // XXX incomplete
    00227   SB(_m[t].m4, 5, 3, h);
    00228 }
    00229
    00230
    00237 static inline void MakeClear(TileIndex t, ClearGround g, uint density)
    00238 {
    00239   /* If this is a non-bridgeable tile, clear the bridge bits while the rest
    00240    * of the tile information is still here. */
    00241   if (!MayHaveBridgeAbove(t)) SB(_m[t].m6, 6, 2, 0);
    00242
    00243   SetTileType(t, MP_CLEAR);
    00244   SetTileOwner(t, OWNER_NONE);
    00245   _m[t].m2 = 0;
    00246   _m[t].m3 = 0;
    00247   _m[t].m4 = 0 << 5 | 0 << 2;
    00248   SetClearGroundDensity(t, g, density); // Sets m5
    00249   SB(_m[t].m6, 2, 4, 0); // Other bits are "tropic zone" and "bridge above"
    00250   _me[t].m7 = 0;
    00251 }
    00252
    00253
    00260 static inline void MakeField(TileIndex t, uint field_type, IndustryID industry)
    00261 {
    00262   SetTileType(t, MP_CLEAR);
    00263   SetTileOwner(t, OWNER_NONE);
    00264   _m[t].m2 = industry;
    00265   _m[t].m3 = field_type;
    00266   _m[t].m4 = 0 << 5 | 0 << 2;
    00267   SetClearGroundDensity(t, CLEAR_FIELDS, 3);
    00268   SB(_m[t].m6, 2, 4, 0);
    00269   _me[t].m7 = 0;
    00270 }
    00271
    00272 #endif /* CLEAR_MAP_H */