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 "newgrf_storage.h"
00016 #include "subsidy_type.h"
00017 #include "industry_map.h"
00018 #include "tilearea_type.h"
00019
00020
00021 typedef Pool<Industry, IndustryID, 64, 64000> IndustryPool;
00022 extern IndustryPool _industry_pool;
00023
00029 enum ProductionLevels {
00030 PRODLEVEL_CLOSURE = 0x00,
00031 PRODLEVEL_MINIMUM = 0x04,
00032 PRODLEVEL_DEFAULT = 0x10,
00033 PRODLEVEL_MAXIMUM = 0x80,
00034 };
00035
00039 struct Industry : IndustryPool::PoolItem<&_industry_pool> {
00040 TileArea location;
00041 Town *town;
00042 CargoID produced_cargo[2];
00043 uint16 produced_cargo_waiting[2];
00044 uint16 incoming_cargo_waiting[3];
00045 byte production_rate[2];
00046 byte prod_level;
00047 CargoID accepts_cargo[3];
00048 uint16 this_month_production[2];
00049 uint16 this_month_transported[2];
00050 byte last_month_pct_transported[2];
00051 uint16 last_month_production[2];
00052 uint16 last_month_transported[2];
00053 uint16 counter;
00054
00055 IndustryType type;
00056 OwnerByte owner;
00057 byte random_colour;
00058 Year last_prod_year;
00059 byte was_cargo_delivered;
00060
00061 PartOfSubsidyByte part_of_subsidy;
00062
00063 OwnerByte founder;
00064 Date construction_date;
00065 uint8 construction_type;
00066 Date last_cargo_accepted_at;
00067 byte selected_layout;
00068
00069 byte random_triggers;
00070 uint16 random;
00071
00072 PersistentStorage *psa;
00073 uint8 head_to_head;
00074
00075 Industry(TileIndex tile = INVALID_TILE) : location(tile, 0, 0) {}
00076 ~Industry();
00077
00078 void RecomputeProductionMultipliers();
00079
00085 inline bool TileBelongsToIndustry(TileIndex tile) const
00086 {
00087 return IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == this->index;
00088 }
00089
00096 static inline Industry *GetByTile(TileIndex tile)
00097 {
00098 return Industry::Get(GetIndustryIndex(tile));
00099 }
00100
00101 static Industry *GetRandom();
00102 static void PostDestructor(size_t index);
00103
00109 static inline void IncIndustryTypeCount(IndustryType type)
00110 {
00111 assert(type < NUM_INDUSTRYTYPES);
00112 counts[type]++;
00113 }
00114
00120 static inline void DecIndustryTypeCount(IndustryType type)
00121 {
00122 assert(type < NUM_INDUSTRYTYPES);
00123 counts[type]--;
00124 }
00125
00131 static inline uint16 GetIndustryTypeCount(IndustryType type)
00132 {
00133 assert(type < NUM_INDUSTRYTYPES);
00134 return counts[type];
00135 }
00136
00138 static inline void ResetIndustryCounts()
00139 {
00140 memset(&counts, 0, sizeof(counts));
00141 }
00142
00143 protected:
00144 static uint16 counts[NUM_INDUSTRYTYPES];
00145 };
00146
00147 void PlantRandomFarmField(const Industry *i);
00148
00149 void ReleaseDisastersTargetingIndustry(IndustryID);
00150
00151 bool IsTileForestIndustry(TileIndex tile);
00152
00153 extern uint8 _head_to_head;
00154 #define FOR_ALL_INDUSTRIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Industry, industry_index, var, start) if (_head_to_head == 0 || var->head_to_head == _head_to_head)
00155 #define FOR_ALL_INDUSTRIES(var) FOR_ALL_INDUSTRIES_FROM(var, 0)
00156
00158 struct IndustryTypeBuildData {
00159 uint32 probability;
00160 byte min_number;
00161 uint16 target_count;
00162 uint16 max_wait;
00163 uint16 wait_count;
00164
00165 void Reset();
00166
00167 bool GetIndustryTypeData(IndustryType it);
00168 };
00169
00173 struct IndustryBuildData {
00174 IndustryTypeBuildData builddata[NUM_INDUSTRYTYPES];
00175 uint32 wanted_inds;
00176
00177 void Reset();
00178
00179 void SetupTargetCount();
00180 void TryBuildNewIndustry();
00181
00182 void MonthlyLoop();
00183 };
00184
00185 extern IndustryBuildData _industry_builder;
00186
00187 #endif