Author: sveinung
Date: Thu Nov 19 10:27:44 2015
New Revision: 30685

URL: http://svn.gna.org/viewcvs/freeciv?rev=30685&view=rev
Log:
Show action selection dialog when reconnecting

A unit performing an ORDER_ACTION_MOVE order during turn change may cause
an action selection dialog to pop up. A player may be disconnected during
turn change.

Remember action selection dialogs the player haven't seen yet. Pop them up
when he connects. An action selection dialog is considered seen when the
client asks what the alternatives are.

This patch doesn't save the fact that a unit wants an action dialog to pop
up.

See patch #6601

Modified:
    branches/S2_6/client/control.c
    branches/S2_6/client/packhand.c
    branches/S2_6/common/fc_types.h
    branches/S2_6/common/packets.def
    branches/S2_6/common/unit.c
    branches/S2_6/common/unit.h
    branches/S2_6/fc_version
    branches/S2_6/server/unithand.c
    branches/S2_6/server/unittools.c

Modified: branches/S2_6/client/control.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/control.c?rev=30685&r1=30684&r2=30685&view=diff
==============================================================================
--- branches/S2_6/client/control.c      (original)
+++ branches/S2_6/client/control.c      Thu Nov 19 10:27:44 2015
@@ -953,6 +953,12 @@
    * Stop if one is (about to pop) up. */
   if (have_asked_server_for_actions
       || action_selection_actor_unit() != IDENTITY_NUMBER_ZERO) {
+    return;
+  }
+
+  /* The server may inform about units that wants input before the client
+   * is ready to give orders. */
+  if (!can_client_issue_orders()) {
     return;
   }
 

Modified: branches/S2_6/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/packhand.c?rev=30685&r1=30684&r2=30685&view=diff
==============================================================================
--- branches/S2_6/client/packhand.c     (original)
+++ branches/S2_6/client/packhand.c     Thu Nov 19 10:27:44 2015
@@ -107,6 +107,8 @@
                                struct tile_list *worked_tiles,
                                bool is_new, bool popup, bool investigate);
 static bool handle_unit_packet_common(struct unit *packet_unit);
+static void unit_actor_wants_input(struct unit *pdiplomat,
+                                   int target_tile_id);
 
 
 /* The dumbest of cities, placeholders for unknown and unseen cities. */
@@ -245,6 +247,10 @@
       punit->orders.list[i].target = packet->orders_targets[i];
     }
   }
+
+  punit->action_decision_want = packet->action_decision_want;
+  punit->action_decision_tile
+      = index_to_tile(packet->action_decision_tile);
 
   punit->client.asking_city_name = FALSE;
 
@@ -1230,6 +1236,10 @@
 
   set_client_state(C_S_RUNNING);
 
+  /* The action queue can have units the server requested to be added
+   * while the client connected. */
+  choose_action_queue_next();
+
   game.info.phase = phase;
 
   /* Possibly replace wait cursor with something else */
@@ -1706,6 +1716,15 @@
     /* This won't change punit; it enqueues the call for later handling. */
     agents_unit_changed(punit);
     editgui_notify_object_changed(OBJTYPE_UNIT, punit->id, FALSE);
