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
00074 Industry(TileIndex tile = INVALID_TILE) : location(tile, 0, 0) {}
00075 ~Industry();
00076
00077 void RecomputeProductionMultipliers();
00078
00084 inline bool TileBelongsToIndustry(TileIndex tile) const
00085 {
00086 return IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == this->index;
00087 }
00088
00095 static inline Industry *GetByTile(TileIndex tile)
00096 {
00097 return Industry::Get(GetIndustryIndex(tile));
00098 }
00099
00100 static Industry *GetRandom();
00101 static void PostDestructor(size_t index);
00102
00108 static inline void IncIndustryTypeCount(IndustryType type)
00109 {
00110 assert(type < NUM_INDUSTRYTYPES);
00111 counts[type]++;
00112 }
00113
00119 static inline void DecIndustryTypeCount(IndustryType type)
00120 {
00121 assert(type < NUM_INDUSTRYTYPES);
00122 counts[type]--;
00123 }
00124
00130 static inline uint16 GetIndustryTypeCount(IndustryType type)
00131 {
00132 assert(type < NUM_INDUSTRYTYPES);
00133 return counts[type];
00134 }
00135
00137 static inline void ResetIndustryCounts()
00138 {
00139 memset(&counts, 0, sizeof(counts));
00140 }
00141
00142 protected:
00143 static uint16 counts[NUM_INDUSTRYTYPES];
00144 };
00145
00146 void PlantRandomFarmField(const Industry *i);
00147
00148 void ReleaseDisastersTargetingIndustry(IndustryID);
00149
00150 bool IsTileForestIndustry(TileIndex tile);
00151
00152 #define FOR_ALL_INDUSTRIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Industry, industry_index, var, start)
00153 #define FOR_ALL_INDUSTRIES(var) FOR_ALL_INDUSTRIES_FROM(var, 0)
00154
00156 struct IndustryTypeBuildData {
00157 uint32 probability;
00158 byte min_number;
00159 uint16 target_count;
00160 uint16 max_wait;
00161 uint16 wait_count;
00162
00163 void Reset();
00164
00165 bool GetIndustryTypeData(IndustryType it);
00166 };
00167
00171 struct IndustryBuildData {
00172 IndustryTypeBuildData builddata[NUM_INDUSTRYTYPES];
00173 uint32 wanted_inds;
00174
00175 void Reset();
00176
00177 void SetupTargetCount();
00178 void TryBuildNewIndustry();
00179
00180 void MonthlyLoop();
00181 };
00182
00183 extern IndustryBuildData _industry_builder;
00184
00185 #endif