diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp --- a/src/autoreplace_cmd.cpp +++ b/src/autoreplace_cmd.cpp @@ -260,7 +260,7 @@ static CommandCost ReplaceVehicle(Vehicl /* Ensure that the player will not end up having negative money while autoreplacing * This is needed because the only other check is done after the income from selling the old vehicle is substracted from the cost */ - if (CmdFailed(tmp_move) || p->money64 < (cost.GetCost() + total_cost)) { + if (CmdFailed(tmp_move) || p->player_money < (cost.GetCost() + total_cost)) { SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES); /* Pay back the loan */ sell_value.MultiplyCost(-1); @@ -372,8 +372,8 @@ CommandCost MaybeReplaceVehicle(Vehicle cost.AddCost(temp_cost); } while (w->type == VEH_TRAIN && (w = GetNextVehicle(w)) != NULL); - if (!(flags & DC_EXEC) && (p->money64 < (int32)(cost.GetCost() + p->engine_renew_money) || cost.GetCost() == 0)) { - if (!check && p->money64 < (int32)(cost.GetCost() + p->engine_renew_money) && ( _local_player == v->owner ) && cost.GetCost() != 0) { + if (!(flags & DC_EXEC) && (p->player_money < (cost.GetCost() + p->engine_renew_money) || cost.GetCost() == 0)) { + if (!check && p->player_money < (cost.GetCost() + p->engine_renew_money) && ( _local_player == v->owner ) && cost.GetCost() != 0) { StringID message; SetDParam(0, v->unitnumber); switch (v->type) { diff --git a/src/economy.cpp b/src/economy.cpp --- a/src/economy.cpp +++ b/src/economy.cpp @@ -88,7 +88,7 @@ int64 CalculateCompanyValue(const Player } } - value += p->money64 - p->current_loan; // add real money value + value += p->player_money - p->current_loan; // add real money value return max(value, 1LL); } @@ -287,8 +287,7 @@ void ChangeOwnershipOfPlayerItems(Player * removing his/her property doesn't fail because of lack of money. * Not too drastically though, because it could overflow */ if (new_player == PLAYER_SPECTATOR) { - GetPlayer(old_player)->money64 = MAX_UVALUE(uint64) >>2; // jackpot ;p - UpdatePlayerMoney32(GetPlayer(old_player)); + GetPlayer(old_player)->player_money = MAX_UVALUE(uint64) >> 2; // jackpot ;p } if (new_player == PLAYER_SPECTATOR) { @@ -1788,9 +1787,8 @@ static void DoAcquireCompany(Player *p) for (i = 0; i != 4; i++) { if (p->share_owners[i] != PLAYER_SPECTATOR) { owner = GetPlayer(p->share_owners[i]); - owner->money64 += value; + owner->player_money += value; owner->yearly_expenses[0][EXPENSES_OTHER] += value; - UpdatePlayerMoney32(owner); } } diff --git a/src/main_gui.cpp b/src/main_gui.cpp --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -92,7 +92,7 @@ void HandleOnEditText(const char *str) #ifdef ENABLE_NETWORK case 3: { // Give money, you can only give money in excess of loan const Player *p = GetPlayer(_current_player); - int32 money = min(p->money64 - p->current_loan, atoi(str) / _currency->rate); + int32 money = min(p->player_money - p->current_loan, atoi(str) / _currency->rate); money = clamp(money, 0, 20000000); // Clamp between 20 million and 0 @@ -2208,7 +2208,7 @@ static void StatusBarWndProc(Window *w, if (p != NULL) { /* Draw player money */ - SetDParam64(0, p->money64); + SetDParam64(0, p->player_money); DrawStringCentered(570, 1, p->player_money >= 0 ? STR_0004 : STR_0005, 0); } diff --git a/src/misc_cmd.cpp b/src/misc_cmd.cpp --- a/src/misc_cmd.cpp +++ b/src/misc_cmd.cpp @@ -145,9 +145,8 @@ CommandCost CmdIncreaseLoan(TileIndex ti } if (flags & DC_EXEC) { - p->money64 += loan; + p->player_money += loan; p->current_loan += loan; - UpdatePlayerMoney32(p); InvalidatePlayerWindows(p); } @@ -185,9 +184,8 @@ CommandCost CmdDecreaseLoan(TileIndex ti } if (flags & DC_EXEC) { - p->money64 -= loan; + p->player_money -= loan; p->current_loan -= loan; - UpdatePlayerMoney32(p); InvalidatePlayerWindows(p); } return CommandCost(); @@ -311,7 +309,7 @@ CommandCost CmdGiveMoney(TileIndex tile, SET_EXPENSES_TYPE(EXPENSES_OTHER); /* You can only transfer funds that is in excess of your loan */ - if (p->money64 - p->current_loan < amount.GetCost() || amount.GetCost() <= 0) return CMD_ERROR; + if (p->player_money - p->current_loan < amount.GetCost() || amount.GetCost() <= 0) return CMD_ERROR; if (!_networking || !IsValidPlayer((PlayerID)p2)) return CMD_ERROR; if (flags & DC_EXEC) { diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -103,11 +103,10 @@ static void Place_LandInfo(TileIndex til p = GetPlayer(IsValidPlayer(_local_player) ? _local_player : PLAYER_FIRST); t = ClosestTownFromTile(tile, _patches.dist_local_authority); - old_money = p->money64; - p->money64 = p->player_money = 0x7fffffff; + old_money = p->player_money; + p->player_money = 0x7fffffff; costclear = DoCommand(tile, 0, 0, 0, CMD_LANDSCAPE_CLEAR); - p->money64 = old_money; - UpdatePlayerMoney32(p); + p->player_money = old_money; /* Because build_date is not set yet in every TileDesc, we make sure it is empty */ td.build_date = 0; diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -1278,7 +1278,7 @@ void NetworkPopulateCompanyInfo() // Set some general stuff _network_player_info[p->index].inaugurated_year = p->inaugurated_year; _network_player_info[p->index].company_value = p->old_economy[0].company_value; - _network_player_info[p->index].money = p->money64; + _network_player_info[p->index].money = p->player_money; _network_player_info[p->index].performance = p->old_economy[0].performance_history; } diff --git a/src/oldloader.cpp b/src/oldloader.cpp --- a/src/oldloader.cpp +++ b/src/oldloader.cpp @@ -954,7 +954,7 @@ static bool LoadOldPlayer(LoadgameState p->name_1 = RemapOldStringID(_old_string_id); p->president_name_1 = RemapOldStringID(_old_string_id_2); - p->money64 = p->player_money; + p->player_money = p->player_money; if (num == 0) { /* If the first player has no name, make sure we call it UNNAMED */ @@ -972,7 +972,7 @@ static bool LoadOldPlayer(LoadgameState Ps: this also means that if you had exact 893288 pounds, you will go back to 10000.. this is a very VERY small chance ;) */ if (p->player_money == 893288) - p->money64 = p->player_money = p->current_loan = 100000; + p->player_money = p->current_loan = 100000; _player_colors[num] = p->player_color; p->inaugurated_year -= ORIGINAL_BASE_YEAR; diff --git a/src/player.h b/src/player.h --- a/src/player.h +++ b/src/player.h @@ -166,9 +166,8 @@ struct Player { PlayerFace face; - int32 player_money; int32 current_loan; - int64 money64; ///< internal 64-bit version of the money. the 32-bit field will be clamped to plus minus 2 billion + int64 player_money; byte player_color; Livery livery[LS_END]; @@ -215,7 +214,6 @@ void ChangeOwnershipOfPlayerItems(Player void GetNameOfOwner(Owner owner, TileIndex tile); int64 CalculateCompanyValue(const Player* p); void InvalidatePlayerWindows(const Player* p); -void UpdatePlayerMoney32(Player *p); void SetLocalPlayer(PlayerID new_player); #define FOR_ALL_PLAYERS(p) for (p = _players; p != endof(_players); p++) diff --git a/src/player_gui.cpp b/src/player_gui.cpp --- a/src/player_gui.cpp +++ b/src/player_gui.cpp @@ -87,7 +87,7 @@ static void DrawPlayerEconomyStats(const } DrawString(2, y, STR_7026_BANK_BALANCE, 0); - SetDParam64(0, p->money64); + SetDParam64(0, p->player_money); DrawStringRightAligned(182, y, STR_7028, 0); y += 10; @@ -100,7 +100,7 @@ static void DrawPlayerEconomyStats(const GfxFillRect(182 - 75, y - 2, 182, y - 2, 215); - SetDParam64(0, p->money64 - p->current_loan); + SetDParam64(0, p->player_money - p->current_loan); DrawStringRightAligned(182, y, STR_7028, 0); } diff --git a/src/players.cpp b/src/players.cpp --- a/src/players.cpp +++ b/src/players.cpp @@ -188,8 +188,7 @@ bool CheckPlayerHasMoney(CommandCost cos static void SubtractMoneyFromAnyPlayer(Player *p, CommandCost cost) { - p->money64 -= cost.GetCost(); - UpdatePlayerMoney32(p); + p->player_money -= cost.GetCost(); p->yearly_expenses[0][_yearly_expenses_type] += cost.GetCost(); @@ -229,18 +228,6 @@ void SubtractMoneyFromPlayerFract(Player if (cost != 0) SubtractMoneyFromAnyPlayer(p, CommandCost(cost)); } -/** the player_money field is kept as it is, but money64 contains the actual amount of money. */ -void UpdatePlayerMoney32(Player *p) -{ - if (p->money64 < -2000000000) { - p->player_money = -2000000000; - } else if (p->money64 > 2000000000) { - p->player_money = 2000000000; - } else { - p->player_money = (int32)p->money64; - } -} - void GetNameOfOwner(Owner owner, TileIndex tile) { SetDParam(2, owner); @@ -474,7 +461,7 @@ Player *DoStartupNewPlayer(bool is_ai) p->name_1 = STR_SV_UNNAMED; p->is_active = true; - p->money64 = p->player_money = p->current_loan = 100000; + p->player_money = p->current_loan = 100000; p->is_ai = is_ai; p->ai.state = 5; // AIS_WANT_NEW_ROUTE @@ -1135,8 +1122,8 @@ 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, money64, SLE_VAR_I64 | SLE_FILE_I32, 0, 0), - SLE_CONDVAR(Player, money64, 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), @@ -1318,7 +1305,6 @@ static void Load_PLYR() Player *p = GetPlayer((PlayerID)index); SaveLoad_PLYR(p); _player_colors[index] = p->player_color; - UpdatePlayerMoney32(p); /* This is needed so an AI is attached to a loaded AI */ if (p->is_ai && (!_networking || _network_server) && _ai.enabled)