Author: sveinung
Date: Thu Nov 26 10:25:28 2015
New Revision: 30792

URL: http://svn.gna.org/viewcvs/freeciv?rev=30792&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.

See patch #6412

Modified:
    branches/S2_6/client/packhand.c
    branches/S2_6/fc_version
    branches/S2_6/server/unithand.c
    branches/S2_6/server/unithand.h
    branches/S2_6/server/unittools.c

Modified: branches/S2_6/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/packhand.c?rev=30792&r1=30791&r2=30792&view=diff
==============================================================================
--- branches/S2_6/client/packhand.c     (original)
+++ branches/S2_6/client/packhand.c     Thu Nov 26 10:25:28 2015
@@ -1653,30 +1653,6 @@
           repaint_city = TRUE;
         } else {
           refresh_city_dialog(ccity);
-        }
-
-        if (gui_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;
-            }
-          }
         }
       }
 
@@ -4102,6 +4078,13 @@
 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;
+  }
+
   process_diplomat_arrival(pdiplomat, target_tile_id);
 }
 

Modified: branches/S2_6/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/fc_version?rev=30792&r1=30791&r2=30792&view=diff
==============================================================================
--- branches/S2_6/fc_version    (original)
+++ branches/S2_6/fc_version    Thu Nov 26 10:25:28 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.19b"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-2.6-2015.Nov.26"
 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=30792&r1=30791&r2=30792&view=diff
==============================================================================
--- branches/S2_6/server/unithand.c     (original)
+++ branches/S2_6/server/unithand.c     Thu Nov 26 10:25:28 2015
@@ -453,6 +453,16 @@
   }
 
   return NULL;
+}
+
+/**************************************************************************
+  Find a city to target for an action on the specified tile.
+
+  Returns NULL if no proper target is found.
+**************************************************************************/
+struct city *action_tgt_city(struct unit *actor, struct tile *target_tile)
+{
+  return tgt_city(actor, target_tile);
 }
 
 /**************************************************************************

Modified: branches/S2_6/server/unithand.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/unithand.h?rev=30792&r1=30791&r2=30792&view=diff
==============================================================================
--- branches/S2_6/server/unithand.h     (original)
+++ branches/S2_6/server/unithand.h     Thu Nov 26 10:25:28 2015
@@ -30,4 +30,6 @@
 void city_add_or_build_error(struct player *pplayer, struct unit *punit,
                              enum unit_add_build_city_result res);
 
+struct city *action_tgt_city(struct unit *actor, struct tile *target_tile);
+
 #endif  /* FC__UNITHAND_H */

Modified: branches/S2_6/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/unittools.c?rev=30792&r1=30791&r2=30792&view=diff
==============================================================================
--- branches/S2_6/server/unittools.c    (original)
+++ branches/S2_6/server/unittools.c    Thu Nov 26 10:25:28 2015
@@ -3656,6 +3656,81 @@
     } 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. */
+
+        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;
+  }
+
   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