forked from freeciv/freeciv-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Server: Backport 0051-Adjust-nationality-of-remaining-units-after-pla…
…yer-r.patch Signed-off-by: Marko Lindqvist <[email protected]>
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
freeciv/patches/backports/0051-Adjust-nationality-of-remaining-units-after-player-r.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
From d9e61b2de945fc3cb8f934c6b514f5b4f441b1bd Mon Sep 17 00:00:00 2001 | ||
From: Marko Lindqvist <[email protected]> | ||
Date: Sun, 31 Mar 2024 18:34:19 +0300 | ||
Subject: [PATCH 51/57] Adjust nationality of remaining units after player | ||
removal | ||
|
||
Nationality of the units owned by other players could | ||
previously be that of removed player, leading to a crash. | ||
Now switch nationality of such units to that of their | ||
current owner when player of their nationality is removed. | ||
|
||
See RM #383 | ||
|
||
Signed-off-by: Marko Lindqvist <[email protected]> | ||
--- | ||
common/player.c | 17 +++++++++++++++-- | ||
1 file changed, 15 insertions(+), 2 deletions(-) | ||
|
||
diff --git a/common/player.c b/common/player.c | ||
index d539a79dad..209b9c6571 100644 | ||
--- a/common/player.c | ||
+++ b/common/player.c | ||
@@ -659,8 +659,12 @@ void player_set_color(struct player *pplayer, | ||
} | ||
|
||
/*******************************************************************//** | ||
- Clear all player data. If full is set, then the nation and the team will | ||
- be cleared too. | ||
+ Clear all player data. | ||
+ | ||
+ If full is set, also | ||
+ - The nation is cleared | ||
+ - The team is cleared | ||
+ - Nationality information of remaining units is adjusted | ||
***********************************************************************/ | ||
void player_clear(struct player *pplayer, bool full) | ||
{ | ||
@@ -717,6 +721,15 @@ void player_clear(struct player *pplayer, bool full) | ||
if (full) { | ||
team_remove_player(pplayer); | ||
|
||
+ players_iterate_alive(owner) { | ||
+ unit_list_iterate(owner->units, owned) { | ||
+ if (unit_nationality(owned) == pplayer) { | ||
+ /* Switch nationality to that of current owner. */ | ||
+ owned->nationality = owner; | ||
+ } | ||
+ } unit_list_iterate_end; | ||
+ } players_iterate_alive_end; | ||
+ | ||
/* This comes last because log calls in the above functions | ||
* may use it. */ | ||
if (pplayer->nation != NULL) { | ||
-- | ||
2.43.0 | ||
|