industry_sl.cpp

Go to the documentation of this file.
00001 /* $Id: industry_sl.cpp 15428 2009-02-09 02:57:15Z rubidium $ */
00002 
00005 #include "../stdafx.h"
00006 #include "../tile_type.h"
00007 #include "../strings_type.h"
00008 #include "../company_type.h"
00009 #include "../industry.h"
00010 #include "../newgrf_commons.h"
00011 
00012 #include "saveload.h"
00013 
00014 static const SaveLoad _industry_desc[] = {
00015   SLE_CONDVAR(Industry, xy,                         SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
00016   SLE_CONDVAR(Industry, xy,                         SLE_UINT32,                  6, SL_MAX_VERSION),
00017       SLE_VAR(Industry, width,                      SLE_UINT8),
00018       SLE_VAR(Industry, height,                     SLE_UINT8),
00019       SLE_REF(Industry, town,                       REF_TOWN),
00020   SLE_CONDNULL( 2, 0, 60),       
00021   SLE_CONDARR(Industry, produced_cargo,             SLE_UINT8,  2,              78, SL_MAX_VERSION),
00022   SLE_CONDARR(Industry, incoming_cargo_waiting,     SLE_UINT16, 3,              70, SL_MAX_VERSION),
00023       SLE_ARR(Industry, produced_cargo_waiting,     SLE_UINT16, 2),
00024       SLE_ARR(Industry, production_rate,            SLE_UINT8,  2),
00025   SLE_CONDNULL( 3, 0, 60),       
00026   SLE_CONDARR(Industry, accepts_cargo,              SLE_UINT8,  3,              78, SL_MAX_VERSION),
00027       SLE_VAR(Industry, prod_level,                 SLE_UINT8),
00028       SLE_ARR(Industry, this_month_production,      SLE_UINT16, 2),
00029       SLE_ARR(Industry, this_month_transported,     SLE_UINT16, 2),
00030       SLE_ARR(Industry, last_month_pct_transported, SLE_UINT8,  2),
00031       SLE_ARR(Industry, last_month_production,      SLE_UINT16, 2),
00032       SLE_ARR(Industry, last_month_transported,     SLE_UINT16, 2),
00033 
00034       SLE_VAR(Industry, counter,                    SLE_UINT16),
00035 
00036       SLE_VAR(Industry, type,                       SLE_UINT8),
00037       SLE_VAR(Industry, owner,                      SLE_UINT8),
00038       SLE_VAR(Industry, random_colour,              SLE_UINT8),
00039   SLE_CONDVAR(Industry, last_prod_year,             SLE_FILE_U8 | SLE_VAR_I32,  0, 30),
00040   SLE_CONDVAR(Industry, last_prod_year,             SLE_INT32,                 31, SL_MAX_VERSION),
00041       SLE_VAR(Industry, was_cargo_delivered,        SLE_UINT8),
00042 
00043   SLE_CONDVAR(Industry, founder,                    SLE_UINT8,                 70, SL_MAX_VERSION),
00044   SLE_CONDVAR(Industry, construction_date,          SLE_INT32,                 70, SL_MAX_VERSION),
00045   SLE_CONDVAR(Industry, construction_type,          SLE_UINT8,                 70, SL_MAX_VERSION),
00046   SLE_CONDVAR(Industry, last_cargo_accepted_at,     SLE_INT32,                 70, SL_MAX_VERSION),
00047   SLE_CONDVAR(Industry, selected_layout,            SLE_UINT8,                 73, SL_MAX_VERSION),
00048 
00049   SLE_CONDARRX(cpp_offsetof(Industry, psa) + cpp_offsetof(Industry::PersistentStorage, storage), SLE_UINT32, 16, 76, SL_MAX_VERSION),
00050 
00051   SLE_CONDVAR(Industry, random_triggers,            SLE_UINT8,                 82, SL_MAX_VERSION),
00052   SLE_CONDVAR(Industry, random,                     SLE_UINT16,                82, SL_MAX_VERSION),
00053 
00054   /* reserve extra space in savegame here. (currently 32 bytes) */
00055   SLE_CONDNULL(32, 2, SL_MAX_VERSION),
00056 
00057   SLE_END()
00058 };
00059 
00060 static void Save_INDY()
00061 {
00062   Industry *ind;
00063 
00064   /* Write the industries */
00065   FOR_ALL_INDUSTRIES(ind) {
00066     SlSetArrayIndex(ind->index);
00067     SlObject(ind, _industry_desc);
00068   }
00069 }
00070 
00071 /* Save and load the mapping between the industry/tile id on the map, and the grf file
00072  * it came from. */
00073 static const SaveLoad _industries_id_mapping_desc[] = {
00074   SLE_VAR(EntityIDMapping, grfid,         SLE_UINT32),
00075   SLE_VAR(EntityIDMapping, entity_id,     SLE_UINT8),
00076   SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT8),
00077   SLE_END()
00078 };
00079 
00080 static void Save_IIDS()
00081 {
00082   uint i;
00083   uint j = _industry_mngr.GetMaxMapping();
00084 
00085   for (i = 0; i < j; i++) {
00086     SlSetArrayIndex(i);
00087     SlObject(&_industry_mngr.mapping_ID[i], _industries_id_mapping_desc);
00088   }
00089 }
00090 
00091 static void Save_TIDS()
00092 {
00093   uint i;
00094   uint j = _industile_mngr.GetMaxMapping();
00095 
00096   for (i = 0; i < j; i++) {
00097     SlSetArrayIndex(i);
00098     SlObject(&_industile_mngr.mapping_ID[i], _industries_id_mapping_desc);
00099   }
00100 }
00101 
00102 static void Load_INDY()
00103 {
00104   int index;
00105 
00106   ResetIndustryCounts();
00107 
00108   while ((index = SlIterateArray()) != -1) {
00109     Industry *i = new (index) Industry();
00110     SlObject(i, _industry_desc);
00111     IncIndustryTypeCount(i->type);
00112   }
00113 }
00114 
00115 static void Load_IIDS()
00116 {
00117   int index;
00118   uint max_id;
00119 
00120   /* clear the current mapping stored.
00121    * This will create the manager if ever it is not yet done */
00122   _industry_mngr.ResetMapping();
00123 
00124   /* get boundary for the temporary map loader NUM_INDUSTRYTYPES? */
00125   max_id = _industry_mngr.GetMaxMapping();
00126 
00127   while ((index = SlIterateArray()) != -1) {
00128     if ((uint)index >= max_id) break;
00129     SlObject(&_industry_mngr.mapping_ID[index], _industries_id_mapping_desc);
00130   }
00131 }
00132 
00133 static void Load_TIDS()
00134 {
00135   int index;
00136   uint max_id;
00137 
00138   /* clear the current mapping stored.
00139    * This will create the manager if ever it is not yet done */
00140   _industile_mngr.ResetMapping();
00141 
00142   /* get boundary for the temporary map loader NUM_INDUSTILES? */
00143   max_id = _industile_mngr.GetMaxMapping();
00144 
00145   while ((index = SlIterateArray()) != -1) {
00146     if ((uint)index >= max_id) break;
00147     SlObject(&_industile_mngr.mapping_ID[index], _industries_id_mapping_desc);
00148   }
00149 }
00150 
00151 extern const ChunkHandler _industry_chunk_handlers[] = {
00152   { 'INDY', Save_INDY, Load_INDY, CH_ARRAY},
00153   { 'IIDS', Save_IIDS, Load_IIDS, CH_ARRAY},
00154   { 'TIDS', Save_TIDS, Load_TIDS, CH_ARRAY | CH_LAST},
00155 };

Generated on Mon Mar 9 23:33:50 2009 for openttd by  doxygen 1.5.6