Author: cazfi
Date: Mon May  8 13:02:27 2017
New Revision: 35450

URL: http://svn.gna.org/viewcvs/freeciv?rev=35450&view=rev
Log:
Fix "Manual Turn Done in AI mode"

Reported by Jacob Nevins <jtn>

See hrm Bug #657412

Modified:
    trunk/client/client_main.c
    trunk/client/mapctrl_common.c
    trunk/client/mapctrl_common.h
    trunk/client/options.c
    trunk/client/packhand.c
    trunk/server/srv_main.c

Modified: trunk/client/client_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/client_main.c?rev=35450&r1=35449&r2=35450&view=diff
==============================================================================
--- trunk/client/client_main.c  (original)
+++ trunk/client/client_main.c  Mon May  8 13:02:27 2017
@@ -778,12 +778,12 @@
 **************************************************************************/
 void send_turn_done(void)
 {
-  log_debug("send_turn_done() turn_done_button_state=%d",
-            get_turn_done_button_state());
-
-  if (!get_turn_done_button_state()) {
+  log_debug("send_turn_done() can_end_turn=%d",
+            can_end_turn());
+
+  if (!can_end_turn()) {
     /*
-     * The turn done button is disabled but the user may have press
+     * The turn done button is disabled but the user may have pressed
      * the return key.
      */
 

Modified: trunk/client/mapctrl_common.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/mapctrl_common.c?rev=35450&r1=35449&r2=35450&view=diff
==============================================================================
--- trunk/client/mapctrl_common.c       (original)
+++ trunk/client/mapctrl_common.c       Mon May  8 13:02:27 2017
@@ -519,8 +519,16 @@
 **************************************************************************/
 bool get_turn_done_button_state(void)
 {
+  return can_end_turn()
+    && (is_human(client.conn.playing) || gui_options.ai_manual_turn_done);
+}
+
+/**************************************************************************
+  Return TRUE iff client can end turn.
+**************************************************************************/
+bool can_end_turn(void)
+{
   return (can_client_issue_orders()
-          && is_human(client.conn.playing)
           && client.conn.playing->is_alive
           && !client.conn.playing->phase_done
           && !is_server_busy()
@@ -622,7 +630,7 @@
 }
 
 /**************************************************************************
- Update the turn done button state.
+  Update the turn done button state.
 **************************************************************************/
 void update_turn_done_button_state(void)
 {
@@ -630,11 +638,8 @@
 
   set_turn_done_button_state(turn_done_state);
 
-  if (turn_done_state) {
-    if (waiting_for_end_turn
-        || (NULL != client.conn.playing
-            && is_ai(client.conn.playing)
-            && !gui_options.ai_manual_turn_done)) {
+  if (can_end_turn()) {
+    if (waiting_for_end_turn) {
       send_turn_done();
     } else {
       update_turn_done_button(TRUE);

Modified: trunk/client/mapctrl_common.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/mapctrl_common.h?rev=35450&r1=35449&r2=35450&view=diff
==============================================================================
--- trunk/client/mapctrl_common.h       (original)
+++ trunk/client/mapctrl_common.h       Mon May  8 13:02:27 2017
@@ -1,4 +1,4 @@
-/**********************************************************************
+/***********************************************************************
  Freeciv - Copyright (C) 2002 - The Freeciv Project
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -57,6 +57,7 @@
 void maybe_activate_keyboardless_goto(int canvas_x, int canvas_y);
 
 bool get_turn_done_button_state(void);
+bool can_end_turn(void);
 void scroll_mapview(enum direction8 gui_dir);
 void action_button_pressed(int canvas_x, int canvas_y,
                 enum quickselect_type qtype);

Modified: trunk/client/options.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/options.c?rev=35450&r1=35449&r2=35450&view=diff
==============================================================================
--- trunk/client/options.c      (original)
+++ trunk/client/options.c      Mon May  8 13:02:27 2017
@@ -53,6 +53,7 @@
 #include "climisc.h"
 #include "connectdlg_common.h"
 #include "global_worklist.h"
+#include "mapctrl_common.h"
 #include "mapview_common.h"
 #include "music.h"
 #include "overview_common.h"
@@ -1848,6 +1849,7 @@
 /* Some changed callbacks. */
 static void reqtree_show_icons_callback(struct option *poption);
 static void view_option_changed_callback(struct option *poption);
+static void manual_turn_done_callback(struct option *poption);
 static void voteinfo_bar_callback(struct option *poption);
 static void font_changed_callback(struct option *poption);
 static void mapimg_changed_callback(struct option *poption);
@@ -2172,7 +2174,7 @@
                   N_("Disable this option if you do not want to "
                      "press the Turn Done button manually when watching "
                      "an AI player."),
-                  COC_INTERFACE, GUI_STUB, TRUE, NULL),
+                  COC_INTERFACE, GUI_STUB, TRUE, manual_turn_done_callback),
   GEN_BOOL_OPTION(auto_center_on_unit, N_("Auto center on units"),
                   N_("Set this option to have the active unit centered "
                      "automatically when the unit focus changes."),
@@ -6291,6 +6293,19 @@
 }
 
 /****************************************************************************
+  Callback for when ai_manual_turn_done is changed.
+****************************************************************************/
+static void manual_turn_done_callback(struct option *poption)
+{
+  update_turn_done_button_state();
+  if (!gui_options.ai_manual_turn_done && is_ai(client.conn.playing)) {
+    if (can_end_turn()) {
+      user_ended_turn();
+    }
+  }
+}
+
+/****************************************************************************
   Callback for when any voteinfo bar option is changed.
 ****************************************************************************/
 static void voteinfo_bar_callback(struct option *poption)

Modified: trunk/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/packhand.c?rev=35450&r1=35449&r2=35450&view=diff
==============================================================================
--- trunk/client/packhand.c     (original)
+++ trunk/client/packhand.c     Mon May  8 13:02:27 2017
@@ -2319,6 +2319,10 @@
     if (pplayer == my_player)  {
       if (is_ai(my_player)) {
         output_window_append(ftc_client, _("AI mode is now ON."));
+        if (!gui_options.ai_manual_turn_done && !pplayer->phase_done) {
+          /* End turn immediately */
+          user_ended_turn();
+        }
       } else {
         output_window_append(ftc_client, _("AI mode is now OFF."));
       }

Modified: trunk/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/srv_main.c?rev=35450&r1=35449&r2=35450&view=diff
==============================================================================
--- trunk/server/srv_main.c     (original)
+++ trunk/server/srv_main.c     Mon May  8 13:02:27 2017
@@ -1914,7 +1914,7 @@
    * timeout is set to -1 this function call is skipped entirely and the
    * server will run rampant. */
   players_iterate_alive(pplayer) {
-    if (pplayer->is_connected && is_human(pplayer)) {
+    if (pplayer->is_connected && (is_human(pplayer) || pplayer->phase_done)) {
       connected = TRUE;
       break;
     }


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to