Author: sveinung
Date: Sat Mar  5 23:19:58 2016
New Revision: 32184

URL: http://svn.gna.org/viewcvs/freeciv?rev=32184&view=rev
Log:
action_decision_taken() does too much. Split it.

action_decision_taken() does 3 things. Split it in 3 functions so each thing
can be done independently. Don't call all 3 functions where it doesn't make
sense.

See patch #7034

Modified:
    trunk/client/control.c
    trunk/client/control.h
    trunk/client/gui-gtk-2.0/action_dialog.c
    trunk/client/gui-gtk-3.0/action_dialog.c
    trunk/client/gui-gtk-3.x/action_dialog.c
    trunk/client/gui-qt/dialogs.cpp
    trunk/client/gui-sdl2/action_dialog.c
    trunk/client/packhand.c

Modified: trunk/client/control.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/control.c?rev=32184&r1=32183&r2=32184&view=diff
==============================================================================
--- trunk/client/control.c      (original)
+++ trunk/client/control.c      Sat Mar  5 23:19:58 2016
@@ -998,12 +998,11 @@
 }
 
 /**************************************************************************
-  The player made a decision about what to do.
-**************************************************************************/
-void action_decision_taken(const int old_actor_id)
-{
-  struct unit *old;
-
+  The action selection process is no longer in progres for the specified
+  unit. It is safe to let another unit enter it.
+**************************************************************************/
+void action_selection_no_longer_in_progress(const int old_actor_id)
+{
   /* IDENTITY_NUMBER_ZERO is accepted for cases where the unit is gone
    * without a trace. */
   fc_assert_msg(old_actor_id == action_selection_in_progress_for
@@ -1013,12 +1012,31 @@
 
   /* Stop objecting to allowing the next unit to ask. */
   action_selection_in_progress_for = IDENTITY_NUMBER_ZERO;
+}
+
+/**************************************************************************
+  Have the server record that a decision no longer is wanted for the
+  specified unit.
+**************************************************************************/
+void action_decision_clear_want(const int old_actor_id)
+{
+  struct unit *old;
 
   if ((old = game_unit_by_number(old_actor_id))) {
     /* Have the server record that a decision no longer is wanted. */
     dsend_packet_unit_sscs_set(&client.conn, old_actor_id,
                                USSDT_UNQUEUE, IDENTITY_NUMBER_ZERO);
   }
+}
+
+/**************************************************************************
+  Move on to the next unit in focus that needs an action decision.
+**************************************************************************/
+void action_selection_next_in_focus(const int old_actor_id)
+{
+  struct unit *old;
+
+  old = game_unit_by_number(old_actor_id);
 
   /* Go to the next unit in focus that needs a decision. */
   unit_list_iterate(get_units_in_focus(), funit) {

Modified: trunk/client/control.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/control.h?rev=32184&r1=32183&r2=32184&view=diff
==============================================================================
--- trunk/client/control.h      (original)
+++ trunk/client/control.h      Sat Mar  5 23:19:58 2016
@@ -184,7 +184,9 @@
 double blink_turn_done_button(void);
 
 bool should_ask_server_for_actions(struct unit *punit);
-void action_decision_taken(const int old_actor_id);
+void action_selection_no_longer_in_progress(const int old_actor_id);
+void action_decision_clear_want(const int old_actor_id);
+void action_selection_next_in_focus(const int old_actor_id);
 void action_decision_request(struct unit *actor_unit);
 
 void key_cancel_action(void);

Modified: trunk/client/gui-gtk-2.0/action_dialog.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-2.0/action_dialog.c?rev=32184&r1=32183&r2=32184&view=diff
==============================================================================
--- trunk/client/gui-gtk-2.0/action_dialog.c    (original)
+++ trunk/client/gui-gtk-2.0/action_dialog.c    Sat Mar  5 23:19:58 2016
@@ -107,7 +107,11 @@
 static void diplomat_queue_handle_primary(void)
 {
   if (!is_more_user_input_needed) {
-    action_decision_taken(actor_unit_id);
+    /* The client isn't waiting for information for any unanswered follow
+     * up questions. */
+    action_selection_no_longer_in_progress(actor_unit_id);
+    action_decision_clear_want(actor_unit_id);
+    action_selection_next_in_focus(actor_unit_id);
   }
 }
 

Modified: trunk/client/gui-gtk-3.0/action_dialog.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-3.0/action_dialog.c?rev=32184&r1=32183&r2=32184&view=diff
==============================================================================
--- trunk/client/gui-gtk-3.0/action_dialog.c    (original)
+++ trunk/client/gui-gtk-3.0/action_dialog.c    Sat Mar  5 23:19:58 2016
@@ -107,7 +107,11 @@
 static void diplomat_queue_handle_primary(void)
 {
   if (!is_more_user_input_needed) {
-    action_decision_taken(actor_unit_id);
+    /* The client isn't waiting for information for any unanswered follow
+     * up questions. */
+    action_selection_no_longer_in_progress(actor_unit_id);
+    action_decision_clear_want(actor_unit_id);
+    action_selection_next_in_focus(actor_unit_id);
   }
 }
 

Modified: trunk/client/gui-gtk-3.x/action_dialog.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-3.x/action_dialog.c?rev=32184&r1=32183&r2=32184&view=diff
==============================================================================
--- trunk/client/gui-gtk-3.x/action_dialog.c    (original)
+++ trunk/client/gui-gtk-3.x/action_dialog.c    Sat Mar  5 23:19:58 2016
@@ -107,7 +107,11 @@
 static void diplomat_queue_handle_primary(void)
 {
   if (!is_more_user_input_needed) {
-    action_decision_taken(actor_unit_id);
+    /* The client isn't waiting for information for any unanswered follow
+     * up questions. */
+    action_selection_no_longer_in_progress(actor_unit_id);
+    action_decision_clear_want(actor_unit_id);
+    action_selection_next_in_focus(actor_unit_id);
   }
 }
 

Modified: trunk/client/gui-qt/dialogs.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/dialogs.cpp?rev=32184&r1=32183&r2=32184&view=diff
==============================================================================
--- trunk/client/gui-qt/dialogs.cpp     (original)
+++ trunk/client/gui-qt/dialogs.cpp     Sat Mar  5 23:19:58 2016
@@ -1269,10 +1269,14 @@
   Move the queue of diplomats that need user input forward unless the
   current diplomat will need more input.
 **************************************************************************/
-static void diplomat_queue_handle_primary(int actor_id)
+static void diplomat_queue_handle_primary(int actor_unit_id)
 {
   if (!is_more_user_input_needed) {
-    action_decision_taken(actor_id);
+    /* The client isn't waiting for information for any unanswered follow
+     * up questions. */
+    action_selection_no_longer_in_progress(actor_unit_id);
+    action_decision_clear_want(actor_unit_id);
+    action_selection_next_in_focus(actor_unit_id);
   }
 }
 

Modified: trunk/client/gui-sdl2/action_dialog.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/action_dialog.c?rev=32184&r1=32183&r2=32184&view=diff
==============================================================================
--- trunk/client/gui-sdl2/action_dialog.c       (original)
+++ trunk/client/gui-sdl2/action_dialog.c       Sat Mar  5 23:19:58 2016
@@ -77,9 +77,11 @@
 static void act_sel_done_primary(int actor_unit_id)
 {
   if (!is_more_user_input_needed) {
-    /* The client isn't waiting for more information about the selected
-     * action. */
-    action_decision_taken(actor_unit_id);
+    /* The client isn't waiting for information for any unanswered follow
+     * up questions. */
+    action_selection_no_longer_in_progress(actor_unit_id);
+    action_decision_clear_want(actor_unit_id);
+    action_selection_next_in_focus(actor_unit_id);
   }
 }
 

Modified: trunk/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/packhand.c?rev=32184&r1=32183&r2=32184&view=diff
==============================================================================
--- trunk/client/packhand.c     (original)
+++ trunk/client/packhand.c     Sat Mar  5 23:19:58 2016
@@ -413,8 +413,9 @@
   /* Close diplomat dialog if the diplomat is lost */
   if (action_selection_actor_unit() == punit->id) {
     action_selection_close();
-    /* Open another diplomat dialog if there are other diplomats waiting */
-    action_decision_taken(unit_id);
+    /* Open another action selection dialog if there are other actors in the
+     * current selection that want a decision. */
+    action_selection_next_in_focus(unit_id);
   }
 
   need_economy_report_update = (0 < punit->upkeep[O_GOLD]);
@@ -4283,14 +4284,17 @@
     log_error("handle_unit_action_answer() the action %d doesn't exist.",
               action_type);
 
-    action_decision_taken(diplomat_id);
+    action_selection_no_longer_in_progress(diplomat_id);
+    action_decision_clear_want(diplomat_id);
+    action_selection_next_in_focus(diplomat_id);
     return;
   }
 
   if (!pdiplomat) {
     log_debug("Bad actor %d.", diplomat_id);
 
-    action_decision_taken(diplomat_id);
+    action_selection_no_longer_in_progress(diplomat_id);
+    action_selection_next_in_focus(diplomat_id);
     return;
   }
 
@@ -4304,7 +4308,9 @@
       popup_bribe_dialog(pdiplomat, punit, cost);
     } else {
       log_debug("Bad target %d.", target_id);
-      action_decision_taken(diplomat_id);
+      action_selection_no_longer_in_progress(diplomat_id);
+      action_decision_clear_want(diplomat_id);
+      action_selection_next_in_focus(diplomat_id);
     }
     break;
   case ACTION_SPY_INCITE_CITY:
@@ -4316,17 +4322,23 @@
       popup_incite_dialog(pdiplomat, pcity, cost);
     } else {
       log_debug("Bad target %d.", target_id);
-      action_decision_taken(diplomat_id);
+      action_selection_no_longer_in_progress(diplomat_id);
+      action_decision_clear_want(diplomat_id);
+      action_selection_next_in_focus(diplomat_id);
     }
     break;
   case ACTION_COUNT:
     log_debug("Server didn't respond to query.");
-    action_decision_taken(diplomat_id);
+    action_selection_no_longer_in_progress(diplomat_id);
+    action_decision_clear_want(diplomat_id);
+    action_selection_next_in_focus(diplomat_id);
     break;
   default:
     log_error("handle_unit_action_answer() invalid action_type (%d).",
               action_type);
-    action_decision_taken(diplomat_id);
+    action_selection_no_longer_in_progress(diplomat_id);
+    action_decision_clear_want(diplomat_id);
+    action_selection_next_in_focus(diplomat_id);
     break;
   };
 }
