[Freeciv-Dev] (PR#13159) Cannot load games
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13159 >
Oops. This is more than a little buggy.
This patch should fix it. A new parameter is given to
server_player_init telling whether the player should be assigned a team.
When loading savegames we don't assign a team on initialization. We do
assign a team loaded from the savegame, if one exists. For players
without teams listed in the savegame, we assign them to an empty team.
In future this could be used so that barbarians and observers are
teamless. Maybe.
-jason
Index: server/barbarian.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/barbarian.c,v
retrieving revision 1.91
diff -u -r1.91 barbarian.c
--- server/barbarian.c 5 May 2005 19:22:25 -0000 1.91
+++ server/barbarian.c 22 May 2005 18:38:33 -0000
@@ -117,7 +117,7 @@
/* make a new player */
- server_player_init(barbarians, TRUE);
+ server_player_init(barbarians, TRUE, TRUE);
barbarians->nation = game.control.nation_count - 1;
pick_random_player_name(game.control.nation_count - 1, barbarians->name);
Index: server/connecthand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/connecthand.c,v
retrieving revision 1.49
diff -u -r1.49 connecthand.c
--- server/connecthand.c 22 May 2005 18:06:37 -0000 1.49
+++ server/connecthand.c 22 May 2005 18:38:34 -0000
@@ -675,7 +675,7 @@
return FALSE;
} else {
pplayer = &game.players[game.info.nplayers];
- server_player_init(pplayer, FALSE);
+ server_player_init(pplayer, FALSE, TRUE);
game.info.nplayers++;
}
}
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.380
diff -u -r1.380 plrhand.c
--- server/plrhand.c 22 May 2005 18:06:37 -0000 1.380
+++ server/plrhand.c 22 May 2005 18:38:34 -0000
@@ -1453,7 +1453,7 @@
packet->nation=plr->nation;
packet->is_male=plr->is_male;
packet->is_observer=plr->is_observer;
- packet->team = plr->team->index;
+ packet->team = plr->team ? plr->team->index : -1;
packet->is_started = plr->is_started;
packet->city_style=plr->city_style;
@@ -1649,17 +1649,26 @@
pplayer->connections);
}
-/**********************************************************************
-The initmap option is used because we don't want to initialize the map
-before the x and y sizes have been determined
-***********************************************************************/
-void server_player_init(struct player *pplayer, bool initmap)
+/****************************************************************************
+ Initialize ANY newly-created player on the server.
+
+ The initmap option is used because we don't want to initialize the map
+ before the x and y sizes have been determined. This should generally
+ be FALSE in pregame.
+
+ The needs_team options should be set for players who should be assigned
+ a team. They will be put on their own newly-created team.
+****************************************************************************/
+void server_player_init(struct player *pplayer,
+ bool initmap, bool needs_team)
{
if (initmap) {
player_map_allocate(pplayer);
}
pplayer->player_no = pplayer - game.players;
- team_add_player(pplayer, find_empty_team());
+ if (needs_team) {
+ team_add_player(pplayer, find_empty_team());
+ }
ai_data_init(pplayer);
}
@@ -1943,7 +1952,8 @@
*
* FIXME: could we use map_is_empty here? */
server_player_init(pplayer,
- (server_state == RUN_GAME_STATE || !game.is_new_game));
+ (server_state == RUN_GAME_STATE || !game.is_new_game),
+ TRUE);
sz_strlcpy(pplayer->name, OBSERVER_NAME);
sz_strlcpy(pplayer->username, ANON_USER_NAME);
@@ -2004,7 +2014,7 @@
Nation_type_id *civilwar_nations = get_nation_civilwar(pplayer->nation);
/* make a new player */
- server_player_init(cplayer, TRUE);
+ server_player_init(cplayer, TRUE, TRUE);
/* select a new name and nation for the copied player. */
/* Rebel will always be an AI player */
Index: server/plrhand.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.h,v
retrieving revision 1.73
diff -u -r1.73 plrhand.h
--- server/plrhand.h 6 May 2005 03:23:55 -0000 1.73
+++ server/plrhand.h 22 May 2005 18:38:34 -0000
@@ -29,7 +29,8 @@
enum plr_info_level { INFO_MINIMUM, INFO_MEETING, INFO_EMBASSY, INFO_FULL };
-void server_player_init(struct player *pplayer, bool initmap);
+void server_player_init(struct player *pplayer,
+ bool initmap, bool needs_team);
void server_remove_player(struct player *pplayer);
void kill_player(struct player *pplayer);
void kill_dying_players(void);
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.251
diff -u -r1.251 savegame.c
--- server/savegame.c 22 May 2005 17:48:11 -0000 1.251
+++ server/savegame.c 22 May 2005 18:38:35 -0000
@@ -1677,8 +1677,9 @@
struct government *gov;
int id;
int target_no;
+ struct team *pteam;
- server_player_init(plr, TRUE);
+ server_player_init(plr, TRUE, FALSE);
ai = ai_data_get(plr);
plr->ai.barbarian_type = secfile_lookup_int_default(file, 0,
"player%d.ai.is_barbarian",
@@ -1731,7 +1732,10 @@
/* not all players have teams */
id = secfile_lookup_int_default(file, -1, "player%d.team_no", plrno);
- plr->team = team_get_by_id(id);
+ pteam = team_get_by_id(id);
+ if (pteam) {
+ team_add_player(plr, pteam);
+ }
if (is_barbarian(plr)) {
plr->nation = game.control.nation_count - 1;
@@ -2539,7 +2543,8 @@
* Nations can't be saved correctly because race must be < 62 */
secfile_insert_int(file, plrno, "player%d.race", plrno);
- secfile_insert_int(file, plr->team->index, "player%d.team_no", plrno);
+ secfile_insert_int(file, plr->team ? plr->team->index : -1,
+ "player%d.team_no", plrno);
gov = get_government(plr->government);
secfile_insert_str(file, gov->name_orig, "player%d.government_name", plrno);
@@ -3631,6 +3636,12 @@
technology_order_size);
}
+ players_iterate(pplayer) {
+ if (!pplayer->team) {
+ team_add_player(pplayer, find_empty_team());
+ }
+ } players_iterate_end;
+
/* Update all city information. This must come after all cities are
* loaded (in player_load) but before player (dumb) cities are loaded
* (in player_map_load).
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.263
diff -u -r1.263 srv_main.c
--- server/srv_main.c 22 May 2005 18:05:07 -0000 1.263
+++ server/srv_main.c 22 May 2005 18:38:35 -0000
@@ -1448,7 +1448,7 @@
const int old_nplayers = game.info.nplayers;
struct player *pplayer = get_player(old_nplayers);
- server_player_init(pplayer, FALSE);
+ server_player_init(pplayer, FALSE, TRUE);
nation = select_random_nation();
assert(nation != NO_NATION_SELECTED);
Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.412
diff -u -r1.412 stdinhand.c
--- server/stdinhand.c 22 May 2005 18:06:37 -0000 1.412
+++ server/stdinhand.c 22 May 2005 18:38:36 -0000
@@ -904,7 +904,7 @@
}
pplayer = &game.players[game.info.nplayers];
- server_player_init(pplayer, FALSE);
+ server_player_init(pplayer, FALSE, TRUE);
sz_strlcpy(pplayer->name, arg);
sz_strlcpy(pplayer->username, ANON_USER_NAME);
pplayer->was_created = TRUE; /* must use /remove explicitly to remove */
|
|