tron@2186: /* $Id$ */ tron@2186: truelight@0: #ifndef INDUSTRY_H truelight@0: #define INDUSTRY_H truelight@0: matthijs@5216: #include "oldpool.h" truelight@1267: belugas@3689: typedef byte IndustryGfx; belugas@3689: typedef uint8 IndustryType; belugas@3689: truelight@4328: enum { truelight@4328: INVALID_INDUSTRY = 0xFFFF, truelight@4328: }; truelight@4328: belugas@4924: typedef enum IndustryLifeTypes { belugas@4924: INDUSTRYLIFE_NOT_CLOSABLE, ///< Industry can never close belugas@4924: INDUSTRYLIFE_PRODUCTION, ///< Industry can close and change of production belugas@4924: INDUSTRYLIFE_CLOSABLE, ///< Industry can only close (no production change) belugas@4924: } IndustryLifeType; belugas@4924: truelight@0: struct Industry { truelight@0: TileIndex xy; truelight@0: byte width; /* swapped order of w/h with town */ truelight@0: byte height; tron@2630: const Town* town; Darkvater@3344: CargoID produced_cargo[2]; truelight@0: uint16 cargo_waiting[2]; truelight@0: byte production_rate[2]; Darkvater@3344: CargoID accepts_cargo[3]; truelight@0: byte prod_level; truelight@0: uint16 last_mo_production[2]; truelight@0: uint16 last_mo_transported[2]; truelight@0: byte pct_transported[2]; truelight@0: uint16 total_production[2]; truelight@0: uint16 total_transported[2]; truelight@0: uint16 counter; truelight@0: truelight@0: byte type; tron@3350: byte owner; belugas@4942: byte random_color; rubidium@4326: Year last_prod_year; truelight@0: byte was_cargo_delivered; truelight@919: rubidium@4330: IndustryID index; truelight@0: }; truelight@0: belugas@3689: typedef struct IndustryTileTable { belugas@3689: TileIndexDiffC ti; belugas@3689: IndustryGfx gfx; belugas@3689: } IndustryTileTable; belugas@3689: belugas@3689: typedef struct IndustrySpec { belugas@3689: /** Tables with the 'layout' of different composition of GFXes */ belugas@3689: const IndustryTileTable *const *table; belugas@3689: /** Number of elements in the table */ belugas@3689: byte num_table; belugas@3689: /** Base cost multiplier*/ belugas@3689: byte cost_multiplier; belugas@3689: /** Industries this industry cannot be close to */ belugas@3689: IndustryType conflicting[3]; belugas@3689: /** index to a procedure to check for conflicting circumstances */ belugas@3689: byte check_proc; belugas@3689: belugas@3689: CargoID produced_cargo[2]; belugas@3689: byte production_rate[2]; belugas@3689: /** The minimum amount of cargo transported to the stations; if the belugas@3689: * waiting cargo is less than this number, no cargo is moved to it*/ belugas@3689: byte minimal_cargo; belugas@3689: CargoID accepts_cargo[3]; belugas@3689: belugas@4966: IndustryLifeType life_type; ///< This is also known as Industry production flag, in newgrf specs belugas@4965: belugas@4966: byte climate_availability; ///< Bitmask, giving landscape enums as bit position belugas@4924: belugas@4942: StringID name; belugas@3689: StringID closure_text; belugas@3689: StringID production_up_text; belugas@3689: StringID production_down_text; belugas@3689: } IndustrySpec; belugas@3689: belugas@3689: const IndustrySpec *GetIndustrySpec(IndustryType thistype); belugas@3689: matthijs@5216: DECLARE_OLD_POOL(Industry, Industry, 3, 8000) truelight@919: truelight@1267: /** matthijs@1330: * Check if an Industry really exists. matthijs@1330: */ truelight@4346: static inline bool IsValidIndustry(const Industry *industry) matthijs@1330: { truelight@4346: return industry->xy != 0; matthijs@1330: } matthijs@1330: rubidium@5299: static inline bool IsValidIndustryID(IndustryID index) rubidium@5299: { rubidium@5299: return index < GetIndustryPoolSize() && IsValidIndustry(GetIndustry(index)); rubidium@5299: } rubidium@5299: truelight@4354: VARDEF int _total_industries; truelight@4354: matthijs@5247: static inline IndustryID GetMaxIndustryIndex(void) truelight@4354: { truelight@4354: /* TODO - This isn't the real content of the function, but truelight@4354: * with the new pool-system this will be replaced with one that matthijs@5247: * _really_ returns the highest index. Now it just returns truelight@4354: * the next safe value we are sure about everything is below. truelight@4354: */ rubidium@5298: return GetIndustryPoolSize() - 1; matthijs@5247: } matthijs@5247: matthijs@5247: static inline uint GetNumIndustries(void) matthijs@5247: { truelight@4357: return _total_industries; truelight@4354: } truelight@4354: truelight@4356: /** rubidium@5299: * Return a random valid industry. truelight@4356: */ truelight@4356: static inline Industry *GetRandomIndustry(void) truelight@4356: { rubidium@5299: int num = RandomRange(GetNumIndustries()); rubidium@5299: IndustryID index = INVALID_INDUSTRY; truelight@4356: matthijs@5247: if (GetNumIndustries() == 0) return NULL; truelight@4356: rubidium@5299: while (num >= 0) { truelight@4356: num--; truelight@4356: index++; rubidium@5299: truelight@4356: /* Make sure we have a valid industry */ rubidium@5299: while (!IsValidIndustryID(index)) { truelight@4356: index++; rubidium@5299: assert(index <= GetMaxIndustryIndex()); truelight@4356: } truelight@4356: } truelight@4356: truelight@4356: return GetIndustry(index); truelight@4356: } truelight@4356: truelight@4403: void DestroyIndustry(Industry *i); truelight@4403: truelight@4403: static inline void DeleteIndustry(Industry *i) truelight@4403: { truelight@4403: DestroyIndustry(i); truelight@4403: i->xy = 0; truelight@4403: } truelight@4403: tron@4976: #define FOR_ALL_INDUSTRIES_FROM(i, start) for (i = GetIndustry(start); i != NULL; i = (i->index + 1U < GetIndustryPoolSize()) ? GetIndustry(i->index + 1U) : NULL) if (IsValidIndustry(i)) truelight@1267: #define FOR_ALL_INDUSTRIES(i) FOR_ALL_INDUSTRIES_FROM(i, 0) truelight@1267: tron@4277: VARDEF const Industry** _industry_sort; truelight@1267: VARDEF bool _industry_sort_dirty; truelight@919: belugas@3496: truelight@0: void DeleteIndustry(Industry *is); truelight@4328: void PlantRandomFarmField(const Industry *i); truelight@0: truelight@0: enum { rubidium@4344: IT_COAL_MINE = 0, rubidium@4344: IT_POWER_STATION = 1, rubidium@4344: IT_SAWMILL = 2, rubidium@4344: IT_FOREST = 3, rubidium@4344: IT_OIL_REFINERY = 4, rubidium@4344: IT_OIL_RIG = 5, rubidium@4344: IT_FACTORY = 6, rubidium@4344: IT_PRINTING_WORKS = 7, rubidium@4344: IT_STEEL_MILL = 8, rubidium@4344: IT_FARM = 9, rubidium@4344: IT_COPPER_MINE = 10, rubidium@4344: IT_OIL_WELL = 11, rubidium@4344: IT_BANK_TEMP = 12, rubidium@4344: IT_FOOD_PROCESS = 13, rubidium@4344: IT_PAPER_MILL = 14, rubidium@4344: IT_GOLD_MINE = 15, rubidium@4344: IT_BANK_TROPIC_ARCTIC = 16, rubidium@4344: IT_DIAMOND_MINE = 17, rubidium@4344: IT_IRON_MINE = 18, rubidium@4344: IT_FRUIT_PLANTATION = 19, rubidium@4344: IT_RUBBER_PLANTATION = 20, rubidium@4344: IT_WATER_SUPPLY = 21, rubidium@4344: IT_WATER_TOWER = 22, rubidium@4344: IT_FACTORY_2 = 23, rubidium@4344: IT_FARM_2 = 24, rubidium@4344: IT_LUMBER_MILL = 25, rubidium@4344: IT_COTTON_CANDY = 26, rubidium@4344: IT_CANDY_FACTORY = 27, rubidium@4344: IT_BATTERY_FARM = 28, rubidium@4344: IT_COLA_WELLS = 29, rubidium@4344: IT_TOY_SHOP = 30, rubidium@4344: IT_TOY_FACTORY = 31, rubidium@4344: IT_PLASTIC_FOUNTAINS = 32, rubidium@4344: IT_FIZZY_DRINK_FACTORY = 33, rubidium@4344: IT_BUBBLE_GENERATOR = 34, rubidium@4344: IT_TOFFEE_QUARRY = 35, rubidium@4344: IT_SUGAR_MINE = 36, belugas@3499: IT_END, rubidium@4344: IT_INVALID = 255, truelight@0: }; truelight@0: Darkvater@2436: #endif /* INDUSTRY_H */