industry.h

Go to the documentation of this file.
00001 /* $Id: industry.h 21267 2010-11-20 13:33:24Z alberth $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
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   typedef PersistentStorageArray<int32, 16> PersistentStorage;
00042 
00043   TileArea location;                  
00044   const Town *town;                   
00045   CargoID produced_cargo[2];          
00046   uint16 produced_cargo_waiting[2];   
00047   uint16 incoming_cargo_waiting[3];   
00048   byte production_rate[2];            
00049   byte prod_level;                    
00050   CargoID accepts_cargo[3];           
00051   uint16 this_month_production[2];    
00052   uint16 this_month_transported[2];   
00053   byte last_month_pct_transported[2]; 
00054   uint16 last_month_production[2];    
00055   uint16 last_month_transported[2];   
00056   uint16 counter;                     
00057 
00058   IndustryType type;                  
00059   OwnerByte owner;                    
00060   byte random_colour;                 
00061   Year last_prod_year;                
00062   byte was_cargo_delivered;           
00063 
00064   PartOfSubsidyByte part_of_subsidy;  
00065 
00066   OwnerByte founder;                  
00067   Date construction_date;             
00068   uint8 construction_type;            
00069   Date last_cargo_accepted_at;        
00070   byte selected_layout;               
00071 
00072   byte random_triggers;               
00073   uint16 random;                      
00074 
00075   PersistentStorage psa;              
00076 
00077   Industry(TileIndex tile = INVALID_TILE) : location(tile, 0, 0) {}
00078   ~Industry();
00079 
00080   void RecomputeProductionMultipliers();
00081 
00088   static FORCEINLINE Industry *GetByTile(TileIndex tile)
00089   {
00090     return Industry::Get(GetIndustryIndex(tile));
00091   }
00092 
00093   static Industry *GetRandom();
00094   static void PostDestructor(size_t index);
00095 
00101   static inline void IncIndustryTypeCount(IndustryType type)
00102   {
00103     assert(type < NUM_INDUSTRYTYPES);
00104     counts[type]++;
00105   }
00106 
00112   static inline void DecIndustryTypeCount(IndustryType type)
00113   {
00114     assert(type < NUM_INDUSTRYTYPES);
00115     counts[type]--;
00116   }
00117 
00123   static inline uint16 GetIndustryTypeCount(IndustryType type)
00124   {
00125     assert(type < NUM_INDUSTRYTYPES);
00126     return counts[type];
00127   }
00128 
00130   static inline void ResetIndustryCounts()
00131   {
00132     memset(&counts, 0, sizeof(counts));
00133   }
00134 
00135 protected:
00136   static uint16 counts[NUM_INDUSTRYTYPES]; 
00137 };
00138 
00139 void PlantRandomFarmField(const Industry *i);
00140 
00141 void ReleaseDisastersTargetingIndustry(IndustryID);
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 /* INDUSTRY_H */

Generated on Sun Jan 9 16:01:55 2011 for OpenTTD by  doxygen 1.6.1