OpenTTD: src/industry.h Source File

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 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
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 byte random_triggers;
70 uint16 random;
71
72 PersistentStorage *psa;
73
74 Industry(TileIndex tile = INVALID_TILE) : location(tile, 0, 0) {}
75 ~Industry();
76
77 void RecomputeProductionMultipliers();
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
150 bool IsTileForestIndustry(TileIndex tile);
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
156 struct IndustryTypeBuildData {
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
171 struct IndustryBuildData {
172 IndustryTypeBuildData builddata[NUM_INDUSTRYTYPES];
173 uint32 wanted_inds;
174
175 void Reset();
176
177 void SetupTargetCount();
178 void TryBuildNewIndustry();
179
180 void MonthlyLoop();
181 };
182
183 extern IndustryBuildData _industry_builder;
184
185 #endif /* INDUSTRY_H */