# economy_sl.cpp

Go to the documentation of this file.

    00001 /* $Id: economy_sl.cpp 16742 2009-07-04 17:39:00Z rubidium $ */
    00002
    00005 #include "../stdafx.h"
    00006 #include "../economy_func.h"
    00007 #include "../economy_base.h"
    00008
    00009 #include "saveload.h"
    00010
    00011 bool _cargo_payment_savegame = false;
    00012
    00014 static void SaveLoad_PRIC()
    00015 {
    00016   int vt = CheckSavegameVersion(65) ? (SLE_FILE_I32 | SLE_VAR_I64) : SLE_INT64;
    00017   SlArray(&_price,      NUM_PRICES, vt);
    00018   SlArray(&_price_frac, NUM_PRICES, SLE_UINT16);
    00019 }
    00020
    00022 static void SaveLoad_CAPR()
    00023 {
    00024   uint num_cargo = CheckSavegameVersion(55) ? 12 : NUM_CARGO;
    00025   int vt = CheckSavegameVersion(65) ? (SLE_FILE_I32 | SLE_VAR_I64) : SLE_INT64;
    00026   SlArray(&_cargo_payment_rates,      num_cargo, vt);
    00027   SlArray(&_cargo_payment_rates_frac, num_cargo, SLE_UINT16);
    00028 }
    00029
    00030 static const SaveLoad _economy_desc[] = {
    00031   SLE_CONDVAR(Economy, max_loan,                      SLE_FILE_I32 | SLE_VAR_I64,  0, 64),
    00032   SLE_CONDVAR(Economy, max_loan,                      SLE_INT64,                  65, SL_MAX_VERSION),
    00033   SLE_CONDVAR(Economy, max_loan_unround,              SLE_FILE_I32 | SLE_VAR_I64,  0, 64),
    00034   SLE_CONDVAR(Economy, max_loan_unround,              SLE_INT64,                  65, SL_MAX_VERSION),
    00035   SLE_CONDVAR(Economy, max_loan_unround_fract,        SLE_UINT16,                 70, SL_MAX_VERSION),
    00036       SLE_VAR(Economy, fluct,                         SLE_INT16),
    00037       SLE_VAR(Economy, interest_rate,                 SLE_UINT8),
    00038       SLE_VAR(Economy, infl_amount,                   SLE_UINT8),
    00039       SLE_VAR(Economy, infl_amount_pr,                SLE_UINT8),
    00040   SLE_CONDVAR(Economy, industry_daily_change_counter, SLE_UINT32,                102, SL_MAX_VERSION),
    00041       SLE_END()
    00042 };
    00043
    00045 static void Save_ECMY()
    00046 {
    00047   SlObject(&_economy, _economy_desc);
    00048 }
    00049
    00051 static void Load_ECMY()
    00052 {
    00053   SlObject(&_economy, _economy_desc);
    00054   StartupIndustryDailyChanges(CheckSavegameVersion(102));  // old savegames will need to be initialized
    00055 }
    00056
    00057 static const SaveLoad _cargopayment_desc[] = {
    00058   SLE_REF(CargoPayment, front,         REF_VEHICLE),
    00059   SLE_VAR(CargoPayment, route_profit,  SLE_INT64),
    00060   SLE_VAR(CargoPayment, visual_profit, SLE_INT64),
    00061
    00062   SLE_END()
    00063 };
    00064
    00065 static void Save_CAPY()
    00066 {
    00067   CargoPayment *cp;
    00068   FOR_ALL_CARGO_PAYMENTS(cp) {
    00069     SlSetArrayIndex(cp->index);
    00070     SlObject(cp, _cargopayment_desc);
    00071   }
    00072 }
    00073
    00074 static void Load_CAPY()
    00075 {
    00076   int index;
    00077
    00078   while ((index = SlIterateArray()) != -1) {
    00079     CargoPayment *cp = new (index) CargoPayment();
    00080     SlObject(cp, _cargopayment_desc);
    00081   }
    00082
    00083   _cargo_payment_savegame = true;
    00084 }
    00085
    00086 extern const ChunkHandler _economy_chunk_handlers[] = {
    00087   { 'CAPY', Save_CAPY,     Load_CAPY,     CH_ARRAY},
    00088   { 'PRIC', SaveLoad_PRIC, SaveLoad_PRIC, CH_RIFF | CH_AUTO_LENGTH},
    00089   { 'CAPR', SaveLoad_CAPR, SaveLoad_CAPR, CH_RIFF | CH_AUTO_LENGTH},
    00090   { 'ECMY', Save_ECMY,     Load_ECMY,     CH_RIFF | CH_LAST},
    00091 };