Author: cazfi
Date: Mon May  8 13:02:44 2017
New Revision: 35452

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

Reported by Jacob Nevins <jtn>

See hrm Bug #657412

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

Modified: branches/S2_6/client/client_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/client_main.c?rev=35452&r1=35451&r2=35452&view=diff
==============================================================================
--- branches/S2_6/client/client_main.c  (original)
+++ branches/S2_6/client/client_main.c  Mon May  8 13:02:44 2017
@@ -777,12 +777,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: branches/S2_6/client/mapctrl_common.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/mapctrl_common.c?rev=35452&r1=35451&r2=35452&view=diff
==============================================================================
--- branches/S2_6/client/mapctrl_common.c       (original)
+++ branches/S2_6/client/mapctrl_common.c       Mon May  8 13:02:44 2017
@@ -517,8 +517,16 @@
 **************************************************************************/
 bool get_turn_done_button_state(void)
 {
+  return can_end_turn()
+    && (!client.conn.playing->ai_controlled || 
gui_options.ai_manual_turn_done);
+}
+
+/**************************************************************************
+  Return TRUE iff client can end turn.
+**************************************************************************/
+bool can_end_turn(void)
+{
   return (can_client_issue_orders()
-          && !client.conn.playing->ai_controlled
           && client.conn.playing->is_alive
           && !client.conn.playing->phase_done
           && !is_server_busy()
@@ -620,7 +628,7 @@
 }
 
 /**************************************************************************
- Update the turn done button state.
+  Update the turn done button state.
 **************************************************************************/
 void update_turn_done_button_state(void)
 {
@@ -628,11 +636,8 @@
 
   set_turn_done_button_state(turn_done_state);
 
-  if (turn_done_state) {
-    if (waiting_for_end_turn
-        || (NULL != client.conn.playing
-            && client.conn.playing->ai_controlled
-            && !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: branches/S2_6/client/mapctrl_common.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/mapctrl_common.h?rev=35452&r1=35451&r2=35452&view=diff
==============================================================================
--- branches/S2_6/client/mapctrl_common.h       (original)
+++ branches/S2_6/client/mapctrl_common.h       Mon May  8 13:02:44 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: branches/S2_6/client/options.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/options.c?rev=35452&r1=35451&r2=35452&view=diff
==============================================================================
--- branches/S2_6/client/options.c      (original)
+++ branches/S2_6/client/options.c      Mon May  8 13:02:44 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"
@@ -1811,6 +1812,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);
@@ -2141,7 +2143,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."),
@@ -6124,6 +6126,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 && client.conn.playing->ai_controlled) {
+    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: branches/S2_6/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/packhand.c?rev=35452&r1=35451&r2=35452&view=diff
==============================================================================
--- branches/S2_6/client/packhand.c     (original)
+++ branches/S2_6/client/packhand.c     Mon May  8 13:02:44 2017
@@ -2255,6 +2255,10 @@
     if (pplayer == my_player)  {
       if (my_player->ai_controlled) {
         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: branches/S2_6/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/srv_main.c?rev=35452&r1=35451&r2=35452&view=diff
==============================================================================
--- branches/S2_6/server/srv_main.c     (original)
+++ branches/S2_6/server/srv_main.c     Mon May  8 13:02:44 2017
@@ -1954,7 +1954,8 @@
    * 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 && !pplayer->ai_controlled) {
+    if (pplayer->is_connected
+        && (!pplayer->ai_controlled || 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