OpenTTD
industry.h
Go to the documentation of this file.
1 /* $Id: industry.h 27929 2017-10-25 15:38:19Z frosch $ */
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 
69  uint16 random;
70 
72 
73  Industry(TileIndex tile = INVALID_TILE) : location(tile, 0, 0) {}
74  ~Industry();
75 
77 
83  inline bool TileBelongsToIndustry(TileIndex tile) const
84  {
85  return IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == this->index;
86  }
87 
94  static inline Industry *GetByTile(TileIndex tile)
95  {
96  return Industry::Get(GetIndustryIndex(tile));
97  }
98 
99  static Industry *GetRandom();
100  static void PostDestructor(size_t index);
101 
107  static inline void IncIndustryTypeCount(IndustryType type)
108  {
109  assert(type < NUM_INDUSTRYTYPES);
110  counts[type]++;
111  }
112 
118  static inline void DecIndustryTypeCount(IndustryType type)
119  {
120  assert(type < NUM_INDUSTRYTYPES);
121  counts[type]--;
122  }
123 
129  static inline uint16 GetIndustryTypeCount(IndustryType type)
130  {
131  assert(type < NUM_INDUSTRYTYPES);
132  return counts[type];
133  }
134 
136  static inline void ResetIndustryCounts()
137  {
138  memset(&counts, 0, sizeof(counts));
139  }
140 
141 protected:
142  static uint16 counts[NUM_INDUSTRYTYPES];
143 };
144 
145 void PlantRandomFarmField(const Industry *i);
146 
147 void ReleaseDisastersTargetingIndustry(IndustryID);
148 
150 
151 #define FOR_ALL_INDUSTRIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Industry, industry_index, var, start)
152 #define FOR_ALL_INDUSTRIES(var) FOR_ALL_INDUSTRIES_FROM(var, 0)
153 
156  uint32 probability;
157  byte min_number;
158  uint16 target_count;
159  uint16 max_wait;
160  uint16 wait_count;
161 
162  void Reset();
163 
164  bool GetIndustryTypeData(IndustryType it);
165 };
166 
172  uint32 wanted_inds;
173 
174  void Reset();
175 
176  void SetupTargetCount();
177  void TryBuildNewIndustry();
178 
179  void MonthlyLoop();
180 };
181 
183 
184 #endif /* INDUSTRY_H */