tron@2186: /* $Id$ */ tron@2186: belugas@6527: /** @file industry.h */ belugas@6527: 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, rubidium@9403: INDUTILE_NOANIM = 0xFF, ///< flag to mark industry tiles as having no animation truelight@4328: }; truelight@4328: rubidium@6574: enum IndustryLifeType { 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) rubidium@6574: }; belugas@4924: belugas@6527: /** belugas@6527: * Defines the internal data of a functionnal industry belugas@6527: */ truelight@0: struct Industry { belugas@6527: TileIndex xy; ///< coordinates of the primary tile the industry is built one belugas@6527: byte width; truelight@0: byte height; belugas@6527: const Town* town; ///< Nearest town belugas@6527: CargoID produced_cargo[2]; ///< 2 production cargo slots belugas@6527: uint16 cargo_waiting[2]; ///< amount of cargo produced per cargo belugas@6527: byte production_rate[2]; ///< production rate for each cargo belugas@6527: CargoID accepts_cargo[3]; ///< 3 input cargo slots belugas@6527: byte prod_level; ///< general production level belugas@6527: uint16 last_mo_production[2]; ///< stats of last month production per cargo belugas@6527: uint16 last_mo_transported[2]; ///< stats of last month transport per cargo belugas@6527: byte pct_transported[2]; ///< percentage transported per cargo belugas@6527: uint16 total_production[2]; ///< total units produced per cargo belugas@6527: uint16 total_transported[2]; ///< total units transported per cargo belugas@6527: uint16 counter; ///< used for animation and/or production (if available cargo) truelight@0: belugas@6527: byte type; ///< type of industry. see IT_COAL_MINE and others belugas@6527: OwnerByte owner; ///< owner of the industry. Which SHOULD always be (imho) OWNER_NONE belugas@6527: byte random_color; ///< randomized colour of the industry, for display purpose belugas@6527: Year last_prod_year; ///< last year of production belugas@6527: byte was_cargo_delivered; ///< flag that indicate this has been the closest industry chosen for cargo delivery by a station. see DeliverGoodsToIndustry truelight@919: belugas@6527: IndustryID index; ///< index of the industry in the pool of industries truelight@0: }; truelight@0: rubidium@6574: struct IndustryTileTable { belugas@3689: TileIndexDiffC ti; belugas@3689: IndustryGfx gfx; rubidium@6574: }; belugas@3689: belugas@6527: /** belugas@6527: * Defines the data structure for constructing industry. belugas@6527: */ rubidium@6574: struct IndustrySpec { belugas@6527: const IndustryTileTable *const *table;///< List of the tiles composing the industry belugas@6527: byte num_table; ///< Number of elements in the table belugas@6527: byte cost_multiplier; ///< Base cost multiplier*/ belugas@6527: IndustryType conflicting[3]; ///< Industries this industry cannot be close to belugas@6527: byte check_proc; ///< Index to a procedure to check for conflicting circumstances belugas@3689: CargoID produced_cargo[2]; belugas@3689: byte production_rate[2]; belugas@6527: byte minimal_cargo; ///< minimum amount of cargo transported to the stations belugas@6527: ///< If the waiting cargo is less than this number, no cargo is moved to it belugas@6527: CargoID accepts_cargo[3]; ///< 3 accepted cargos belugas@6527: IndustryLifeType life_type; ///< This is also known as Industry production flag, in newgrf specs belugas@6527: byte climate_availability; ///< Bitmask, giving landscape enums as bit position belugas@6527: StringID name; ///< Displayed name of the industry belugas@6592: StringID new_industry_text; ///< Message appearing when the industry is built belugas@6527: StringID closure_text; ///< Message appearing when the industry closes belugas@6527: StringID production_up_text; ///< Message appearing when the industry's production is increasing belugas@6527: StringID production_down_text; ///< Message appearing when the industry's production is decreasing rubidium@6574: }; belugas@3689: belugas@6527: /** belugas@6527: * Defines the data structure of each indivudual tile of an industry. belugas@6527: */ rubidium@6574: struct IndustryTileSpec { belugas@6527: CargoID accepts_cargo[3]; ///< Cargo accepted by this tile belugas@6527: Slope slopes_refused; ///< slope pattern on which this tile cannot be built rubidium@9403: byte anim_production; ///< Animation frame to start when goods are produced rubidium@9403: byte anim_next; ///< Next frame in an animation rubidium@9403: bool anim_state; ///< When true, the tile has to be drawn using the animation rubidium@9403: ///< state instead of the construction state rubidium@6574: }; belugas@6418: belugas@6527: const IndustrySpec *GetIndustrySpec(IndustryType thistype); ///< Array of industries default data belugas@6527: const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx); ///< Array of industry tiles default data belugas@3689: matthijs@5216: DECLARE_OLD_POOL(Industry, Industry, 3, 8000) truelight@919: truelight@1267: /** matthijs@1330: * Check if an Industry really exists. belugas@6527: * @param industry to check belugas@6527: * @return true if position is a valid one matthijs@1330: */ truelight@4346: static inline bool IsValidIndustry(const Industry *industry) matthijs@1330: { truelight@4346: return industry->xy != 0; matthijs@1330: } matthijs@1330: belugas@6527: /** belugas@6527: * Check if an Industry exists whithin the pool of industries belugas@6527: * @param index of the desired industry belugas@6527: * @return true if it is inside the pool belugas@6527: */ rubidium@5299: static inline bool IsValidIndustryID(IndustryID index) rubidium@5299: { rubidium@5299: return index < GetIndustryPoolSize() && IsValidIndustry(GetIndustry(index)); rubidium@5299: } rubidium@5299: belugas@6527: VARDEF int _total_industries; //general counter truelight@4354: rubidium@6573: static inline IndustryID GetMaxIndustryIndex() 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: rubidium@6573: static inline uint GetNumIndustries() matthijs@5247: { truelight@4357: return _total_industries; truelight@4354: } truelight@4354: truelight@4356: /** rubidium@5299: * Return a random valid industry. truelight@4356: */ rubidium@6573: static inline Industry *GetRandomIndustry() 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 */