summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2006-11-13 20:33:51 +0000
committerbjarni <bjarni@openttd.org>2006-11-13 20:33:51 +0000
commited46b7d3807f4cd6bfe3ace57faa41076ab3e998 (patch)
tree995d92da1def66f510b9f9b1a66bbbca39cc849d
parent21dd00b2992c84d5a17568d1de2da5f6d3439184 (diff)
downloadopenttd-ed46b7d3807f4cd6bfe3ace57faa41076ab3e998.tar.xz
(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
-rw-r--r--economy.c9
-rw-r--r--player.h1
-rw-r--r--players.c14
-rw-r--r--window.c37
-rw-r--r--window.h2
5 files changed, 42 insertions, 21 deletions
diff --git a/economy.c b/economy.c
index cee067b42..37d0d2325 100644
--- a/economy.c
+++ b/economy.c
@@ -333,13 +333,8 @@ void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID 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;
diff --git a/player.h b/player.h
index 05b429d79..a359b1064 100644
--- a/player.h
+++ b/player.h
@@ -252,7 +252,6 @@ 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 */
diff --git a/players.c b/players.c
index abd188a0b..5b3298398 100644
--- a/players.c
+++ b/players.c
@@ -26,6 +26,7 @@
#include "engine.h"
#include "ai/ai.h"
#include "date.h"
+#include "window.h"
uint16 GetDrawStringPlayerColor(PlayerID player)
@@ -616,19 +617,6 @@ void PlayersYearlyLoop(void)
}
}
-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;
diff --git a/window.c b/window.c
index d6eaa16da..4f2a238f4 100644
--- a/window.c
+++ b/window.c
@@ -348,6 +348,43 @@ void DeleteWindowByClass(WindowClass cls)
}
}
+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);
diff --git a/window.h b/window.h
index 3252bcfaf..a110f3547 100644
--- a/window.h
+++ b/window.h
@@ -613,6 +613,8 @@ void SendWindowMessageClass(WindowClass wnd_class, uint msg, uint wparam, uint l
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);