Changeset - r6952:db104ead2672
[Not reviewed]
master
0 10 0
rubidium - 17 years ago 2007-06-18 21:00:14
rubidium@openttd.org
(svn r10207) -Codechange: remove the redundant player_money in favour of the money64, which is now renamed to player_money.
10 files changed with 24 insertions and 45 deletions:
0 comments (0 inline, 0 general)
src/autoreplace_cmd.cpp
Show inline comments
 
@@ -257,13 +257,13 @@ static CommandCost ReplaceVehicle(Vehicl
 
			tmp_move = DoCommand(0, (temp->index << 16) | old_v->next->index, 1, 0, CMD_MOVE_RAIL_VEHICLE);
 
			DoCommand(0, temp->index, 0, DC_EXEC, GetCmdSellVeh(old_v));
 
		}
 

	
 
		/* 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);
 
			SubtractMoneyFromPlayer(sell_value);
 
			return CMD_ERROR;
 
		}
 
@@ -369,14 +369,14 @@ CommandCost MaybeReplaceVehicle(Vehicle 
 
				 */
 
				v = w;
 
			}
 
			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) {
 
					case VEH_TRAIN:    message = STR_TRAIN_AUTORENEW_FAILED;       break;
 
					case VEH_ROAD:     message = STR_ROADVEHICLE_AUTORENEW_FAILED; break;
 
					case VEH_SHIP:     message = STR_SHIP_AUTORENEW_FAILED;        break;
src/economy.cpp
Show inline comments
 
@@ -85,13 +85,13 @@ int64 CalculateCompanyValue(const Player
 
					v->type == VEH_SHIP) {
 
				value += v->value * 3 >> 1;
 
			}
 
		}
 
	}
 

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

	
 
/** 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)
 
@@ -284,14 +284,13 @@ void ChangeOwnershipOfPlayerItems(Player
 
	_current_player = old_player;
 

	
 
	/* Temporarily increase the player's money, to be sure that
 
	 * 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) {
 
		Subsidy *s;
 

	
 
		for (s = _subsidies; s != endof(_subsidies); s++) {
 
@@ -1785,15 +1784,14 @@ static void DoAcquireCompany(Player *p)
 
	}
 

	
 
	value = CalculateCompanyValue(p) >> 2;
 
	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);
 
		}
 
	}
 

	
 
	p->is_active = false;
 

	
 
	DeletePlayerWindows(pi);
src/main_gui.cpp
Show inline comments
 
@@ -89,13 +89,13 @@ void HandleOnEditText(const char *str)
 
		if (*str == '\0') return;
 
		DoCommandP(0, id, 0, NULL, CMD_RENAME_WAYPOINT | CMD_MSG(STR_CANT_CHANGE_WAYPOINT_NAME));
 
		break;
 
#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
 

	
 
		/* Give 'id' the money, and substract it from ourself */
 
		DoCommandP(0, money, id, CcGiveMoney, CMD_GIVE_MONEY | CMD_MSG(STR_INSUFFICIENT_FUNDS));
 
	} break;
 
