00001
00002
00003
00004
00005
00006
00007
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));
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));
00137 _m[t].m5 += c << 5;
00138 }
00139
00146 static inline void SetClearCounter(TileIndex t, uint c)
00147 {
00148 assert(IsTileType(t, MP_CLEAR));
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));
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);
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
00223 static inline uint GetFence(TileIndex t, DiagDirection side)
00224 {
00225 assert(IsClearGround(t, CLEAR_FIELDS));
00226 switch (side) {
00227 default: NOT_REACHED();
00228 case DIAGDIR_SE: return GB(_m[t].m4, 2, 3);
00229 case DIAGDIR_SW: return GB(_m[t].m4, 5, 3);
00230 case DIAGDIR_NE: return GB(_m[t].m3, 5, 3);
00231 case DIAGDIR_NW: return GB(_m[t].m6, 2, 3);
00232 }
00233 }
00234
00242 static inline void SetFence(TileIndex t, DiagDirection side, uint h)
00243 {
00244 assert(IsClearGround(t, CLEAR_FIELDS));
00245 switch (side) {
00246 default: NOT_REACHED();
00247 case DIAGDIR_SE: SB(_m[t].m4, 2, 3, h); break;
00248 case DIAGDIR_SW: SB(_m[t].m4, 5, 3, h); break;
00249 case DIAGDIR_NE: SB(_m[t].m3, 5, 3, h); break;
00250 case DIAGDIR_NW: SB(_m[t].m6, 2, 3, h); break;
00251 }
00252 }
00253
00254
00261 static inline void MakeClear(TileIndex t, ClearGround g, uint density)
00262 {
00263
00264
00265 if (!MayHaveBridgeAbove(t)) SB(_m[t].m6, 6, 2, 0);
00266
00267 SetTileType(t, MP_CLEAR);
00268 _m[t].m1 = 0;
00269 SetTileOwner(t, OWNER_NONE);
00270 _m[t].m2 = 0;
00271 _m[t].m3 = 0;
00272 _m[t].m4 = 0 << 5 | 0 << 2;
00273 SetClearGroundDensity(t, g, density);
00274 SB(_m[t].m6, 2, 4, 0);
00275 _me[t].m7 = 0;
00276 }
00277
00278
00285 static inline void MakeField(TileIndex t, uint field_type, IndustryID industry)
00286 {
00287 SetTileType(t, MP_CLEAR);
00288 _m[t].m1 = 0;
00289 SetTileOwner(t, OWNER_NONE);
00290 _m[t].m2 = industry;
00291 _m[t].m3 = field_type;
00292 _m[t].m4 = 0 << 5 | 0 << 2;
00293 SetClearGroundDensity(t, CLEAR_FIELDS, 3);
00294 SB(_m[t].m6, 2, 4, 0);
00295 _me[t].m7 = 0;
00296 }
00297
00304 static inline void MakeSnow(TileIndex t, uint density = 0)
00305 {
00306 assert(GetClearGround(t) != CLEAR_SNOW);
00307 SetBit(_m[t].m3, 4);
00308 if (GetRawClearGround(t) == CLEAR_FIELDS) {
00309 SetClearGroundDensity(t, CLEAR_GRASS, density);
00310 } else {
00311 SetClearDensity(t, density);
00312 }
00313 }
00314
00320 static inline void ClearSnow(TileIndex t)
00321 {
00322 assert(GetClearGround(t) == CLEAR_SNOW);
00323 ClrBit(_m[t].m3, 4);
00324 SetClearDensity(t, 3);
00325 }
00326
00327 #endif