diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/client/climisc.c freeciv/client/climisc.c --- FreecivCVS/client/climisc.c Sun May 28 00:46:42 2000 +++ freeciv/client/climisc.c Wed May 31 09:16:44 2000 @@ -319,6 +319,24 @@ } /************************************************************************** +Format a duration, in seconds, so it comes up in minutes or hours if +that would be more meaningful. (Three characters, maximum.) +**************************************************************************/ +void format_duration(char *buffer, int buffer_size, int duration) +{ + if (duration < 0) + duration = 0; + if (duration <= 999) + my_snprintf(buffer, buffer_size, Q_("?seconds:%d"), duration); + else if (duration < 5970) /* < 99.5 minutes */ + my_snprintf(buffer, buffer_size, Q_("?minutes:%dm"), duration/60); + else if (duration < 358200) /* < 99.5 hours */ + my_snprintf(buffer, buffer_size, Q_("?hours:%dh"), duration/3600); + else + my_snprintf(buffer, buffer_size, "+++"); +} + +/************************************************************************** Copy a string that describes the given clause into the return buffer. **************************************************************************/ void client_diplomacy_clause_string(char *buf, int bufsiz, diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/client/climisc.h freeciv/client/climisc.h --- FreecivCVS/client/climisc.h Sun May 28 00:46:42 2000 +++ freeciv/client/climisc.h Wed May 31 09:06:54 2000 @@ -24,6 +24,8 @@ void climap_update_continents(int x, int y); void client_change_all(int x, int y); +void format_duration(char *buffer, int buffer_size, int duration); + void client_diplomacy_clause_string(char *buf, int bufsiz, struct Clause *pclause); diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/client/gui-gtk/gui_main.c freeciv/client/gui-gtk/gui_main.c --- FreecivCVS/client/gui-gtk/gui_main.c Sun May 21 15:54:26 2000 +++ freeciv/client/gui-gtk/gui_main.c Wed May 31 09:06:54 2000 @@ -834,8 +834,10 @@ if(flip) { update_timeout_label(); - if(seconds_to_turndone) - seconds_to_turndone--; + if(seconds_to_turndone > 0) + seconds_to_turndone--; + else + seconds_to_turndone = 0; } flip=!flip; diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/client/gui-gtk/mapview.c freeciv/client/gui-gtk/mapview.c --- FreecivCVS/client/gui-gtk/mapview.c Wed May 24 15:13:21 2000 +++ freeciv/client/gui-gtk/mapview.c Wed May 31 09:06:54 2000 @@ -267,7 +267,7 @@ { char buffer[512]; - my_snprintf(buffer, sizeof(buffer), "%d", seconds_to_turndone); + format_duration(buffer, sizeof(buffer), seconds_to_turndone); gtk_set_label(timeout_label, buffer); } diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/client/gui-xaw/gui_main.c freeciv/client/gui-xaw/gui_main.c --- FreecivCVS/client/gui-xaw/gui_main.c Fri Apr 7 18:06:24 2000 +++ freeciv/client/gui-xaw/gui_main.c Wed May 31 09:06:54 2000 @@ -781,8 +781,10 @@ if(flip) { update_timeout_label(); - if(seconds_to_turndone) + if(seconds_to_turndone > 0) seconds_to_turndone--; + else + seconds_to_turndone = 0; } flip=!flip; diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/client/gui-xaw/mapview.c freeciv/client/gui-xaw/mapview.c --- FreecivCVS/client/gui-xaw/mapview.c Wed May 24 15:13:21 2000 +++ freeciv/client/gui-xaw/mapview.c Wed May 31 09:06:54 2000 @@ -36,6 +36,8 @@ #include "civclient.h" +#include "climisc.h" + #include "colors.h" #include "control.h" /* set_unit_focus_no_center and get_unit_in_focus */ #include "graphics.h" @@ -248,7 +250,7 @@ { char buffer[512]; - my_snprintf(buffer, sizeof(buffer), "%d", seconds_to_turndone); + format_duration(buffer, sizeof(buffer), seconds_to_turndone); xaw_set_label(timeout_label, buffer); } diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/client/packhand.c freeciv/client/packhand.c --- FreecivCVS/client/packhand.c Mon May 29 13:52:57 2000 +++ freeciv/client/packhand.c Wed May 31 09:06:54 2000 @@ -690,6 +690,11 @@ boot_help = (get_client_state() == CLIENT_GAME_RUNNING_STATE && game.spacerace != pinfo->spacerace); game.spacerace=pinfo->spacerace; + if (game.timeout) { + if (pinfo->seconds_to_turndone) + seconds_to_turndone = pinfo->seconds_to_turndone; + } else + seconds_to_turndone = 0; if (boot_help) { boot_help_texts(); /* reboot, after setting game.spacerace */ } diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/common/capstr.c freeciv/common/capstr.c --- FreecivCVS/common/capstr.c Sun May 28 00:46:43 2000 +++ freeciv/common/capstr.c Wed May 31 09:06:54 2000 @@ -72,7 +72,7 @@ #define CAPABILITY "+1.10 +fog_of_war +fortify_two_step +get_sabotage_list \ ocean_reclamation +dipl_cli_pop_dlg advance_focus_packet +30players \ -submarine_flags +gen_impr +dipl_states" +submarine_flags +gen_impr +dipl_states send_secs_to_turn_done" /* "+1.10" is protocol for 1.10.0 stable release @@ -101,6 +101,10 @@ "dipl_states" is for servers and clients that understand diplomatic states: alliances, cease-fires, and what-have-you. + + "send_secs_to_turn_done" is that timeout information is sent in the + game_info packet, explicitly stating how many seconds are left in the + turn, for when clients re-connect, or when the timeout changes mid-turn. */ void init_our_capability(void) diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/common/game.h freeciv/common/game.h --- FreecivCVS/common/game.h Mon May 29 13:52:57 2000 +++ freeciv/common/game.h Wed May 31 09:06:54 2000 @@ -13,6 +13,11 @@ #ifndef FC__GAME_H #define FC__GAME_H +#include /* time_t */ +#ifdef HAVE_SYS_TIME_H +#include +#endif + #include "shared.h" #include "player.h" @@ -45,6 +50,7 @@ int tech; int skill_level; int timeout; + time_t turn_start; int end_year; int year; int techlevel; @@ -85,6 +91,7 @@ int add_to_size_limit; int spacerace; int turnblock; + int fixedlength; int auto_ai_toggle; int fogofwar; int fogofwar_old; /* as the fog_of_war bit get changed by setting @@ -273,9 +280,9 @@ #define GAME_MIN_AUTO_AI_TOGGLE 0 #define GAME_MAX_AUTO_AI_TOGGLE 1 -#define GAME_DEFAULT_TIMEOUT 0 -#define GAME_MIN_TIMEOUT 0 -#define GAME_MAX_TIMEOUT 999 +#define GAME_DEFAULT_TIMEOUT 0 +#define GAME_MIN_TIMEOUT 0 +#define GAME_MAX_TIMEOUT 86400 #define GAME_DEFAULT_BARBARIANRATE 2 #define GAME_MIN_BARBARIANRATE 0 diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/common/packets.c freeciv/common/packets.c --- FreecivCVS/common/packets.c Mon May 29 13:52:57 2000 +++ freeciv/common/packets.c Wed May 31 09:06:54 2000 @@ -1689,6 +1689,10 @@ cptr=put_uint8(cptr, pinfo->civstyle); cptr=put_uint8(cptr, pinfo->spacerace); + /* computed values */ + if (pc && has_capability("send_secs_to_turn_done", pc->capability)) + cptr=put_uint32(cptr, pinfo->seconds_to_turndone); + put_uint16(buffer, cptr-buffer); return send_connection_data(pc, buffer, cptr-buffer); @@ -1733,6 +1737,12 @@ iget_uint8(&iter, &pinfo->foodbox); iget_uint8(&iter, &pinfo->civstyle); iget_uint8(&iter, &pinfo->spacerace); + + /* computed values */ + if (pc && has_capability("send_secs_to_turn_done", pc->capability)) + iget_uint32(&iter, &pinfo->seconds_to_turndone); + else + pinfo->seconds_to_turndone = 0; pack_iter_end(&iter, pc); remove_packet_from_buffer(&pc->buffer); diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/common/packets.h freeciv/common/packets.h --- FreecivCVS/common/packets.h Mon May 29 13:52:57 2000 +++ freeciv/common/packets.h Wed May 31 09:06:54 2000 @@ -723,6 +723,8 @@ int foodbox; int techpenalty; int spacerace; + /* the following values are computed each time packet_game_info is sent */ + int seconds_to_turndone; }; /********************************************************* diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/server/civserver.c freeciv/server/civserver.c --- FreecivCVS/server/civserver.c Sun May 28 00:46:53 2000 +++ freeciv/server/civserver.c Wed May 31 09:06:54 2000 @@ -876,6 +876,7 @@ do_apollo_program(); make_history_report(); freelog(LOG_DEBUG, "Turn ended."); + game.turn_start = time(NULL); return 1; } @@ -937,6 +938,7 @@ server_state=SELECT_RACES_STATE; /* loaded ??? */ force_end_of_sniff=1; + game.turn_start = time(NULL); } @@ -1216,6 +1218,9 @@ { int i; + /* fixedlength is only applicable if we have a timeout set */ + if (game.fixedlength && game.timeout) + return 0; for(i=0; itime_at_turn_end) + && (time(NULL)>game.turn_start + game.timeout) && (server_state == RUN_GAME_STATE)){ con_prompt_off(); return 0; @@ -176,6 +177,8 @@ #endif continue; } + if (!game.timeout) + game.turn_start = time(NULL); if(FD_ISSET(sock, &readfs)) { /* new players connects */ freelog(LOG_VERBOSE, "got new connection"); @@ -231,8 +234,8 @@ con_prompt_off(); if((game.timeout) - && (time(NULL)>time_at_turn_end) - && (game.timeout)) return 0; + && (time(NULL)>game.turn_start + game.timeout)) + return 0; return 1; } diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/server/stdinhand.c freeciv/server/stdinhand.c --- FreecivCVS/server/stdinhand.c Sun May 28 00:46:54 2000 +++ freeciv/server/stdinhand.c Wed May 31 09:06:54 2000 @@ -575,7 +575,14 @@ N_("Turn-blocking game play mode"), N_("If this is set to 1 the game turn is not advanced until all players " "have finished their turn, including disconnected players.") }, - + + { "fixedlength", &game.fixedlength, + SSET_META, SSET_TO_CLIENT, + 0, 1, 0, + N_("Fixed-length turns play mode"), + N_("If this is set to 1 the game turn will not advance until the timeout " + "has expired, irrespective of players clicking on \"Turn Done\".") }, + { "demography", NULL, SSET_META, SSET_TO_CLIENT, 0, 0, 0, @@ -2177,6 +2184,8 @@ settings[cmd].name, val); /* canonify map generator settings( all of which are int ) */ adjust_terrain_param(); + /* send any modified game parameters to the clients */ + send_game_info(0); } } else { cmd_reply(CMD_SET, caller, C_SYNTAX,