Delete pointless project file remnants.
[openttd-joker.git] / src / industry.h
blob66d6962392f789269bd9e35066662947e98aa943
1 /* $Id: industry.h 24900 2013-01-08 22:46:42Z planetmaker $ */
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 */
10 /** @file industry.h Base of all industries. */
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"
21 typedef Pool<Industry, IndustryID, 64, 64000> IndustryPool;
22 extern IndustryPool _industry_pool;
24 /**
25 * Production level maximum, minimum and default values.
26 * It is not a value been really used in order to change, but rather an indicator
27 * of how the industry is behaving.
29 enum ProductionLevels {
30 PRODLEVEL_CLOSURE = 0x00, ///< signal set to actually close the industry
31 PRODLEVEL_MINIMUM = 0x04, ///< below this level, the industry is set to be closing
32 PRODLEVEL_DEFAULT = 0x10, ///< default level set when the industry is created
33 PRODLEVEL_MAXIMUM = 0x80, ///< the industry is running at full speed
36 /**
37 * Defines the internal data of a functional industry.
39 struct Industry : IndustryPool::PoolItem<&_industry_pool> {
40 TileArea location; ///< Location of the industry
41 Town *town; ///< Nearest town
42 CargoID produced_cargo[2]; ///< 2 production cargo slots
43 uint16 produced_cargo_waiting[2]; ///< amount of cargo produced per cargo
44 uint16 incoming_cargo_waiting[3]; ///< incoming cargo waiting to be processed
45 byte production_rate[2]; ///< production rate for each cargo
46 byte prod_level; ///< general production level
47 CargoID accepts_cargo[3]; ///< 3 input cargo slots
48 uint16 this_month_production[2]; ///< stats of this month's production per cargo
49 uint16 this_month_transported[2]; ///< stats of this month's transport per cargo
50 byte last_month_pct_transported[2]; ///< percentage transported per cargo in the last full month
51 uint16 last_month_production[2]; ///< total units produced per cargo in the last full month
52 uint16 last_month_transported[2]; ///< total units transported per cargo in the last full month
53 uint16 counter; ///< used for animation and/or production (if available cargo)
55 IndustryType type; ///< type of industry.
56 OwnerByte owner; ///< owner of the industry. Which SHOULD always be (imho) OWNER_NONE
57 byte random_colour; ///< randomized colour of the industry, for display purpose
58 Year last_prod_year; ///< last year of production
59 byte was_cargo_delivered; ///< flag that indicate this has been the closest industry chosen for cargo delivery by a station. see DeliverGoodsToIndustry
61 PartOfSubsidyByte part_of_subsidy; ///< NOSAVE: is this industry a source/destination of a subsidy?
63 OwnerByte founder; ///< Founder of the industry
64 Date construction_date; ///< Date of the construction of the industry
65 uint8 construction_type; ///< Way the industry was constructed (@see IndustryConstructionType)
66 Date last_cargo_accepted_at; ///< Last day cargo was accepted by this industry
67 byte selected_layout; ///< Which tile layout was used when creating the industry
69 uint16 random; ///< Random value used for randomisation of all kinds of things
71 PersistentStorage *psa; ///< Persistent storage for NewGRF industries.
73 Industry(TileIndex tile = INVALID_TILE) : location(tile, 0, 0) {}
74 ~Industry();
76 void RecomputeProductionMultipliers();
78 /**
79 * Check if a given tile belongs to this industry.
80 * @param tile The tile to check.
81 * @return True if the tile is part of this industry.
83 inline bool TileBelongsToIndustry(TileIndex tile) const
85 return IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == this->index;
88 /**
89 * Get the industry of the given tile
90 * @param tile the tile to get the industry from
91 * @pre IsTileType(t, MP_INDUSTRY)
92 * @return the industry
94 static inline Industry *GetByTile(TileIndex tile)
96 return Industry::Get(GetIndustryIndex(tile));
99 static Industry *GetRandom();
100 static void PostDestructor(size_t index);
103 * Increment the count of industries for this type.
104 * @param type IndustryType to increment
105 * @pre type < NUM_INDUSTRYTYPES
107 static inline void IncIndustryTypeCount(IndustryType type)
109 assert(type < NUM_INDUSTRYTYPES);
110 counts[type]++;
114 * Decrement the count of industries for this type.
115 * @param type IndustryType to decrement
116 * @pre type < NUM_INDUSTRYTYPES
118 static inline void DecIndustryTypeCount(IndustryType type)
120 assert(type < NUM_INDUSTRYTYPES);
121 counts[type]--;
125 * Get the count of industries for this type.
126 * @param type IndustryType to query
127 * @pre type < NUM_INDUSTRYTYPES
129 static inline uint16 GetIndustryTypeCount(IndustryType type)
131 assert(type < NUM_INDUSTRYTYPES);
132 return counts[type];
135 /** Resets industry counts. */
136 static inline void ResetIndustryCounts()
138 memset(&counts, 0, sizeof(counts));
141 protected:
142 static uint16 counts[NUM_INDUSTRYTYPES]; ///< Number of industries per type ingame
145 void PlantRandomFarmField(const Industry *i);
147 void ReleaseDisastersTargetingIndustry(IndustryID);
149 bool IsTileForestIndustry(TileIndex tile);
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)
154 /** Data for managing the number of industries of a single industry type. */
155 struct IndustryTypeBuildData {
156 uint32 probability; ///< Relative probability of building this industry.
157 byte min_number; ///< Smallest number of industries that should exist (either \c 0 or \c 1).
158 uint16 target_count; ///< Desired number of industries of this type.
159 uint16 max_wait; ///< Starting number of turns to wait (copied to #wait_count).
160 uint16 wait_count; ///< Number of turns to wait before trying to build again.
162 void Reset();
164 bool GetIndustryTypeData(IndustryType it);
168 * Data for managing the number and type of industries in the game.
170 struct IndustryBuildData {
171 IndustryTypeBuildData builddata[NUM_INDUSTRYTYPES]; ///< Industry build data for every industry type.
172 uint32 wanted_inds; ///< Number of wanted industries (bits 31-16), and a fraction (bits 15-0).
174 void Reset();
176 void SetupTargetCount();
177 void TryBuildNewIndustry();
179 void MonthlyLoop();
182 extern IndustryBuildData _industry_builder;
184 #endif /* INDUSTRY_H */