Author: sveinung
Date: Wed Oct 14 12:38:32 2015
New Revision: 30072

URL: http://svn.gna.org/viewcvs/freeciv?rev=30072&view=rev
Log:
Server side actor unit arrival pop up

The client can pop up the action selection dialog when a transported actor
unit is moved inside a city it can act against. (Think of a Freight in a
Transport arriving in a city it can establish a trade route to) If this
should happen is controlled by a client setting.

Move the code that detects actor unit arrival to the server. This will
allow it to share more code with the "is this move an action" test.

See patch #6412

Modified:
    trunk/client/packhand.c
    trunk/common/packets.def
    trunk/fc_version
    trunk/server/unithand.c
    trunk/server/unittools.c

Modified: trunk/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/packhand.c?rev=30072&r1=30071&r2=30072&view=diff
==============================================================================
--- trunk/client/packhand.c     (original)
+++ trunk/client/packhand.c     Wed Oct 14 12:38:32 2015
@@ -1664,30 +1664,6 @@
           repaint_city = TRUE;
         } else {
           refresh_city_dialog(ccity);
-        }
-
-        if (options.popup_actor_arrival
-            && client_has_player()
-            && client_player() == unit_owner(punit)
-            && !client_player()->ai_controlled
-            && can_client_issue_orders()
-            && !unit_has_orders(punit)
-             /* the server handles non transported units */
-            && NULL != unit_transport_get(punit)
-            && utype_may_act_at_all(unit_type_get(punit))) {
-          /* Open action dialog only if 'punit' and all its transporters
-           * (recursively) don't have orders. */
-          struct unit *ptrans;
-
-          for (ptrans = unit_transport_get(punit);;
-               ptrans = unit_transport_get(ptrans)) {
-            if (NULL == ptrans) {
-              process_diplomat_arrival(punit, unit_tile(punit)->index);
-              break;
-            } else if (unit_has_orders(ptrans)) {
-              break;
-            }
-          }
         }
       }
 
@@ -4129,10 +4105,17 @@
 /**************************************************************************
   Handle request for user input on what diplomat action to do.
 **************************************************************************/
-void handle_unit_diplomat_wants_input(int diplomat_id, int target_tile_id)
+void handle_unit_diplomat_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 && !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);

Modified: trunk/common/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/packets.def?rev=30072&r1=30071&r2=30072&view=diff
==============================================================================
--- trunk/common/packets.def    (original)
+++ trunk/common/packets.def    Wed Oct 14 12:38:32 2015
@@ -1035,6 +1035,8 @@
 PACKET_UNIT_DIPLOMAT_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/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/fc_version?rev=30072&r1=30071&r2=30072&view=diff
==============================================================================
--- trunk/fc_version    (original)
+++ trunk/fc_version    Wed Oct 14 12:38:32 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.Oct.11"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2015.Oct.14"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=30072&r1=30071&r2=30072&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Wed Oct 14 12:38:32 2015
@@ -3000,7 +3000,8 @@
 
         dlsend_packet_unit_diplomat_wants_input(player_reply_dest(pplayer),
                                                 punit->id,
-                                                pdesttile->index);
+                                                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=30072&r1=30071&r2=30072&view=diff
==============================================================================
--- trunk/server/unittools.c    (original)
+++ trunk/server/unittools.c    Wed Oct 14 12:38:32 2015
@@ -3641,6 +3641,78 @@
     } players_iterate_end;
   } unit_move_data_list_iterate_rev_end;
 
+  /* Inform the owner's client about actor unit arrival. Can, depending on
+   * the client settings, cause the client to start the process that makes
+   * the action selection dialog pop up. */
+  if ((pcity = tile_city(pdesttile))) {
+    /* Arrival in a city counts. */
+
+    unit_move_data_list_iterate(plist, pmove_data) {
+      struct unit *ptrans;
+      bool ok;
+      struct unit *act_unit;
+      struct player *act_player;
+
+      act_unit = pmove_data->punit;
+      act_player = unit_owner(act_unit);
+
+      if (act_unit == NULL
+          || !unit_alive(act_unit->id)) {
+        /* The unit died before reaching this point. */
+        continue;
+      }
+
+      if (unit_tile(act_unit) != pdesttile) {
+        /* The unit didn't arrive at the destination tile. */
+        continue;
+      }
+
+      if (act_player->ai_controlled) {
+        /* The AI doesn't need reminders. */
+        continue;
+      }
+
+      if (!unit_transported(act_unit)) {
+        /* Don't show the action selection dialog again. Non transported
+         * units are handled before they move to the tile.  */
+        continue;
+      }
+
+      /* Open action dialog only if 'act_unit' and all its transporters
+       * (recursively) don't have orders. */
+      if (unit_has_orders(act_unit)) {
+        /* The unit it self has orders. */
+        continue;
+      }
+
+      for (ptrans = unit_transport_get(act_unit);;
+           ptrans = unit_transport_get(ptrans)) {
+        if (NULL == ptrans) {
+          /* No (recursive) transport has orders. */
+          ok = TRUE;
+          break;
+        } else if (unit_has_orders(ptrans)) {
+          /* A unit transporting the unit has orders */
+          ok = FALSE;
+          break;
+        }
+      }
+
+      if (!ok) {
+        /* A unit transporting act_unit has orders. */
+        continue;
+      }
+
+      if (action_tgt_city(act_unit, pdesttile)) {
+        /* There is a valid target. */
+
+        dlsend_packet_unit_diplomat_wants_input(
+              player_reply_dest(act_player), act_unit->id,
+              pdesttile->index, TRUE);
+      }
+    } unit_move_data_list_iterate_end;
+  }
+
   unit_move_data_list_destroy(plist);
 
   /* Check cities at source and destination. */


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

Reply via email to