[Freeciv-Dev] patch to add synchronous game turns
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Greetings!
I've modified the server adding a synchronous game turn option.
With this option enabled the game turn does not advance until all
players have completed their turn. This is handy for games which are
played over a long period of time enabling players to disconnect and
reconnect without fear of losing turns.
This patch is applicable to version 1.8.1 of the codeline.
-- Gary
--- civserver.c 1999/08/18 18:13:34 1.1
+++ civserver.c 1999/08/19 02:35:28
@@ -128,6 +128,30 @@
int rand_init=0;
+/* global flag to detect synchronous game play */
+int syncplay=0;
+
+/*
+ * check to see if all players have moved.
+ * returns 1 if true, 0 otherwise
+ */
+int all_players_done()
+{
+ int i;
+
+
+ /* determine whose turn it is */
+ for(i=0; i<game.nplayers; i++) {
+ if (!game.players[i].ai.control && !game.players[i].turn_done)
+ {
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+
/**************************************************************************
...
**************************************************************************/
@@ -455,8 +479,20 @@
ai_start_turn();
freelog(LOG_DEBUG, "sniffingpackets");
- while(sniff_packets()==1);
-
+
+ /* if synchronous game play wait until all players have moved */
+ if (syncplay)
+ {
+ while(!all_players_done())
+ {
+ sniff_packets();
+ }
+ }
+ else /* normal mode */
+ {
+ while(sniff_packets()==1) ;
+ }
+
for(i=0;i<game.nplayers;i++)
connection_do_buffer(game.players[i].conn);
freelog(LOG_DEBUG, "Autosettlers");
--- stdinhand.c 1999/08/19 02:25:08 1.1
+++ stdinhand.c 1999/08/19 02:31:13
@@ -40,6 +40,7 @@
extern int gamelog_level;
extern char metaserver_info_line[256];
+extern int syncplay;
enum cmdlevel_id default_access_level = ALLOW_INFO;
@@ -466,6 +467,13 @@
" Only applies if the game log feature is enabled (with the -g command
line\n"
" option). Levels: 0=no logging, 20=standard logging, 30=detailed
logging,\n"
" 40=debuging logging." },
+
+ { "syncplay", &syncplay,
+ SSET_META, SSET_SERVER_ONLY,
+ 0,1,0,
+ "Synchronous game play",
+ " If this is set to 1 game turn is not advanced until\n"
+ " all players have finished their turns."},
{ NULL, NULL,
SSET_LAST, SSET_SERVER_ONLY,
- [Freeciv-Dev] patch to add synchronous game turns,
Gary Moyer <=
|
|