OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

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
21 typedef Pool<Industry, IndustryID, 64, 64000> IndustryPool;
22 extern IndustryPool _industry_pool;
23
29 enum ProductionLevels {
30 PRODLEVEL_CLOSURE = 0x00,
31 PRODLEVEL_MINIMUM = 0x04,
32 PRODLEVEL_DEFAULT = 0x10,
33 PRODLEVEL_MAXIMUM = 0x80,
34 };
35
39 struct Industry : IndustryPool::PoolItem<&_industry_pool> {
40 TileArea location;
41 Town *town;
42 CargoID produced_cargo[2];
43 uint16 produced_cargo_waiting[2];
44 uint16 incoming_cargo_waiting[3];
45 byte production_rate[2];
46 byte prod_level;
47 CargoID accepts_cargo[3];
48 uint16 this_month_production[2];
49 uint16 this_month_transported[2];
50 byte last_month_pct_transported[2];
51 uint16 last_month_production[2];
52 uint16 last_month_transported[2];
53 uint16 counter;
54
55 IndustryType type;
56 OwnerByte owner;
57 byte random_colour;
58 Year last_prod_year;
59 byte was_cargo_delivered;
60
61 PartOfSubsidyByte part_of_subsidy;
62
63 OwnerByte founder;
64 Date construction_date;
65 uint8 construction_type;
66 Date last_cargo_accepted_at;
67 byte selected_layout;
68
69 uint16 random;
70
71 PersistentStorage *psa;
72
73 Industry(TileIndex tile = INVALID_TILE) : location(tile, 0, 0) {}
74 ~Industry();
75
76 void RecomputeProductionMultipliers();
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
149 bool IsTileForestIndustry(TileIndex tile);
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
155 struct IndustryTypeBuildData {
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
170 struct IndustryBuildData {
171 IndustryTypeBuildData builddata[NUM_INDUSTRYTYPES];
172 uint32 wanted_inds;
173
174 void Reset();
175
176 void SetupTargetCount();
177 void TryBuildNewIndustry();
178
179 void MonthlyLoop();
180 };
181
182 extern IndustryBuildData _industry_builder;
183
184 #endif /* INDUSTRY_H */