Files
@ r24213:10613c2a6ba0
Branch filter:
Location: cpp/openttd-patchpack/source/src/industry.h - annotation
r24213:10613c2a6ba0
8.2 KiB
text/x-c
Codechange: Store GS lang texts in std::strings.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r9111:983de9c5a848 r6201:2e76eb9a1d7a r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r23041:7dd9cd83d20f r7610:6031d09c03ef r12648:24c912bd53f6 r12816:33099b7286d4 r23040:680908bb49de r14159:6cb75763eb03 r23420:9c4e5ff5cf11 r5475:3f5cd13d1b63 r6390:c8b3b64c49ff r11967:df0600d2c7e7 r11967:df0600d2c7e7 r7390:444ff4a56f72 r6201:2e76eb9a1d7a r16190:5ca23ce41763 r16190:5ca23ce41763 r16190:5ca23ce41763 r16190:5ca23ce41763 r16190:5ca23ce41763 r16190:5ca23ce41763 r16190:5ca23ce41763 r16190:5ca23ce41763 r16190:5ca23ce41763 r16190:5ca23ce41763 r16190:5ca23ce41763 r16190:5ca23ce41763 r16531:d1a9e93ee01b r6201:2e76eb9a1d7a r11967:df0600d2c7e7 r23040:680908bb49de r23040:680908bb49de r23420:9c4e5ff5cf11 r23040:680908bb49de r23040:680908bb49de r23040:680908bb49de r23040:680908bb49de r23040:680908bb49de r23040:680908bb49de r23040:680908bb49de r23040:680908bb49de r23040:680908bb49de r23040:680908bb49de r23040:680908bb49de r23040:680908bb49de r5475:3f5cd13d1b63 r23677:3b8ed1534593 r23677:3b8ed1534593 r23677:3b8ed1534593 r23677:3b8ed1534593 r23677:3b8ed1534593 r5475:3f5cd13d1b63 r23677:3b8ed1534593 r23677:3b8ed1534593 r24054:96f94ee4b3e1 r12648:24c912bd53f6 r23677:3b8ed1534593 r23677:3b8ed1534593 r23677:3b8ed1534593 r23041:7dd9cd83d20f r23677:3b8ed1534593 r7390:444ff4a56f72 r23677:3b8ed1534593 r7860:c73688ce46ca r23677:3b8ed1534593 r7610:6031d09c03ef r14159:6cb75763eb03 r7390:444ff4a56f72 r12242:f11b2e8973ab r16186:88dee3f13edf r16186:88dee3f13edf r12816:33099b7286d4 r18600:daee608b9023 r18600:daee608b9023 r19944:25a78576fb5e r18600:daee608b9023 r18600:daee608b9023 r18600:daee608b9023 r18600:daee608b9023 r18600:daee608b9023 r18600:daee608b9023 r23041:7dd9cd83d20f r23041:7dd9cd83d20f r23041:7dd9cd83d20f r23041:7dd9cd83d20f r23041:7dd9cd83d20f r23041:7dd9cd83d20f r23041:7dd9cd83d20f r23041:7dd9cd83d20f r23041:7dd9cd83d20f r23041:7dd9cd83d20f r23041:7dd9cd83d20f r23041:7dd9cd83d20f r23041:7dd9cd83d20f r23041:7dd9cd83d20f r23041:7dd9cd83d20f r23041:7dd9cd83d20f r18600:daee608b9023 r12816:33099b7286d4 r13060:e57594b0ca84 r12816:33099b7286d4 r12816:33099b7286d4 r12816:33099b7286d4 r18782:6453522c2154 r12816:33099b7286d4 r12816:33099b7286d4 r12816:33099b7286d4 r12816:33099b7286d4 r12242:f11b2e8973ab r12968:8f3f0d6af8a6 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r24054:96f94ee4b3e1 r24054:96f94ee4b3e1 r24054:96f94ee4b3e1 r24054:96f94ee4b3e1 r24054:96f94ee4b3e1 r24054:96f94ee4b3e1 r24054:96f94ee4b3e1 r24054:96f94ee4b3e1 r24054:96f94ee4b3e1 r14875:c6c6704d8c04 r14875:c6c6704d8c04 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r24054:96f94ee4b3e1 r24054:96f94ee4b3e1 r6637:08ab9ae07700 r5475:3f5cd13d1b63 r10491:e3e4bb1ebaea r10491:e3e4bb1ebaea r18209:6978a751427f r18209:6978a751427f r16441:6b2cb101747b r16441:6b2cb101747b r16441:6b2cb101747b r16444:36b3473785ee r16442:65c76775ce4b r16444:36b3473785ee r16444:36b3473785ee r16441:6b2cb101747b r16445:78655b2f7c0d r16445:78655b2f7c0d r16447:4063bb00c470 r16441:6b2cb101747b r16441:6b2cb101747b r16440:1bdd98dfbb9e r16440:1bdd98dfbb9e r16440:1bdd98dfbb9e r16440:1bdd98dfbb9e r16441:6b2cb101747b r16444:36b3473785ee r16441:6b2cb101747b r16445:78655b2f7c0d r16445:78655b2f7c0d r16442:65c76775ce4b r16440:1bdd98dfbb9e r16446:9455c82d3bdb r16446:9455c82d3bdb r16440:1bdd98dfbb9e r16440:1bdd98dfbb9e r16440:1bdd98dfbb9e r16440:1bdd98dfbb9e r24053:47b8c8b643e3 r24053:47b8c8b643e3 r24053:47b8c8b643e3 r24053:47b8c8b643e3 r24053:47b8c8b643e3 r24053:47b8c8b643e3 r24053:47b8c8b643e3 r24053:47b8c8b643e3 r5475:3f5cd13d1b63 | /*
* This file is part of OpenTTD.
* 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.
* 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.
* 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/>.
*/
/** @file industry.h Base of all industries. */
#ifndef INDUSTRY_H
#define INDUSTRY_H
#include <algorithm>
#include "newgrf_storage.h"
#include "subsidy_type.h"
#include "industry_map.h"
#include "industrytype.h"
#include "tilearea_type.h"
#include "station_base.h"
typedef Pool<Industry, IndustryID, 64, 64000> IndustryPool;
extern IndustryPool _industry_pool;
/**
* Production level maximum, minimum and default values.
* It is not a value been really used in order to change, but rather an indicator
* of how the industry is behaving.
*/
enum ProductionLevels {
PRODLEVEL_CLOSURE = 0x00, ///< signal set to actually close the industry
PRODLEVEL_MINIMUM = 0x04, ///< below this level, the industry is set to be closing
PRODLEVEL_DEFAULT = 0x10, ///< default level set when the industry is created
PRODLEVEL_MAXIMUM = 0x80, ///< the industry is running at full speed
};
/**
* Defines the internal data of a functional industry.
*/
struct Industry : IndustryPool::PoolItem<&_industry_pool> {
TileArea location; ///< Location of the industry
Town *town; ///< Nearest town
Station *neutral_station; ///< Associated neutral station
CargoID produced_cargo[INDUSTRY_NUM_OUTPUTS]; ///< 16 production cargo slots
uint16 produced_cargo_waiting[INDUSTRY_NUM_OUTPUTS]; ///< amount of cargo produced per cargo
uint16 incoming_cargo_waiting[INDUSTRY_NUM_INPUTS]; ///< incoming cargo waiting to be processed
byte production_rate[INDUSTRY_NUM_OUTPUTS]; ///< production rate for each cargo
byte prod_level; ///< general production level
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]; ///< 16 input cargo slots
uint16 this_month_production[INDUSTRY_NUM_OUTPUTS]; ///< stats of this month's production per cargo
uint16 this_month_transported[INDUSTRY_NUM_OUTPUTS]; ///< stats of this month's transport per cargo
byte last_month_pct_transported[INDUSTRY_NUM_OUTPUTS]; ///< percentage transported per cargo in the last full month
uint16 last_month_production[INDUSTRY_NUM_OUTPUTS]; ///< total units produced per cargo in the last full month
uint16 last_month_transported[INDUSTRY_NUM_OUTPUTS]; ///< total units transported per cargo in the last full month
uint16 counter; ///< used for animation and/or production (if available cargo)
IndustryType type; ///< type of industry.
Owner owner; ///< owner of the industry. Which SHOULD always be (imho) OWNER_NONE
byte random_colour; ///< randomized colour of the industry, for display purpose
Year last_prod_year; ///< last year of production
byte was_cargo_delivered; ///< flag that indicate this has been the closest industry chosen for cargo delivery by a station. see DeliverGoodsToIndustry
PartOfSubsidy part_of_subsidy; ///< NOSAVE: is this industry a source/destination of a subsidy?
StationList stations_near; ///< NOSAVE: List of nearby stations.
mutable std::string cached_name; ///< NOSAVE: Cache of the resolved name of the industry
Owner founder; ///< Founder of the industry
Date construction_date; ///< Date of the construction of the industry
uint8 construction_type; ///< Way the industry was constructed (@see IndustryConstructionType)
Date last_cargo_accepted_at[INDUSTRY_NUM_INPUTS]; ///< Last day each cargo type was accepted by this industry
byte selected_layout; ///< Which tile layout was used when creating the industry
uint16 random; ///< Random value used for randomisation of all kinds of things
PersistentStorage *psa; ///< Persistent storage for NewGRF industries.
Industry(TileIndex tile = INVALID_TILE) : location(tile, 0, 0) {}
~Industry();
void RecomputeProductionMultipliers();
/**
* Check if a given tile belongs to this industry.
* @param tile The tile to check.
* @return True if the tile is part of this industry.
*/
inline bool TileBelongsToIndustry(TileIndex tile) const
{
return IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == this->index;
}
inline int GetCargoProducedIndex(CargoID cargo) const
{
if (cargo == CT_INVALID) return -1;
const CargoID *pos = std::find(this->produced_cargo, endof(this->produced_cargo), cargo);
if (pos == endof(this->produced_cargo)) return -1;
return pos - this->produced_cargo;
}
inline int GetCargoAcceptedIndex(CargoID cargo) const
{
if (cargo == CT_INVALID) return -1;
const CargoID *pos = std::find(this->accepts_cargo, endof(this->accepts_cargo), cargo);
if (pos == endof(this->accepts_cargo)) return -1;
return pos - this->accepts_cargo;
}
/**
* Get the industry of the given tile
* @param tile the tile to get the industry from
* @pre IsTileType(t, MP_INDUSTRY)
* @return the industry
*/
static inline Industry *GetByTile(TileIndex tile)
{
return Industry::Get(GetIndustryIndex(tile));
}
static Industry *GetRandom();
static void PostDestructor(size_t index);
/**
* Increment the count of industries for this type.
* @param type IndustryType to increment
* @pre type < NUM_INDUSTRYTYPES
*/
static inline void IncIndustryTypeCount(IndustryType type)
{
assert(type < NUM_INDUSTRYTYPES);
counts[type]++;
}
/**
* Decrement the count of industries for this type.
* @param type IndustryType to decrement
* @pre type < NUM_INDUSTRYTYPES
*/
static inline void DecIndustryTypeCount(IndustryType type)
{
assert(type < NUM_INDUSTRYTYPES);
counts[type]--;
}
/**
* Get the count of industries for this type.
* @param type IndustryType to query
* @pre type < NUM_INDUSTRYTYPES
*/
static inline uint16 GetIndustryTypeCount(IndustryType type)
{
assert(type < NUM_INDUSTRYTYPES);
return counts[type];
}
/** Resets industry counts. */
static inline void ResetIndustryCounts()
{
memset(&counts, 0, sizeof(counts));
}
inline const char *GetCachedName() const
{
if (this->cached_name.empty()) this->FillCachedName();
return this->cached_name.c_str();
}
private:
void FillCachedName() const;
protected:
static uint16 counts[NUM_INDUSTRYTYPES]; ///< Number of industries per type ingame
};
void ClearAllIndustryCachedNames();
void PlantRandomFarmField(const Industry *i);
void ReleaseDisastersTargetingIndustry(IndustryID);
bool IsTileForestIndustry(TileIndex tile);
/** Data for managing the number of industries of a single industry type. */
struct IndustryTypeBuildData {
uint32 probability; ///< Relative probability of building this industry.
byte min_number; ///< Smallest number of industries that should exist (either \c 0 or \c 1).
uint16 target_count; ///< Desired number of industries of this type.
uint16 max_wait; ///< Starting number of turns to wait (copied to #wait_count).
uint16 wait_count; ///< Number of turns to wait before trying to build again.
void Reset();
bool GetIndustryTypeData(IndustryType it);
};
/**
* Data for managing the number and type of industries in the game.
*/
struct IndustryBuildData {
IndustryTypeBuildData builddata[NUM_INDUSTRYTYPES]; ///< Industry build data for every industry type.
uint32 wanted_inds; ///< Number of wanted industries (bits 31-16), and a fraction (bits 15-0).
void Reset();
void SetupTargetCount();
void TryBuildNewIndustry();
void MonthlyLoop();
};
extern IndustryBuildData _industry_builder;
/** Special values for the industry list window for the data parameter of #InvalidateWindowData. */
enum IndustryDirectoryInvalidateWindowData {
IDIWD_FORCE_REBUILD,
IDIWD_PRODUCTION_CHANGE,
IDIWD_FORCE_RESORT,
};
#endif /* INDUSTRY_H */
|