economy_sl.cpp

Go to the documentation of this file.
00001 /* $Id$ */
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 "../economy_func.h"
00014 #include "../economy_base.h"
00015 
00016 #include "saveload.h"
00017 
00019 static void Load_PRIC()
00020 {
00021   /* Old games store 49 base prices, very old games store them as int32 */
00022   int vt = IsSavegameVersionBefore(65) ? SLE_FILE_I32 : SLE_FILE_I64;
00023   SlArray(NULL, 49, vt | SLE_VAR_NULL);
00024   SlArray(NULL, 49, SLE_FILE_U16 | SLE_VAR_NULL);
00025 }
00026 
00028 static void Load_CAPR()
00029 {
00030   uint num_cargo = IsSavegameVersionBefore(55) ? 12 : NUM_CARGO;
00031   int vt = IsSavegameVersionBefore(65) ? SLE_FILE_I32 : SLE_FILE_I64;
00032   SlArray(NULL, num_cargo, vt | SLE_VAR_NULL);
00033   SlArray(NULL, num_cargo, SLE_FILE_U16 | SLE_VAR_NULL);
00034 }
00035 
00036 static const SaveLoad _economy_desc[] = {
00037   SLE_CONDNULL(4,                                                                  0, 64),             // max_loan
00038   SLE_CONDNULL(8,                                                                 65, 143), // max_loan
00039   SLE_CONDVAR(Economy, old_max_loan_unround,          SLE_FILE_I32 | SLE_VAR_I64,  0, 64),
00040   SLE_CONDVAR(Economy, old_max_loan_unround,          SLE_INT64,                  65, 125),
00041   SLE_CONDVAR(Economy, old_max_loan_unround_fract,    SLE_UINT16,                 70, 125),
00042   SLE_CONDVAR(Economy, inflation_prices,              SLE_UINT64,                126, SL_MAX_VERSION),
00043   SLE_CONDVAR(Economy, inflation_payment,             SLE_UINT64,                126, SL_MAX_VERSION),
00044       SLE_VAR(Economy, fluct,                         SLE_INT16),
00045       SLE_VAR(Economy, interest_rate,                 SLE_UINT8),
00046       SLE_VAR(Economy, infl_amount,                   SLE_UINT8),
00047       SLE_VAR(Economy, infl_amount_pr,                SLE_UINT8),
00048   SLE_CONDVAR(Economy, industry_daily_change_counter, SLE_UINT32,                102, SL_MAX_VERSION),
00049       SLE_END()
00050 };
00051 
00053 static void Save_ECMY()
00054 {
00055   SlObject(&_economy, _economy_desc);
00056 }
00057 
00059 static void Load_ECMY()
00060 {
00061   SlObject(&_economy, _economy_desc);
00062   StartupIndustryDailyChanges(IsSavegameVersionBefore(102));  // old savegames will need to be initialized
00063 }
00064 
00065 static const SaveLoad _cargopayment_desc[] = {
00066   SLE_REF(CargoPayment, front,         REF_VEHICLE),
00067   SLE_VAR(CargoPayment, route_profit,  SLE_INT64),
00068   SLE_VAR(CargoPayment, visual_profit, SLE_INT64),
00069 
00070   SLE_CONDVAR(CargoPayment, transfer_profit, SLE_INT64, 161, SL_MAX_VERSION),
00071 
00072   SLE_END()
00073 };
00074 
00075 static void Save_CAPY()
00076 {
00077   CargoPayment *cp;
00078   FOR_ALL_CARGO_PAYMENTS(cp) {
00079     SlSetArrayIndex(cp->index);
00080     SlObject(cp, _cargopayment_desc);
00081   }
00082 }
00083 
00084 static void Load_CAPY()
00085 {
00086   int index;
00087 
00088   while ((index = SlIterateArray()) != -1) {
00089     CargoPayment *cp = new (index) CargoPayment();
00090     SlObject(cp, _cargopayment_desc);
00091   }
00092 }
00093 
00094 static void Ptrs_CAPY()
00095 {
00096   CargoPayment *cp;
00097   FOR_ALL_CARGO_PAYMENTS(cp) {
00098     SlObject(cp, _cargopayment_desc);
00099   }
00100 }
00101 
00102 
00103 extern const ChunkHandler _economy_chunk_handlers[] = {
00104   { 'CAPY', Save_CAPY,     Load_CAPY,     Ptrs_CAPY, NULL, CH_ARRAY},
00105   { 'PRIC', NULL,          Load_PRIC,     NULL,      NULL, CH_RIFF | CH_AUTO_LENGTH},
00106   { 'CAPR', NULL,          Load_CAPR,     NULL,      NULL, CH_RIFF | CH_AUTO_LENGTH},
00107   { 'ECMY', Save_ECMY,     Load_ECMY,     NULL,      NULL, CH_RIFF | CH_LAST},
00108 };

Generated on Mon May 9 05:18:59 2011 for OpenTTD by  doxygen 1.6.1