Author: cazfi
Date: Wed Dec 16 21:04:49 2015
New Revision: 31023

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

See patch #6457

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

Modified: trunk/ai/default/aiferry.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/aiferry.c?rev=31023&r1=31022&r2=31023&view=diff
==============================================================================
--- trunk/ai/default/aiferry.c  (original)
+++ trunk/ai/default/aiferry.c  Wed Dec 16 21:04:49 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: trunk/client/control.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/control.c?rev=31023&r1=31022&r2=31023&view=diff
==============================================================================
--- trunk/client/control.c      (original)
+++ trunk/client/control.c      Wed Dec 16 21:04:49 2015
@@ -1761,10 +1761,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: trunk/common/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/packets.def?rev=31023&r1=31022&r2=31023&view=diff
==============================================================================
--- trunk/common/packets.def    (original)
+++ trunk/common/packets.def    Wed Dec 16 21:04:49 2015
@@ -1004,7 +1004,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: trunk/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/fc_version?rev=31023&r1=31022&r2=31023&view=diff
==============================================================================
--- trunk/fc_version    (original)
+++ trunk/fc_version    Wed Dec 16 21:04:49 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.Dec.16"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2015.Dec.16b"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=31023&r1=31022&r2=31023&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Wed Dec 16 21:04:49 2015
@@ -3688,10 +3688,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. */
@@ -3705,11 +3711,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)) {
+   * 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