@@ -2205,13 +2205,13 @@ static void StatusBarWndProc(Window *w, 
 
		DrawStringCentered(
 
			70, 1, (_pause_game || _patches.status_long_date) ? STR_00AF : STR_00AE, 0
 
		);
 

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

	
 
		/* Draw status bar */
 
		if (w->message.msg) { // true when saving is active
 
			DrawStringCentered(320, 1, STR_SAVING_GAME, 0);
src/misc_cmd.cpp
Show inline comments
 
@@ -142,15 +142,14 @@ CommandCost CmdIncreaseLoan(TileIndex ti
 
		case 1: // Take a loan as big as possible
 
			loan = _economy.max_loan - p->current_loan;
 
			break;
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		p->money64 += loan;
 
		p->player_money += loan;
 
		p->current_loan += loan;
 
		UpdatePlayerMoney32(p);
 
		InvalidatePlayerWindows(p);
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
@@ -182,15 +181,14 @@ CommandCost CmdDecreaseLoan(TileIndex ti
 
	if (p->player_money < loan) {
 
		SetDParam(0, loan);
 
		return_cmd_error(STR_702E_REQUIRED);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		p->money64 -= loan;
 
		p->player_money -= loan;
 
		p->current_loan -= loan;
 
		UpdatePlayerMoney32(p);
 
		InvalidatePlayerWindows(p);
 
	}
 
	return CommandCost();
 
}
 

	
 
/** Change the name of the company.
 
@@ -308,13 +306,13 @@ CommandCost CmdGiveMoney(TileIndex tile,
 
	const Player *p = GetPlayer(_current_player);
 
	CommandCost amount(min((int32)p1, 20000000));
 

	
 
	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) {
 
		/* Add money to player */
 
		PlayerID old_cp = _current_player;
 
		_current_player = (PlayerID)p2;
src/misc_gui.cpp
Show inline comments
 
@@ -100,17 +100,16 @@ static void Place_LandInfo(TileIndex til
 
	w = AllocateWindowDesc(&_land_info_desc);
 
	WP(w, void_d).data = &_landinfo_data;
 

	
 
	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;
 
	GetAcceptedCargo(tile, ac);
 
	GetTileDesc(tile, &td);
 

	
src/network/network_server.cpp
Show inline comments
 
@@ -1275,13 +1275,13 @@ 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;
 
	}
 

	
 
	// Go through all vehicles and count the type of vehicles
 
	FOR_ALL_VEHICLES(v) {
 
		if (!IsValidPlayer(v->owner)) continue;
src/oldloader.cpp
Show inline comments
 
@@ -951,13 +951,13 @@ static bool LoadOldPlayer(LoadgameState 
 
	_current_player_id = (PlayerID)num;
 

	
 
	if (!LoadChunk(ls, p, player_chunk)) return false;
 

	
 
	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 */
 
		if (p->name_1 == 0)
 
			p->name_1 = STR_SV_UNNAMED;
 
	} else {
 
@@ -969,13 +969,13 @@ static bool LoadOldPlayer(LoadgameState 
 
	/* Sometimes it is better to not ask.. in old scenarios, the money
 
	was always 893288 pounds. In the newer versions this is correct,
 
	but correct for those oldies
 
	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;
 
	if (p->location_of_house == 0xFFFF)
 
		p->location_of_house = 0;
 

	
src/player.h
Show inline comments
 
@@ -163,15 +163,14 @@ struct Player {
 

	
 
	uint16 president_name_1;
 
	uint32 president_name_2;
 

	
 
	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];
 
	byte player_money_fraction;
 
	byte avail_railtypes;
 
	byte avail_roadtypes;
 
@@ -212,13 +211,12 @@ struct Player {
 
uint16 GetDrawStringPlayerColor(PlayerID player);
 

	
 
void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_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++)
 

	
 
VARDEF PlayerID _local_player;
 
VARDEF PlayerID _current_player;
 

	
src/player_gui.cpp
Show inline comments
 
@@ -84,26 +84,26 @@ static void DrawPlayerEconomyStats(const
 
		DrawString(202, y + 10, STR_MAX_LOAN, 0);
 
	} else {
 
		y = 15;
 
	}
 

	
 
	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;
 

	
 
	DrawString(2, y, STR_7027_LOAN, 0);
 
	SetDParam64(0, p->current_loan);
 
	DrawStringRightAligned(182, y, STR_7028, 0);
 

	
 
	y += 12;
 

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

	
 
static const Widget _player_finances_widgets[] = {
 
{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,               STR_018B_CLOSE_WINDOW},
 
{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   379,     0,    13, STR_700E_FINANCES,      STR_018C_WINDOW_TITLE_DRAG_THIS},
src/players.cpp
Show inline comments
 
@@ -185,14 +185,13 @@ bool CheckPlayerHasMoney(CommandCost cos
 
	}
 
	return true;
 
}
 

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

	
 
	if (HASBIT(1 << EXPENSES_TRAIN_INC    |
 
	           1 << EXPENSES_ROADVEH_INC  |
 
	           1 << EXPENSES_AIRCRAFT_INC |
 
@@ -226,24 +225,12 @@ void SubtractMoneyFromPlayerFract(Player
 
	p->player_money_fraction = m - (byte)cost;
 
	cost >>= 8;
 
	if (p->player_money_fraction > m) cost++;
 
	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);
 

	
 
	if (owner != OWNER_TOWN) {
 
		if (!IsValidPlayer(owner)) {
 
@@ -471,13 +458,13 @@ Player *DoStartupNewPlayer(bool is_ai)
 
	p->player_color = GeneratePlayerColor();
 
	ResetPlayerLivery(p);
 
	_player_colors[p->index] = p->player_color;
 
	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
 
	p->share_owners[0] = p->share_owners[1] = p->share_owners[2] = p->share_owners[3] = PLAYER_SPECTATOR;
 

	
 
	p->avail_railtypes = GetPlayerRailtypes(p->index);
 
@@ -1132,14 +1119,14 @@ 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, 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),
 

	
 
	    SLE_VAR(Player, player_color,          SLE_UINT8),
 
	    SLE_VAR(Player, player_money_fraction, SLE_UINT8),
 
	SLE_CONDVAR(Player, avail_railtypes,       SLE_UINT8,                   0, 57),
 
@@ -1315,13 +1302,12 @@ static void Load_PLYR()
 
{
 
	int index;
 
	while ((index = SlIterateArray()) != -1) {
 
		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)
 
			AI_StartNewAI(p->index);
 
	}
 
}
0 comments (0 inline, 0 general)