[Freeciv-Dev] (PR#8906) save shuffled_players
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=8906 >
This patch saves and loads shuffled_players. The players are not
reshuffled on load. See PR#436. This should also allow a server option
to prevent reshuffling each turn (useful in conjunction with alternating
movement).
Nonetheless a save+load of an autogame still gives different results.
jason
? orig
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.311
diff -u -r1.311 plrhand.c
--- server/plrhand.c 28 May 2004 06:52:30 -0000 1.311
+++ server/plrhand.c 4 Jun 2004 07:12:46 -0000
@@ -1628,11 +1628,35 @@
shuffled_plr[pos] = tmp_plr;
}
+#ifdef DEBUG
+ for (i = 0; i < game.nplayers; i++) {
+ freelog(LOG_DEBUG, "Shuffling player %d as %d.",
+ i, shuffled_plr[i]->player_no);
+ }
+#endif
+
/* Record how many players there were when shuffled: */
shuffled_nplayers = game.nplayers;
}
/**************************************************************************
+ Initialize the shuffled players list (as from a loaded savegame).
+**************************************************************************/
+void set_shuffled_players(int *shuffled_players)
+{
+ int i;
+
+ for (i = 0; i < game.nplayers; i++) {
+ shuffled_plr[i] = get_player(shuffled_players[i]);
+
+ freelog(LOG_DEBUG, "Set shuffled player %d as %d.",
+ i, shuffled_plr[i]->player_no);
+ }
+
+ shuffled_nplayers = game.nplayers;
+}
+
+/**************************************************************************
Return i'th shuffled player. If number of players has grown between
re-shuffles, added players are given in unshuffled order at the end.
Number of players should not have shrunk.
Index: server/plrhand.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.h,v
retrieving revision 1.64
diff -u -r1.64 plrhand.h
--- server/plrhand.h 28 May 2004 06:52:30 -0000 1.64
+++ server/plrhand.h 4 Jun 2004 07:12:46 -0000
@@ -78,6 +78,7 @@
void do_conquer_cost(struct player *pplayer);
void shuffle_players(void);
+void set_shuffled_players(int *shuffled_players);
struct player *shuffled_player(int i);
#define shuffled_players_iterate(pplayer) \
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.157
diff -u -r1.157 savegame.c
--- server/savegame.c 31 May 2004 06:41:11 -0000 1.157
+++ server/savegame.c 4 Jun 2004 07:12:47 -0000
@@ -2401,6 +2401,21 @@
game.nplayers = 0;
}
+ if (secfile_lookup_int_default(file, -1,
+ "game.shuffled_player_%d", 0) >= 0) {
+ int shuffled_players[game.nplayers];
+
+ for (i = 0; i < game.nplayers; i++) {
+ shuffled_players[i]
+ = secfile_lookup_int(file, "game.shuffled_player_%d", i);
+ }
+ set_shuffled_players(shuffled_players);
+ } else {
+ /* No shuffled players included, so shuffle them (this may include
+ * scenarios). */
+ shuffle_players();
+ }
+
if (!game.is_new_game) {
/* Set active city improvements/wonders and their effects */
improvements_update_obsolete();
@@ -2600,5 +2615,10 @@
players_iterate(pplayer) {
player_save(pplayer, pplayer->player_no, file);
} players_iterate_end;
+
+ for (i = 0; i < game.nplayers; i++) {
+ secfile_insert_int(file, shuffled_player(i)->player_no,
+ "game.shuffled_player_%d", i);
+ }
}
}
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.165
diff -u -r1.165 srv_main.c
--- server/srv_main.c 2 Jun 2004 23:22:08 -0000 1.165
+++ server/srv_main.c 4 Jun 2004 07:12:47 -0000
@@ -457,9 +457,10 @@
}
}
- /* FIXME: player shuffling shouldn't be repeated unless is_new_turn. */
- freelog(LOG_DEBUG, "Shuffleplayers");
- shuffle_players();
+ if (is_new_turn) {
+ freelog(LOG_DEBUG, "Shuffleplayers");
+ shuffle_players();
+ }
sanity_check();
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#8906) save shuffled_players,
Jason Short <=
|
|