Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef INDUSTRY_H
00013 #define INDUSTRY_H
00014
00015 #include "core/pool_type.hpp"
00016 #include "newgrf_storage.h"
00017 #include "subsidy_type.h"
00018 #include "industry_map.h"
00019 #include "tilearea_type.h"
00020
00021
00022 typedef Pool<Industry, IndustryID, 64, 64000> IndustryPool;
00023 extern IndustryPool _industry_pool;
00024
00030 enum ProductionLevels {
00031 PRODLEVEL_CLOSURE = 0x00,
00032 PRODLEVEL_MINIMUM = 0x04,
00033 PRODLEVEL_DEFAULT = 0x10,
00034 PRODLEVEL_MAXIMUM = 0x80,
00035 };
00036
00040 struct Industry : IndustryPool::PoolItem<&_industry_pool> {
00041 TileArea location;
00042 Town *town;
00043 CargoID produced_cargo[2];
00044 uint16 produced_cargo_waiting[2];
00045 uint16 incoming_cargo_waiting[3];
00046 byte production_rate[2];
00047 byte prod_level;
00048 CargoID accepts_cargo[3];
00049 uint16 this_month_production[2];
00050 uint16 this_month_transported[2];
00051 byte last_month_pct_transported[2];
00052 uint16 last_month_production[2];
00053 uint16 last_month_transported[2];
00054 uint16 counter;
00055
00056 IndustryType type;
00057 OwnerByte owner;
00058 byte random_colour;
00059 Year last_prod_year;
00060 byte was_cargo_delivered;
00061
00062 PartOfSubsidyByte part_of_subsidy;
00063
00064 OwnerByte founder;
00065 Date construction_date;
00066 uint8 construction_type;
00067 Date last_cargo_accepted_at;
00068 byte selected_layout;
00069
00070 byte random_triggers;
00071 uint16 random;
00072
00073 PersistentStorage *psa;
00074
00075 Industry(TileIndex tile = INVALID_TILE) : location(tile, 0, 0) {}
00076 ~Industry();
00077
00078 void RecomputeProductionMultipliers();
00079
00086 static FORCEINLINE Industry *GetByTile(TileIndex tile)
00087 {
00088 return Industry::Get(GetIndustryIndex(tile));
00089 }
00090
00091 static Industry *GetRandom();
00092 static void PostDestructor(size_t index);
00093
00099 static inline void IncIndustryTypeCount(IndustryType type)
00100 {
00101 assert(type < NUM_INDUSTRYTYPES);
00102 counts[type]++;
00103 }
00104
00110 static inline void DecIndustryTypeCount(IndustryType type)
00111 {
00112 assert(type < NUM_INDUSTRYTYPES);
00113 counts[type]--;
00114 }
00115
00121 static inline uint16 GetIndustryTypeCount(IndustryType type)
00122 {
00123 assert(type < NUM_INDUSTRYTYPES);
00124 return counts[type];
00125 }
00126
00128 static inline void ResetIndustryCounts()
00129 {
00130 memset(&counts, 0, sizeof(counts));
00131 }
00132
00133 protected:
00134 static uint16 counts[NUM_INDUSTRYTYPES];
00135 };
00136
00137 void PlantRandomFarmField(const Industry *i);
00138
00139 void ReleaseDisastersTargetingIndustry(IndustryID);
00140
00141 bool IsTileForestIndustry(TileIndex tile);
00142
00143 #define FOR_ALL_INDUSTRIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Industry, industry_index, var, start)
00144 #define FOR_ALL_INDUSTRIES(var) FOR_ALL_INDUSTRIES_FROM(var, 0)
00145
00147 struct IndustryTypeBuildData {
00148 uint32 probability;
00149 byte min_number;
00150 uint16 target_count;
00151 uint16 max_wait;
00152 uint16 wait_count;
00153
00154 void Reset();
00155
00156 bool GetIndustryTypeData(IndustryType it);
00157 };
00158
00162 struct IndustryBuildData {
00163 IndustryTypeBuildData builddata[NUM_INDUSTRYTYPES];
00164 uint32 wanted_inds;
00165
00166 void Reset();
00167
00168 void SetupTargetCount();
00169 void TryBuildNewIndustry();
00170
00171 void MonthlyLoop();
00172 };
00173
00174 extern IndustryBuildData _industry_builder;
00175
00176 #endif