diff -Nurd -Xfreeciv/diff_ignore freeciv/client/packhand.c freeciv+autogame/client/packhand.c --- freeciv/client/packhand.c Tue May 7 00:40:52 2002 +++ freeciv+autogame/client/packhand.c Mon May 13 12:29:29 2002 @@ -694,7 +694,7 @@ update_unit_info_label(get_unit_in_focus()); - seconds_to_turndone=game.timeout; + seconds_to_turndone = game.autogame ? -1 : game.timeout; turn_gold_difference=game.player_ptr->economic.gold-last_turn_gold_amount; last_turn_gold_amount=game.player_ptr->economic.gold; @@ -1091,8 +1091,13 @@ game.tech=pinfo->tech; game.researchcost=pinfo->researchcost; game.skill_level=pinfo->skill_level; - game.timeout=pinfo->timeout; - + if (pinfo->timeout < 0) { + game.timeout = 0; + game.autogame = TRUE; + } else { + game.timeout=pinfo->timeout; + game.autogame = FALSE; + } game.end_year=pinfo->end_year; game.year=pinfo->year; game.turn=pinfo->turn; @@ -1149,7 +1154,7 @@ boot_help = (get_client_state() == CLIENT_GAME_RUNNING_STATE && game.spacerace != pinfo->spacerace); game.spacerace=pinfo->spacerace; - if (game.timeout != 0) { + if (!game.autogame && game.timeout != 0) { if (pinfo->seconds_to_turndone != 0) seconds_to_turndone = pinfo->seconds_to_turndone; } else diff -Nurd -Xfreeciv/diff_ignore freeciv/common/game.c freeciv+autogame/common/game.c --- freeciv/common/game.c Tue Apr 30 05:52:54 2002 +++ freeciv+autogame/common/game.c Mon May 13 12:29:29 2002 @@ -645,6 +645,7 @@ game.gold = GAME_DEFAULT_GOLD; game.tech = GAME_DEFAULT_TECHLEVEL; game.skill_level = GAME_DEFAULT_SKILL_LEVEL; + game.autogame = GAME_DEFAULT_AUTOGAME; game.timeout = GAME_DEFAULT_TIMEOUT; game.timeoutint = GAME_DEFAULT_TIMEOUTINT; game.timeoutintinc = GAME_DEFAULT_TIMEOUTINTINC; diff -Nurd -Xfreeciv/diff_ignore freeciv/common/game.h freeciv+autogame/common/game.h --- freeciv/common/game.h Tue Apr 30 05:52:54 2002 +++ freeciv+autogame/common/game.h Mon May 13 12:37:48 2002 @@ -59,6 +59,7 @@ int dispersion; int tech; int skill_level; + bool autogame; int timeout; int timeoutint; /* increase timeout every N turns... */ int timeoutinc; /* ... by this amount ... */ @@ -368,18 +369,18 @@ #define GAME_DEFAULT_AUTO_AI_TOGGLE FALSE +#define GAME_DEFAULT_AUTOGAME FALSE +#define GAME_MIN_AUTOGAME FALSE +#define GAME_MAX_AUTOGAME TRUE + #define GAME_DEFAULT_TIMEOUT 0 +#define GAME_MIN_TIMEOUT 0 +#define GAME_MAX_TIMEOUT 8639999 + #define GAME_DEFAULT_TIMEOUTINT 0 #define GAME_DEFAULT_TIMEOUTINTINC 0 #define GAME_DEFAULT_TIMEOUTINC 0 #define GAME_DEFAULT_TIMEOUTINCMULT 1 - -#ifndef NDEBUG -#define GAME_MIN_TIMEOUT -1 -#else -#define GAME_MIN_TIMEOUT 0 -#endif -#define GAME_MAX_TIMEOUT 8639999 #define GAME_DEFAULT_TCPTIMEOUT 10 #define GAME_MIN_TCPTIMEOUT 0 diff -Nurd -Xfreeciv/diff_ignore freeciv/server/gamehand.c freeciv+autogame/server/gamehand.c --- freeciv/server/gamehand.c Thu Apr 25 07:09:37 2002 +++ freeciv+autogame/server/gamehand.c Mon May 13 12:29:29 2002 @@ -213,7 +213,7 @@ ginfo.tech = game.tech; ginfo.researchcost = game.researchcost; ginfo.skill_level = game.skill_level; - ginfo.timeout = game.timeout; + ginfo.timeout = game.autogame ? -1 : game.timeout; ginfo.end_year = game.end_year; ginfo.year = game.year; ginfo.turn = game.turn; diff -Nurd -Xfreeciv/diff_ignore freeciv/server/meta.c freeciv+autogame/server/meta.c --- freeciv/server/meta.c Tue Mar 5 07:46:26 2002 +++ freeciv+autogame/server/meta.c Mon May 13 12:29:29 2002 @@ -322,7 +322,7 @@ num_nonbarbarians, game.min_players, game.max_players); cat_snprintf(info, sizeof(info), "Timeout:%d Year: %s\n", - game.timeout, textyear(game.year)); + game.autogame ? -1 : game.timeout, textyear(game.year)); cat_snprintf(info, sizeof(info), diff -Nurd -Xfreeciv/diff_ignore freeciv/server/savegame.c freeciv+autogame/server/savegame.c --- freeciv/server/savegame.c Thu Apr 25 07:09:38 2002 +++ freeciv+autogame/server/savegame.c Mon May 13 12:29:29 2002 @@ -1681,7 +1681,17 @@ if (game.skill_level==0) game.skill_level = GAME_OLD_DEFAULT_SKILL_LEVEL; + game.autogame = secfile_lookup_bool_default(file, + GAME_DEFAULT_AUTOGAME, + "game.autogame"); game.timeout = secfile_lookup_int(file, "game.timeout"); + + if (game.timeout < 0) { + /* backward compatibility */ + game.timeout = 0; + game.autogame = TRUE; + } + game.timeoutint = secfile_lookup_int_default(file, GAME_DEFAULT_TIMEOUTINT, "game.timeoutint"); @@ -2060,6 +2070,7 @@ secfile_insert_int(file, game.gold, "game.gold"); secfile_insert_int(file, game.tech, "game.tech"); secfile_insert_int(file, game.skill_level, "game.skill_level"); + secfile_insert_int(file, game.autogame, "game.autogame"); secfile_insert_int(file, game.timeout, "game.timeout"); secfile_insert_int(file, game.timeoutint, "game.timeoutint"); secfile_insert_int(file, game.timeoutintinc, "game.timeoutintinc"); diff -Nurd -Xfreeciv/diff_ignore freeciv/server/sernet.c freeciv+autogame/server/sernet.c --- freeciv/server/sernet.c Thu Apr 25 07:09:38 2002 +++ freeciv+autogame/server/sernet.c Mon May 13 12:29:29 2002 @@ -347,7 +347,7 @@ if(year!=game.year) { if (server_state == RUN_GAME_STATE) year=game.year; } - if (game.timeout == 0) + if (!game.autogame && game.timeout == 0) game.turn_start = time(NULL); while(TRUE) { @@ -409,7 +409,7 @@ } /* Don't wait if timeout == -1 (i.e. on auto games) */ - if (server_state != PRE_GAME_STATE && game.timeout == -1) { + if (server_state != PRE_GAME_STATE && game.autogame) { (void) send_server_info_to_metaserver(FALSE, FALSE); /* kick out of the srv_main loop */ @@ -454,8 +454,8 @@ if(select(max_desc+1, &readfs, &writefs, &exceptfs, &tv)==0) { /* timeout */ (void) send_server_info_to_metaserver(FALSE, FALSE); - if(game.timeout != 0 - && (time(NULL)>game.turn_start + game.timeout) + if((game.autogame + || (game.timeout != 0 && (time(NULL)>game.turn_start + game.timeout))) && (server_state == RUN_GAME_STATE)){ con_prompt_off(); return 0; @@ -481,7 +481,7 @@ #endif /* !__VMS */ } } - if (game.timeout == 0) + if (!game.autogame && game.timeout == 0) game.turn_start = time(NULL); if(FD_ISSET(sock, &exceptfs)) { /* handle Ctrl-Z suspend/resume */ @@ -619,7 +619,8 @@ } con_prompt_off(); - if (game.timeout != 0 && (time(NULL) > game.turn_start + game.timeout)) { + if (game.autogame + || (game.timeout != 0 && (time(NULL) > game.turn_start + game.timeout))) { return 0; } return 1; diff -Nurd -Xfreeciv/diff_ignore freeciv/server/srv_main.c freeciv+autogame/server/srv_main.c --- freeciv/server/srv_main.c Thu Apr 25 07:09:38 2002 +++ freeciv+autogame/server/srv_main.c Mon May 13 12:29:29 2002 @@ -869,7 +869,7 @@ static void check_for_full_turn_done(void) { /* fixedlength is only applicable if we have a timeout set */ - if (game.fixedlength && game.timeout != 0) + if (game.fixedlength && !game.autogame && game.timeout != 0) return; players_iterate(pplayer) { diff -Nurd -Xfreeciv/diff_ignore freeciv/server/stdinhand.c freeciv+autogame/server/stdinhand.c --- freeciv/server/stdinhand.c Tue May 7 22:36:40 2002 +++ freeciv+autogame/server/stdinhand.c Mon May 13 12:29:29 2002 @@ -155,6 +155,7 @@ /* * Triggers used in settings_s. */ + static bool valid_notradesize(int value, char **reject_message); static bool valid_fulltradesize(int value, char **reject_message); static bool autotoggle(bool value, char **reject_message); @@ -175,7 +176,28 @@ buffer[0] = '\0'; return TRUE; } - + +static bool set_autogame_from_timeout(int value, char **reject_message) +{ + /* even when the timeout is set to 0, autogame is disabled */ + game.autogame = FALSE; + + return TRUE; +} + +static bool set_timeout_from_autogame(bool value, char **reject_message) +{ + if (value) { + game.timeout = 0; + } + + return TRUE; +} + +/* + * macros to select type-specific fields in a settings_s + */ + #define GEN_BOOL(name, value, sclass, to_client, short_help, extra_help, func, default) \ { name, sclass, to_client, short_help, extra_help, SSET_BOOL, \ &value, default, func, \ @@ -663,24 +685,22 @@ N_("Year the game ends"), "", NULL, GAME_MIN_END_YEAR, GAME_MAX_END_YEAR, GAME_DEFAULT_END_YEAR) -#ifndef NDEBUG - GEN_INT( "timeout", game.timeout, SSET_META, SSET_TO_CLIENT, - N_("Maximum seconds per turn"), - N_("If all players have not hit \"Turn Done\" before this " - "time is up, then the turn ends automatically. Zero " - "means there is no timeout. In DEBUG servers, a timeout " - "of -1 sets the autogame test mode. Use this with the command " - "\"timeoutincrease\" to have a dynamic timer."), NULL, - GAME_MIN_TIMEOUT, GAME_MAX_TIMEOUT, GAME_DEFAULT_TIMEOUT) -#else GEN_INT( "timeout", game.timeout, SSET_META, SSET_TO_CLIENT, N_("Maximum seconds per turn"), N_("If all players have not hit \"Turn Done\" before this " "time is up, then the turn ends automatically. Zero " "means there is no timeout. Use this with the command " - "\"timeoutincrease\" to have a dynamic timer."), NULL, + "\"timeoutincrease\" to have a dynamic timer."), + set_autogame_from_timeout, GAME_MIN_TIMEOUT, GAME_MAX_TIMEOUT, GAME_DEFAULT_TIMEOUT) -#endif + + GEN_BOOL( "autogame", game.autogame, SSET_META, SSET_SERVER_ONLY, + N_("Whether the game runs automatically"), + N_("If this is set to 1, the game will proceed automatically. " + "This cancels any existing timeout, and is cancelled " + "by setting a timeout (even a timeout of 0)."), + set_timeout_from_autogame, + GAME_DEFAULT_AUTOGAME) GEN_INT("tcptimeout", game.tcptimeout, SSET_META, SSET_TO_CLIENT, N_("Seconds to let a client connection block"), @@ -2559,7 +2579,7 @@ clen = strlen(command); } } else { - cmd = -1; /* to indicate that no comannd was specified */ + cmd = -1; /* to indicate that no command was specified */ } #define cmd_reply_show(string) cmd_reply(CMD_SHOW, caller, C_COMMENT, string) @@ -2721,10 +2741,9 @@ switch (op->type) { case SSET_BOOL: if (sscanf(arg, "%d", &val) != 1) { - cmd_reply(CMD_SET, caller, C_SYNTAX, _("Value must be an integer.")); + cmd_reply(CMD_SET, caller, C_SYNTAX, _("Value must be 0 or 1.")); } else if (val != 0 && val != 1) { - cmd_reply(CMD_SET, caller, C_SYNTAX, - _("Value out of range (minimum: 0, maximum: 1).")); + cmd_reply(CMD_SET, caller, C_SYNTAX, _("Value must be 0 or 1.")); } else { char *reject_message = NULL; bool b_val = (val != 0); @@ -2744,7 +2763,12 @@ case SSET_INT: if (sscanf(arg, "%d", &val) != 1) { cmd_reply(CMD_SET, caller, C_SYNTAX, _("Value must be an integer.")); - } else if (val < op->int_min_value || val > op->int_max_value) { + } else if (!(val >= op->int_min_value && val <= op->int_max_value) + /* + * for timeout, 0 means "infinite" and can always be set - + * a more general mechanism should be introduced for this - rp + */ + && !(val == 0 && !strcmp(op->name,"timeout"))) { cmd_reply(CMD_SET, caller, C_SYNTAX, _("Value out of range (minimum: %d, maximum: %d)."), op->int_min_value, op->int_max_value); @@ -3526,6 +3550,7 @@ reject_message = NULL; /* we should modify this, but since we cannot fail... */ return TRUE; } + #ifdef HAVE_LIBREADLINE /********************* RL completion functions ***************************/