Changeset - r6955:42f59093f6f9
[Not reviewed]
master
0 7 0
rubidium - 17 years ago 2007-06-18 22:49:55
rubidium@openttd.org
(svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
7 files changed with 42 insertions and 33 deletions:
0 comments (0 inline, 0 general)
src/economy.cpp
Show inline comments
 
@@ -93,7 +93,7 @@ Money CalculateCompanyValue(const Player
 
	value.AddCost(-p->current_loan);
 
	value.AddCost(p->player_money);
 

	
 
	return max(value.GetCost(), 1);
 
	return max(value.GetCost(), 1LL);
 
}
 

	
 
/** if update is set to true, the economy is updated with this score
 
@@ -1451,7 +1451,7 @@ void VehiclePayment(Vehicle *front_v)
 
	}
 

	
 
	/* Ensure a negative total is only applied to the vehicle if there is value to reduce. */
 
	front_v->cargo_feeder_share = max(front_v->cargo_feeder_share + total_cargo_feeder_share, 0);
 
	front_v->cargo_feeder_share = max(front_v->cargo_feeder_share + total_cargo_feeder_share, 0LL);
 

	
 
	if (virtual_profit_total > 0) {
 
		ShowFeederIncomeAnimation(front_v->x_pos, front_v->y_pos, front_v->z_pos, virtual_profit_total);
 
@@ -1920,7 +1920,8 @@ CommandCost CmdBuyCompany(TileIndex tile
 
/** Prices */
 
static void SaveLoad_PRIC()
 
{
 
	SlArray(&_price,      NUM_PRICES, SLE_INT32);
 
	int vt = CheckSavegameVersion(65) ? (SLE_FILE_I32 | SLE_VAR_I64) : SLE_INT64;
 
	SlArray(&_price,      NUM_PRICES, vt);
 
	SlArray(&_price_frac, NUM_PRICES, SLE_UINT16);
 
}
 

	
 
@@ -1928,18 +1929,21 @@ static void SaveLoad_PRIC()
 
static void SaveLoad_CAPR()
 
{
 
	uint num_cargo = CheckSavegameVersion(55) ? 12 : NUM_CARGO;
 
	SlArray(&_cargo_payment_rates,      num_cargo, SLE_INT32);
 
	int vt = CheckSavegameVersion(65) ? (SLE_FILE_I32 | SLE_VAR_I64) : SLE_INT64;
 
	SlArray(&_cargo_payment_rates,      num_cargo, vt);
 
	SlArray(&_cargo_payment_rates_frac, num_cargo, SLE_UINT16);
 
}
 

	
 
static const SaveLoad _economy_desc[] = {
 
	SLE_VAR(Economy, max_loan,         SLE_INT32),
 
	SLE_VAR(Economy, max_loan_unround, SLE_INT32),
 
	SLE_VAR(Economy, fluct,            SLE_FILE_I16 | SLE_VAR_I32),
 
	SLE_VAR(Economy, interest_rate,    SLE_UINT8),
 
	SLE_VAR(Economy, infl_amount,      SLE_UINT8),
 
	SLE_VAR(Economy, infl_amount_pr,   SLE_UINT8),
 
	SLE_END()
 
	SLE_CONDVAR(Economy, max_loan,         SLE_FILE_I32 | SLE_VAR_I64,  0, 64),
 
	SLE_CONDVAR(Economy, max_loan,         SLE_INT64,                  65, SL_MAX_VERSION),
 
	SLE_CONDVAR(Economy, max_loan_unround, SLE_FILE_I32 | SLE_VAR_I64,  0, 64),
 
	SLE_CONDVAR(Economy, max_loan_unround, SLE_INT64,                  65, SL_MAX_VERSION),
 
	    SLE_VAR(Economy, fluct,            SLE_FILE_I16 | SLE_VAR_I32),
 
	    SLE_VAR(Economy, interest_rate,    SLE_UINT8),
 
	    SLE_VAR(Economy, infl_amount,      SLE_UINT8),
 
	    SLE_VAR(Economy, infl_amount_pr,   SLE_UINT8),
 
	    SLE_END()
 
};
 

	
 
/** Economy variables */
src/openttd.h
Show inline comments
 
@@ -69,7 +69,7 @@ typedef uint16 SignID;
 
typedef uint16 GroupID;
 
typedef uint16 EngineRenewID;
 
typedef uint16 DestinationID;
 
typedef int32 Money;
 
typedef int64 Money;
 

	
 
/* DestinationID must be at least as large as every these below, because it can
 
 * be any of them
 
@@ -386,8 +386,6 @@ public:
 
	 * @param cst the initial cost of this command
 
	 */
 
	CommandCost(Money cst) : cost(cst), message(INVALID_STRING_ID), success(true) {}
 
	/** "Hack" to make everything compile nicely, not needed when cost is int64 */
 
	CommandCost(uint cst) : cost(cst), message(INVALID_STRING_ID), success(true) {}
 

	
 
	/**
 
	 * Adds the cost of the given command return value to this cost.
src/player.h
Show inline comments
 
@@ -16,7 +16,7 @@ struct PlayerEconomyEntry {
 
	Money expenses;
 
	int32 delivered_cargo;
 
	int32 performance_history; ///< player score (scale 0-1000)
 
	int64 company_value;
 
	Money company_value;
 
};
 

	
 
struct AiBuildRec {
 
@@ -166,7 +166,7 @@ struct Player {
 

	
 
	PlayerFace face;
 

	
 
	int64 player_money;
 
	Money player_money;
 
	Money current_loan;
 

	
 
	byte player_color;
 
@@ -197,7 +197,7 @@ struct Player {
 
	PlayerAI ai;
 
	PlayerAiNew ainew;
 

	
 
	int64 yearly_expenses[3][13];
 
	Money yearly_expenses[3][13];
 
	PlayerEconomyEntry cur_economy;
 
	PlayerEconomyEntry old_economy[24];
 
	EngineRenewList engine_renew_list; ///< Defined later
src/players.cpp
Show inline comments
 
@@ -188,11 +188,11 @@ bool CheckPlayerHasMoney(CommandCost cos
 

	
 
static void SubtractMoneyFromAnyPlayer(Player *p, CommandCost cost)
 
{
 
	CommandCost tmp((int32)p->player_money);
 
	CommandCost tmp(p->player_money);
 
	tmp.AddCost(-cost.GetCost());
 
	p->player_money = tmp.GetCost();
 

	
 
	tmp = CommandCost((int32)p->yearly_expenses[0][_yearly_expenses_type]);
 
	tmp = CommandCost(p->yearly_expenses[0][_yearly_expenses_type]);
 
	tmp.AddCost(cost);
 
	p->yearly_expenses[0][_yearly_expenses_type] = tmp.GetCost();
 

	
 
@@ -1130,10 +1130,11 @@ static const SaveLoad _player_desc[] = {
 
	    SLE_VAR(Player, face,            SLE_UINT32),
 

	
 
	/* money was changed to a 64 bit field in savegame version 1. */
 
	SLE_CONDVAR(Player, player_money,          SLE_VAR_I64 | SLE_FILE_I32, 0, 0),
 
	SLE_CONDVAR(Player, player_money,          SLE_INT64, 1, SL_MAX_VERSION),
 
	SLE_CONDVAR(Player, player_money,          SLE_VAR_I64 | SLE_FILE_I32,  0, 0),
 
	SLE_CONDVAR(Player, player_money,          SLE_INT64,                   1, SL_MAX_VERSION),
 

	
 
	    SLE_VAR(Player, current_loan,          SLE_INT32),
 
	SLE_CONDVAR(Player, current_loan,          SLE_VAR_I64 | SLE_FILE_I32,  0, 64),
 
	SLE_CONDVAR(Player, current_loan,          SLE_INT64,                  65, SL_MAX_VERSION),
 

	
 
	    SLE_VAR(Player, player_color,          SLE_UINT8),
 
	    SLE_VAR(Player, player_money_fraction, SLE_UINT8),
 
@@ -1155,7 +1156,8 @@ static const SaveLoad _player_desc[] = {
 
	    SLE_VAR(Player, quarters_of_bankrupcy, SLE_UINT8),
 
	    SLE_VAR(Player, bankrupt_asked,        SLE_UINT8),
 
	    SLE_VAR(Player, bankrupt_timeout,      SLE_INT16),
 
	    SLE_VAR(Player, bankrupt_value,        SLE_INT32),
 
	SLE_CONDVAR(Player, bankrupt_value,        SLE_VAR_I64 | SLE_FILE_I32,  0, 64),
 
	SLE_CONDVAR(Player, bankrupt_value,        SLE_INT64,                  65, SL_MAX_VERSION),
 

	
 
	/* yearly expenses was changed to 64-bit in savegame version 2. */
 
	SLE_CONDARR(Player, yearly_expenses,       SLE_FILE_I32 | SLE_VAR_I64, 3 * 13, 0, 1),
 
@@ -1180,11 +1182,11 @@ static const SaveLoad _player_desc[] = {
 

	
 
static const SaveLoad _player_economy_desc[] = {
 
	/* these were changed to 64-bit in savegame format 2 */
 
	SLE_CONDVAR(PlayerEconomyEntry, income,              SLE_INT32,                  0, 1),
 
	SLE_CONDVAR(PlayerEconomyEntry, expenses,            SLE_INT32,                  0, 1),
 
	SLE_CONDVAR(PlayerEconomyEntry, income,              SLE_FILE_I32 | SLE_VAR_I64, 0, 1),
 
	SLE_CONDVAR(PlayerEconomyEntry, income,              SLE_INT64,                  2, SL_MAX_VERSION),
 
	SLE_CONDVAR(PlayerEconomyEntry, expenses,            SLE_FILE_I32 | SLE_VAR_I64, 0, 1),
 
	SLE_CONDVAR(PlayerEconomyEntry, expenses,            SLE_INT64,                  2, SL_MAX_VERSION),
 
	SLE_CONDVAR(PlayerEconomyEntry, company_value,       SLE_FILE_I32 | SLE_VAR_I64, 0, 1),
 
	SLE_CONDVAR(PlayerEconomyEntry, income,              SLE_FILE_I64 | SLE_VAR_I32, 2, SL_MAX_VERSION),
 
	SLE_CONDVAR(PlayerEconomyEntry, expenses,            SLE_FILE_I64 | SLE_VAR_I32, 2, SL_MAX_VERSION),
 
	SLE_CONDVAR(PlayerEconomyEntry, company_value,       SLE_INT64,                  2, SL_MAX_VERSION),
 

	
 
	    SLE_VAR(PlayerEconomyEntry, delivered_cargo,     SLE_INT32),
src/saveload.cpp
Show inline comments
 
@@ -29,7 +29,7 @@
 
#include <setjmp.h>
 
#include <list>
 

	
 
extern const uint16 SAVEGAME_VERSION = 64;
 
extern const uint16 SAVEGAME_VERSION = 65;
 
uint16 _sl_version;       ///< the major savegame version identifier
 
byte   _sl_minor_version; ///< the minor savegame version, DO NOT USE!
 

	
src/station_cmd.cpp
Show inline comments
 
@@ -2917,7 +2917,8 @@ static const SaveLoad _goods_desc[] = {
 
	    SLE_VAR(GoodsEntry, enroute_time,       SLE_UINT8),
 
	    SLE_VAR(GoodsEntry, last_speed,         SLE_UINT8),
 
	    SLE_VAR(GoodsEntry, last_age,           SLE_UINT8),
 
	SLE_CONDVAR(GoodsEntry, feeder_profit,      SLE_INT32,                 14, SL_MAX_VERSION),
 
	SLE_CONDVAR(GoodsEntry, feeder_profit,      SLE_FILE_I32 | SLE_VAR_I64,14, 64),
 
	SLE_CONDVAR(GoodsEntry, feeder_profit,      SLE_INT64,                 65, SL_MAX_VERSION),
 

	
 
	SLE_END()
 
};
src/vehicle.cpp
Show inline comments
 
@@ -2810,11 +2810,15 @@ extern const SaveLoad _common_veh_desc[]
 
	SLE_CONDVAR(Vehicle, cargo_paid_for,       SLE_UINT16,                45, SL_MAX_VERSION),
 
	SLE_CONDVAR(Vehicle, vehicle_flags,        SLE_UINT8,                 40, SL_MAX_VERSION),
 

	
 
	    SLE_VAR(Vehicle, profit_this_year,     SLE_INT32),
 
	    SLE_VAR(Vehicle, profit_last_year,     SLE_INT32),
 
	SLE_CONDVAR(Vehicle, cargo_feeder_share,   SLE_INT32,                 51, SL_MAX_VERSION),
 
	SLE_CONDVAR(Vehicle, profit_this_year,     SLE_FILE_I32 | SLE_VAR_I64, 0, 64),
 
	SLE_CONDVAR(Vehicle, profit_this_year,     SLE_INT64,                 65, SL_MAX_VERSION),
 
	SLE_CONDVAR(Vehicle, profit_last_year,     SLE_FILE_I32 | SLE_VAR_I64, 0, 64),
 
	SLE_CONDVAR(Vehicle, profit_last_year,     SLE_INT64,                 65, SL_MAX_VERSION),
 
	SLE_CONDVAR(Vehicle, cargo_feeder_share,   SLE_FILE_I32 | SLE_VAR_I64,51, 64),
 
	SLE_CONDVAR(Vehicle, cargo_feeder_share,   SLE_INT64,                 65, SL_MAX_VERSION),
 
	SLE_CONDVAR(Vehicle, cargo_loaded_at_xy,   SLE_UINT32,                51, SL_MAX_VERSION),
 
	    SLE_VAR(Vehicle, value,                SLE_UINT32),
 
	SLE_CONDVAR(Vehicle, value,                SLE_FILE_I32 | SLE_VAR_I64, 0, 64),
 
	SLE_CONDVAR(Vehicle, value,                SLE_INT64,                 65, SL_MAX_VERSION),
 

	
 
	    SLE_VAR(Vehicle, random_bits,          SLE_UINT8),
 
	    SLE_VAR(Vehicle, waiting_triggers,     SLE_UINT8),
0 comments (0 inline, 0 general)