OpenTTD
industry.h
Go to the documentation of this file.
1 /* $Id: industry.h 24900 2013-01-08 22:46:42Z planetmaker $ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #ifndef INDUSTRY_H
13 #define INDUSTRY_H
14 
15 #include "newgrf_storage.h"
16 #include "subsidy_type.h"
17 #include "industry_map.h"
18 #include "tilearea_type.h"
19 
20 
22 extern IndustryPool _industry_pool;
23 
34 };
35 
39 struct Industry : IndustryPool::PoolItem<&_industry_pool> {
45  byte production_rate[2];
46  byte prod_level;
53  uint16 counter;
54 
55  IndustryType type;
60 
62 
68 
70  uint16 random;
71 
73 
74  Industry(TileIndex tile = INVALID_TILE) : location(tile, 0, 0) {}
75  ~Industry();
76 
78 
84  inline bool TileBelongsToIndustry(TileIndex tile) const
85  {
86  return IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == this->index;
87  }
88 
95  static inline Industry *GetByTile(TileIndex tile)
96  {
97  return Industry::Get(GetIndustryIndex(tile));
98  }
99 
100  static Industry *GetRandom();
101  static void PostDestructor(size_t index);
102 
108  static inline void IncIndustryTypeCount(IndustryType type)
109  {
110  assert(type < NUM_INDUSTRYTYPES);
111  counts[type]++;
112  }
113 
119  static inline void DecIndustryTypeCount(IndustryType type)
120  {
121  assert(type < NUM_INDUSTRYTYPES);
122  counts[type]--;
123  }
124 
130  static inline uint16 GetIndustryTypeCount(IndustryType type)
131  {
132  assert(type < NUM_INDUSTRYTYPES);
133  return counts[type];
134  }
135 
137  static inline void ResetIndustryCounts()
138  {
139  memset(&counts, 0, sizeof(counts));
140  }
141 
142 protected:
143  static uint16 counts[NUM_INDUSTRYTYPES];
144 };
145 
146 void PlantRandomFarmField(const Industry *i);
147 
148 void ReleaseDisastersTargetingIndustry(IndustryID);
149 
151 
152 #define FOR_ALL_INDUSTRIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Industry, industry_index, var, start)
153 #define FOR_ALL_INDUSTRIES(var) FOR_ALL_INDUSTRIES_FROM(var, 0)
154 
157  uint32 probability;
158  byte min_number;
159  uint16 target_count;
160  uint16 max_wait;
161  uint16 wait_count;
162 
163  void Reset();
164 
165  bool GetIndustryTypeData(IndustryType it);
166 };
167 
173  uint32 wanted_inds;
174 
175  void Reset();
176 
177  void SetupTargetCount();
178  void TryBuildNewIndustry();
179 
180  void MonthlyLoop();
181 };
182 
184 
185 #endif /* INDUSTRY_H */