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: 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@3545: }; tron@3314: 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: 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@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)); 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: belugas@3499: static inline IndustryGfx GetIndustryGfx(TileIndex t) tron@3331: { tron@3369: assert(IsTileType(t, MP_INDUSTRY)); tron@3331: return _m[t].m5; tron@3331: } tron@3331: belugas@3499: static inline void SetIndustryGfx(TileIndex t, IndustryGfx gfx) tron@3331: { tron@3369: assert(IsTileType(t, MP_INDUSTRY)); tron@3331: _m[t].m5 = gfx; tron@3331: } tron@3331: rubidium@4330: static inline void MakeIndustry(TileIndex t, IndustryID index, IndustryGfx 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@3499: typedef struct IndustryTypeSolver { belugas@3499: IndustryGfx MinGfx; belugas@3499: IndustryGfx MaxGfx; tron@4077: } IndustryTypeSolver; belugas@3499: belugas@3499: static const IndustryTypeSolver industry_gfx_Solver [IT_END] = { belugas@3499: { 0, 6}, //IT_COAL_MINE belugas@3499: { 7, 10}, //IT_POWER_STATION, belugas@3499: { 11, 15}, //IT_SAWMILL, belugas@3499: { 16, 17}, //IT_FOREST, belugas@3499: { 18, 23}, //IT_OIL_REFINERY, belugas@3499: { 24, 28}, //IT_OIL_RIG, belugas@3499: { 29, 31}, //IT_OIL_WELL, belugas@3499: { 32, 38}, //IT_FARM, belugas@3499: { 39, 42}, //IT_FACTORY, belugas@3499: { 43, 46}, //IT_PRINTING_WORKS, belugas@3499: { 47, 51}, //IT_COPPER_MINE, belugas@3499: { 52, 57}, //IT_STEEL_MILL, belugas@3499: { 58, 59}, //IT_BANK_TEMP, belugas@3499: { 60, 63}, //IT_FOOD_PROCESS, belugas@3499: { 64, 71}, //IT_PAPER_MILL, belugas@3499: { 72, 88}, //IT_GOLD_MINE, belugas@3499: { 89, 90}, //IT_BANK_TROPIC_ARCTIC, belugas@3499: { 91, 99}, //IT_DIAMOND_MINE, belugas@3499: {100, 115}, //IT_IRON_MINE, belugas@3499: {116, 116}, //IT_FRUIT_PLANTATION, belugas@3499: {117, 117}, //IT_RUBBER_PLANTATION, belugas@3499: {118, 119}, //IT_WATER_SUPPLY, belugas@3499: {120, 120}, //IT_WATER_TOWER, belugas@3499: {121, 124}, //IT_FACTORY_2, belugas@3499: {125, 128}, //IT_LUMBER_MILL, belugas@3499: {129, 130}, //IT_COTTON_CANDY, belugas@3499: {131, 134}, //IT_CANDY_FACTORY or sweet factory belugas@3499: {135, 136}, //IT_BATTERY_FARM, belugas@3499: {137, 137}, //IT_COLA_WELLS, belugas@3499: {138, 141}, //IT_TOY_SHOP, belugas@3499: {142, 147}, //IT_TOY_FACTORY, belugas@3499: {148, 155}, //IT_PLASTIC_FOUNTAINS, belugas@3499: {156, 159}, //IT_FIZZY_DRINK_FACTORY, belugas@3499: {160, 163}, //IT_BUBBLE_GENERATOR, belugas@3499: {164, 166}, //IT_TOFFEE_QUARRY, belugas@3499: {167, 174} //IT_SUGAR_MINE, belugas@3499: }; belugas@3499: belugas@3538: /** belugas@3538: * Get the animation loop number belugas@3538: * @param tile the tile to get the animation loop number of belugas@3538: * @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 belugas@3538: * @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: belugas@3495: #endif /* INDUSTRY_MAP_H */