summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-06-18 22:49:55 +0000
committerrubidium <rubidium@openttd.org>2007-06-18 22:49:55 +0000
commit7d6c255044a1e6b9a60d31468d870493270db13c (patch)
tree12388382acdeed152b3d989c6d8532a41083e4e5 /src
parentfbb22487fc5757874b119f62ab8128314d6664ab (diff)
downloadopenttd-7d6c255044a1e6b9a60d31468d870493270db13c.tar.xz
(svn r10210) -Codechange: make all money related variables 64 bits, so overflowing them should become a little harder.
Diffstat (limited to 'src')
-rw-r--r--src/economy.cpp26
-rw-r--r--src/openttd.h4
-rw-r--r--src/player.h6
-rw-r--r--src/players.cpp22
-rw-r--r--src/saveload.cpp2
-rw-r--r--src/station_cmd.cpp3
-rw-r--r--src/vehicle.cpp12
7 files changed, 42 insertions, 33 deletions
diff --git a/src/economy.cpp b/src/economy.cpp
index 078d153d6..dd51e0911 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -93,7 +93,7 @@ Money CalculateCompanyValue(const Player* p)
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, uint32 flags, uint32 p1, uint32 p2)
/** 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 */
diff --git a/src/openttd.h b/src/openttd.h
index b64c982d9..460f29bd6 100644
--- a/src/openttd.h
+++ b/src/openttd.h
@@ -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.
diff --git a/src/player.h b/src/player.h
index cf25473c6..5c0825662 100644
--- a/src/player.h
+++ b/src/player.h
@@ -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
diff --git a/src/players.cpp b/src/players.cpp
index f099008ec..56c117c94 100644
--- a/src/players.cpp
+++ b/src/players.cpp
@@ -188,11 +188,11 @@ bool CheckPlayerHasMoney(CommandCost cost)
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),
diff --git a/src/saveload.cpp b/src/saveload.cpp
index bf78d5048..902f2636a 100644
--- a/src/saveload.cpp
+++ b/src/saveload.cpp
@@ -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!
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index 529fc17bc..5dd2b2a9b 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -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()
};
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 10ab2c8b1..10c34823b 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -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),