tron@2955: /* $Id$ */ tron@2955: glx@9574: /** @file clear_map.h Map accessors for 'clear' tiles */ belugas@6449: tron@3145: #ifndef CLEAR_MAP_H tron@3145: #define CLEAR_MAP_H tron@2955: tron@2955: #include "macros.h" tron@3076: #include "tile.h" maedhros@5828: #include "bridge_map.h" tron@2955: glx@9574: /** glx@9574: * Ground types. Valid densities in comments after the enum. tron@2955: */ rubidium@6574: enum ClearGround { belugas@6449: CLEAR_GRASS = 0, ///< 0-3 belugas@6449: CLEAR_ROUGH = 1, ///< 3 belugas@6449: CLEAR_ROCKS = 2, ///< 3 belugas@6449: CLEAR_FIELDS = 3, ///< 3 belugas@6449: CLEAR_SNOW = 4, ///< 0-3 belugas@6449: CLEAR_DESERT = 5 ///< 1,3 rubidium@6574: }; tron@2955: tron@2955: glx@9574: /** glx@9574: * Get the type of clear tile. glx@9574: * @param t the tile to get the clear ground type of glx@9574: * @pre IsTileType(t, MP_CLEAR) glx@9574: * @return the ground type glx@9574: */ tron@3369: static inline ClearGround GetClearGround(TileIndex t) tron@3369: { tron@3369: assert(IsTileType(t, MP_CLEAR)); rubidium@5838: return (ClearGround)GB(_m[t].m5, 2, 3); tron@3369: } tron@2955: glx@9574: /** glx@9574: * Set the type of clear tile. glx@9574: * @param t the tile to set the clear ground type of glx@9574: * @param ct the ground type glx@9574: * @pre IsTileType(t, MP_CLEAR) glx@9574: */ tron@3369: static inline bool IsClearGround(TileIndex t, ClearGround ct) tron@3369: { tron@3369: return GetClearGround(t) == ct; tron@3369: } tron@3369: tron@3369: glx@9574: /** glx@9574: * Get the density of a non-field clear tile. glx@9574: * @param t the tile to get the density of glx@9574: * @pre IsTileType(t, MP_CLEAR) glx@9574: * @return the density glx@9574: */ 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: glx@9574: /** glx@9574: * Increment the density of a non-field clear tile. glx@9574: * @param t the tile to increment the density of glx@9574: * @param d the amount to increment the density with glx@9574: * @pre IsTileType(t, MP_CLEAR) glx@9574: */ 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: glx@9574: /** glx@9574: * Get the counter used to advance to the next clear density/field type. glx@9574: * @param t the tile to get the counter of glx@9574: * @pre IsTileType(t, MP_CLEAR) glx@9574: * @return the value of the counter glx@9574: */ 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: glx@9574: /** glx@9574: * Increments the counter used to advance to the next clear density/field type. glx@9574: * @param t the tile to increment the counter of glx@9574: * @param c the amount to increment the counter with glx@9574: * @pre IsTileType(t, MP_CLEAR) glx@9574: */ 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: glx@9574: /** glx@9574: * Sets the counter used to advance to the next clear density/field type. glx@9574: * @param t the tile to set the counter of glx@9574: * @param c the amount to set the counter to glx@9574: * @pre IsTileType(t, MP_CLEAR) glx@9574: */ 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: glx@9574: /** glx@9574: * Sets ground type and density in one go, also sets the counter to 0 glx@9574: * @param t the tile to set the ground type and density for glx@9574: * @param type the new ground type of the tile glx@9574: * @param density the density of the ground tile glx@9574: * @pre IsTileType(t, MP_CLEAR) glx@9574: */ 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: glx@9574: /** glx@9574: * Get the field type (production stage) of the field glx@9574: * @param t the field to get the type of glx@9574: * @pre GetClearGround(t) == CLEAR_FIELDS glx@9574: * @return the field type glx@9574: */ 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: glx@9574: /** glx@9574: * Set the field type (production stage) of the field glx@9574: * @param t the field to get the type of glx@9574: * @param f the field type glx@9574: * @pre GetClearGround(t) == CLEAR_FIELDS glx@9574: */ 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: glx@9574: /** glx@9574: * Get the industry (farm) that made the field glx@9574: * @param t the field to get creating industry of glx@9574: * @pre GetClearGround(t) == CLEAR_FIELDS glx@9574: * @return the industry that made the field glx@9574: */ glx@9574: static inline IndustryID GetIndustryIndexOfField(TileIndex t) truelight@4328: { truelight@4328: assert(GetClearGround(t) == CLEAR_FIELDS); glx@9574: return(IndustryID) _m[t].m2; truelight@4328: } truelight@4328: glx@9574: /** glx@9574: * Set the industry (farm) that made the field glx@9574: * @param t the field to get creating industry of glx@9574: * @param i the industry that made the field glx@9574: * @pre GetClearGround(t) == CLEAR_FIELDS glx@9574: */ glx@9574: static inline void SetIndustryIndexOfField(TileIndex t, IndustryID i) truelight@4328: { truelight@4328: assert(GetClearGround(t) == CLEAR_FIELDS); truelight@4328: _m[t].m2 = i; truelight@4328: } tron@2979: glx@9574: glx@9574: /** glx@9574: * Is there a fence at the south eastern border? glx@9574: * @param t the tile to check for fences glx@9574: * @pre IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES) glx@9574: * @return 0 if there is no fence, otherwise the fence type glx@9574: */ 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: glx@9574: /** glx@9574: * Sets the type of fence (and whether there is one) for the south glx@9574: * eastern border. glx@9574: * @param t the tile to check for fences glx@9574: * @param h 0 if there is no fence, otherwise the fence type glx@9574: * @pre IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES) glx@9574: */ 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: glx@9574: /** glx@9574: * Is there a fence at the south western border? glx@9574: * @param t the tile to check for fences glx@9574: * @pre IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES) glx@9574: * @return 0 if there is no fence, otherwise the fence type glx@9574: */ 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: glx@9574: /** glx@9574: * Sets the type of fence (and whether there is one) for the south glx@9574: * western border. glx@9574: * @param t the tile to check for fences glx@9574: * @param h 0 if there is no fence, otherwise the fence type glx@9574: * @pre IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES) glx@9574: */ 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: glx@9574: /** glx@9574: * Make a clear tile. glx@9574: * @param t the tile to make a clear tile glx@9574: * @param g the type of ground glx@9574: * @param density the density of the grass/snow/desert etc glx@9574: */ tron@3076: static inline void MakeClear(TileIndex t, ClearGround g, uint density) tron@3076: { maedhros@5828: /* If this is a non-bridgeable tile, clear the bridge bits while the rest maedhros@5828: * of the tile information is still here. */ belugas@5847: if (!MayHaveBridgeAbove(t)) SB(_m[t].m6, 6, 2, 0); maedhros@5828: 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); belugas@6449: SB(_m[t].m6, 2, 4, 0); // Clear the rest of m6, bits 2 to 5 tron@3291: } tron@3291: tron@3291: glx@9574: /** glx@9574: * Make a (farm) field tile. glx@9574: * @param t the tile to make a farm field glx@9574: * @param field_type the 'growth' level of the field glx@9574: * @param industry the industry this tile belongs to glx@9574: */ glx@9574: static inline void MakeField(TileIndex t, uint field_type, IndustryID 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 */