Author: sveinung
Date: Thu Nov 19 10:26:31 2015
New Revision: 30682

URL: http://svn.gna.org/viewcvs/freeciv?rev=30682&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:
    trunk/client/control.c
    trunk/client/packhand.c
    trunk/common/fc_types.h
    trunk/common/packets.def
    trunk/common/unit.c
    trunk/common/unit.h
    trunk/fc_version
    trunk/server/unithand.c
    trunk/server/unittools.c

Modified: trunk/client/control.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/control.c?rev=30682&r1=30681&r2=30682&view=diff
==============================================================================
--- trunk/client/control.c      (original)
+++ trunk/client/control.c      Thu Nov 19 10:26:31 2015
@@ -965,6 +965,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: trunk/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/packhand.c?rev=30682&r1=30681&r2=30682&view=diff
==============================================================================
--- trunk/client/packhand.c     (original)
+++ trunk/client/packhand.c     Thu Nov 19 10:26:31 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. */
@@ -250,6 +252,10 @@
                 || action_id_is_valid(punit->orders.list[i].action));
     }
   }
+
+  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;
 
@@ -1265,6 +1271,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 */
@@ -1717,6 +1727,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;
@@ -1755,6 +1774,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;
@@ -4121,21 +4145,17 @@
 /**************************************************************************
   Handle request for user input on what diplomat action to do.
 **************************************************************************/
-void handle_unit_actor_wants_input(int diplomat_id, int target_tile_id,
-                                   bool is_arrival)
-{
-  struct unit *pdiplomat = player_unit_by_number(client_player(),
-                                                     diplomat_id);
-
-  if (is_arrival && !gui_options.popup_actor_arrival) {
+static void unit_actor_wants_input(struct unit *pdiplomat,
+                                   int target_tile_id)
+{
+  if (pdiplomat->action_decision_want == ACT_DEC_PASSIVE
+      && !gui_options.popup_actor_arrival) {
     /* The player isn't interested in getting a pop up for a mere
      * arrival. */
     return;
   }
 
-  if (can_client_issue_orders()) {
-    process_diplomat_arrival(pdiplomat, target_tile_id);
-  }
+  process_diplomat_arrival(pdiplomat, target_tile_id);
 }
 
 /**************************************************************************

Modified: trunk/common/fc_types.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/fc_types.h?rev=30682&r1=30681&r2=30682&view=diff
==============================================================================
--- trunk/common/fc_types.h     (original)
+++ trunk/common/fc_types.h     Thu Nov 19 10:26:31 2015
@@ -695,6 +695,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: trunk/common/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/packets.def?rev=30682&r1=30681&r2=30682&view=diff
==============================================================================
--- trunk/common/packets.def    (original)
+++ trunk/common/packets.def    Thu Nov 19 10:26:31 2015
@@ -241,6 +241,7 @@
 type RDIR               = uint8(enum route_direction)
 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)
@@ -926,6 +927,9 @@
   ACTIVITY orders_activities[MAX_LEN_ROUTE:orders_length];
   ACTION_TGT orders_targets[MAX_LEN_ROUTE:orders_length];
   GEN_ACTION orders_actions[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)
@@ -1033,13 +1037,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;
-
-  BOOL is_arrival;
 end
 
 PACKET_UNIT_GET_ACTIONS = 87; cs, handle-per-conn, dsend

Modified: trunk/common/unit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unit.c?rev=30682&r1=30681&r2=30682&view=diff
==============================================================================
--- trunk/common/unit.c (original)
+++ trunk/common/unit.c Thu Nov 19 10:26:31 2015
@@ -1747,6 +1747,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: trunk/common/unit.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unit.h?rev=30682&r1=30681&r2=30682&view=diff
==============================================================================
--- trunk/common/unit.h (original)
+++ trunk/common/unit.h Thu Nov 19 10:26:31 2015
@@ -168,6 +168,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: trunk/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/fc_version?rev=30682&r1=30681&r2=30682&view=diff
==============================================================================
--- trunk/fc_version    (original)
+++ trunk/fc_version    Thu Nov 19 10:26:31 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-3.0-2015.Nov.15"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2015.Nov.19"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=30682&r1=30681&r2=30682&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Thu Nov 19 10:26:31 2015
@@ -908,6 +908,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) {
@@ -2964,18 +2976,13 @@
           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,
-                                             FALSE);
         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: trunk/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unittools.c?rev=30682&r1=30681&r2=30682&view=diff
==============================================================================
--- trunk/server/unittools.c    (original)
+++ trunk/server/unittools.c    Thu Nov 19 10:26:31 2015
@@ -2318,6 +2318,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);
 }
 
 /**************************************************************************
@@ -3709,9 +3714,12 @@
       if (action_tgt_city(act_unit, pdesttile, FALSE)) {
         /* There is a valid target. */
 
-        dlsend_packet_unit_actor_wants_input(
-              player_reply_dest(act_player), act_unit->id,
-              pdesttile->index, TRUE);
+        act_unit->action_decision_want = ACT_DEC_PASSIVE;
+        act_unit->action_decision_tile = pdesttile;
+
+        /* Let the client know that this unit wants the player to decide
+         * what to do. */
+        send_unit_info(player_reply_dest(act_player), act_unit);
       }
     } unit_move_data_list_iterate_end;
   }


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

Reply via email to