16#include "../engine_base.h"
17#include "../string_func.h"
19#include "../safeguards.h"
21static const SaveLoad _engine_desc[] = {
48 if (index < _temp_engine.size()) {
49 return &_temp_engine[index];
50 }
else if (index == _temp_engine.size()) {
51 return &_temp_engine.emplace_back();
65 SlSetArrayIndex(e->index);
99 if (e->index >= _temp_engine.size())
break;
101 const Engine *se = GetTempDataEngine(e->index);
112 e->flags = se->
flags;
121 ResetTempEngineData();
124void ResetTempEngineData()
126 _temp_engine.clear();
127 _temp_engine.shrink_to_fit();
139 SlCopy(names.data(), std::size(names), SLE_STRINGID);
142 for (
EngineID engine = EngineID::Begin(); engine < std::size(names); ++engine) {
143 Engine *e = GetTempDataEngine(engine);
166 for (
const auto &mapping : _engine_mngr.mappings) {
167 total += std::size(mapping);
171 std::vector<EngineIDMapping> temp;
173 for (
const auto &mapping : _engine_mngr.mappings) {
174 temp.insert(std::end(temp), std::begin(mapping), std::end(mapping));
178 std::ranges::sort(temp, std::less{}, &EngineIDMapping::engine);
181 SlSetArrayIndex(eid.engine);
190 _engine_mngr.mappings = {};
constexpr Timpl & Set()
Set all bits.
constexpr Timpl & Reset(Tvalue_type value)
Reset the value-th bit.
A sort-of mixin that adds 'at(pos)' and 'operator[](pos)' implementations for 'ConvertibleThroughBase...
static const SaveLoad _engine_id_mapping_desc[]
Save and load the mapping between the engine id in the pool, and the grf file it came from.
void CopyTempEngineData()
Copy data from temporary engine array into the real engine pool.
Loading for engine chunks before table headers were added.
const SaveLoadCompat _engine_id_mapping_sl_compat[]
Original field order for _engine_id_mapping_desc.
const SaveLoadCompat _engine_sl_compat[]
Original field order for _engine_desc.
EngineFlag
Engine.flags is a bitmask, with the following values.
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
void SlCopy(void *object, size_t length, VarType conv)
Copy a list of SL_VARs to/from a savegame.
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
Functions/types related to saving and loading games.
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler 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.
@ SL_MAX_VERSION
Highest possible saveload version.
@ SL_MIN_VERSION
First savegame version.
@ CH_READONLY
Chunk is never saved.
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Declaration of functions used in more save/load files.
std::string CopyFromOldName(StringID id)
Copy and convert old custom names to UTF-8.
Handlers and description of chunk.
void Load() const override
Load the chunk.
void Save() const override
Save the chunk.
void Load() const override
Load the chunk.
void Save() const override
Save the chunk.
void Load() const override
Load the chunk.
VehicleType type
The engine type.
uint32_t grfid
The GRF ID of the file the entity belongs to.
uint8_t substitute_id
The (original) entity ID to use if this GRF is not available (currently not used)
uint16_t internal_id
The internal ID within the GRF file.
uint16_t reliability_spd_dec
Speed of reliability decay between services (per day).
uint16_t reliability_start
Initial reliability of the engine.
TimerGameCalendar::Date intro_date
Date of introduction of the engine.
EngineFlags flags
Flags of the engine.
CompanyMask company_avail
Bit for each company whether the engine is available for that company.
uint16_t reliability_max
Maximal reliability of the engine.
uint16_t reliability_final
Final reliability of the engine.
CompanyID preview_company
Company which is currently being offered a preview CompanyID::Invalid() means no company.
uint16_t duration_phase_3
Third reliability phase in months, decaying to reliability_final.
uint16_t duration_phase_2
Second reliability phase in months, keeping reliability_max.
uint8_t preview_wait
Daily countdown timer for timeout of offering the engine to the preview_company company.
CompanyMask company_hidden
Bit for each company whether the engine is normally hidden in the build gui for that company.
uint16_t reliability
Current reliability of the engine.
CompanyMask preview_asked
Bit for each company which has already been offered a preview.
int32_t age
Age of the engine in months.
std::string name
Custom name of engine.
uint16_t duration_phase_1
First reliability phase in months, increasing reliability from reliability_start to reliability_max.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.