10 #include "../stdafx.h" 12 #include "../engine_base.h" 13 #include "../string_func.h" 16 #include "../safeguards.h" 18 static const SaveLoad _engine_desc[] = {
49 static std::vector<Engine*> _temp_engine;
58 uint8 *zero = CallocT<uint8>(
sizeof(
Engine));
77 if (index < _temp_engine.size()) {
78 return _temp_engine[index];
79 }
else if (index == _temp_engine.size()) {
81 return _temp_engine[index];
87 static void Save_ENGN()
90 SlSetArrayIndex(e->index);
95 static void Load_ENGN()
102 Engine *e = GetTempDataEngine(index);
121 if (e->index >= _temp_engine.size())
break;
123 const Engine *se = GetTempDataEngine(e->index);
134 e->flags = se->
flags;
144 for (std::vector<Engine*>::iterator it = _temp_engine.begin(); it != _temp_engine.end(); ++it) {
147 _temp_engine.clear();
150 static void Load_ENGS()
160 Engine *e = GetTempDataEngine(engine);
174 static void Save_EIDS()
178 SlSetArrayIndex(index);
179 SlObject(&eid, _engine_id_mapping_desc);
184 static void Load_EIDS()
186 _engine_mngr.clear();
189 _engine_mngr.emplace_back();
191 SlObject(eid, _engine_id_mapping_desc);
196 {
'EIDS', Save_EIDS, Load_EIDS,
nullptr,
nullptr, CH_ARRAY },
197 {
'ENGN', Save_ENGN, Load_ENGN,
nullptr,
nullptr, CH_ARRAY },
198 {
'ENGS',
nullptr, Load_ENGS,
nullptr,
nullptr, CH_RIFF |
CH_LAST },
#define SLE_CONDNULL(length, from, to)
Empty space in some savegame versions.
uint16 reliability_start
Initial reliability of the engine.
uint16 reliability
Current reliability of the engine.
void CopyTempEngineData()
Copy data from temporary engine array into the real engine pool.
static bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
2.0 0.3.0 2.1 0.3.1, 0.3.2
#define SLE_CONDSTR(base, variable, type, length, from, to)
Storage of a string in some savegame versions.
Date intro_date
Date of introduction of the engine.
char * CopyFromOldName(StringID id)
Copy and convert old custom names to UTF-8.
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...
CompanyMask company_hidden
Bit for each company whether the engine is normally hidden in the build gui for that company...
byte flags
Flags of the engine.
uint16 duration_phase_2
Second reliability phase in months, keeping reliability_max.
void SlArray(void *array, size_t length, VarType conv)
Save/Load an array.
uint16 reliability_spd_dec
Speed of reliability decay between services (per day).
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Highest possible saveload version.
uint16 duration_phase_3
Third reliability phase on months, decaying to reliability_final.
uint16 duration_phase_1
First reliability phase in months, increasing reliability from reliability_start to reliability_max...
CompanyMask company_avail
Bit for each company whether the engine is available for that company.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
uint16 reliability_max
Maximal reliability of the engine.
#define lengthof(x)
Return the length of an fixed size array.
uint16 reliability_final
Final reliability of the engine.
char * name
Custom name of engine.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Handlers and description of chunk.
#define SLE_END()
End marker of a struct/class save or load.
CompanyID preview_company
Company which is currently being offered a preview INVALID_COMPANY means no company.
byte preview_wait
Daily countdown timer for timeout of offering the engine to the preview_company company.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
uint16 EngineID
Unique identification number of an engine.
CompanyMask preview_asked
Bit for each company which has already been offered a preview.
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
static Engine * CallocEngine()
Allocate an Engine structure, but not using the pools.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
#define SLE_STR(base, variable, type, length)
Storage of a string in every savegame version.
Declaration of functions used in more save/load files.
Last chunk in this array.
static void FreeEngine(Engine *e)
Deallocate an Engine constructed by CallocEngine.