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
 
@@ -90,13 +90,13 @@ Money CalculateCompanyValue(const Player
 
	}
 

	
 
	/* Add real money value */
 
	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
 
 *  (also the house is updated, should only be true in the on-tick event)
 
 * @param update the economy with calculated score
 
 * @param p player been evaluated
 
@@ -1448,13 +1448,13 @@ void VehiclePayment(Vehicle *front_v)
 

	
 
			SETBIT(v->vehicle_flags, VF_CARGO_UNLOADING);
 
		}
 
	}
 

	
 
	/* 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);
 
	}
 

	
 
	if (route_profit != 0) {
 
@@ -1917,32 +1917,36 @@ CommandCost CmdBuyCompany(TileIndex tile
 
	return CommandCost(p->bankrupt_value);
 
}
 

	
 
/** 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);
 
}
 

	
 
/** Cargo payment rates */
 
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 */
 
static void SaveLoad_ECMY()
 
{
 
	SlObject(&_economy, _economy_desc);
src/openttd.h
Show inline comments
 
@@ -66,13 +66,13 @@ typedef uint16 DepotID;
 
typedef uint16 WaypointID;
 
typedef uint16 OrderID;
 
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
 
 */
 
assert_compile(sizeof(DestinationID) == sizeof(DepotID));
 
assert_compile(sizeof(DestinationID) == sizeof(WaypointID));
 
@@ -383,14 +383,12 @@ public:
 

	
 
	/**
 
	 * Creates a command return value with the given start cost
 
	 * @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.
 
	 * Also takes a possible error message when it is set.
 
	 * @param ret the command to add the cost of.
 
	 * @return this class.
src/player.h
Show inline comments
 
@@ -13,13 +13,13 @@
 

	
 
struct PlayerEconomyEntry {
 
	Money income;
 
	Money expenses;
 
	int32 delivered_cargo;
 
	int32 performance_history; ///< player score (scale 0-1000)
 
	int64 company_value;
 
	Money company_value;
 
};
 

	
 
struct AiBuildRec {
 
	TileIndex spec_tile;
 
	TileIndex use_tile;
 
	byte rand_rng;
 
@@ -163,13 +163,13 @@ struct Player {
 

	
 
	uint16 president_name_1;
 
	uint32 president_name_2;
 

	
 
	PlayerFace face;
 

	
 
	int64 player_money;
 
	Money player_money;
 
	Money current_loan;
 

	
 
	byte player_color;
 
	Livery livery[LS_END];
 
	byte player_money_fraction;
 
	byte avail_railtypes;
 
@@ -194,13 +194,13 @@ struct Player {
 

	
 
	bool is_active;
 
	bool is_ai;
 
	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
 
	bool engine_renew;
 
	bool renew_keep_length;
 
	int16 engine_renew_months;
src/players.cpp
Show inline comments
 
@@ -185,17 +185,17 @@ bool CheckPlayerHasMoney(CommandCost cos
 
	}
 
	return true;
 
}
 

	
 
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();
 

	
 
	if (HASBIT(1 << EXPENSES_TRAIN_INC    |
 
	           1 << EXPENSES_ROADVEH_INC  |
 
	           1 << EXPENSES_AIRCRAFT_INC |
 
@@ -1127,16 +1127,17 @@ static const SaveLoad _player_desc[] = {
 
	    SLE_VAR(Player, president_name_1,SLE_UINT16),
 
	    SLE_VAR(Player, president_name_2,SLE_UINT32),
 

	
 
	    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),
 
	SLE_CONDVAR(Player, avail_railtypes,       SLE_UINT8,                   0, 57),
 
	    SLE_VAR(Player, block_preview,         SLE_UINT8),
 

	
 
@@ -1152,13 +1153,14 @@ static const SaveLoad _player_desc[] = {
 

	
 
	    SLE_VAR(Player, num_valid_stat_ent,    SLE_UINT8),
 

	
 
	    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),
 
	SLE_CONDARR(Player, yearly_expenses,       SLE_INT64, 3 * 13,                  2, SL_MAX_VERSION),
 

	
 
	SLE_CONDVAR(Player, is_ai,                 SLE_BOOL, 2, SL_MAX_VERSION),
 
@@ -1177,17 +1179,17 @@ static const SaveLoad _player_desc[] = {
 

	
 
	SLE_END()
 
};
 

	
 
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),
 
	    SLE_VAR(PlayerEconomyEntry, performance_history, SLE_INT32),
 

	
 
	SLE_END()
src/saveload.cpp
Show inline comments
 
@@ -26,13 +26,13 @@
 
#include "saveload.h"
 
#include "network/network.h"
 
#include "variables.h"
 
#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!
 

	
 
typedef void WriterProc(uint len);
 
typedef uint ReaderProc();
 

	
src/station_cmd.cpp
Show inline comments
 
@@ -2914,13 +2914,14 @@ static const SaveLoad _goods_desc[] = {
 
	SLE_CONDVAR(GoodsEntry, enroute_from,       SLE_FILE_U8 | SLE_VAR_U16,  0, 6),
 
	SLE_CONDVAR(GoodsEntry, enroute_from,       SLE_UINT16,                 7, SL_MAX_VERSION),
 
	SLE_CONDVAR(GoodsEntry, enroute_from_xy,    SLE_UINT32,                44, SL_MAX_VERSION),
 
	    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()
 
};
 

	
 
static const SaveLoad _station_speclist_desc[] = {
 
	SLE_CONDVAR(StationSpecList, grfid,    SLE_UINT32, 27, SL_MAX_VERSION),
src/vehicle.cpp
Show inline comments
 
@@ -2807,17 +2807,21 @@ extern const SaveLoad _common_veh_desc[]
 
	SLE_CONDVAR(Vehicle, build_year,           SLE_INT32,                 31, SL_MAX_VERSION),
 

	
 
	    SLE_VAR(Vehicle, load_unload_time_rem, SLE_UINT16),
 
	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),
 

	
 
	    SLE_REF(Vehicle, next_shared,          REF_VEHICLE),
 
	    SLE_REF(Vehicle, prev_shared,          REF_VEHICLE),
0 comments (0 inline, 0 general)