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@8108: #include "tile_map.h" frosch@9718: #include "water_map.h" 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@7473: GFX_WATERTILE_SPECIALCHECK = 255, ///< not really a tile, but rather a very special check belugas@3545: }; tron@3314: rubidium@6418: /** rubidium@6418: * Get the industry ID of the given tile rubidium@6418: * @param t the tile to get the industry ID from rubidium@6418: * @pre IsTileType(t, MP_INDUSTRY) rubidium@6418: * @return the industry ID rubidium@6418: */ 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@6418: /** rubidium@6418: * Get the industry of the given tile rubidium@6418: * @param t the tile to get the industry from rubidium@6418: * @pre IsTileType(t, MP_INDUSTRY) rubidium@6418: * @return the industry rubidium@6418: */ rubidium@7318: static inline Industry *GetIndustryByTile(TileIndex t) tron@3314: { tron@3314: return GetIndustry(GetIndustryIndex(t)); tron@3314: } tron@3320: rubidium@6418: /** rubidium@6418: * Is this industry tile fully built? rubidium@6418: * @param t the tile to analyze rubidium@6418: * @pre IsTileType(t, MP_INDUSTRY) rubidium@6418: * @return true if and only if the industry tile is fully built rubidium@6418: */ tron@3369: static inline bool IsIndustryCompleted(TileIndex t) tron@3321: { tron@3369: assert(IsTileType(t, MP_INDUSTRY)); skidd13@7928: 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@7654: 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@7622: static inline IndustryGfx GetCleanIndustryGfx(TileIndex t) rubidium@7622: { rubidium@7622: assert(IsTileType(t, MP_INDUSTRY)); rubidium@7622: return _m[t].m5 | (GB(_m[t].m6, 2, 1) << 8); rubidium@7622: } rubidium@7622: rubidium@6418: /** rubidium@6418: * Get the industry graphics ID for the given industry tile rubidium@6418: * @param t the tile to get the gfx for rubidium@6418: * @pre IsTileType(t, MP_INDUSTRY) rubidium@6418: * @return the gfx ID rubidium@6418: */ belugas@3499: static inline IndustryGfx GetIndustryGfx(TileIndex t) tron@3331: { tron@3369: assert(IsTileType(t, MP_INDUSTRY)); rubidium@7622: return GetTranslatedIndustryTileID(GetCleanIndustryGfx(t)); tron@3331: } tron@3331: rubidium@6418: /** rubidium@6418: * Set the industry graphics ID for the given industry tile rubidium@6418: * @param t the tile to set the gfx for rubidium@6418: * @pre IsTileType(t, MP_INDUSTRY) rubidium@6418: * @param gfx the graphics ID rubidium@6418: */ belugas@3499: static inline void SetIndustryGfx(TileIndex t, IndustryGfx gfx) tron@3331: { tron@3369: assert(IsTileType(t, MP_INDUSTRY)); rubidium@7622: _m[t].m5 = GB(gfx, 0, 8); rubidium@7622: SB(_m[t].m6, 2, 1, GB(gfx, 8, 1)); tron@3331: } tron@3331: rubidium@6418: /** frosch@9718: * Tests if the industry tile was built on water. frosch@9718: * @param t the industry tile frosch@9718: * @return true iff on water frosch@9718: */ frosch@9718: static inline bool IsIndustryTileOnWater(TileIndex t) frosch@9718: { frosch@9718: assert(IsTileType(t, MP_INDUSTRY)); frosch@9718: return (GetWaterClass(t) != WATER_CLASS_INVALID); frosch@9718: } frosch@9718: frosch@9718: /** rubidium@6418: * Make the given tile an industry tile rubidium@8119: * @param t the tile to make an industry tile rubidium@8119: * @param index the industry this tile belongs to rubidium@8119: * @param gfx the graphics to use for the tile rubidium@8119: * @param random the random value rubidium@6418: */ frosch@9718: static inline void MakeIndustry(TileIndex t, IndustryID index, IndustryGfx gfx, uint8 random, WaterClass wc) 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@6874: SetIndustryGfx(t, gfx); rubidium@8119: _me[t].m7 = random; frosch@9718: SetWaterClass(t, wc); 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)); peter1138@9839: SB(_m[tile].m1, 0, 4, 0); peter1138@9838: SB(_m[tile].m1, 7, 1, 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@5434: * @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@5434: * @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@5435: /** rubidium@5435: * Get the animation state rubidium@5435: * @param tile the tile to get the animation state of rubidium@5435: * @pre IsTileType(tile, MP_INDUSTRY) rubidium@5435: */ rubidium@5435: static inline byte GetIndustryAnimationState(TileIndex tile) rubidium@5435: { rubidium@5435: assert(IsTileType(tile, MP_INDUSTRY)); rubidium@5436: return _m[tile].m3; rubidium@5435: } rubidium@5435: rubidium@5435: /** rubidium@5435: * Set the animation state rubidium@5435: * @param tile the tile to set the animation state of rubidium@6418: * @param state the new animation state rubidium@5435: * @pre IsTileType(tile, MP_INDUSTRY) rubidium@5435: */ rubidium@5435: static inline void SetIndustryAnimationState(TileIndex tile, byte state) rubidium@5435: { rubidium@5435: assert(IsTileType(tile, MP_INDUSTRY)); rubidium@5436: _m[tile].m3 = state; rubidium@5435: } rubidium@5435: belugas@6874: /** belugas@6874: * Get the random bits for this tile. belugas@6874: * Used for grf callbacks belugas@6874: * @param tile TileIndex of the tile to query belugas@6874: * @pre IsTileType(tile, MP_INDUSTRY) belugas@6874: * @return requested bits belugas@6874: */ belugas@6874: static inline byte GetIndustryRandomBits(TileIndex tile) belugas@6874: { belugas@6874: assert(IsTileType(tile, MP_INDUSTRY)); rubidium@7621: return _me[tile].m7; rubidium@7621: } rubidium@7621: rubidium@7621: /** rubidium@7621: * Set the random bits for this tile. rubidium@7621: * Used for grf callbacks rubidium@7621: * @param tile TileIndex of the tile to query rubidium@7621: * @param bits the random bits rubidium@7621: * @pre IsTileType(tile, MP_INDUSTRY) rubidium@7621: */ belugas@7689: static inline void SetIndustryRandomBits(TileIndex tile, byte bits) rubidium@7621: { rubidium@7621: assert(IsTileType(tile, MP_INDUSTRY)); rubidium@7621: _me[tile].m7 = bits; belugas@6874: } belugas@6874: belugas@6874: /** belugas@6874: * Get the activated triggers bits for this industry tile belugas@6874: * Used for grf callbacks belugas@6874: * @param tile TileIndex of the tile to query belugas@6874: * @pre IsTileType(tile, MP_INDUSTRY) belugas@6874: * @return requested triggers belugas@6874: */ belugas@6874: static inline byte GetIndustryTriggers(TileIndex tile) belugas@6874: { belugas@6874: assert(IsTileType(tile, MP_INDUSTRY)); rubidium@7621: return GB(_m[tile].m6, 3, 3); belugas@6874: } belugas@6874: belugas@6874: belugas@6874: /** belugas@6874: * Set the activated triggers bits for this industry tile belugas@6874: * Used for grf callbacks belugas@6874: * @param tile TileIndex of the tile to query rubidium@7621: * @param triggers the triggers to set belugas@6874: * @pre IsTileType(tile, MP_INDUSTRY) belugas@6874: */ belugas@6874: static inline void SetIndustryTriggers(TileIndex tile, byte triggers) belugas@6874: { belugas@6874: assert(IsTileType(tile, MP_INDUSTRY)); rubidium@7621: SB(_m[tile].m6, 3, 3, triggers); belugas@6874: } belugas@6874: belugas@3495: #endif /* INDUSTRY_MAP_H */