Changeset - r5376:226f4edfd4b1
[Not reviewed]
master
0 7 0
rubidium - 17 years ago 2006-12-26 12:56:48
rubidium@openttd.org
(svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
7 files changed with 58 insertions and 29 deletions:
0 comments (0 inline, 0 general)
economy.c
Show inline comments
 
@@ -417,13 +417,14 @@ static void PlayersCheckBankrupt(Player 
 
				 * he/she is no long in control of this company */
 
				if (!_networking) {
 
					p->bankrupt_asked = 0xFF;
 
					p->bankrupt_timeout = 0x456;
 
					break;
 
				} else if (owner == _local_player) {
 
					_local_player = _network_playas = PLAYER_SPECTATOR;
 
					_network_playas = PLAYER_SPECTATOR;
 
					SetLocalPlayer(PLAYER_SPECTATOR);
 
				}
 

	
 
#ifdef ENABLE_NETWORK
 
				/* The server has to handle all administrative issues, for example
 
				 * updating and notifying all clients of what has happened */
 
				if (_network_server) {
genworld.c
Show inline comments
 
@@ -130,13 +130,13 @@ static void *_GenerateWorld(void *arg)
 
			RunTileLoop();
 
			IncreaseGeneratingWorldProgress(GWP_RUNTILELOOP);
 
		}
 
	}
 

	
 
	ResetObjectToPlace();
 
	_local_player = _gw.lp;
 
	SetLocalPlayer(_gw.lp);
 

	
 
	SetGeneratingWorldProgress(GWP_GAME_START, 1);
 
	/* Call any callback */
 
	if (_gw.proc != NULL) _gw.proc();
 
	IncreaseGeneratingWorldProgress(GWP_GAME_START);
 

	
 
@@ -246,13 +246,13 @@ void GenerateWorld(int mode, uint size_x
 
	_gw.lp     = _local_player;
 
	_gw.wait_for_draw = false;
 
	_gw.quit_thread   = false;
 
	_gw.threaded      = true;
 

	
 
	/* This disables some commands and stuff */
 
	_local_player   = PLAYER_SPECTATOR;
 
	SetLocalPlayer(PLAYER_SPECTATOR);
 
	/* Make sure everything is done via OWNER_NONE */
 
	_current_player = OWNER_NONE;
 

	
 
	/* Set the date before loading sprites as some newgrfs check it */
 
	SetDate(ConvertYMDToDate(_patches.starting_year, 0, 1));
 

	
misc_gui.c
Show inline comments
 
@@ -1644,13 +1644,14 @@ static int32 ClickMoneyCheat(int32 p1, i
 

	
 
// p1 player to set to, p2 is -1 or +1 (down/up)
 
static int32 ClickChangePlayerCheat(int32 p1, int32 p2)
 
{
 
	while (IsValidPlayer((PlayerID)p1)) {
 
		if (_players[p1].is_active) {
 
			_local_player = (PlayerID)p1;
 
			SetLocalPlayer((PlayerID)p1);
 

	
 
			MarkWholeScreenDirty();
 
			return _local_player;
 
		}
 
		p1 += p2;
 
	}
 

	
network_client.c
Show inline comments
 
@@ -506,28 +506,25 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER
 

	
 
		/* New company/spectator (invalid player) or company we want to join is not active
 
		 * Switch local player to spectator and await the server's judgement */
 
		if (_network_playas == PLAYER_NEW_COMPANY || !IsValidPlayer(_network_playas) ||
 
				!GetPlayer(_network_playas)->is_active) {
 

	
 
			_local_player = PLAYER_SPECTATOR;
 
			SetLocalPlayer(PLAYER_SPECTATOR);
 

	
 
			if (_network_playas == PLAYER_SPECTATOR) {
 
				// The client wants to be a spectator..
 
				DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
 
			} else {
 
				/* We have arrived and ready to start playing; send a command to make a new player;
 
				 * the server will give us a client-id and let us in */
 
				NetworkSend_Command(0, 0, 0, CMD_PLAYER_CTRL, NULL);
 
			}
 
		} else {
 
			// take control over an existing company
 
			_local_player = _network_playas;
 
			_patches.autorenew = GetPlayer(_local_player)->engine_renew;
 
			_patches.autorenew_months = GetPlayer(_local_player)->engine_renew_months;
 
			_patches.autorenew_money = GetPlayer(_local_player)->engine_renew_money;
 
			SetLocalPlayer(_network_playas);
 
			DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
 
		}
 
	}
 

	
 
	return NETWORK_RECV_STATUS_OKAY;
 
}
openttd.c
Show inline comments
 
@@ -298,13 +298,13 @@ static void LoadIntroGame(void)
 
	if (SaveOrLoad(filename, SL_LOAD) != SL_OK) {
 
		GenerateWorld(GW_EMPTY, 64, 64); // if failed loading, make empty world.
 
		WaitTillGeneratedWorld();
 
	}
 

	
 
	_pause = 0;
 
	_local_player = 0;
 
	SetLocalPlayer(0);
 
	/* Make sure you can't scroll in the menu */
 
	_scrolling_viewport = 0;
 
	_cursor.fix_at = false;
 
	MarkWholeScreenDirty();
 

	
 
	// Play main theme
 
@@ -592,20 +592,20 @@ static void ShowScreenshotResult(bool b)
 
}
 

	
 
static void MakeNewGameDone(void)
 
{
 
	/* In a dedicated server, the server does not play */
 
	if (_network_dedicated) {
 
		_local_player = PLAYER_SPECTATOR;
 
		SetLocalPlayer(PLAYER_SPECTATOR);
 
		return;
 
	}
 

	
 
	/* Create a single player */
 
	DoStartupNewPlayer(false);
 

	
 
	_local_player = 0;
 
	SetLocalPlayer(0);
 
	_current_player = _local_player;
 
	DoCommandP(0, (_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4, _patches.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
 

	
 
	SettingsDisableElrail(_patches.disable_elrails);
 

	
 
	MarkWholeScreenDirty();
 
@@ -620,13 +620,13 @@ static void MakeNewGame(bool from_height
 
	GenerateWorldSetCallback(&MakeNewGameDone);
 
	GenerateWorld(from_heightmap ? GW_HEIGHTMAP : GW_NEWGAME, 1 << _patches.map_x, 1 << _patches.map_y);
 
}
 

	
 
static void MakeNewEditorWorldDone(void)
 
{
 
	_local_player = OWNER_NONE;
 
	SetLocalPlayer(OWNER_NONE);
 

	
 
	MarkWholeScreenDirty();
 
}
 

	
 
static void MakeNewEditorWorld(void)
 
{
 
@@ -679,13 +679,13 @@ static void StartScenario(void)
 
	// Inititalize data
 
	StartupEconomy();
 
	StartupPlayers();
 
	StartupEngines();
 
	StartupDisasters();
 

	
 
	_local_player = 0;
 
	SetLocalPlayer(0);
 
	_current_player = _local_player;
 
	DoCommandP(0, (_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4, _patches.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
 

	
 
	MarkWholeScreenDirty();
 
}
 

	
 
@@ -770,13 +770,13 @@ void SwitchMode(int new_mode)
 
		if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL)) {
 
			LoadIntroGame();
 
			ShowErrorMessage(INVALID_STRING_ID, STR_4009_GAME_LOAD_FAILED, 0, 0);
 
		} else {
 
			/* Update the local player for a loaded game. It is either always
 
			 * player #1 (eg 0) or in the case of a dedicated server a spectator */
 
			_local_player = _network_dedicated ? PLAYER_SPECTATOR : 0;
 
			SetLocalPlayer(_network_dedicated ? PLAYER_SPECTATOR : 0);
 
			DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // decrease pause counter (was increased from opening load dialog)
 
#ifdef ENABLE_NETWORK
 
			if (_network_server) {
 
				snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Loaded game)", _file_to_saveload.title);
 
			}
 
#endif /* ENABLE_NETWORK */
 
@@ -791,25 +791,25 @@ void SwitchMode(int new_mode)
 
		}
 
#endif /* ENABLE_NETWORK */
 
		MakeNewGame(true);
 
		break;
 

	
 
	case SM_LOAD_HEIGHTMAP: /* Load heightmap from scenario editor */
 
		_local_player = OWNER_NONE;
 
		SetLocalPlayer(OWNER_NONE);
 

	
 
		GenerateWorld(GW_HEIGHTMAP, 1 << _patches.map_x, 1 << _patches.map_y);
 
		MarkWholeScreenDirty();
 
		break;
 

	
 
	case SM_LOAD_SCENARIO: { /* Load scenario from scenario editor */
 
		if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR)) {
 
			Player *p;
 

	
 
			_opt_ptr = &_opt;
 

	
 
			_local_player = OWNER_NONE;
 
			SetLocalPlayer(OWNER_NONE);
 
			_generating_world = true;
 
			/* Delete all players */
 
			FOR_ALL_PLAYERS(p) {
 
				if (p->is_active) {
 
					ChangeOwnershipOfPlayerItems(p->index, PLAYER_SPECTATOR);
 
					p->is_active = false;
 
@@ -835,13 +835,13 @@ void SwitchMode(int new_mode)
 
		} else {
 
			DeleteWindowById(WC_SAVELOAD, 0);
 
		}
 
		break;
 

	
 
	case SM_GENRANDLAND: /* Generate random land within scenario editor */
 
		_local_player = OWNER_NONE;
 
		SetLocalPlayer(OWNER_NONE);
 
		GenerateWorld(GW_RANDOM, 1 << _patches.map_x, 1 << _patches.map_y);
 
		// XXX: set date
 
		MarkWholeScreenDirty();
 
		break;
 
	}
 

	
 
@@ -1272,24 +1272,29 @@ bool AfterLoadGame(void)
 
	}
 

	
 
	/* From version 16.0, we included autorenew on engines, which are now saved, but
 
	 *  of course, we do need to initialize them for older savegames. */
 
	if (CheckSavegameVersion(16)) {
 
		FOR_ALL_PLAYERS(p) {
 
			p->engine_renew_list = NULL;
 
			p->engine_renew = false;
 
			p->engine_renew_list   = NULL;
 
			p->engine_renew        = false;
 
			p->engine_renew_months = -6;
 
			p->engine_renew_money = 100000;
 
			p->engine_renew_money  = 100000;
 
		}
 
		if (IsValidPlayer(_local_player)) {
 
			// Set the human controlled player to the patch settings
 
			// Scenario editor do not have any companies
 
			p = GetPlayer(_local_player);
 
			p->engine_renew = _patches.autorenew;
 

	
 
		/* When loading a game, _local_player is not yet set to the correct value.
 
		 * However, in a dedicated server we are a spectator, so nothing needs to
 
		 * happen. In case we are not a dedicated server, the local player always
 
		 * becomes player 0, unless we are in the scenario editor where all the
 
		 * players are 'invalid'.
 
		 */
 
		if (!_network_dedicated && IsValidPlayer(0)) {
 
			p = GetPlayer(0);
 
			p->engine_renew        = _patches.autorenew;
 
			p->engine_renew_months = _patches.autorenew_months;
 
			p->engine_renew_money = _patches.autorenew_money;
 
			p->engine_renew_money  = _patches.autorenew_money;
 
		}
 
	}
 

	
 
	/* Elrails got added in rev 24 */
 
	if (CheckSavegameVersion(24)) {
 
		Vehicle *v;
player.h
Show inline comments
 
@@ -203,12 +203,13 @@ uint16 GetDrawStringPlayerColor(PlayerID
 

	
 
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;
 

	
 
/* Player identifiers All players below MAX_PLAYERS are playable
players.c
Show inline comments
 
@@ -25,12 +25,35 @@
 
#include "variables.h"
 
#include "engine.h"
 
#include "ai/ai.h"
 
#include "date.h"
 
#include "window.h"
 

	
 
/**
 
 * Sets the local player and updates the patch settings that are set on a
 
 * per-company (player) basis to reflect the core's state in the GUI.
 
 * @param new_player the new player
 
 * @pre IsValidPlayer(new_player) || new_player == PLAYER_SPECTATOR || new_player == OWNER_NONE
 
 */
 
void SetLocalPlayer(PlayerID new_player)
 
{
 
	/* Player could also be PLAYER_SPECTATOR or OWNER_NONE */
 
	assert(IsValidPlayer(new_player) || new_player == PLAYER_SPECTATOR || new_player == OWNER_NONE);
 

	
 
	_local_player = new_player;
 

	
 
	/* Do not update the patches if we are in the intro GUI */
 
	if (IsValidPlayer(new_player) && _game_mode != GM_MENU) {
 
		const Player *p = GetPlayer(new_player);
 
		_patches.autorenew        = p->engine_renew;
 
		_patches.autorenew_months = p->engine_renew_months;
 
		_patches.autorenew_money  = p->engine_renew_money;
 
		InvalidateWindow(WC_GAME_OPTIONS, 0);
 
	}
 
}
 

	
 

	
 
uint16 GetDrawStringPlayerColor(PlayerID player)
 
{
 
	/* Get the color for DrawString-subroutines which matches the color
 
	 * of the player */
 
	if (!IsValidPlayer(player)) return _colour_gradient[COLOUR_WHITE][4] | IS_PALETTE_COLOR;
 
@@ -835,21 +858,22 @@ int32 CmdPlayerCtrl(TileIndex tile, uint
 
				NetworkClientInfo *ci = &_network_client_info[cid];
 
				ci->client_playas = PLAYER_SPECTATOR;
 
				NetworkUpdateClientInfo(ci->client_index);
 
			} else
 
#endif /* ENABLE_NETWORK */
 
			{
 
				_local_player = _network_playas = PLAYER_SPECTATOR;
 
				_network_playas = PLAYER_SPECTATOR;
 
				SetLocalPlayer(PLAYER_SPECTATOR);
 
			}
 
			break;
 
		}
 

	
 
		/* This is the joining client who wants a new company */
 
		if (_local_player != _network_playas) {
 
			assert(_local_player == PLAYER_SPECTATOR && _network_playas == p->index);
 
			_local_player = p->index;
 
			SetLocalPlayer(p->index);
 
			MarkWholeScreenDirty();
 
		}
 

	
 
		/* Now that we have a new player, broadcast its autorenew settings to
 
		 * all clients so everything is in sync */
 
		DoCommand(0,
0 comments (0 inline, 0 general)