tron@3314: /* $Id$ */ tron@3314: belugas@3495: /** @file industry_map.h Accessors for industries */ belugas@3495: belugas@3495: #ifndef INDUSTRY_MAP_H belugas@3495: #define INDUSTRY_MAP_H belugas@3495: tron@3314: #include "industry.h" tron@3314: #include "macros.h" tron@3314: #include "tile.h" tron@3314: tron@3314: tron@3314: static inline uint GetIndustryIndex(TileIndex t) tron@3314: { tron@3369: assert(IsTileType(t, MP_INDUSTRY)); tron@3314: return _m[t].m2; tron@3314: } tron@3314: tron@3314: static inline Industry* GetIndustryByTile(TileIndex t) tron@3314: { tron@3314: return GetIndustry(GetIndustryIndex(t)); tron@3314: } tron@3320: tron@3369: static inline bool IsIndustryCompleted(TileIndex t) tron@3321: { tron@3369: assert(IsTileType(t, MP_INDUSTRY)); tron@3369: return HASBIT(_m[t].m1, 7); tron@3321: } tron@3321: belugas@3495: /** belugas@3495: * Set if the industry that owns the tile as under construction or not belugas@3495: * @param tile the tile to query belugas@3495: * @param isCompleted whether it is completed or not belugas@3495: * @pre IsTileType(tile, MP_INDUSTRY) belugas@3495: */ belugas@3495: static inline void SetIndustryCompleted(TileIndex tile, bool isCompleted) belugas@3495: { belugas@3495: assert(IsTileType(tile, MP_INDUSTRY)); belugas@3495: SB(_m[tile].m1, 7, 1, isCompleted ? 1 :0); belugas@3495: } belugas@3495: belugas@3495: /** belugas@3495: * Returns the industry construction stage of the specified tile belugas@3495: * @param tile the tile to query belugas@3495: * @pre IsTileType(tile, MP_INDUSTRY) belugas@3495: * @return the construction stage belugas@3495: */ belugas@3495: static inline byte GetIndustryConstructionStage(TileIndex tile) belugas@3495: { belugas@3495: assert(IsTileType(tile, MP_INDUSTRY)); belugas@3495: return GB(_m[tile].m1, 0, 2); belugas@3495: } belugas@3495: belugas@3495: /** belugas@3495: * Sets the industry construction stage of the specified tile belugas@3495: * @param tile the tile to query belugas@3495: * @param value the new construction stage belugas@3495: * @pre IsTileType(tile, MP_INDUSTRY) belugas@3495: */ belugas@3495: static inline void SetIndustryConstructionStage(TileIndex tile, byte value) belugas@3495: { belugas@3495: assert(IsTileType(tile, MP_INDUSTRY)); belugas@3495: SB(_m[tile].m1, 0, 2, value); belugas@3495: } tron@3321: tron@3331: static inline uint GetIndustryGfx(TileIndex t) tron@3331: { tron@3369: assert(IsTileType(t, MP_INDUSTRY)); tron@3331: return _m[t].m5; tron@3331: } tron@3331: tron@3331: static inline void SetIndustryGfx(TileIndex t, uint gfx) tron@3331: { tron@3369: assert(IsTileType(t, MP_INDUSTRY)); tron@3331: _m[t].m5 = gfx; tron@3331: } tron@3331: tron@3320: static inline void MakeIndustry(TileIndex t, uint index, uint gfx) tron@3320: { tron@3320: SetTileType(t, MP_INDUSTRY); tron@3320: _m[t].m1 = 0; tron@3320: _m[t].m2 = index; tron@3320: _m[t].m3 = 0; tron@3320: _m[t].m4 = 0; tron@3320: _m[t].m5 = gfx; tron@3320: } belugas@3495: belugas@3495: /** belugas@3495: * Returns this indutry tile's construction counter value belugas@3495: * @param tile the tile to query belugas@3495: * @pre IsTileType(tile, MP_INDUSTRY) belugas@3495: * @return the construction counter belugas@3495: */ belugas@3495: static inline byte GetIndustryConstructionCounter(TileIndex tile) belugas@3495: { belugas@3495: assert(IsTileType(tile, MP_INDUSTRY)); belugas@3495: return GB(_m[tile].m1, 2, 2); belugas@3495: } belugas@3495: belugas@3495: /** belugas@3495: * Sets this indutry tile's construction counter value belugas@3495: * @param tile the tile to query belugas@3495: * @param value the new value for the construction counter belugas@3495: * @pre IsTileType(tile, MP_INDUSTRY) belugas@3495: */ belugas@3495: static inline void SetIndustryConstructionCounter(TileIndex tile, byte value) belugas@3495: { belugas@3495: assert(IsTileType(tile, MP_INDUSTRY)); belugas@3495: SB(_m[tile].m1, 2, 2, value); belugas@3495: } belugas@3495: belugas@3495: /** belugas@3495: * Reset the construction stage counter of the industry, belugas@3495: * as well as the completion bit. belugas@3495: * In fact, it is the same as restarting construction frmo ground up belugas@3495: * @param tile the tile to query belugas@3495: * @param generating_world whether generating a world or not belugas@3495: * @pre IsTileType(tile, MP_INDUSTRY) belugas@3495: */ belugas@3495: static inline void ResetIndustryConstructionStage(TileIndex tile) belugas@3495: { belugas@3495: assert(IsTileType(tile, MP_INDUSTRY)); belugas@3495: _m[tile].m1 = 0; belugas@3495: } belugas@3495: belugas@3495: #endif /* INDUSTRY_MAP_H */