industry_sl.cpp

Go to the documentation of this file.
00001 /* $Id: industry_sl.cpp 19393 2010-03-12 21:12:35Z rubidium $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #include "../stdafx.h"
00013 #include "../industry.h"
00014 #include "../newgrf_commons.h"
00015 
00016 #include "saveload.h"
00017 
00018 static const SaveLoad _industry_desc[] = {
00019   SLE_CONDVAR(Industry, location.tile,              SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
00020   SLE_CONDVAR(Industry, location.tile,              SLE_UINT32,                  6, SL_MAX_VERSION),
00021       SLE_VAR(Industry, location.w,                 SLE_FILE_U8 | SLE_VAR_U16),
00022       SLE_VAR(Industry, location.h,                 SLE_FILE_U8 | SLE_VAR_U16),
00023       SLE_REF(Industry, town,                       REF_TOWN),
00024   SLE_CONDNULL( 2, 0, 60),       
00025   SLE_CONDARR(Industry, produced_cargo,             SLE_UINT8,  2,              78, SL_MAX_VERSION),
00026   SLE_CONDARR(Industry, incoming_cargo_waiting,     SLE_UINT16, 3,              70, SL_MAX_VERSION),
00027       SLE_ARR(Industry, produced_cargo_waiting,     SLE_UINT16, 2),
00028       SLE_ARR(Industry, production_rate,            SLE_UINT8,  2),
00029   SLE_CONDNULL( 3, 0, 60),       
00030   SLE_CONDARR(Industry, accepts_cargo,              SLE_UINT8,  3,              78, SL_MAX_VERSION),
00031       SLE_VAR(Industry, prod_level,                 SLE_UINT8),
00032       SLE_ARR(Industry, this_month_production,      SLE_UINT16, 2),
00033       SLE_ARR(Industry, this_month_transported,     SLE_UINT16, 2),
00034       SLE_ARR(Industry, last_month_pct_transported, SLE_UINT8,  2),
00035       SLE_ARR(Industry, last_month_production,      SLE_UINT16, 2),
00036       SLE_ARR(Industry, last_month_transported,     SLE_UINT16, 2),
00037 
00038       SLE_VAR(Industry, counter,                    SLE_UINT16),
00039 
00040       SLE_VAR(Industry, type,                       SLE_UINT8),
00041       SLE_VAR(Industry, owner,                      SLE_UINT8),
00042       SLE_VAR(Industry, random_colour,              SLE_UINT8),
00043   SLE_CONDVAR(Industry, last_prod_year,             SLE_FILE_U8 | SLE_VAR_I32,  0, 30),
00044   SLE_CONDVAR(Industry, last_prod_year,             SLE_INT32,                 31, SL_MAX_VERSION),
00045       SLE_VAR(Industry, was_cargo_delivered,        SLE_UINT8),
00046 
00047   SLE_CONDVAR(Industry, founder,                    SLE_UINT8,                 70, SL_MAX_VERSION),
00048   SLE_CONDVAR(Industry, construction_date,          SLE_INT32,                 70, SL_MAX_VERSION),
00049   SLE_CONDVAR(Industry, construction_type,          SLE_UINT8,                 70, SL_MAX_VERSION),
00050   SLE_CONDVAR(Industry, last_cargo_accepted_at,     SLE_INT32,                 70, SL_MAX_VERSION),
00051   SLE_CONDVAR(Industry, selected_layout,            SLE_UINT8,                 73, SL_MAX_VERSION),
00052 
00053   SLE_CONDARR(Industry, psa.storage,                SLE_UINT32, 16,            76, SL_MAX_VERSION),
00054 
00055   SLE_CONDVAR(Industry, random_triggers,            SLE_UINT8,                 82, SL_MAX_VERSION),
00056   SLE_CONDVAR(Industry, random,                     SLE_UINT16,                82, SL_MAX_VERSION),
00057 
00058   /* reserve extra space in savegame here. (currently 32 bytes) */
00059   SLE_CONDNULL(32, 2, SL_MAX_VERSION),
00060 
00061   SLE_END()
00062 };
00063 
00064 static void Save_INDY()
00065 {
00066   Industry *ind;
00067 
00068   /* Write the industries */
00069   FOR_ALL_INDUSTRIES(ind) {
00070     SlSetArrayIndex(ind->index);
00071     SlObject(ind, _industry_desc);
00072   }
00073 }
00074 
00075 /* Save and load the mapping between the industry/tile id on the map, and the grf file
00076  * it came from. */
00077 static const SaveLoad _industries_id_mapping_desc[] = {
00078   SLE_VAR(EntityIDMapping, grfid,         SLE_UINT32),
00079   SLE_VAR(EntityIDMapping, entity_id,     SLE_UINT8),
00080   SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT8),
00081   SLE_END()
00082 };
00083 
00084 static void Save_IIDS()
00085 {
00086   uint i;
00087   uint j = _industry_mngr.GetMaxMapping();
00088 
00089   for (i = 0; i < j; i++) {
00090     SlSetArrayIndex(i);
00091     SlObject(&_industry_mngr.mapping_ID[i], _industries_id_mapping_desc);
00092   }
00093 }
00094 
00095 static void Save_TIDS()
00096 {
00097   uint i;
00098   uint j = _industile_mngr.GetMaxMapping();
00099 
00100   for (i = 0; i < j; i++) {
00101     SlSetArrayIndex(i);
00102     SlObject(&_industile_mngr.mapping_ID[i], _industries_id_mapping_desc);
00103   }
00104 }
00105 
00106 static void Load_INDY()
00107 {
00108   int index;
00109 
00110   ResetIndustryCounts();
00111 
00112   while ((index = SlIterateArray()) != -1) {
00113     Industry *i = new (index) Industry();
00114     SlObject(i, _industry_desc);
00115     IncIndustryTypeCount(i->type);
00116   }
00117 }
00118 
00119 static void Load_IIDS()
00120 {
00121   int index;
00122   uint max_id;
00123 
00124   /* clear the current mapping stored.
00125    * This will create the manager if ever it is not yet done */
00126   _industry_mngr.ResetMapping();
00127 
00128   /* get boundary for the temporary map loader NUM_INDUSTRYTYPES? */
00129   max_id = _industry_mngr.GetMaxMapping();
00130 
00131   while ((index = SlIterateArray()) != -1) {
00132     if ((uint)index >= max_id) break;
00133     SlObject(&_industry_mngr.mapping_ID[index], _industries_id_mapping_desc);
00134   }
00135 }
00136 
00137 static void Load_TIDS()
00138 {
00139   int index;
00140   uint max_id;
00141 
00142   /* clear the current mapping stored.
00143    * This will create the manager if ever it is not yet done */
00144   _industile_mngr.ResetMapping();
00145 
00146   /* get boundary for the temporary map loader NUM_INDUSTILES? */
00147   max_id = _industile_mngr.GetMaxMapping();
00148 
00149   while ((index = SlIterateArray()) != -1) {
00150     if ((uint)index >= max_id) break;
00151     SlObject(&_industile_mngr.mapping_ID[index], _industries_id_mapping_desc);
00152   }
00153 }
00154 
00155 static void Ptrs_INDY()
00156 {
00157   Industry *i;
00158 
00159   FOR_ALL_INDUSTRIES(i) {
00160     SlObject(i, _industry_desc);
00161   }
00162 }
00163 
00164 extern const ChunkHandler _industry_chunk_handlers[] = {
00165   { 'INDY', Save_INDY, Load_INDY, Ptrs_INDY, CH_ARRAY},
00166   { 'IIDS', Save_IIDS, Load_IIDS,      NULL, CH_ARRAY},
00167   { 'TIDS', Save_TIDS, Load_TIDS,      NULL, CH_ARRAY | CH_LAST},
00168 };

Generated on Sat Jun 19 17:14:53 2010 for OpenTTD by  doxygen 1.6.1