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@8604: #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, belugas@7969: GFX_WATERTILE_SPECIALCHECK = 255, ///< not really a tile, but rather a very special check belugas@3545: }; tron@3314: rubidium@6914: /** rubidium@6914: * Get the industry ID of the given tile rubidium@6914: * @param t the tile to get the industry ID from rubidium@6914: * @pre IsTileType(t, MP_INDUSTRY) rubidium@6914: * @return the industry ID rubidium@6914: */ 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: rubidium@6914: /** rubidium@6914: * Get the industry of the given tile rubidium@6914: * @param t the tile to get the industry from rubidium@6914: * @pre IsTileType(t, MP_INDUSTRY) rubidium@6914: * @return the industry rubidium@6914: */ rubidium@7814: static inline Industry *GetIndustryByTile(TileIndex t) tron@3314: { tron@3314: return GetIndustry(GetIndustryIndex(t)); tron@3314: } tron@3320: rubidium@6914: /** rubidium@6914: * Is this industry tile fully built? rubidium@6914: * @param t the tile to analyze rubidium@6914: * @pre IsTileType(t, MP_INDUSTRY) rubidium@6914: * @return true if and only if the industry tile is fully built rubidium@6914: */ tron@3369: static inline bool IsIndustryCompleted(TileIndex t) tron@3321: { tron@3369: assert(IsTileType(t, MP_INDUSTRY)); skidd13@8424: 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@8150: 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@8118: static inline IndustryGfx GetCleanIndustryGfx(TileIndex t) rubidium@8118: { rubidium@8118: assert(IsTileType(t, MP_INDUSTRY)); rubidium@8118: return _m[t].m5 | (GB(_m[t].m6, 2, 1) << 8); rubidium@8118: } rubidium@8118: rubidium@6914: /** rubidium@6914: * Get the industry graphics ID for the given industry tile rubidium@6914: * @param t the tile to get the gfx for rubidium@6914: * @pre IsTileType(t, MP_INDUSTRY) rubidium@6914: * @return the gfx ID rubidium@6914: */ belugas@3499: static inline IndustryGfx GetIndustryGfx(TileIndex t) tron@3331: { tron@3369: assert(IsTileType(t, MP_INDUSTRY)); rubidium@8118: return GetTranslatedIndustryTileID(GetCleanIndustryGfx(t)); tron@3331: } tron@3331: rubidium@6914: /** rubidium@6914: * Set the industry graphics ID for the given industry tile rubidium@6914: * @param t the tile to set the gfx for rubidium@6914: * @pre IsTileType(t, MP_INDUSTRY) rubidium@6914: * @param gfx the graphics ID rubidium@6914: */ belugas@3499: static inline void SetIndustryGfx(TileIndex t, IndustryGfx gfx) tron@3331: { tron@3369: assert(IsTileType(t, MP_INDUSTRY)); rubidium@8118: _m[t].m5 = GB(gfx, 0, 8); rubidium@8118: SB(_m[t].m6, 2, 1, GB(gfx, 8, 1)); tron@3331: } tron@3331: rubidium@6914: /** rubidium@6914: * Make the given tile an industry tile rubidium@8615: * @param t the tile to make an industry tile rubidium@8615: * @param index the industry this tile belongs to rubidium@8615: * @param gfx the graphics to use for the tile rubidium@8615: * @param random the random value rubidium@6914: */ rubidium@8615: 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; belugas@7370: SetIndustryGfx(t, gfx); rubidium@8615: _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 rubidium@6914: * @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: belugas@7370: /** belugas@7370: * Get the random bits for this tile. belugas@7370: * Used for grf callbacks belugas@7370: * @param tile TileIndex of the tile to query belugas@7370: * @pre IsTileType(tile, MP_INDUSTRY) belugas@7370: * @return requested bits belugas@7370: */ belugas@7370: static inline byte GetIndustryRandomBits(TileIndex tile) belugas@7370: { belugas@7370: assert(IsTileType(tile, MP_INDUSTRY)); rubidium@8117: return _me[tile].m7; rubidium@8117: } rubidium@8117: rubidium@8117: /** rubidium@8117: * Set the random bits for this tile. rubidium@8117: * Used for grf callbacks rubidium@8117: * @param tile TileIndex of the tile to query rubidium@8117: * @param bits the random bits rubidium@8117: * @pre IsTileType(tile, MP_INDUSTRY) rubidium@8117: */ belugas@8185: static inline void SetIndustryRandomBits(TileIndex tile, byte bits) rubidium@8117: { rubidium@8117: assert(IsTileType(tile, MP_INDUSTRY)); rubidium@8117: _me[tile].m7 = bits; belugas@7370: } belugas@7370: belugas@7370: /** belugas@7370: * Get the activated triggers bits for this industry tile belugas@7370: * Used for grf callbacks belugas@7370: * @param tile TileIndex of the tile to query belugas@7370: * @pre IsTileType(tile, MP_INDUSTRY) belugas@7370: * @return requested triggers belugas@7370: */ belugas@7370: static inline byte GetIndustryTriggers(TileIndex tile) belugas@7370: { belugas@7370: assert(IsTileType(tile, MP_INDUSTRY)); rubidium@8117: return GB(_m[tile].m6, 3, 3); belugas@7370: } belugas@7370: belugas@7370: belugas@7370: /** belugas@7370: * Set the activated triggers bits for this industry tile belugas@7370: * Used for grf callbacks belugas@7370: * @param tile TileIndex of the tile to query rubidium@8117: * @param triggers the triggers to set belugas@7370: * @pre IsTileType(tile, MP_INDUSTRY) belugas@7370: */ belugas@7370: static inline void SetIndustryTriggers(TileIndex tile, byte triggers) belugas@7370: { belugas@7370: assert(IsTileType(tile, MP_INDUSTRY)); rubidium@8117: SB(_m[tile].m6, 3, 3, triggers); belugas@7370: } belugas@7370: belugas@3495: #endif /* INDUSTRY_MAP_H */