tron@2955: /* $Id$ */ tron@2955: rubidium@6914: /** @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: maedhros@5828: #include "bridge_map.h" rubidium@8709: #include "industry_type.h" tron@2955: rubidium@6914: /** rubidium@6914: * 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: rubidium@6914: /** rubidium@6914: * Get the type of clear tile. rubidium@6914: * @param t the tile to get the clear ground type of rubidium@6914: * @pre IsTileType(t, MP_CLEAR) rubidium@6914: * @return the ground type rubidium@6914: */ 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: rubidium@6914: /** rubidium@6914: * Set the type of clear tile. rubidium@6914: * @param t the tile to set the clear ground type of rubidium@6914: * @param ct the ground type rubidium@6914: * @pre IsTileType(t, MP_CLEAR) rubidium@6914: */ tron@3369: static inline bool IsClearGround(TileIndex t, ClearGround ct) tron@3369: { tron@3369: return GetClearGround(t) == ct; tron@3369: } tron@3369: tron@3369: rubidium@6914: /** rubidium@6914: * Get the density of a non-field clear tile. rubidium@6914: * @param t the tile to get the density of rubidium@6914: * @pre IsTileType(t, MP_CLEAR) rubidium@6914: * @return the density rubidium@6914: */ 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: rubidium@6914: /** rubidium@6914: * Increment the density of a non-field clear tile. rubidium@6914: * @param t the tile to increment the density of rubidium@6914: * @param d the amount to increment the density with rubidium@6914: * @pre IsTileType(t, MP_CLEAR) rubidium@6914: */ 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: rubidium@6914: /** rubidium@6914: * Get the counter used to advance to the next clear density/field type. rubidium@6914: * @param t the tile to get the counter of rubidium@6914: * @pre IsTileType(t, MP_CLEAR) rubidium@6914: * @return the value of the counter rubidium@6914: */ 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: rubidium@6914: /** rubidium@6914: * Increments the counter used to advance to the next clear density/field type. rubidium@6914: * @param t the tile to increment the counter of rubidium@6914: * @param c the amount to increment the counter with rubidium@6914: * @pre IsTileType(t, MP_CLEAR) rubidium@6914: */ 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: rubidium@6914: /** rubidium@6914: * Sets the counter used to advance to the next clear density/field type. rubidium@6914: * @param t the tile to set the counter of rubidium@6914: * @param c the amount to set the counter to rubidium@6914: * @pre IsTileType(t, MP_CLEAR) rubidium@6914: */ 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: rubidium@6914: /** rubidium@6914: * Sets ground type and density in one go, also sets the counter to 0 rubidium@6914: * @param t the tile to set the ground type and density for rubidium@6914: * @param type the new ground type of the tile rubidium@6914: * @param density the density of the ground tile rubidium@6914: * @pre IsTileType(t, MP_CLEAR) rubidium@6914: */ 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: rubidium@6914: /** rubidium@6914: * Get the field type (production stage) of the field rubidium@6914: * @param t the field to get the type of rubidium@6914: * @pre GetClearGround(t) == CLEAR_FIELDS rubidium@6914: * @return the field type rubidium@6914: */ 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: rubidium@6914: /** rubidium@6914: * Set the field type (production stage) of the field rubidium@6914: * @param t the field to get the type of rubidium@6914: * @param f the field type rubidium@6914: * @pre GetClearGround(t) == CLEAR_FIELDS rubidium@6914: */ 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: rubidium@6914: /** rubidium@6914: * Get the industry (farm) that made the field rubidium@6914: * @param t the field to get creating industry of rubidium@6914: * @pre GetClearGround(t) == CLEAR_FIELDS rubidium@6914: * @return the industry that made the field rubidium@6914: */ rubidium@6914: static inline IndustryID GetIndustryIndexOfField(TileIndex t) truelight@4328: { truelight@4328: assert(GetClearGround(t) == CLEAR_FIELDS); rubidium@6914: return(IndustryID) _m[t].m2; truelight@4328: } truelight@4328: rubidium@6914: /** rubidium@6914: * Set the industry (farm) that made the field rubidium@6914: * @param t the field to get creating industry of rubidium@6914: * @param i the industry that made the field rubidium@6914: * @pre GetClearGround(t) == CLEAR_FIELDS rubidium@6914: */ rubidium@6914: 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: rubidium@6914: rubidium@6914: /** rubidium@6914: * Is there a fence at the south eastern border? rubidium@6914: * @param t the tile to check for fences rubidium@6914: * @pre IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES) rubidium@6914: * @return 0 if there is no fence, otherwise the fence type rubidium@6914: */ 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: rubidium@6914: /** rubidium@6914: * Sets the type of fence (and whether there is one) for the south rubidium@6914: * eastern border. rubidium@6914: * @param t the tile to check for fences rubidium@6914: * @param h 0 if there is no fence, otherwise the fence type rubidium@6914: * @pre IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES) rubidium@6914: */ 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: rubidium@6914: /** rubidium@6914: * Is there a fence at the south western border? rubidium@6914: * @param t the tile to check for fences rubidium@6914: * @pre IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES) rubidium@6914: * @return 0 if there is no fence, otherwise the fence type rubidium@6914: */ 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: rubidium@6914: /** rubidium@6914: * Sets the type of fence (and whether there is one) for the south rubidium@6914: * western border. rubidium@6914: * @param t the tile to check for fences rubidium@6914: * @param h 0 if there is no fence, otherwise the fence type rubidium@6914: * @pre IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES) rubidium@6914: */ 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: rubidium@6914: /** rubidium@6914: * Make a clear tile. rubidium@6914: * @param t the tile to make a clear tile rubidium@6914: * @param g the type of ground rubidium@6914: * @param density the density of the grass/snow/desert etc rubidium@6914: */ 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: rubidium@6914: /** rubidium@6914: * Make a (farm) field tile. rubidium@6914: * @param t the tile to make a farm field rubidium@6914: * @param field_type the 'growth' level of the field rubidium@6914: * @param industry the industry this tile belongs to rubidium@6914: */ rubidium@6914: 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 */