From 91233ea596aa3cdf00447b23d68cae6083efb6bb Mon Sep 17 00:00:00 2001 From: smatz Date: Sun, 4 Jan 2009 15:32:25 +0000 Subject: (svn r14828) -Codechange: move most of save/load-specific code to separate files --- src/engine.cpp | 111 --------------------------------------------------------- 1 file changed, 111 deletions(-) (limited to 'src/engine.cpp') diff --git a/src/engine.cpp b/src/engine.cpp index 564ff33f5..c8a256f10 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -9,7 +9,6 @@ #include "company_func.h" #include "command_func.h" #include "news_func.h" -#include "saveload.h" #include "variables.h" #include "train.h" #include "aircraft.h" @@ -27,7 +26,6 @@ #include "oldpool_func.h" #include "core/alloc_func.hpp" #include "vehicle_func.h" -#include #include "table/strings.h" #include "table/engines.h" @@ -613,112 +611,3 @@ CargoID GetEngineCargoType(EngineID engine) default: NOT_REACHED(); return CT_INVALID; } } - -static const SaveLoad _engine_desc[] = { - SLE_CONDVAR(Engine, intro_date, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), - SLE_CONDVAR(Engine, intro_date, SLE_INT32, 31, SL_MAX_VERSION), - SLE_CONDVAR(Engine, age, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), - SLE_CONDVAR(Engine, age, SLE_INT32, 31, SL_MAX_VERSION), - SLE_VAR(Engine, reliability, SLE_UINT16), - SLE_VAR(Engine, reliability_spd_dec, SLE_UINT16), - SLE_VAR(Engine, reliability_start, SLE_UINT16), - SLE_VAR(Engine, reliability_max, SLE_UINT16), - SLE_VAR(Engine, reliability_final, SLE_UINT16), - SLE_VAR(Engine, duration_phase_1, SLE_UINT16), - SLE_VAR(Engine, duration_phase_2, SLE_UINT16), - SLE_VAR(Engine, duration_phase_3, SLE_UINT16), - - SLE_VAR(Engine, lifelength, SLE_UINT8), - SLE_VAR(Engine, flags, SLE_UINT8), - SLE_VAR(Engine, preview_company_rank,SLE_UINT8), - SLE_VAR(Engine, preview_wait, SLE_UINT8), - SLE_CONDNULL(1, 0, 44), - SLE_CONDVAR(Engine, company_avail, SLE_FILE_U8 | SLE_VAR_U16, 0, 103), - SLE_CONDVAR(Engine, company_avail, SLE_UINT16, 104, SL_MAX_VERSION), - SLE_CONDSTR(Engine, name, SLE_STR, 0, 84, SL_MAX_VERSION), - - /* reserve extra space in savegame here. (currently 16 bytes) */ - SLE_CONDNULL(16, 2, SL_MAX_VERSION), - - SLE_END() -}; - -static std::map _temp_engine; - -Engine *GetTempDataEngine(EngineID index) -{ - return &_temp_engine[index]; -} - -static void Save_ENGN() -{ - Engine *e; - FOR_ALL_ENGINES(e) { - SlSetArrayIndex(e->index); - SlObject(e, _engine_desc); - } -} - -static void Load_ENGN() -{ - /* As engine data is loaded before engines are initialized we need to load - * this information into a temporary array. This is then copied into the - * engine pool after processing NewGRFs by CopyTempEngineData(). */ - int index; - while ((index = SlIterateArray()) != -1) { - Engine *e = GetTempDataEngine(index); - SlObject(e, _engine_desc); - } -} - -/** - * Copy data from temporary engine array into the real engine pool. - */ -void CopyTempEngineData() -{ - Engine *e; - FOR_ALL_ENGINES(e) { - if (e->index >= _temp_engine.size()) break; - - const Engine *se = GetTempDataEngine(e->index); - e->intro_date = se->intro_date; - e->age = se->age; - e->reliability = se->reliability; - e->reliability_spd_dec = se->reliability_spd_dec; - e->reliability_start = se->reliability_start; - e->reliability_max = se->reliability_max; - e->reliability_final = se->reliability_final; - e->duration_phase_1 = se->duration_phase_1; - e->duration_phase_2 = se->duration_phase_2; - e->duration_phase_3 = se->duration_phase_3; - e->lifelength = se->lifelength; - e->flags = se->flags; - e->preview_company_rank= se->preview_company_rank; - e->preview_wait = se->preview_wait; - e->company_avail = se->company_avail; - if (se->name != NULL) e->name = strdup(se->name); - } - - /* Get rid of temporary data */ - _temp_engine.clear(); -} - -static void Load_ENGS() -{ - /* Load old separate String ID list into a temporary array. This - * was always 256 entries. */ - StringID names[256]; - - SlArray(names, lengthof(names), SLE_STRINGID); - - /* Copy each string into the temporary engine array. */ - for (EngineID engine = 0; engine < lengthof(names); engine++) { - Engine *e = GetTempDataEngine(engine); - e->name = CopyFromOldName(names[engine]); - } -} - -extern const ChunkHandler _engine_chunk_handlers[] = { - { 'ENGN', Save_ENGN, Load_ENGN, CH_ARRAY }, - { 'ENGS', NULL, Load_ENGS, CH_RIFF | CH_LAST }, -}; -- cgit v1.2.3-54-g00ecf