tron@2955: /* $Id$ */ tron@2955: tron@3145: #ifndef CLEAR_MAP_H tron@3145: #define CLEAR_MAP_H tron@2955: tron@2955: #include "macros.h" tron@3076: #include "tile.h" tron@2955: tron@2955: /* ground type, m5 bits 2...4 tron@2955: * valid densities (bits 0...1) in comments after the enum tron@2955: */ tron@2955: typedef enum ClearGround { tron@3447: CLEAR_GRASS = 0, // 0-3 tron@3447: CLEAR_ROUGH = 1, // 3 tron@3447: CLEAR_ROCKS = 2, // 3 tron@3447: CLEAR_FIELDS = 3, // 3 tron@3447: CLEAR_SNOW = 4, // 0-3 tron@3447: CLEAR_DESERT = 5 // 1,3 tron@2955: } ClearGround; tron@2955: tron@2955: tron@3369: static inline ClearGround GetClearGround(TileIndex t) tron@3369: { tron@3369: assert(IsTileType(t, MP_CLEAR)); tron@3369: return GB(_m[t].m5, 2, 3); tron@3369: } tron@2955: tron@3369: static inline bool IsClearGround(TileIndex t, ClearGround ct) tron@3369: { tron@3369: return GetClearGround(t) == ct; tron@3369: } tron@3369: tron@3369: tron@3369: static inline uint GetClearDensity(TileIndex t) tron@3369: { tron@3369: assert(IsTileType(t, MP_CLEAR)); tron@3369: return GB(_m[t].m5, 0, 2); tron@3369: } tron@3369: tron@3369: static inline void AddClearDensity(TileIndex t, int d) tron@3369: { tron@3369: assert(IsTileType(t, MP_CLEAR)); // XXX incomplete tron@3369: _m[t].m5 += d; tron@3369: } tron@3369: tron@3369: tron@3369: static inline uint GetClearCounter(TileIndex t) tron@3369: { tron@3369: assert(IsTileType(t, MP_CLEAR)); tron@3369: return GB(_m[t].m5, 5, 3); tron@3369: } tron@3369: tron@3369: static inline void AddClearCounter(TileIndex t, int c) tron@3369: { tron@3369: assert(IsTileType(t, MP_CLEAR)); // XXX incomplete tron@3369: _m[t].m5 += c << 5; tron@3369: } tron@3369: tron@3369: static inline void SetClearCounter(TileIndex t, uint c) tron@3369: { tron@3369: assert(IsTileType(t, MP_CLEAR)); // XXX incomplete tron@3369: SB(_m[t].m5, 5, 3, c); tron@3369: } tron@3369: tron@2955: tron@2955: /* Sets type and density in one go, also sets the counter to 0 */ tron@2955: static inline void SetClearGroundDensity(TileIndex t, ClearGround type, uint density) tron@2955: { tron@3369: assert(IsTileType(t, MP_CLEAR)); // XXX incomplete tron@2955: _m[t].m5 = 0 << 5 | type << 2 | density; tron@2955: } tron@2955: tron@3369: tron@3369: static inline uint GetFieldType(TileIndex t) tron@3369: { tron@3447: assert(GetClearGround(t) == CLEAR_FIELDS); tron@3369: return GB(_m[t].m3, 0, 4); tron@3369: } tron@3369: tron@3369: static inline void SetFieldType(TileIndex t, uint f) tron@3369: { tron@3447: assert(GetClearGround(t) == CLEAR_FIELDS); // XXX incomplete tron@3369: SB(_m[t].m3, 0, 4, f); tron@3369: } tron@3369: truelight@4328: static inline uint16 GetIndustryIndexOfField(TileIndex t) truelight@4328: { truelight@4328: assert(GetClearGround(t) == CLEAR_FIELDS); truelight@4328: return _m[t].m2; truelight@4328: } truelight@4328: truelight@4328: static inline void SetIndustryIndexOfField(TileIndex t, uint16 i) truelight@4328: { truelight@4328: assert(GetClearGround(t) == CLEAR_FIELDS); truelight@4328: _m[t].m2 = i; truelight@4328: } tron@2979: tron@2979: /* Is used by tree tiles, too */ tron@3369: static inline uint GetFenceSE(TileIndex t) tron@3369: { tron@3369: assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)); tron@3369: return GB(_m[t].m4, 2, 3); tron@3369: } tron@2979: tron@3369: static inline void SetFenceSE(TileIndex t, uint h) tron@3369: { tron@3369: assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)); // XXX incomplete tron@3369: SB(_m[t].m4, 2, 3, h); tron@3369: } tron@3369: tron@3369: static inline uint GetFenceSW(TileIndex t) tron@3369: { tron@3369: assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)); tron@3369: return GB(_m[t].m4, 5, 3); tron@3369: } tron@3369: tron@3369: static inline void SetFenceSW(TileIndex t, uint h) tron@3369: { tron@3369: assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)); // XXX incomplete tron@3369: SB(_m[t].m4, 5, 3, h); tron@3369: } tron@2979: tron@3076: tron@3076: static inline void MakeClear(TileIndex t, ClearGround g, uint density) tron@3076: { tron@3076: SetTileType(t, MP_CLEAR); tron@3076: SetTileOwner(t, OWNER_NONE); tron@3076: _m[t].m2 = 0; tron@3076: _m[t].m3 = 0; tron@3076: _m[t].m4 = 0 << 5 | 0 << 2; tron@3291: SetClearGroundDensity(t, g, density); tron@3291: } tron@3291: tron@3291: truelight@4328: static inline void MakeField(TileIndex t, uint field_type, uint16 industry) tron@3291: { tron@3291: SetTileType(t, MP_CLEAR); tron@3291: SetTileOwner(t, OWNER_NONE); truelight@4328: _m[t].m2 = industry; tron@3291: _m[t].m3 = field_type; tron@3291: _m[t].m4 = 0 << 5 | 0 << 2; tron@3447: SetClearGroundDensity(t, CLEAR_FIELDS, 3); tron@3076: } tron@3076: peter1138@4666: #endif /* CLEAR_MAP_H */