10 #include "../stdafx.h"
15 #include "../industry.h"
18 #include "../safeguards.h"
24 inline static const SaveLoad description[] = {
31 void Save(
Industry *i)
const override
40 void Load(
Industry *i)
const override
45 for (
size_t index = 0; index < len; ++index) {
46 auto &a = i->
accepted.emplace_back();
52 static inline std::array<CargoID, INDUSTRY_NUM_INPUTS> old_cargo;
53 static inline std::array<uint16_t, INDUSTRY_NUM_INPUTS> old_waiting;
54 static inline std::array<TimerGameEconomy::Date, INDUSTRY_NUM_INPUTS> old_last_accepted;
56 static void ResetOldStructure()
58 SlIndustryAccepted::old_cargo.fill(INVALID_CARGO);
59 SlIndustryAccepted::old_waiting.fill(0);
60 SlIndustryAccepted::old_last_accepted.fill(0);
66 inline static const SaveLoad description[] = {
70 inline const static SaveLoadCompatTable compat_description = _industry_produced_history_sl_compat;
92 if (--len > p->
history.size())
break;
100 inline static const SaveLoad description[] = {
108 void Save(
Industry *i)
const override
117 void Load(
Industry *i)
const override
122 for (
size_t index = 0; index < len; ++index) {
123 auto &p = i->
produced.emplace_back();
129 static inline std::array<CargoID, INDUSTRY_NUM_OUTPUTS> old_cargo;
130 static inline std::array<uint16_t, INDUSTRY_NUM_OUTPUTS> old_waiting;
131 static inline std::array<uint8_t, INDUSTRY_NUM_OUTPUTS> old_rate;
132 static inline std::array<uint16_t, INDUSTRY_NUM_OUTPUTS> old_this_month_production;
133 static inline std::array<uint16_t, INDUSTRY_NUM_OUTPUTS> old_this_month_transported;
134 static inline std::array<uint16_t, INDUSTRY_NUM_OUTPUTS> old_last_month_production;
135 static inline std::array<uint16_t, INDUSTRY_NUM_OUTPUTS> old_last_month_transported;
137 static void ResetOldStructure()
139 SlIndustryProduced::old_cargo.fill(INVALID_CARGO);
140 SlIndustryProduced::old_waiting.fill(0);
141 SlIndustryProduced::old_rate.fill(0);
142 SlIndustryProduced::old_this_month_production.fill(0);
143 SlIndustryProduced::old_this_month_transported.fill(0);
144 SlIndustryProduced::old_last_month_production.fill(0);
145 SlIndustryProduced::old_this_month_production.fill(0);
149 static const SaveLoad _industry_desc[] = {
214 SlSetArrayIndex(ind->index);
219 void LoadMoveAcceptsProduced(
Industry *i, uint inputs, uint outputs)
const
222 for (uint j = 0; j != inputs; ++j) {
223 auto &a = i->
accepted.emplace_back();
224 a.cargo = SlIndustryAccepted::old_cargo[j];
225 a.waiting = SlIndustryAccepted::old_waiting[j];
226 a.last_accepted = SlIndustryAccepted::old_last_accepted[j];
230 for (uint j = 0; j != outputs; ++j) {
231 auto &p = i->
produced.emplace_back();
232 p.cargo = SlIndustryProduced::old_cargo[j];
233 p.waiting = SlIndustryProduced::old_waiting[j];
234 p.rate = SlIndustryProduced::old_rate[j];
235 p.history[THIS_MONTH].production = SlIndustryProduced::old_this_month_production[j];
236 p.history[THIS_MONTH].transported = SlIndustryProduced::old_this_month_transported[j];
237 p.history[LAST_MONTH].production = SlIndustryProduced::old_last_month_production[j];
238 p.history[LAST_MONTH].transported = SlIndustryProduced::old_last_month_transported[j];
248 SlIndustryAccepted::ResetOldStructure();
249 SlIndustryProduced::ResetOldStructure();
261 std::copy(std::begin(_old_ind_persistent_storage.
storage), std::end(_old_ind_persistent_storage.
storage), std::begin(i->
psa->
storage));
366 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
SaveLoadTable GetLoadDescription() const
Get the description for how to load the chunk.
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.