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" rubidium@6872: #include "tile_map.h" tron@3314: belugas@3545: belugas@3553: belugas@3553: /** belugas@3553: * The following enums are indices used to know what to draw for this industry tile. belugas@3553: * They all are pointing toward array _industry_draw_tile_data, in table/industry_land.h belugas@3553: * How to calculate the correct position ? GFXid << 2 | IndustryStage (0 to 3) belugas@3553: */ belugas@3545: enum { rubidium@4583: GFX_COAL_MINE_TOWER_NOT_ANIMATED = 0, rubidium@4583: GFX_COAL_MINE_TOWER_ANIMATED = 1, rubidium@4583: GFX_POWERPLANT_CHIMNEY = 8, rubidium@4583: GFX_POWERPLANT_SPARKS = 10, rubidium@4583: GFX_OILRIG_1 = 24, rubidium@4583: GFX_OILRIG_2 = 25, rubidium@4583: GFX_OILRIG_3 = 26, rubidium@4583: GFX_OILRIG_4 = 27, rubidium@4583: GFX_OILRIG_5 = 28, rubidium@4583: GFX_OILWELL_NOT_ANIMATED = 29, rubidium@4583: GFX_OILWELL_ANIMATED_1 = 30, rubidium@4583: GFX_OILWELL_ANIMATED_2 = 31, rubidium@4583: GFX_OILWELL_ANIMATED_3 = 32, rubidium@4583: GFX_COPPER_MINE_TOWER_NOT_ANIMATED = 47, rubidium@4583: GFX_COPPER_MINE_TOWER_ANIMATED = 48, rubidium@4583: GFX_COPPER_MINE_CHIMNEY = 49, rubidium@4583: GFX_GOLD_MINE_TOWER_NOT_ANIMATED = 79, rubidium@4583: GFX_GOLD_MINE_TOWER_ANIMATED = 88, rubidium@4583: GFX_TOY_FACTORY = 143, rubidium@4583: GFX_PLASTIC_FOUNTAIN_ANIMATED_1 = 148, rubidium@4583: GFX_PLASTIC_FOUNTAIN_ANIMATED_2 = 149, rubidium@4583: GFX_PLASTIC_FOUNTAIN_ANIMATED_3 = 150, rubidium@4583: GFX_PLASTIC_FOUNTAIN_ANIMATED_4 = 151, rubidium@4583: GFX_PLASTIC_FOUNTAIN_ANIMATED_5 = 152, rubidium@4583: GFX_PLASTIC_FOUNTAIN_ANIMATED_6 = 153, rubidium@4583: GFX_PLASTIC_FOUNTAIN_ANIMATED_7 = 154, rubidium@4583: GFX_PLASTIC_FOUNTAIN_ANIMATED_8 = 155, rubidium@4583: GFX_BUBBLE_GENERATOR = 161, rubidium@4583: GFX_BUBBLE_CATCHER = 162, rubidium@4583: GFX_TOFFEE_QUARY = 165, rubidium@4583: GFX_SUGAR_MINE_SIEVE = 174, rubidium@6868: GFX_WATERTILE_SPECIALCHECK = 255, ///< not really a tile, but rather a very special check belugas@3545: }; tron@3314: richk@6719: /** richk@6719: * Get the industry ID of the given tile richk@6719: * @param t the tile to get the industry ID from richk@6719: * @pre IsTileType(t, MP_INDUSTRY) richk@6719: * @return the industry ID richk@6719: */ rubidium@4330: static inline IndustryID GetIndustryIndex(TileIndex t) tron@3314: { tron@3369: assert(IsTileType(t, MP_INDUSTRY)); tron@3314: return _m[t].m2; tron@3314: } tron@3314: richk@6719: /** richk@6719: * Get the industry of the given tile richk@6719: * @param t the tile to get the industry from richk@6719: * @pre IsTileType(t, MP_INDUSTRY) richk@6719: * @return the industry richk@6719: */ richk@6743: static inline Industry *GetIndustryByTile(TileIndex t) tron@3314: { tron@3314: return GetIndustry(GetIndustryIndex(t)); tron@3314: } tron@3320: richk@6719: /** richk@6719: * Is this industry tile fully built? richk@6719: * @param t the tile to analyze richk@6719: * @pre IsTileType(t, MP_INDUSTRY) richk@6719: * @return true if and only if the industry tile is fully built richk@6719: */ tron@3369: static inline bool IsIndustryCompleted(TileIndex t) tron@3321: { tron@3369: assert(IsTileType(t, MP_INDUSTRY)); rubidium@6871: return HasBit(_m[t].m1, 7); tron@3321: } tron@3321: belugas@3499: IndustryType GetIndustryType(TileIndex tile); belugas@3499: 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)); rubidium@6870: return IsIndustryCompleted(tile) ? (byte)INDUSTRY_COMPLETED : 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: rubidium@6870: static inline IndustryGfx GetCleanIndustryGfx(TileIndex t) rubidium@6870: { rubidium@6870: assert(IsTileType(t, MP_INDUSTRY)); rubidium@6870: return _m[t].m5 | (GB(_m[t].m6, 2, 1) << 8); rubidium@6870: } rubidium@6870: richk@6719: /** richk@6719: * Get the industry graphics ID for the given industry tile richk@6719: * @param t the tile to get the gfx for richk@6719: * @pre IsTileType(t, MP_INDUSTRY) richk@6719: * @return the gfx ID richk@6719: */ belugas@3499: static inline IndustryGfx GetIndustryGfx(TileIndex t) tron@3331: { tron@3369: assert(IsTileType(t, MP_INDUSTRY)); rubidium@6870: return GetTranslatedIndustryTileID(GetCleanIndustryGfx(t)); tron@3331: } tron@3331: richk@6719: /** richk@6719: * Set the industry graphics ID for the given industry tile richk@6719: * @param t the tile to set the gfx for richk@6719: * @pre IsTileType(t, MP_INDUSTRY) richk@6719: * @param gfx the graphics ID richk@6719: */ belugas@3499: static inline void SetIndustryGfx(TileIndex t, IndustryGfx gfx) tron@3331: { tron@3369: assert(IsTileType(t, MP_INDUSTRY)); rubidium@6870: _m[t].m5 = GB(gfx, 0, 8); rubidium@6870: SB(_m[t].m6, 2, 1, GB(gfx, 8, 1)); tron@3331: } tron@3331: richk@6719: /** richk@6719: * Make the given tile an industry tile rubidium@6872: * @param t the tile to make an industry tile rubidium@6872: * @param index the industry this tile belongs to rubidium@6872: * @param gfx the graphics to use for the tile rubidium@6872: * @param random the random value richk@6719: */ rubidium@6872: static inline void MakeIndustry(TileIndex t, IndustryID index, IndustryGfx gfx, uint8 random) 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; richk@6720: SetIndustryGfx(t, gfx); rubidium@6872: _me[t].m7 = random; 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: * @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@3538: /** belugas@3538: * Get the animation loop number belugas@3538: * @param tile the tile to get the animation loop number of rubidium@5685: * @pre IsTileType(tile, MP_INDUSTRY) belugas@3538: */ belugas@3538: static inline byte GetIndustryAnimationLoop(TileIndex tile) belugas@3538: { belugas@3538: assert(IsTileType(tile, MP_INDUSTRY)); belugas@3538: return _m[tile].m4; belugas@3538: } belugas@3538: belugas@3538: /** belugas@3538: * Set the animation loop number belugas@3538: * @param tile the tile to set the animation loop number of belugas@3538: * @param count the new animation frame number rubidium@5685: * @pre IsTileType(tile, MP_INDUSTRY) belugas@3538: */ belugas@3538: static inline void SetIndustryAnimationLoop(TileIndex tile, byte count) belugas@3538: { belugas@3538: assert(IsTileType(tile, MP_INDUSTRY)); belugas@3538: _m[tile].m4 = count; belugas@3538: } belugas@3538: rubidium@5686: /** rubidium@5686: * Get the animation state rubidium@5686: * @param tile the tile to get the animation state of rubidium@5686: * @pre IsTileType(tile, MP_INDUSTRY) rubidium@5686: */ rubidium@5686: static inline byte GetIndustryAnimationState(TileIndex tile) rubidium@5686: { rubidium@5686: assert(IsTileType(tile, MP_INDUSTRY)); rubidium@5687: return _m[tile].m3; rubidium@5686: } rubidium@5686: rubidium@5686: /** rubidium@5686: * Set the animation state rubidium@5686: * @param tile the tile to set the animation state of richk@6719: * @param state the new animation state rubidium@5686: * @pre IsTileType(tile, MP_INDUSTRY) rubidium@5686: */ rubidium@5686: static inline void SetIndustryAnimationState(TileIndex tile, byte state) rubidium@5686: { rubidium@5686: assert(IsTileType(tile, MP_INDUSTRY)); rubidium@5687: _m[tile].m3 = state; rubidium@5686: } rubidium@5686: richk@6720: /** richk@6720: * Get the random bits for this tile. richk@6720: * Used for grf callbacks richk@6720: * @param tile TileIndex of the tile to query richk@6720: * @pre IsTileType(tile, MP_INDUSTRY) richk@6720: * @return requested bits richk@6720: */ richk@6720: static inline byte GetIndustryRandomBits(TileIndex tile) richk@6720: { richk@6720: assert(IsTileType(tile, MP_INDUSTRY)); rubidium@6870: return _me[tile].m7; rubidium@6870: } rubidium@6870: rubidium@6870: /** rubidium@6870: * Set the random bits for this tile. rubidium@6870: * Used for grf callbacks rubidium@6870: * @param tile TileIndex of the tile to query rubidium@6870: * @param bits the random bits rubidium@6870: * @pre IsTileType(tile, MP_INDUSTRY) rubidium@6870: */ rubidium@6871: static inline void SetIndustryRandomBits(TileIndex tile, byte bits) rubidium@6870: { rubidium@6870: assert(IsTileType(tile, MP_INDUSTRY)); rubidium@6870: _me[tile].m7 = bits; richk@6720: } richk@6720: richk@6720: /** richk@6720: * Get the activated triggers bits for this industry tile richk@6720: * Used for grf callbacks richk@6720: * @param tile TileIndex of the tile to query richk@6720: * @pre IsTileType(tile, MP_INDUSTRY) richk@6720: * @return requested triggers richk@6720: */ richk@6720: static inline byte GetIndustryTriggers(TileIndex tile) richk@6720: { richk@6720: assert(IsTileType(tile, MP_INDUSTRY)); rubidium@6870: return GB(_m[tile].m6, 3, 3); richk@6720: } richk@6720: richk@6720: richk@6720: /** richk@6720: * Set the activated triggers bits for this industry tile richk@6720: * Used for grf callbacks richk@6720: * @param tile TileIndex of the tile to query rubidium@6870: * @param triggers the triggers to set richk@6720: * @pre IsTileType(tile, MP_INDUSTRY) richk@6720: */ richk@6720: static inline void SetIndustryTriggers(TileIndex tile, byte triggers) richk@6720: { richk@6720: assert(IsTileType(tile, MP_INDUSTRY)); rubidium@6870: SB(_m[tile].m6, 3, 3, triggers); richk@6720: } richk@6720: belugas@3495: #endif /* INDUSTRY_MAP_H */