Author: cazfi
Date: Wed Dec 16 21:05:17 2015
New Revision: 31024

URL: http://svn.gna.org/viewcvs/freeciv?rev=31024&view=rev
Log:
Added server side support for loading units to transport on adjacent tile.

See patch #6457

Modified:
    branches/S2_6/ai/default/aiferry.c
    branches/S2_6/client/control.c
    branches/S2_6/common/packets.def
    branches/S2_6/fc_version
    branches/S2_6/server/unithand.c

Modified: branches/S2_6/ai/default/aiferry.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/default/aiferry.c?rev=31024&r1=31023&r2=31024&view=diff
==============================================================================
--- branches/S2_6/ai/default/aiferry.c  (original)
+++ branches/S2_6/ai/default/aiferry.c  Wed Dec 16 21:05:17 2015
@@ -817,7 +817,7 @@
       return FALSE;
     }
 
-    handle_unit_load(pplayer, punit->id, ferryboat->id);
+    handle_unit_load(pplayer, punit->id, ferryboat->id, 
ferryboat->tile->index);
     fc_assert(unit_transported(punit));
   }
 
@@ -858,7 +858,8 @@
       }
       if (bodyguard) {
         fc_assert(same_pos(unit_tile(punit), unit_tile(bodyguard)));
-        handle_unit_load(pplayer, bodyguard->id, ferryboat->id);
+        handle_unit_load(pplayer, bodyguard->id, ferryboat->id,
+                         ferryboat->tile->index);
       }
       if (!aiferry_goto_amphibious(ait, ferryboat, punit, dest_tile)) {
         /* died */

Modified: branches/S2_6/client/control.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/control.c?rev=31024&r1=31023&r2=31024&view=diff
==============================================================================
--- branches/S2_6/client/control.c      (original)
+++ branches/S2_6/client/control.c      Wed Dec 16 21:05:17 2015
@@ -1679,10 +1679,13 @@
   if (ptrans
       && can_client_issue_orders()
       && can_unit_load(pcargo, ptrans)) {
-    dsend_packet_unit_load(&client.conn, pcargo->id, ptrans->id);
+    dsend_packet_unit_load(&client.conn, pcargo->id, ptrans->id,
+                           ptrans->tile->index);
 
     /* Sentry the unit.  Don't request_unit_sentry since this can give a
      * recursive loop. */
+    /* FIXME: Should not sentry if above loading fails (transport moved away,
+     *        or filled already in server side) */
     dsend_packet_unit_change_activity(&client.conn, pcargo->id,
                                       ACTIVITY_SENTRY, EXTRA_NONE);
   }

Modified: branches/S2_6/common/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/packets.def?rev=31024&r1=31023&r2=31024&view=diff
==============================================================================
--- branches/S2_6/common/packets.def    (original)
+++ branches/S2_6/common/packets.def    Wed Dec 16 21:05:17 2015
@@ -988,7 +988,9 @@
 
 # Load the given cargo into the transporter.
 PACKET_UNIT_LOAD = 75; cs, dsend
-  UNIT cargo_id, transporter_id;
+  UNIT cargo_id;
+  UNIT transporter_id;
+  TILE transporter_tile;
 end
 
 # Unload the given cargo from the transporter.

Modified: branches/S2_6/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/fc_version?rev=31024&r1=31023&r2=31024&view=diff
==============================================================================
--- branches/S2_6/fc_version    (original)
+++ branches/S2_6/fc_version    Wed Dec 16 21:05:17 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.Dec.10"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-2.6-2015.Dec.16"
 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=31024&r1=31023&r2=31024&view=diff
==============================================================================
--- branches/S2_6/server/unithand.c     (original)
+++ branches/S2_6/server/unithand.c     Wed Dec 16 21:05:17 2015
@@ -2981,10 +2981,16 @@
 /****************************************************************************
   Handle a client request to load the given unit into the given transporter.
 ****************************************************************************/
-void handle_unit_load(struct player *pplayer, int cargo_id, int trans_id)
+void handle_unit_load(struct player *pplayer, int cargo_id, int trans_id,
+                      int ttile_idx)
 {
   struct unit *pcargo = player_unit_by_number(pplayer, cargo_id);
   struct unit *ptrans = game_unit_by_number(trans_id);
+  struct tile *ptile = index_to_tile(ttile_idx);
+  struct tile *ctile;
+  struct tile *ttile;
+  bool moves = FALSE;
+  bool leave = FALSE;
 
   if (NULL == pcargo) {
     /* Probably died or bribed. */
@@ -2998,11 +3004,51 @@
     return;
   }
 
+  ttile = unit_tile(ptrans);
+  if (!same_pos(ttile, ptile)) {
+    /* Transport no longer in where client assumed it to be. */
+    return;
+  }
+
+  ctile = unit_tile(pcargo);
+
+  if (!same_pos(ctile, ttile)) {
+    if (pcargo->moves_left <= 0 || !unit_can_move_to_tile(pcargo, ttile, 
FALSE)) {
+      return;
+    }
+
+    moves = TRUE;
+  }
+
+  if (unit_transported(pcargo)) {
+    if (!can_unit_unload(pcargo, ptrans)) {
+      /* Can't leave current transport */
+      return;
+    }
+
+    leave = TRUE;
+  }
+
   /* A player may only load their units, but they may be loaded into
    * other player's transporters, depending on the rules in
-   * can_unit_load(). */
-  if (!can_unit_load(pcargo, ptrans)) {
-    return;
+   * could_unit_load(). */
+  if (!could_unit_load(pcargo, ptrans)) {
+    return;
+  }
+
+  /* It's possible. Let's make all the necessary steps. */
+  if (leave) {
+    unit_transport_unload(pcargo);
+  }
+
+  if (moves) {
+    int id = pcargo->id;
+
+    unit_move_handling(pcargo, ttile, FALSE, FALSE);
+
+    if (!unit_alive(id)) {
+      return;
+    }
   }
 
   /* Load the unit and send out info to clients. */


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

Reply via email to