Go to the documentation of this file.
1 /* $Id: industry.h 27929 2017-10-25 15:38:19Z frosch $ */
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 <>.
8  */
12 #ifndef INDUSTRY_H
13 #define INDUSTRY_H
15 #include "newgrf_storage.h"
16 #include "subsidy_type.h"
17 #include "industry_map.h"
18 #include "tilearea_type.h"
22 extern IndustryPool _industry_pool;
34 };
39 struct Industry : IndustryPool::PoolItem<&_industry_pool> {
45  byte production_rate[2];
46  byte prod_level;
53  uint16 counter;
55  IndustryType type;
69  uint16 random;
73  Industry(TileIndex tile = INVALID_TILE) : location(tile, 0, 0) {}
74  ~Industry();
83  inline bool TileBelongsToIndustry(TileIndex tile) const
84  {
85  return IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == this->index;
86  }
94  static inline Industry *GetByTile(TileIndex tile)
95  {
96  return Industry::Get(GetIndustryIndex(tile));
97  }
99  static Industry *GetRandom();
100  static void PostDestructor(size_t index);
107  static inline void IncIndustryTypeCount(IndustryType type)
108  {
109  assert(type < NUM_INDUSTRYTYPES);
110  counts[type]++;
111  }
118  static inline void DecIndustryTypeCount(IndustryType type)
119  {
120  assert(type < NUM_INDUSTRYTYPES);
121  counts[type]--;
122  }
129  static inline uint16 GetIndustryTypeCount(IndustryType type)
130  {
131  assert(type < NUM_INDUSTRYTYPES);
132  return counts[type];
133  }
136  static inline void ResetIndustryCounts()
137  {
138  memset(&counts, 0, sizeof(counts));
139  }
141 protected:
142  static uint16 counts[NUM_INDUSTRYTYPES];
143 };
145 void PlantRandomFarmField(const Industry *i);
147 void ReleaseDisastersTargetingIndustry(IndustryID);
151 #define FOR_ALL_INDUSTRIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Industry, industry_index, var, start)
156  uint32 probability;
157  byte min_number;
158  uint16 target_count;
159  uint16 max_wait;
160  uint16 wait_count;
162  void Reset();
164  bool GetIndustryTypeData(IndustryType it);
165 };
172  uint32 wanted_inds;
174  void Reset();
176  void SetupTargetCount();
177  void TryBuildNewIndustry();
179  void MonthlyLoop();
180 };
184 #endif /* INDUSTRY_H */
static void ResetIndustryCounts()
Resets industry counts.
Definition: industry.h:136
void ReleaseDisastersTargetingIndustry(IndustryID)
Marks all disasters targeting this industry in such a way they won&#39;t call Industry::Get(v->dest_tile)...
Production level maximum, minimum and default values.
Definition: industry.h:29
uint16 max_wait
Starting number of turns to wait (copied to wait_count).
Definition: industry.h:159
basic types related to subsidies
IndustryBuildData _industry_builder
In-game manager of industries.
Part of an industry.
Definition: tile_type.h:51
uint16 counter
used for animation and/or production (if available cargo)
Definition: industry.h:53
below this level, the industry is set to be closing
Definition: industry.h:31
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:246
OwnerByte founder
Founder of the industry.
Definition: industry.h:63
Functionality related to the temporary and persistent storage arrays for NewGRFs. ...
Town * town
Nearest town.
Definition: industry.h:41
uint16 last_month_production[2]
total units produced per cargo in the last full month
Definition: industry.h:51
uint16 this_month_transported[2]
stats of this month&#39;s transport per cargo
Definition: industry.h:49
byte selected_layout
Which tile layout was used when creating the industry.
Definition: industry.h:67
uint8 construction_type
Way the industry was constructed (.
Definition: industry.h:65
default level set when the industry is created
Definition: industry.h:32
signal set to actually close the industry
Definition: industry.h:30
Defines the internal data of a functional industry.
Definition: industry.h:39
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
byte was_cargo_delivered
flag that indicate this has been the closest industry chosen for cargo delivery by a station...
Definition: industry.h:59
uint16 random
Random value used for randomisation of all kinds of things.
Definition: industry.h:69
static Industry * GetRandom()
Return a random valid industry.
int32 Year
Type for the year, note: 0 based, i.e. starts at the year 0.
Definition: date_type.h:20
Accessors for industries.
the industry is running at full speed
Definition: industry.h:33
uint16 incoming_cargo_waiting[3]
incoming cargo waiting to be processed
Definition: industry.h:44
byte random_colour
randomized colour of the industry, for display purpose
Definition: industry.h:57
Date construction_date
Date of the construction of the industry.
Definition: industry.h:64
Data for managing the number and type of industries in the game.
Definition: industry.h:170
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
Definition: tile_map.h:143
PersistentStorage * psa
Persistent storage for NewGRF industries.
Definition: industry.h:71
uint16 produced_cargo_waiting[2]
amount of cargo produced per cargo
Definition: industry.h:43
PartOfSubsidyByte part_of_subsidy
NOSAVE: is this industry a source/destination of a subsidy?
Definition: industry.h:61
bool IsTileForestIndustry(TileIndex tile)
Check whether the tile is a forest.
Year last_prod_year
last year of production
Definition: industry.h:58
uint16 this_month_production[2]
stats of this month&#39;s production per cargo
Definition: industry.h:48
IndustryType type
type of industry.
Definition: industry.h:55
CargoID accepts_cargo[3]
3 input cargo slots
Definition: industry.h:47
TileArea location
Location of the industry.
Definition: industry.h:40
Represents the covered area of e.g.
Definition: tilearea_type.h:18
Class for pooled persistent storage of data.
static uint16 GetIndustryTypeCount(IndustryType type)
Get the count of industries for this type.
Definition: industry.h:129
CargoID produced_cargo[2]
2 production cargo slots
Definition: industry.h:42
byte prod_level
general production level
Definition: industry.h:46
Data for managing the number of industries of a single industry type.
Definition: industry.h:155
byte last_month_pct_transported[2]
percentage transported per cargo in the last full month
Definition: industry.h:50
Base class for all PoolItems.
Definition: pool_type.hpp:146
uint16 last_month_transported[2]
total units transported per cargo in the last full month
Definition: industry.h:52
uint16 wait_count
Number of turns to wait before trying to build again.
Definition: industry.h:160
static void IncIndustryTypeCount(IndustryType type)
Increment the count of industries for this type.
Definition: industry.h:107
Base class for all pools.
Definition: pool_type.hpp:83
static void PostDestructor(size_t index)
Invalidating some stuff after removing item from the pool.
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
void RecomputeProductionMultipliers()
Recompute production_rate for current prod_level.
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
static IndustryID GetIndustryIndex(TileIndex t)
Get the industry ID of the given tile.
Definition: industry_map.h:65
static void DecIndustryTypeCount(IndustryType type)
Decrement the count of industries for this type.
Definition: industry.h:118
Town data structure.
Definition: town.h:55
byte production_rate[2]
production rate for each cargo
Definition: industry.h:45
Type for storing the &#39;area&#39; of something uses on the map.
uint32 probability
Relative probability of building this industry.
Definition: industry.h:156
static uint16 counts[NUM_INDUSTRYTYPES]
Number of industries per type ingame.
Definition: industry.h:142
uint32 wanted_inds
Number of wanted industries (bits 31-16), and a fraction (bits 15-0).
Definition: industry.h:172
int32 Date
The type to store our dates in.
Definition: date_type.h:16
byte min_number
Smallest number of industries that should exist (either 0 or 1).
Definition: industry.h:157
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:85
Date last_cargo_accepted_at
Last day cargo was accepted by this industry.
Definition: industry.h:66
bool TileBelongsToIndustry(TileIndex tile) const
Check if a given tile belongs to this industry.
Definition: industry.h:83
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:22
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Definition: industry.h:94
uint16 target_count
Desired number of industries of this type.
Definition: industry.h:158
OwnerByte owner
owner of the industry. Which SHOULD always be (imho) OWNER_NONE
Definition: industry.h:56