Files @ r25756:de2f5a4c7565
Branch filter:

Location: cpp/openttd-patchpack/source/src/saveload/economy_sl.cpp - annotation

Patric Stout
Codechange: using "until" in function names can be confusing

IsSavegameVersionUntil() did a [0, N] check, not [0, N) as the
name suggests.

Until can be a confusing word, where people consider it to be
including the upperbound. Dictionary states it means "before",
excluding the upperbound. There are long debates about who is right.

So, simply remove away from this ambiguity, and call it "before"
and "before or at". This makes the world easier for everyone.
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r10571:99cb9a95b4cf
r10571:99cb9a95b4cf
r10571:99cb9a95b4cf
r25752:2d6c2238f03d
r25752:2d6c2238f03d
r25752:2d6c2238f03d
r25752:2d6c2238f03d
r10571:99cb9a95b4cf
r12269:f94731e7dc53
r10571:99cb9a95b4cf
r21383:942c32fb8b0e
r21383:942c32fb8b0e
r12930:ae0ddab1903d
r12930:ae0ddab1903d
r10571:99cb9a95b4cf
r13479:b39a51084392
r23264:b36243874b4a
r25698:2dd339d9890b
r25698:2dd339d9890b
r10571:99cb9a95b4cf
r10571:99cb9a95b4cf
r12930:ae0ddab1903d
r12930:ae0ddab1903d
r10571:99cb9a95b4cf
r23266:58eee2f3d1b6
r23264:b36243874b4a
r25698:2dd339d9890b
r25698:2dd339d9890b
r10571:99cb9a95b4cf
r10571:99cb9a95b4cf
r10571:99cb9a95b4cf
r23264:b36243874b4a
r23264:b36243874b4a
r23264:b36243874b4a
r23264:b36243874b4a
r23264:b36243874b4a
r10571:99cb9a95b4cf
r10571:99cb9a95b4cf
r10571:99cb9a95b4cf
r10571:99cb9a95b4cf
r23264:b36243874b4a
r10571:99cb9a95b4cf
r10571:99cb9a95b4cf
r10571:99cb9a95b4cf
r10571:99cb9a95b4cf
r10571:99cb9a95b4cf
r25752:2d6c2238f03d
r25752:2d6c2238f03d
r25700:e59a6326ffc3
r10571:99cb9a95b4cf
r10571:99cb9a95b4cf
r10571:99cb9a95b4cf
r10571:99cb9a95b4cf
r10571:99cb9a95b4cf
r10571:99cb9a95b4cf
r25752:2d6c2238f03d
r25752:2d6c2238f03d
r25700:e59a6326ffc3
r25752:2d6c2238f03d
r25700:e59a6326ffc3
r25700:e59a6326ffc3
r23264:b36243874b4a
r10571:99cb9a95b4cf
r10571:99cb9a95b4cf
r12269:f94731e7dc53
r20053:1f0b373e9dce
r20053:1f0b373e9dce
r20053:1f0b373e9dce
r23264:b36243874b4a
r12269:f94731e7dc53
r12269:f94731e7dc53
r12269:f94731e7dc53
r12269:f94731e7dc53
r25752:2d6c2238f03d
r25752:2d6c2238f03d
r23958:f9b8707c677f
r12269:f94731e7dc53
r12269:f94731e7dc53
r12269:f94731e7dc53
r12269:f94731e7dc53
r12269:f94731e7dc53
r12269:f94731e7dc53
r12269:f94731e7dc53
r25752:2d6c2238f03d
r25752:2d6c2238f03d
r12269:f94731e7dc53
r12269:f94731e7dc53
r12269:f94731e7dc53
r12269:f94731e7dc53
r25752:2d6c2238f03d
r12269:f94731e7dc53
r12269:f94731e7dc53
r12269:f94731e7dc53
r12269:f94731e7dc53
r12269:f94731e7dc53
r23958:f9b8707c677f
r12269:f94731e7dc53
r12269:f94731e7dc53
r12269:f94731e7dc53
r12269:f94731e7dc53
r12269:f94731e7dc53
r25596:7bf7822e5659
r25752:2d6c2238f03d
r25702:89c61c19a4db
r25702:89c61c19a4db
r25752:2d6c2238f03d
r10571:99cb9a95b4cf
r25596:7bf7822e5659
r25596:7bf7822e5659
/*
 * This file is part of OpenTTD.
 * 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.
 * 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.
 * 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/>.
 */

/** @file economy_sl.cpp Code handling saving and loading of economy data */

#include "../stdafx.h"

#include "saveload.h"
#include "compat/economy_sl_compat.h"

#include "../economy_func.h"
#include "../economy_base.h"

#include "../safeguards.h"

