Changeset - r5077:d84dfecd5f73
[Not reviewed]
master
0 5 0
bjarni - 18 years ago 2006-11-13 20:33:51
bjarni@openttd.org
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
-Codechange: closing all windows for a player will now loop all windows and close those, which got the player as caption instead of having a list of windows to close
5 files changed with 42 insertions and 21 deletions:
0 comments (0 inline, 0 general)
economy.c
Show inline comments
 
@@ -330,19 +330,14 @@ void ChangeOwnershipOfPlayerItems(Player
 
		TileIndex tile = 0;
 
		do {
 
			ChangeTileOwner(tile, old_player, new_player);
 
		} while (++tile != MapSize());
 
	}
 

	
 
	// Change color of existing windows
 
	if (new_player != PLAYER_SPECTATOR) {
 
		Window *w;
 
		for (w = _windows; w != _last_window; w++) {
 
			if (w->caption_color == old_player) w->caption_color = new_player;
 
		}
 
	}
 
	/* Change color of existing windows */
 
	if (new_player != PLAYER_SPECTATOR) ChangeWindowOwner(old_player, new_player);
 

	
 
	{
 
		Player *p;
 
		uint i;
 

	
 
		/* Check for shares */
player.h
Show inline comments
 
@@ -249,13 +249,12 @@ static inline bool IsLocalPlayer(void)
 

	
 
static inline bool IsValidPlayer(PlayerID pi)
 
{
 
	return pi < MAX_PLAYERS;
 
}
 

	
 
void DeletePlayerWindows(PlayerID pi);
 
byte GetPlayerRailtypes(PlayerID p);
 

	
 
/** Finds out if a Player has a certain railtype available */
 
static inline bool HasRailtypeAvail(const Player *p, RailType Railtype)
 
{
 
	return HASBIT(p->avail_railtypes, Railtype);
players.c
Show inline comments
 
@@ -23,12 +23,13 @@
 
#include "sound.h"
 
#include "network.h"
 
#include "variables.h"
 
#include "engine.h"
 
#include "ai/ai.h"
 
#include "date.h"
 
#include "window.h"
 

	
 

	
 
uint16 GetDrawStringPlayerColor(PlayerID player)
 
{
 
	/* Get the color for DrawString-subroutines which matches the color
 
	 * of the player */
 
@@ -613,25 +614,12 @@ void PlayersYearlyLoop(void)
 
		} else {
 
			SndPlayFx(SND_00_GOOD_YEAR);
 
		}
 
	}
 
}
 

	
 
void DeletePlayerWindows(PlayerID pi)
 
{
 
	DeleteWindowById(WC_COMPANY, pi);
 
	DeleteWindowById(WC_PLAYER_COLOR, pi);
 
	DeleteWindowById(WC_FINANCES, pi);
 
	DeleteWindowById(WC_STATION_LIST, pi);
 
	DeleteWindowById(WC_TRAINS_LIST,   (INVALID_STATION << 16) | pi);
 
	DeleteWindowById(WC_ROADVEH_LIST,  (INVALID_STATION << 16) | pi);
 
	DeleteWindowById(WC_SHIPS_LIST,    (INVALID_STATION << 16) | pi);
 
	DeleteWindowById(WC_AIRCRAFT_LIST, (INVALID_STATION << 16) | pi);
 
	DeleteWindowById(WC_BUY_COMPANY, pi);
 
}
 

	
 
byte GetPlayerRailtypes(PlayerID p)
 
{
 
	byte rt = 0;
 
	EngineID i;
 

	
 
	for (i = 0; i != TOTAL_NUM_ENGINES; i++) {
window.c
Show inline comments
 
@@ -345,12 +345,49 @@ void DeleteWindowByClass(WindowClass cls
 
		} else {
 
			w++;
 
		}
 
	}
 
}
 

	
 
void DeletePlayerWindows(PlayerID pi)
 
{
 
	Window *w;
 

	
 
	for (w = _windows; w != _last_window;) {
 
		if (w->caption_color == pi) {
 
			DeleteWindow(w);
 
			w = _windows;
 
		} else {
 
			w++;
 
		}
 
	}
 

	
 
	/* Also delete the player specific windows, that haven't got the caption set */
 
	DeleteWindowById(WC_BUY_COMPANY, pi);
 
}
 

	
 
/* Change the owner of all the windows one player can take over from another player (like vehicle view windows) */
 
void ChangeWindowOwner(PlayerID old_player, PlayerID new_player)
 
{
 
	Window *w;
 

	
 
	for (w = _windows; w != _last_window; w++) {
 
		if (w->caption_color != old_player)      continue;
 
		if (w->window_class == WC_PLAYER_COLOR)  continue;
 
		if (w->window_class == WC_FINANCES)      continue;
 
		if (w->window_class == WC_STATION_LIST)  continue;
 
		if (w->window_class == WC_TRAINS_LIST)   continue;
 
		if (w->window_class == WC_ROADVEH_LIST)  continue;
 
		if (w->window_class == WC_SHIPS_LIST)    continue;
 
		if (w->window_class == WC_AIRCRAFT_LIST) continue;
 
		if (w->window_class == WC_BUY_COMPANY)   continue;
 
		if (w->window_class == WC_COMPANY)       continue;
 
		w->caption_color = new_player;
 
	}
 
}
 

	
 

	
 
static Window *BringWindowToFront(Window *w);
 

	
 
Window *BringWindowToFrontById(WindowClass cls, WindowNumber number)
 
{
 
	Window *w = FindWindowById(cls, number);
window.h
Show inline comments
 
@@ -610,12 +610,14 @@ void CallWindowTickEvent(void);
 
void SetWindowDirty(const Window *w);
 
void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, uint msg, uint wparam, uint lparam);
 
void SendWindowMessageClass(WindowClass wnd_class, uint msg, uint wparam, uint lparam);
 

	
 
Window *FindWindowById(WindowClass cls, WindowNumber number);
 
void DeleteWindow(Window *w);
 
void DeletePlayerWindows(PlayerID pi);
 
void ChangeWindowOwner(PlayerID old_player, PlayerID new_player);
 
Window *BringWindowToFrontById(WindowClass cls, WindowNumber number);
 
Window *FindWindowFromPt(int x, int y);
 

	
 
bool IsWindowOfPrototype(const Window *w, const Widget *widget);
 
void AssignWidgetToWindow(Window *w, const Widget *widget);
 
Window *AllocateWindow(
0 comments (0 inline, 0 general)