00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "../stdafx.h"
00013 #include "../strings_type.h"
00014 #include "../industry.h"
00015 #include "../newgrf_commons.h"
00016
00017 #include "saveload.h"
00018
00019 static const SaveLoad _industry_desc[] = {
00020 SLE_CONDVAR(Industry, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
00021 SLE_CONDVAR(Industry, xy, SLE_UINT32, 6, SL_MAX_VERSION),
00022 SLE_VAR(Industry, width, SLE_UINT8),
00023 SLE_VAR(Industry, height, SLE_UINT8),
00024 SLE_REF(Industry, town, REF_TOWN),
00025 SLE_CONDNULL( 2, 0, 60),
00026 SLE_CONDARR(Industry, produced_cargo, SLE_UINT8, 2, 78, SL_MAX_VERSION),
00027 SLE_CONDARR(Industry, incoming_cargo_waiting, SLE_UINT16, 3, 70, SL_MAX_VERSION),
00028 SLE_ARR(Industry, produced_cargo_waiting, SLE_UINT16, 2),
00029 SLE_ARR(Industry, production_rate, SLE_UINT8, 2),
00030 SLE_CONDNULL( 3, 0, 60),
00031 SLE_CONDARR(Industry, accepts_cargo, SLE_UINT8, 3, 78, SL_MAX_VERSION),
00032 SLE_VAR(Industry, prod_level, SLE_UINT8),
00033 SLE_ARR(Industry, this_month_production, SLE_UINT16, 2),
00034 SLE_ARR(Industry, this_month_transported, SLE_UINT16, 2),
00035 SLE_ARR(Industry, last_month_pct_transported, SLE_UINT8, 2),
00036 SLE_ARR(Industry, last_month_production, SLE_UINT16, 2),
00037 SLE_ARR(Industry, last_month_transported, SLE_UINT16, 2),
00038
00039 SLE_VAR(Industry, counter, SLE_UINT16),
00040
00041 SLE_VAR(Industry, type, SLE_UINT8),
00042 SLE_VAR(Industry, owner, SLE_UINT8),
00043 SLE_VAR(Industry, random_colour, SLE_UINT8),
00044 SLE_CONDVAR(Industry, last_prod_year, SLE_FILE_U8 | SLE_VAR_I32, 0, 30),
00045 SLE_CONDVAR(Industry, last_prod_year, SLE_INT32, 31, SL_MAX_VERSION),
00046 SLE_VAR(Industry, was_cargo_delivered, SLE_UINT8),
00047
00048 SLE_CONDVAR(Industry, founder, SLE_UINT8, 70, SL_MAX_VERSION),
00049 SLE_CONDVAR(Industry, construction_date, SLE_INT32, 70, SL_MAX_VERSION),
00050 SLE_CONDVAR(Industry, construction_type, SLE_UINT8, 70, SL_MAX_VERSION),
00051 SLE_CONDVAR(Industry, last_cargo_accepted_at, SLE_INT32, 70, SL_MAX_VERSION),
00052 SLE_CONDVAR(Industry, selected_layout, SLE_UINT8, 73, SL_MAX_VERSION),
00053
00054 SLE_CONDARR(Industry, psa.storage, SLE_UINT32, 16, 76, SL_MAX_VERSION),
00055
00056 SLE_CONDVAR(Industry, random_triggers, SLE_UINT8, 82, SL_MAX_VERSION),
00057 SLE_CONDVAR(Industry, random, SLE_UINT16, 82, SL_MAX_VERSION),
00058
00059
00060 SLE_CONDNULL(32, 2, SL_MAX_VERSION),
00061
00062 SLE_END()
00063 };
00064
00065 static void Save_INDY()
00066 {
00067 Industry *ind;
00068
00069
00070 FOR_ALL_INDUSTRIES(ind) {
00071 SlSetArrayIndex(ind->index);
00072 SlObject(ind, _industry_desc);
00073 }
00074 }
00075
00076
00077
00078 static const SaveLoad _industries_id_mapping_desc[] = {
00079 SLE_VAR(EntityIDMapping, grfid, SLE_UINT32),
00080 SLE_VAR(EntityIDMapping, entity_id, SLE_UINT8),
00081 SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT8),
00082 SLE_END()
00083 };
00084
00085 static void Save_IIDS()
00086 {
00087 uint i;
00088 uint j = _industry_mngr.GetMaxMapping();
00089
00090 for (i = 0; i < j; i++) {
00091 SlSetArrayIndex(i);
00092 SlObject(&_industry_mngr.mapping_ID[i], _industries_id_mapping_desc);
00093 }
00094 }
00095
00096 static void Save_TIDS()
00097 {
00098 uint i;
00099 uint j = _industile_mngr.GetMaxMapping();
00100
00101 for (i = 0; i < j; i++) {
00102 SlSetArrayIndex(i);
00103 SlObject(&_industile_mngr.mapping_ID[i], _industries_id_mapping_desc);
00104 }
00105 }
00106
00107 static void Load_INDY()
00108 {
00109 int index;
00110
00111 ResetIndustryCounts();
00112
00113 while ((index = SlIterateArray()) != -1) {
00114 Industry *i = new (index) Industry();
00115 SlObject(i, _industry_desc);
00116 IncIndustryTypeCount(i->type);
00117 }
00118 }
00119
00120 static void Load_IIDS()
00121 {
00122 int index;
00123 uint max_id;
00124
00125
00126
00127 _industry_mngr.ResetMapping();
00128
00129
00130 max_id = _industry_mngr.GetMaxMapping();
00131
00132 while ((index = SlIterateArray()) != -1) {
00133 if ((uint)index >= max_id) break;
00134 SlObject(&_industry_mngr.mapping_ID[index], _industries_id_mapping_desc);
00135 }
00136 }
00137
00138 static void Load_TIDS()
00139 {
00140 int index;
00141 uint max_id;
00142
00143
00144
00145 _industile_mngr.ResetMapping();
00146
00147
00148 max_id = _industile_mngr.GetMaxMapping();
00149
00150 while ((index = SlIterateArray()) != -1) {
00151 if ((uint)index >= max_id) break;
00152 SlObject(&_industile_mngr.mapping_ID[index], _industries_id_mapping_desc);
00153 }
00154 }
00155
00156 static void Ptrs_INDY()
00157 {
00158 Industry *i;
00159
00160 FOR_ALL_INDUSTRIES(i) {
00161 SlObject(i, _industry_desc);
00162 }
00163 }
00164
00165 extern const ChunkHandler _industry_chunk_handlers[] = {
00166 { 'INDY', Save_INDY, Load_INDY, Ptrs_INDY, CH_ARRAY},
00167 { 'IIDS', Save_IIDS, Load_IIDS, NULL, CH_ARRAY},
00168 { 'TIDS', Save_TIDS, Load_TIDS, NULL, CH_ARRAY | CH_LAST},
00169 };