# economy_sl.cpp

Go to the documentation of this file.

    00001 /* $Id: economy_sl.cpp 18008 2009-11-08 12:23:02Z frosch $ */
    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 = CheckSavegameVersion(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 = CheckSavegameVersion(55) ? 12 : NUM_CARGO;
    00031   int vt = CheckSavegameVersion(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, SL_MAX_VERSION), // 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(CheckSavegameVersion(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_END()
    00071 };
    00072
    00073 static void Save_CAPY()
    00074 {
    00075   CargoPayment *cp;
    00076   FOR_ALL_CARGO_PAYMENTS(cp) {
    00077     SlSetArrayIndex(cp->index);
    00078     SlObject(cp, _cargopayment_desc);
    00079   }
    00080 }
    00081
    00082 static void Load_CAPY()
    00083 {
    00084   int index;
    00085
    00086   while ((index = SlIterateArray()) != -1) {
    00087     CargoPayment *cp = new (index) CargoPayment();
    00088     SlObject(cp, _cargopayment_desc);
    00089   }
    00090 }
    00091
    00092 static void Ptrs_CAPY()
    00093 {
    00094   CargoPayment *cp;
    00095   FOR_ALL_CARGO_PAYMENTS(cp) {
    00096     SlObject(cp, _cargopayment_desc);
    00097   }
    00098 }
    00099
    00100
    00101 extern const ChunkHandler _economy_chunk_handlers[] = {
    00102   { 'CAPY', Save_CAPY,     Load_CAPY,     Ptrs_CAPY, CH_ARRAY},
    00103   { 'PRIC', NULL,          Load_PRIC,     NULL,      CH_RIFF | CH_AUTO_LENGTH},
    00104   { 'CAPR', NULL,          Load_CAPR,     NULL,      CH_RIFF | CH_AUTO_LENGTH},
    00105   { 'ECMY', Save_ECMY,     Load_ECMY,     NULL,      CH_RIFF | CH_LAST},
    00106 };