+
+    if (punit->action_decision_want != packet_unit->action_decision_want
+        && packet_unit->action_decision_want) {
+      /* The unit wants the player to decide. */
+      unit_actor_wants_input(punit,
+          packet_unit->action_decision_tile->index);
+    }
+    punit->action_decision_want = packet_unit->action_decision_want;
+    punit->action_decision_tile = packet_unit->action_decision_tile;
   } else {
     /*** Create new unit ***/
     punit = packet_unit;
@@ -1744,6 +1763,11 @@
     if ((pcity = tile_city(unit_tile(punit)))) {
       /* The unit is in a city - obviously it's occupied. */
       pcity->client.occupied = TRUE;
+    }
+
+    if (punit->action_decision_want) {
+      /* The unit wants the player to decide. */
+      unit_actor_wants_input(punit, punit->action_decision_tile->index);
     }
 
     need_units_report_update = TRUE;
@@ -4074,14 +4098,10 @@
 /**************************************************************************
   Handle request for user input on what diplomat action to do.
 **************************************************************************/
-void handle_unit_actor_wants_input(int diplomat_id, int target_tile_id)
-{
-  struct unit *pdiplomat = player_unit_by_number(client_player(),
-                                                     diplomat_id);
-
-  if (can_client_issue_orders()) {
-    process_diplomat_arrival(pdiplomat, target_tile_id);
-  }
+static void unit_actor_wants_input(struct unit *pdiplomat,
+                                   int target_tile_id)
+{
+  process_diplomat_arrival(pdiplomat, target_tile_id);
 }
 
 /**************************************************************************

Modified: branches/S2_6/common/fc_types.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/fc_types.h?rev=30685&r1=30684&r2=30685&view=diff
==============================================================================
--- branches/S2_6/common/fc_types.h     (original)
+++ branches/S2_6/common/fc_types.h     Thu Nov 19 10:27:44 2015
@@ -665,6 +665,19 @@
 #define SPECENUM_COUNT MOOD_COUNT
 #include "specenum_gen.h"
 
+/* Used in the network protocol. */
+#define SPECENUM_NAME action_decision
+/* Don't want the player to decide what action to take. */
+#define SPECENUM_VALUE0 ACT_DEC_NOTHING
+#define SPECENUM_VALUE0NAME N_("nothing")
+/* Wants a decision because of something done to the actor. */
+#define SPECENUM_VALUE1 ACT_DEC_PASSIVE
+#define SPECENUM_VALUE1NAME N_("passive")
+/* Wants a decision because of something the actor did. */
+#define SPECENUM_VALUE2 ACT_DEC_ACTIVE
+#define SPECENUM_VALUE2NAME N_("active")
+#include "specenum_gen.h"
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */

Modified: branches/S2_6/common/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/packets.def?rev=30685&r1=30684&r2=30685&view=diff
==============================================================================
--- branches/S2_6/common/packets.def    (original)
+++ branches/S2_6/common/packets.def    Thu Nov 19 10:27:44 2015
@@ -238,6 +238,7 @@
 type TRI                = uint8(enum traderoute_illegal_cancelling)
 type MOVE_MODE          = uint8(enum road_move_mode)
 type GEN_ACTION         = uint8(enum gen_action)
+type ACTION_DECISION    = uint8(enum action_decision)
 type REVOLENTYPE        = uint8(enum revolen_type)
 type HAPPYBORDERSTYPE   = uint8(enum happyborders_type)
 type TECH_COST_STYLE    = uint8(enum tech_cost_style)
@@ -910,6 +911,9 @@
   DIRECTION orders_dirs[MAX_LEN_ROUTE:orders_length];
   ACTIVITY orders_activities[MAX_LEN_ROUTE:orders_length];
   EXTRA orders_targets[MAX_LEN_ROUTE:orders_length];
+
+  ACTION_DECISION action_decision_want;
+  TILE action_decision_tile;
 end
 
 PACKET_UNIT_SHORT_INFO = 64; sc, lsend, is-game-info, force, 
cancel(PACKET_UNIT_INFO)
@@ -1028,11 +1032,6 @@
   UNIT target_id;   # city_id or unit_id
   GOLD cost;
   GEN_ACTION action_type;
-end
-
-PACKET_UNIT_ACTOR_WANTS_INPUT = 86; sc, dsend, lsend
-  UNIT diplomat_id;
-  TILE target_tile_id;
 end
 
 PACKET_UNIT_GET_ACTIONS = 87; cs, handle-per-conn, dsend

Modified: branches/S2_6/common/unit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/unit.c?rev=30685&r1=30684&r2=30685&view=diff
==============================================================================
--- branches/S2_6/common/unit.c (original)
+++ branches/S2_6/common/unit.c Thu Nov 19 10:27:44 2015
@@ -1761,6 +1761,9 @@
   set_unit_activity(punit, ACTIVITY_IDLE);
   punit->battlegroup = BATTLEGROUP_NONE;
   punit->has_orders = FALSE;
+
+  punit->action_decision_want = ACT_DEC_NOTHING;
+  punit->action_decision_tile = NULL;
 
   if (is_server()) {
     punit->server.debug = FALSE;

Modified: branches/S2_6/common/unit.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/unit.h?rev=30685&r1=30684&r2=30685&view=diff
==============================================================================
--- branches/S2_6/common/unit.h (original)
+++ branches/S2_6/common/unit.h Thu Nov 19 10:27:44 2015
@@ -169,6 +169,10 @@
     bool vigilant; /* Orders should be cleared if an enemy is met. */
     struct unit_order *list;
   } orders;
+
+  /* The unit may want the player to choose an action. */
+  enum action_decision action_decision_want;
+  struct tile *action_decision_tile;
 
   union {
     struct {

Modified: branches/S2_6/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/fc_version?rev=30685&r1=30684&r2=30685&view=diff
==============================================================================
--- branches/S2_6/fc_version    (original)
+++ branches/S2_6/fc_version    Thu Nov 19 10:27:44 2015
@@ -54,7 +54,7 @@
 #   - Avoid adding a new mandatory capability to the development branch for
 #     as long as possible.  We want to maintain network compatibility with
 #     the stable branch for as long as possible.
-NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-2.6-2015.Nov.15"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-2.6-2015.Nov.19"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: branches/S2_6/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/unithand.c?rev=30685&r1=30684&r2=30685&view=diff
==============================================================================
--- branches/S2_6/server/unithand.c     (original)
+++ branches/S2_6/server/unithand.c     Thu Nov 19 10:27:44 2015
@@ -716,6 +716,18 @@
   actor_unit = game_unit_by_number(actor_unit_id);
   target_tile = index_to_tile(target_tile_id);
 
+  if (disturb_player
+      && actor_unit
+      && actor_unit->action_decision_want
+      && actor_unit->action_decision_tile == target_tile) {
+    /* The client has now asked for alternatives to show the player. */
+    actor_unit->action_decision_want = ACT_DEC_NOTHING;
+    actor_unit->action_decision_tile = NULL;
+
+    /* Let the client know so future changes are seen as changes. */
+    send_unit_info(player_reply_dest(actor_player), actor_unit);
+  }
+
   /* Check if the request is valid. */
   if (!target_tile || !actor_unit || !actor_player
       || actor_unit->owner != actor_player) {
@@ -2271,18 +2283,14 @@
         if (pplayer->ai_controlled) {
           return FALSE;
         }
-        
-        /* If we didn't send_unit_info the client would sometimes
-         * think that the diplomat didn't have any moves left and so
-         * don't pop up the box.  (We are in the middle of the unit
-         * restore cycle when doing goto's, and the unit's movepoints
-         * have been restored, but we only send the unit info at the
-         * end of the function.) */
+
+        punit->action_decision_want = ACT_DEC_ACTIVE;
+        punit->action_decision_tile = pdesttile;
+
+        /* Let the client know that this unit needs the player to decide
+         * what to do. */
         send_unit_info(player_reply_dest(pplayer), punit);
 
-        dlsend_packet_unit_actor_wants_input(player_reply_dest(pplayer),
-                                             punit->id,
-                                             pdesttile->index);
         return FALSE;
       } else if (!may_non_act_move(punit, pcity, pdesttile, igzoc)) {
         /* No action can be done. No regular move can be done. Attack isn't

Modified: branches/S2_6/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/unittools.c?rev=30685&r1=30684&r2=30685&view=diff
==============================================================================
--- branches/S2_6/server/unittools.c    (original)
+++ branches/S2_6/server/unittools.c    Thu Nov 19 10:27:44 2015
@@ -2307,6 +2307,11 @@
     packet->orders_repeat = packet->orders_vigilant = FALSE;
     /* No need to initialize array. */
   }
+
+  packet->action_decision_want = punit->action_decision_want;
+  packet->action_decision_tile = (punit->action_decision_tile
+                                  ? tile_index(punit->action_decision_tile)
+                                  : IDENTITY_NUMBER_ZERO);
 }
 
 /**************************************************************************


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

Reply via email to