/** Prices in pre 126 savegames */
static void Load_PRIC()
{
	/* Old games store 49 base prices, very old games store them as int32 */
	int vt = IsSavegameVersionBefore(SLV_65) ? SLE_FILE_I32 : SLE_FILE_I64;
	SlCopy(nullptr, 49, vt | SLE_VAR_NULL);
	SlCopy(nullptr, 49, SLE_FILE_U16 | SLE_VAR_NULL);
}

/** Cargo payment rates in pre 126 savegames */
static void Load_CAPR()
{
	uint num_cargo = IsSavegameVersionBefore(SLV_55) ? 12 : IsSavegameVersionBefore(SLV_EXTEND_CARGOTYPES) ? 32 : NUM_CARGO;
	int vt = IsSavegameVersionBefore(SLV_65) ? SLE_FILE_I32 : SLE_FILE_I64;
	SlCopy(nullptr, num_cargo, vt | SLE_VAR_NULL);
	SlCopy(nullptr, num_cargo, SLE_FILE_U16 | SLE_VAR_NULL);
}

static const SaveLoad _economy_desc[] = {
	SLE_CONDVAR(Economy, old_max_loan_unround,          SLE_FILE_I32 | SLE_VAR_I64,  SL_MIN_VERSION, SLV_65),
	SLE_CONDVAR(Economy, old_max_loan_unround,          SLE_INT64,                  SLV_65, SLV_126),
	SLE_CONDVAR(Economy, old_max_loan_unround_fract,    SLE_UINT16,                 SLV_70, SLV_126),
	SLE_CONDVAR(Economy, inflation_prices,              SLE_UINT64,                SLV_126, SL_MAX_VERSION),
	SLE_CONDVAR(Economy, inflation_payment,             SLE_UINT64,                SLV_126, SL_MAX_VERSION),
	    SLE_VAR(Economy, fluct,                         SLE_INT16),
	    SLE_VAR(Economy, interest_rate,                 SLE_UINT8),
	    SLE_VAR(Economy, infl_amount,                   SLE_UINT8),
	    SLE_VAR(Economy, infl_amount_pr,                SLE_UINT8),
	SLE_CONDVAR(Economy, industry_daily_change_counter, SLE_UINT32,                SLV_102, SL_MAX_VERSION),
};

/** Economy variables */
static void Save_ECMY()
{
	SlTableHeader(_economy_desc);

	SlSetArrayIndex(0);
	SlObject(&_economy, _economy_desc);
}

/** Economy variables */
static void Load_ECMY()
{
	const std::vector<SaveLoad> slt = SlCompatTableHeader(_economy_desc, _economy_sl_compat);

	if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() == -1) return;
	SlObject(&_economy, slt);
	if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() != -1) SlErrorCorrupt("Too many ECMY entries");

	StartupIndustryDailyChanges(IsSavegameVersionBefore(SLV_102));  // old savegames will need to be initialized
}

static const SaveLoad _cargopayment_desc[] = {
	    SLE_REF(CargoPayment, front,           REF_VEHICLE),
	    SLE_VAR(CargoPayment, route_profit,    SLE_INT64),
	    SLE_VAR(CargoPayment, visual_profit,   SLE_INT64),
	SLE_CONDVAR(CargoPayment, visual_transfer, SLE_INT64, SLV_181, SL_MAX_VERSION),
};

static void Save_CAPY()
{
	SlTableHeader(_cargopayment_desc);

	for (CargoPayment *cp : CargoPayment::Iterate()) {
		SlSetArrayIndex(cp->index);
		SlObject(cp, _cargopayment_desc);
	}
}

static void Load_CAPY()
{
	const std::vector<SaveLoad> slt = SlCompatTableHeader(_cargopayment_desc, _cargopayment_sl_compat);

	int index;

	while ((index = SlIterateArray()) != -1) {
		CargoPayment *cp = new (index) CargoPayment();
		SlObject(cp, slt);
	}
}

static void Ptrs_CAPY()
{
	for (CargoPayment *cp : CargoPayment::Iterate()) {
		SlObject(cp, _cargopayment_desc);
	}
}


static const ChunkHandler economy_chunk_handlers[] = {
	{ 'CAPY', Save_CAPY, Load_CAPY, Ptrs_CAPY, nullptr, CH_TABLE },
	{ 'PRIC', nullptr,   Load_PRIC, nullptr,   nullptr, CH_READONLY  },
	{ 'CAPR', nullptr,   Load_CAPR, nullptr,   nullptr, CH_READONLY  },
	{ 'ECMY', Save_ECMY, Load_ECMY, nullptr,   nullptr, CH_TABLE },
};

extern const ChunkHandlerTable _economy_chunk_handlers(economy_chunk_handlers);