00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "../stdafx.h"
00013 #include "../industry.h"
00014 #include "../newgrf.h"
00015
00016 #include "saveload.h"
00017 #include "newgrf_sl.h"
00018
00019 static OldPersistentStorage _old_ind_persistent_storage;
00020
00021 static const SaveLoad _industry_desc[] = {
00022 SLE_CONDVAR(Industry, location.tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
00023 SLE_CONDVAR(Industry, location.tile, SLE_UINT32, 6, SL_MAX_VERSION),
00024 SLE_VAR(Industry, location.w, SLE_FILE_U8 | SLE_VAR_U16),
00025 SLE_VAR(Industry, location.h, SLE_FILE_U8 | SLE_VAR_U16),
00026 SLE_REF(Industry, town, REF_TOWN),
00027 SLE_CONDNULL( 2, 0, 60),
00028 SLE_CONDARR(Industry, produced_cargo, SLE_UINT8, 2, 78, SL_MAX_VERSION),
00029 SLE_CONDARR(Industry, incoming_cargo_waiting, SLE_UINT16, 3, 70, SL_MAX_VERSION),
00030 SLE_ARR(Industry, produced_cargo_waiting, SLE_UINT16, 2),
00031 SLE_ARR(Industry, production_rate, SLE_UINT8, 2),
00032 SLE_CONDNULL( 3, 0, 60),
00033 SLE_CONDARR(Industry, accepts_cargo, SLE_UINT8, 3, 78, SL_MAX_VERSION),
00034 SLE_VAR(Industry, prod_level, SLE_UINT8),
00035 SLE_ARR(Industry, this_month_production, SLE_UINT16, 2),
00036 SLE_ARR(Industry, this_month_transported, SLE_UINT16, 2),
00037 SLE_ARR(Industry, last_month_pct_transported, SLE_UINT8, 2),
00038 SLE_ARR(Industry, last_month_production, SLE_UINT16, 2),
00039 SLE_ARR(Industry, last_month_transported, SLE_UINT16, 2),
00040
00041 SLE_VAR(Industry, counter, SLE_UINT16),
00042
00043 SLE_VAR(Industry, type, SLE_UINT8),
00044 SLE_VAR(Industry, owner, SLE_UINT8),
00045 SLE_VAR(Industry, random_colour, SLE_UINT8),
00046 SLE_CONDVAR(Industry, last_prod_year, SLE_FILE_U8 | SLE_VAR_I32, 0, 30),
00047 SLE_CONDVAR(Industry, last_prod_year, SLE_INT32, 31, SL_MAX_VERSION),
00048 SLE_VAR(Industry, was_cargo_delivered, SLE_UINT8),
00049
00050 SLE_CONDVAR(Industry, founder, SLE_UINT8, 70, SL_MAX_VERSION),
00051 SLE_CONDVAR(Industry, construction_date, SLE_INT32, 70, SL_MAX_VERSION),
00052 SLE_CONDVAR(Industry, construction_type, SLE_UINT8, 70, SL_MAX_VERSION),
00053 SLE_CONDVAR(Industry, last_cargo_accepted_at, SLE_INT32, 70, SL_MAX_VERSION),
00054 SLE_CONDVAR(Industry, selected_layout, SLE_UINT8, 73, SL_MAX_VERSION),
00055
00056 SLEG_CONDARR(_old_ind_persistent_storage.storage, SLE_UINT32, 16, 76, 160),
00057 SLE_CONDREF(Industry, psa, REF_STORAGE, 161, SL_MAX_VERSION),
00058
00059 SLE_CONDVAR(Industry, random_triggers, SLE_UINT8, 82, SL_MAX_VERSION),
00060 SLE_CONDVAR(Industry, random, SLE_UINT16, 82, SL_MAX_VERSION),
00061
00062 SLE_CONDNULL(32, 2, 143),
00063
00064 SLE_END()
00065 };
00066
00067 static void Save_INDY()
00068 {
00069 Industry *ind;
00070
00071
00072 FOR_ALL_INDUSTRIES(ind) {
00073 SlSetArrayIndex(ind->index);
00074 SlObject(ind, _industry_desc);
00075 }
00076 }
00077
00078 static void Save_IIDS()
00079 {
00080 Save_NewGRFMapping(_industry_mngr);
00081 }
00082
00083 static void Save_TIDS()
00084 {
00085 Save_NewGRFMapping(_industile_mngr);
00086 }
00087
00088 static void Load_INDY()
00089 {
00090 int index;
00091
00092 Industry::ResetIndustryCounts();
00093
00094 while ((index = SlIterateArray()) != -1) {
00095 Industry *i = new (index) Industry();
00096 SlObject(i, _industry_desc);
00097
00098
00099 if (IsSavegameVersionBefore(161) && !IsSavegameVersionBefore(76)) {
00100
00101 assert(PersistentStorage::CanAllocateItem());
00102 i->psa = new PersistentStorage(0);
00103 memcpy(i->psa->storage, _old_ind_persistent_storage.storage, sizeof(i->psa->storage));
00104 }
00105 Industry::IncIndustryTypeCount(i->type);
00106 }
00107 }
00108
00109 static void Load_IIDS()
00110 {
00111 Load_NewGRFMapping(_industry_mngr);
00112 }
00113
00114 static void Load_TIDS()
00115 {
00116 Load_NewGRFMapping(_industile_mngr);
00117 }
00118
00119 static void Ptrs_INDY()
00120 {
00121 Industry *i;
00122
00123 FOR_ALL_INDUSTRIES(i) {
00124 SlObject(i, _industry_desc);
00125 }
00126 }
00127
00129 static const SaveLoad _industry_builder_desc[] = {
00130 SLEG_VAR(_industry_builder.wanted_inds, SLE_UINT32),
00131 SLEG_END()
00132 };
00133
00135 static void LoadSave_IBLD()
00136 {
00137 SlGlobList(_industry_builder_desc);
00138 }
00139
00141 static const SaveLoad _industrytype_builder_desc[] = {
00142 SLE_VAR(IndustryTypeBuildData, probability, SLE_UINT32),
00143 SLE_VAR(IndustryTypeBuildData, min_number, SLE_UINT8),
00144 SLE_VAR(IndustryTypeBuildData, target_count, SLE_UINT16),
00145 SLE_VAR(IndustryTypeBuildData, max_wait, SLE_UINT16),
00146 SLE_VAR(IndustryTypeBuildData, wait_count, SLE_UINT16),
00147 SLE_END()
00148 };
00149
00151 static void Save_ITBL()
00152 {
00153 for (int i = 0; i < NUM_INDUSTRYTYPES; i++) {
00154 SlSetArrayIndex(i);
00155 SlObject(_industry_builder.builddata + i, _industrytype_builder_desc);
00156 }
00157 }
00158
00160 static void Load_ITBL()
00161 {
00162 int index;
00163 for (int i = 0; i < NUM_INDUSTRYTYPES; i++) {
00164 index = SlIterateArray();
00165 assert(index == i);
00166 SlObject(_industry_builder.builddata + i, _industrytype_builder_desc);
00167 }
00168 index = SlIterateArray();
00169 assert(index == -1);
00170 }
00171
00172 extern const ChunkHandler _industry_chunk_handlers[] = {
00173 { 'INDY', Save_INDY, Load_INDY, Ptrs_INDY, NULL, CH_ARRAY},
00174 { 'IIDS', Save_IIDS, Load_IIDS, NULL, NULL, CH_ARRAY},
00175 { 'TIDS', Save_TIDS, Load_TIDS, NULL, NULL, CH_ARRAY},
00176 { 'IBLD', LoadSave_IBLD, LoadSave_IBLD, NULL, NULL, CH_RIFF},
00177 { 'ITBL', Save_ITBL, Load_ITBL, NULL, NULL, CH_ARRAY | CH_LAST},
00178 };