@@ -4369,8 +4381,10 @@
                            target_city, target_unit, target_tile,
                            act_prob);
   } else if (disturb_player) {
-    /* Nothing to do. Go to the next queued dipomat */
-    action_decision_taken(packet->actor_unit_id);
+    /* Nothing to do. */
+    action_selection_no_longer_in_progress(packet->actor_unit_id);
+    action_decision_clear_want(packet->actor_unit_id);
+    action_selection_next_in_focus(packet->actor_unit_id);
   } else {
     /* This was a background request. */
 
@@ -4396,14 +4410,17 @@
   if (!pdiplomat) {
     log_debug("Bad diplomat %d.", diplomat_id);
 
-    action_decision_taken(diplomat_id);
+    action_selection_no_longer_in_progress(diplomat_id);
+    action_selection_next_in_focus(diplomat_id);
     return;
   }
 
   if (!pcity) {
     log_debug("Bad city %d.", city_id);
 
-    action_decision_taken(diplomat_id);
+    action_selection_no_longer_in_progress(diplomat_id);
+    action_decision_clear_want(diplomat_id);
+    action_selection_next_in_focus(diplomat_id);
     return;
   }
 
@@ -4420,7 +4437,8 @@
     popup_sabotage_dialog(pdiplomat, pcity);
   } else {
     log_debug("Can't issue orders");
-    action_decision_taken(diplomat_id);
+    action_selection_no_longer_in_progress(diplomat_id);
+    action_decision_clear_want(diplomat_id);
   }
 }
 


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

Reply via email to