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
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 */
Industry::ResetIndustryCounts
static void ResetIndustryCounts()
Resets industry counts.
Definition: industry.h:136
ReleaseDisastersTargetingIndustry
void ReleaseDisastersTargetingIndustry(IndustryID)
Marks all disasters targeting this industry in such a way they won&#39;t call Industry::Get(v->dest_tile)...
Definition: disaster_vehicle.cpp:943
ProductionLevels
ProductionLevels
Production level maximum, minimum and default values.
Definition: industry.h:29
IndustryTypeBuildData::max_wait
uint16 max_wait
Starting number of turns to wait (copied to wait_count).
Definition: industry.h:159
subsidy_type.h
basic types related to subsidies
_industry_builder
IndustryBuildData _industry_builder
In-game manager of industries.
Definition: industry_cmd.cpp:64
MP_INDUSTRY
Part of an industry.
Definition: tile_type.h:51
Industry::counter
uint16 counter
used for animation and/or production (if available cargo)
Definition: industry.h:53
PRODLEVEL_MINIMUM
below this level, the industry is set to be closing
Definition: industry.h:31
Pool::PoolItem<&_industry_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:246
Industry::founder
OwnerByte founder
Founder of the industry.
Definition: industry.h:63
newgrf_storage.h
Functionality related to the temporary and persistent storage arrays for NewGRFs. ...
Industry::town
Town * town
Nearest town.
Definition: industry.h:41
Industry::last_month_production
uint16 last_month_production[2]
total units produced per cargo in the last full month
Definition: industry.h:51
Industry::this_month_transported
uint16 this_month_transported[2]
stats of this month&#39;s transport per cargo
Definition: industry.h:49
Industry::selected_layout
byte selected_layout
Which tile layout was used when creating the industry.
Definition: industry.h:67
Industry::construction_type
uint8 construction_type
Way the industry was constructed (.
Definition: industry.h:65
PRODLEVEL_DEFAULT
default level set when the industry is created
Definition: industry.h:32
PRODLEVEL_CLOSURE
signal set to actually close the industry
Definition: industry.h:30
Industry
Defines the internal data of a functional industry.
Definition: industry.h:39
Pool::PoolItem<&_industry_pool >::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
Industry::was_cargo_delivered
byte was_cargo_delivered
flag that indicate this has been the closest industry chosen for cargo delivery by a station...
Definition: industry.h:59
Industry::random
uint16 random
Random value used for randomisation of all kinds of things.
Definition: industry.h:69
Industry::GetRandom
static Industry * GetRandom()
Return a random valid industry.
Definition: industry_cmd.cpp:202
Year
int32 Year
Type for the year, note: 0 based, i.e. starts at the year 0.
Definition: date_type.h:20
industry_map.h
Accessors for industries.
PRODLEVEL_MAXIMUM
the industry is running at full speed
Definition: industry.h:33
Industry::incoming_cargo_waiting
uint16 incoming_cargo_waiting[3]
incoming cargo waiting to be processed
Definition: industry.h:44
Industry::random_colour
byte random_colour
randomized colour of the industry, for display purpose
Definition: industry.h:57
Industry::construction_date
Date construction_date
Date of the construction of the industry.
Definition: industry.h:64
IndustryBuildData
Data for managing the number and type of industries in the game.
Definition: industry.h:170
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
Definition: tile_map.h:143
Industry::psa
PersistentStorage * psa
Persistent storage for NewGRF industries.
Definition: industry.h:71
Industry::produced_cargo_waiting
uint16 produced_cargo_waiting[2]
amount of cargo produced per cargo
Definition: industry.h:43
Industry::part_of_subsidy
PartOfSubsidyByte part_of_subsidy
NOSAVE: is this industry a source/destination of a subsidy?
Definition: industry.h:61
IsTileForestIndustry
bool IsTileForestIndustry(TileIndex tile)
Check whether the tile is a forest.
Definition: industry_cmd.cpp:931
Industry::last_prod_year
Year last_prod_year
last year of production
Definition: industry.h:58
Industry::this_month_production
uint16 this_month_production[2]
stats of this month&#39;s production per cargo
Definition: industry.h:48
Industry::type
IndustryType type
type of industry.
Definition: industry.h:55
Industry::accepts_cargo
CargoID accepts_cargo[3]
3 input cargo slots
Definition: industry.h:47
Industry::location
TileArea location
Location of the industry.
Definition: industry.h:40
OrthogonalTileArea
Represents the covered area of e.g.
Definition: tilearea_type.h:18
PersistentStorage
Class for pooled persistent storage of data.
Definition: newgrf_storage.h:223
Industry::GetIndustryTypeCount
static uint16 GetIndustryTypeCount(IndustryType type)
Get the count of industries for this type.
Definition: industry.h:129
Industry::produced_cargo
CargoID produced_cargo[2]
2 production cargo slots
Definition: industry.h:42
Industry::prod_level
byte prod_level
general production level
Definition: industry.h:46
IndustryTypeBuildData
Data for managing the number of industries of a single industry type.
Definition: industry.h:155
TinyEnumT< Owner >
Industry::last_month_pct_transported
byte last_month_pct_transported[2]
percentage transported per cargo in the last full month
Definition: industry.h:50
Pool::PoolItem
Base class for all PoolItems.
Definition: pool_type.hpp:146
SimpleTinyEnumT< PartOfSubsidy, byte >
Industry::last_month_transported
uint16 last_month_transported[2]
total units transported per cargo in the last full month
Definition: industry.h:52
IndustryTypeBuildData::wait_count
uint16 wait_count
Number of turns to wait before trying to build again.
Definition: industry.h:160
Industry::IncIndustryTypeCount
static void IncIndustryTypeCount(IndustryType type)
Increment the count of industries for this type.
Definition: industry.h:107
Pool
Base class for all pools.
Definition: pool_type.hpp:83
Industry::PostDestructor
static void PostDestructor(size_t index)
Invalidating some stuff after removing item from the pool.
Definition: industry_cmd.cpp:191
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
Industry::RecomputeProductionMultipliers
void RecomputeProductionMultipliers()
Recompute production_rate for current prod_level.
Definition: industry_cmd.cpp:2191
NUM_INDUSTRYTYPES
static const IndustryType NUM_INDUSTRYTYPES
total number of industry types, new and old; limited to 240 because we need some special ids like INV...
Definition: industry_type.h:28
GetIndustryIndex
static IndustryID GetIndustryIndex(TileIndex t)
Get the industry ID of the given tile.
Definition: industry_map.h:65
Industry::DecIndustryTypeCount
static void DecIndustryTypeCount(IndustryType type)
Decrement the count of industries for this type.
Definition: industry.h:118
Town
Town data structure.
Definition: town.h:55
Industry::production_rate
byte production_rate[2]
production rate for each cargo
Definition: industry.h:45
tilearea_type.h
Type for storing the &#39;area&#39; of something uses on the map.
IndustryTypeBuildData::probability
uint32 probability
Relative probability of building this industry.
Definition: industry.h:156
Industry::counts
static uint16 counts[NUM_INDUSTRYTYPES]
Number of industries per type ingame.
Definition: industry.h:142
IndustryBuildData::wanted_inds
uint32 wanted_inds
Number of wanted industries (bits 31-16), and a fraction (bits 15-0).
Definition: industry.h:172
Date
int32 Date
The type to store our dates in.
Definition: date_type.h:16
IndustryTypeBuildData::min_number
byte min_number
Smallest number of industries that should exist (either 0 or 1).
Definition: industry.h:157
INVALID_TILE
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:85
Industry::last_cargo_accepted_at
Date last_cargo_accepted_at
Last day cargo was accepted by this industry.
Definition: industry.h:66
Industry::TileBelongsToIndustry
bool TileBelongsToIndustry(TileIndex tile) const
Check if a given tile belongs to this industry.
Definition: industry.h:83
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:22
Industry::GetByTile
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Definition: industry.h:94
IndustryTypeBuildData::target_count
uint16 target_count
Desired number of industries of this type.
Definition: industry.h:158
Industry::owner
OwnerByte owner
owner of the industry. Which SHOULD always be (imho) OWNER_NONE
Definition: industry.h:56