10 #include "../stdafx.h"
15 #include "../industry.h"
18 #include "../safeguards.h"
24 inline static const SaveLoad description[] = {
34 static inline std::array<CargoID, INDUSTRY_NUM_INPUTS> old_cargo;
35 static inline std::array<uint16_t, INDUSTRY_NUM_INPUTS> old_waiting;
36 static inline std::array<TimerGameEconomy::Date, INDUSTRY_NUM_INPUTS> old_last_accepted;
38 static void ResetOldStructure()
40 SlIndustryAccepted::old_cargo.fill(INVALID_CARGO);
41 SlIndustryAccepted::old_waiting.fill(0);
42 SlIndustryAccepted::old_last_accepted.fill(0);
48 inline static const SaveLoad description[] = {
52 inline const static SaveLoadCompatTable compat_description = _industry_produced_history_sl_compat;
74 if (--len > p->
history.size())
break;
82 inline static const SaveLoad description[] = {
93 static inline std::array<CargoID, INDUSTRY_NUM_OUTPUTS> old_cargo;
94 static inline std::array<uint16_t, INDUSTRY_NUM_OUTPUTS> old_waiting;
95 static inline std::array<uint8_t, INDUSTRY_NUM_OUTPUTS> old_rate;
96 static inline std::array<uint16_t, INDUSTRY_NUM_OUTPUTS> old_this_month_production;
97 static inline std::array<uint16_t, INDUSTRY_NUM_OUTPUTS> old_this_month_transported;
98 static inline std::array<uint16_t, INDUSTRY_NUM_OUTPUTS> old_last_month_production;
99 static inline std::array<uint16_t, INDUSTRY_NUM_OUTPUTS> old_last_month_transported;
101 static void ResetOldStructure()
103 SlIndustryProduced::old_cargo.fill(INVALID_CARGO);
104 SlIndustryProduced::old_waiting.fill(0);
105 SlIndustryProduced::old_rate.fill(0);
106 SlIndustryProduced::old_this_month_production.fill(0);
107 SlIndustryProduced::old_this_month_transported.fill(0);
108 SlIndustryProduced::old_last_month_production.fill(0);
109 SlIndustryProduced::old_this_month_production.fill(0);
113 static const SaveLoad _industry_desc[] = {
178 SlSetArrayIndex(ind->index);
183 void LoadMoveAcceptsProduced(
Industry *i, uint inputs, uint outputs)
const
186 for (uint j = 0; j != inputs; ++j) {
187 auto &a = i->
accepted.emplace_back();
188 a.cargo = SlIndustryAccepted::old_cargo[j];
189 a.waiting = SlIndustryAccepted::old_waiting[j];
190 a.last_accepted = SlIndustryAccepted::old_last_accepted[j];
194 for (uint j = 0; j != outputs; ++j) {
195 auto &p = i->
produced.emplace_back();
196 p.cargo = SlIndustryProduced::old_cargo[j];
197 p.waiting = SlIndustryProduced::old_waiting[j];
198 p.rate = SlIndustryProduced::old_rate[j];
199 p.history[THIS_MONTH].production = SlIndustryProduced::old_this_month_production[j];
200 p.history[THIS_MONTH].transported = SlIndustryProduced::old_this_month_transported[j];
201 p.history[LAST_MONTH].production = SlIndustryProduced::old_last_month_production[j];
202 p.history[LAST_MONTH].transported = SlIndustryProduced::old_last_month_transported[j];
212 SlIndustryAccepted::ResetOldStructure();
213 SlIndustryProduced::ResetOldStructure();
225 std::copy(std::begin(_old_ind_persistent_storage.
storage), std::end(_old_ind_persistent_storage.
storage), std::begin(i->
psa->
storage));
330 extern const ChunkHandlerTable _industry_chunk_handlers(industry_chunk_handlers);
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
@ Industry
Source/destination is an industry.
Default handler for saving/loading an object to/from disk.
SaveLoadTable GetDescription() const override
std::vector< Industry::AcceptedCargo > & GetVector(Industry *i) const override
Get instance of vector to load/save.
std::vector< Industry::ProducedCargo > & GetVector(Industry *i) const override
Get instance of vector to load/save.
Default handler for saving/loading a vector to/from disk.
IndustryBuildData _industry_builder
In-game manager of industries.
static const SaveLoad _industrytype_builder_desc[]
Description of the data to save and load in IndustryTypeBuildData.
static const SaveLoad _industry_builder_desc[]
Description of the data to save and load in IndustryBuildData.
Loading of industry chunks before table headers were added.
const SaveLoadCompat _industry_sl_compat[]
Original field order for _industry_desc.
const SaveLoadCompat _industry_builder_sl_compat[]
Original field order for _industry_builder_desc.
const SaveLoadCompat _industrytype_builder_sl_compat[]
Original field order for _industrytype_builder_desc.
static const int INDUSTRY_ORIGINAL_NUM_INPUTS
Original number of accepted cargo types.
static const int INDUSTRY_NUM_OUTPUTS
Number of cargo types an industry can produce.
static const int INDUSTRY_NUM_INPUTS
Number of cargo types an industry can accept.
static const IndustryType NUM_INDUSTRYTYPES
total number of industry types, new and old; limited to 240 because we need some special ids like INV...
static const int INDUSTRY_ORIGINAL_NUM_OUTPUTS
Original number of produced cargo types.
Code handling saving and loading of NewGRF mappings.
size_t SlGetStructListLength(size_t limit)
Get the length of this list; if it exceeds the limit, error out.
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
void SlErrorCorrupt(const std::string &msg)
Error handler for corrupt savegames.
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
void SlGlobList(const SaveLoadTable &slt)
Save or Load (a list of) global variables.
void SlSetStructListLength(size_t length)
Set the length of this list.
Functions/types related to saving and loading games.
#define SLEG_CONDARR(name, variable, type, length, from, to)
Storage of a global fixed-size array of SL_VAR elements in some savegame versions.
#define SLEG_STRUCTLIST(name, handler)
Storage of a list of structs in every savegame version.
@ SLF_ALLOW_CONTROL
Allow control codes in the strings.
#define SLEG_CONDVAR(name, variable, type, from, to)
Storage of a global variable in some savegame versions.
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
#define SLEG_VAR(name, variable, type)
Storage of a global variable in every savegame version.
#define SLE_REF(base, variable, type)
Storage of a reference in every version of a savegame.
std::span< const struct SaveLoadCompat > SaveLoadCompatTable
A table of SaveLoadCompat entries.
#define SLE_CONDSSTR(base, variable, type, from, to)
Storage of a std::string in some savegame versions.
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
bool IsSavegameVersionBefore(SaveLoadVersion major, uint8_t minor=0)
Checks whether the savegame is below major.
@ SLV_INDUSTRY_TEXT
289 PR#8576 v1.11.0-RC1 Additional GS text for industries.
@ SLV_SERVE_NEUTRAL_INDUSTRIES
210 PR#7234 Company stations can serve industries with attached neutral stations.
@ SLV_EXTEND_INDUSTRY_CARGO_SLOTS
202 PR#6867 Increase industry cargo slots to 16 in, 16 out
@ SLV_RIFF_TO_ARRAY
294 PR#9375 Changed many CH_RIFF chunks to CH_ARRAY chunks.
@ SL_MAX_VERSION
Highest possible saveload version.
@ SLV_GS_INDUSTRY_CONTROL
287 PR#7912 and PR#8115 GS industry control.
@ SL_MIN_VERSION
First savegame version.
@ SLV_INDUSTRY_CARGO_REORGANISE
315 PR#10853 Industry accepts/produced data reorganised.
#define SLE_CONDREF(base, variable, type, from, to)
Storage of a reference in some savegame versions.
@ REF_TOWN
Load/save a reference to a town.
@ REF_STATION
Load/save a reference to a station.
@ REF_STORAGE
Load/save a reference to a persistent storage.
#define SLEG_CONDSTRUCTLIST(name, handler, from, to)
Storage of a list of structs in some savegame versions.
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Handlers and description of chunk.
void Load() const override
Load the chunk.
void Save() const override
Save the chunk.
void Save() const override
Save the chunk.
void Load() const override
Load the chunk.
void FixPointers() const override
Fix the pointers.
Industry-type build data.
void Load() const override
Load the chunk.
void Save() const override
Save the chunk.
uint32_t wanted_inds
Number of wanted industries (bits 31-16), and a fraction (bits 15-0).
IndustryTypeBuildData builddata[NUM_INDUSTRYTYPES]
Industry build data for every industry type.
Data for managing the number of industries of a single industry type.
void Reset()
Reset the entry.
std::array< ProducedHistory, 25 > history
History of cargo produced and transported for this month and 24 previous months.
Defines the internal data of a functional industry.
IndustryType type
type of industry.
PersistentStorage * psa
Persistent storage for NewGRF industries.
ProducedCargoes produced
produced cargo slots
AcceptedCargoes accepted
accepted cargo slots
static void ResetIndustryCounts()
Resets industry counts.
static void IncIndustryTypeCount(IndustryType type)
Increment the count of industries for this type.
Class for persistent storage of data.
StorageType storage
Memory for the storage array.
Class for pooled persistent storage of data.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.