Author: sveinung
Date: Wed Mar  2 10:06:54 2016
New Revision: 32150

URL: http://svn.gna.org/viewcvs/freeciv?rev=32150&view=rev
Log:
Assert that decision is taken for the right unit.

When an action decision is taken the action selection process is over. Give
an assertion failure when an action decision is taken for a different unit
than the unit that currently is in the action selection process.

See patch #7006

Modified:
    branches/S2_6/client/control.c

Modified: branches/S2_6/client/control.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/control.c?rev=32150&r1=32149&r2=32150&view=diff
==============================================================================
--- branches/S2_6/client/control.c      (original)
+++ branches/S2_6/client/control.c      Wed Mar  2 10:06:54 2016
@@ -91,10 +91,18 @@
 static struct unit *punit_attacking = NULL;
 static struct unit *punit_defending = NULL;
 
-/* No client supports more than one action selection process at once. It
- * begins when the client asks the server what actions a unit can take. It
- * ends when the last follow up question is answered. */
-static bool action_selection_in_progress = FALSE;
+/* The ID of the unit that currently is in the action selection process.
+ *
+ * The action selection process begins when the client asks the server what
+ * actions a unit can take. It ends when the last follow up question is
+ * answered.
+ *
+ * No common client code using client supports more than one action
+ * selection process at once. The interface between the common client code
+ * and the clients would have to change before that could happen. (See
+ * action_selection_actor_unit() etc)
+ */
+static int action_selection_in_progress_for = IDENTITY_NUMBER_ZERO;
 
 /*
  * This variable is TRUE iff a NON-AI controlled unit was focused this
@@ -300,7 +308,7 @@
 static bool can_ask_server_for_actions(void)
 {
   /* OK as long as no other unit already asked and aren't done yet. */
-  return (!action_selection_in_progress
+  return (action_selection_in_progress_for == IDENTITY_NUMBER_ZERO
           && action_selection_actor_unit() == IDENTITY_NUMBER_ZERO);
 }
 
@@ -317,8 +325,8 @@
   fc_assert_ret(punit->action_decision_tile);
 
   /* Only one action selection dialog at a time is supported. */
-  fc_assert(!action_selection_in_progress);
-  action_selection_in_progress = TRUE;
+  fc_assert(action_selection_in_progress_for == IDENTITY_NUMBER_ZERO);
+  action_selection_in_progress_for = punit->id;
 
   dsend_packet_unit_get_actions(&client.conn,
                                 punit->id,
@@ -966,8 +974,15 @@
 {
   struct unit *old;
 
+  /* 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
+                || old_actor_id == IDENTITY_NUMBER_ZERO,
+                "Decision taken for %d but selection is for %d.",
+                old_actor_id, action_selection_in_progress_for);
+
   /* Stop objecting to allowing the next unit to ask. */
-  action_selection_in_progress = FALSE;
+  action_selection_in_progress_for = IDENTITY_NUMBER_ZERO;
 
   if ((old = game_unit_by_number(old_actor_id))) {
     /* Have the server record that a decision no longer is wanted. */


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

Reply via email to