Author: cazfi
Date: Wed Aug 17 20:25:53 2016
New Revision: 33637

URL: http://svn.gna.org/viewcvs/freeciv?rev=33637&view=rev
Log:
Keep information about carried good in unit structure.

See patch #7600

Modified:
    trunk/client/packhand.c
    trunk/common/networking/packets.def
    trunk/common/traderoutes.c
    trunk/common/traderoutes.h
    trunk/common/unit.c
    trunk/common/unit.h
    trunk/fc_version
    trunk/server/savegame3.c
    trunk/server/unithand.c
    trunk/server/unittools.c
    trunk/server/unittools.h

Modified: trunk/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/packhand.c?rev=33637&r1=33636&r2=33637&view=diff
==============================================================================
--- trunk/client/packhand.c     (original)
+++ trunk/client/packhand.c     Wed Aug 17 20:25:53 2016
@@ -227,6 +227,11 @@
     punit->client.transported_by = packet->transported_by;
   } else {
     punit->client.transported_by = -1;
+  }
+  if (packet->carrying >= 0) {
+    punit->carrying = goods_by_number(packet->carrying);
+  } else {
+    punit->carrying = NULL;
   }
 
   punit->battlegroup = packet->battlegroup;

Modified: trunk/common/networking/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/networking/packets.def?rev=33637&r1=33636&r2=33637&view=diff
==============================================================================
--- trunk/common/networking/packets.def (original)
+++ trunk/common/networking/packets.def Wed Aug 17 20:25:53 2016
@@ -952,6 +952,7 @@
 
   UNIT_TYPE type;
   UNIT transported_by; /* Only valid if transported is set. */
+  SINT8 carrying;
   MOVEFRAGS movesleft;
   UINT8 hp, fuel;
   /* UINT16 size for activity_count assumed in checks in ruleset.c */

Modified: trunk/common/traderoutes.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/traderoutes.c?rev=33637&r1=33636&r2=33637&view=diff
==============================================================================
--- trunk/common/traderoutes.c  (original)
+++ trunk/common/traderoutes.c  Wed Aug 17 20:25:53 2016
@@ -25,6 +25,7 @@
 #include "game.h"
 #include "map.h"
 #include "tile.h"
+#include "unittype.h"
 
 #include "traderoutes.h"
 
@@ -505,11 +506,20 @@
 /****************************************************************************
   Can the city provide goods.
 ****************************************************************************/
-bool goods_can_be_provided(struct city *pcity, struct goods_type *pgood)
-{
+bool goods_can_be_provided(struct city *pcity, struct goods_type *pgood,
+                           struct unit *punit)
+{
+  struct unit_type *ptype;
+
+  if (punit != NULL) {
+    ptype = unit_type_get(punit);
+  } else {
+    ptype = NULL;
+  }
+  
   return are_reqs_active(city_owner(pcity), NULL,
                          pcity, NULL, city_tile(pcity),
-                         NULL, NULL, NULL, NULL, NULL,
+                         punit, ptype, NULL, NULL, NULL,
                          &pgood->reqs, RPT_CERTAIN);
 }
 
@@ -532,13 +542,13 @@
 /****************************************************************************
   Return goods type for the new traderoute between given cities.
 ****************************************************************************/
-struct goods_type *goods_for_new_route(struct city *src, struct city *dest)
+struct goods_type *goods_from_city_to_unit(struct city *src, struct unit 
*punit)
 {
   int i = 0;
   struct goods_type *potential[MAX_GOODS_TYPES];
 
   goods_type_iterate(pgood) {
-    if (goods_can_be_provided(src, pgood)) {
+    if (goods_can_be_provided(src, pgood, punit)) {
       potential[i++] = pgood;
     }
   } goods_type_iterate_end;

Modified: trunk/common/traderoutes.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/traderoutes.h?rev=33637&r1=33636&r2=33637&view=diff
==============================================================================
--- trunk/common/traderoutes.h  (original)
+++ trunk/common/traderoutes.h  Wed Aug 17 20:25:53 2016
@@ -173,8 +173,9 @@
 const char *goods_rule_name(struct goods_type *pgood);
 struct goods_type *goods_by_rule_name(const char *name);
 
-bool goods_can_be_provided(struct city *pcity, struct goods_type *pgood);
-struct goods_type *goods_for_new_route(struct city *src, struct city *dest);
+bool goods_can_be_provided(struct city *pcity, struct goods_type *pgood,
+                           struct unit *punit);
+struct goods_type *goods_from_city_to_unit(struct city *src, struct unit 
*punit);
 bool city_receives_goods(const struct city *pcity,
                          const struct goods_type *pgood);
 

Modified: trunk/common/unit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unit.c?rev=33637&r1=33636&r2=33637&view=diff
==============================================================================
--- trunk/common/unit.c (original)
+++ trunk/common/unit.c Wed Aug 17 20:25:53 2016
@@ -1627,6 +1627,8 @@
 
   punit->transporter = NULL;
   punit->transporting = unit_list_new();
+
+  punit->carrying = NULL;
 
   set_unit_activity(punit, ACTIVITY_IDLE);
   punit->battlegroup = BATTLEGROUP_NONE;

Modified: trunk/common/unit.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unit.h?rev=33637&r1=33636&r2=33637&view=diff
==============================================================================
--- trunk/common/unit.h (original)
+++ trunk/common/unit.h Wed Aug 17 20:25:53 2016
@@ -158,6 +158,8 @@
 
   struct unit *transporter;   /* This unit is transported by ... */
   struct unit_list *transporting; /* This unit transports ... */
+
+  struct goods_type *carrying;
 
   /* The battlegroup ID: defined by the client but stored by the server. */
 #define MAX_NUM_BATTLEGROUPS (4)

Modified: trunk/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/fc_version?rev=33637&r1=33636&r2=33637&view=diff
==============================================================================
--- trunk/fc_version    (original)
+++ trunk/fc_version    Wed Aug 17 20:25:53 2016
@@ -56,7 +56,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-2016.Aug.17"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2016.Aug.17b"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: trunk/server/savegame3.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame3.c?rev=33637&r1=33636&r2=33637&view=diff
==============================================================================
--- trunk/server/savegame3.c    (original)
+++ trunk/server/savegame3.c    Wed Aug 17 20:25:53 2016
@@ -5061,6 +5061,7 @@
   enum tile_special_type cfspe;
   int natnbr;
   int unconverted;
+  const char *str;
 
   sg_warn_ret_val(secfile_lookup_int(loading->file, &punit->id, "%s.id",
                                      unitstr), FALSE, "%s", secfile_error());
@@ -5312,6 +5313,10 @@
   punit->paradropped
     = secfile_lookup_bool_default(loading->file, FALSE,
                                   "%s.paradropped", unitstr);
+  str = secfile_lookup_str_default(loading->file, "", "%s.carrying", unitstr);
+  if (str[0] != '\0') {
+    punit->carrying = goods_by_rule_name(str);
+  }
 
   /* The transport status (punit->transported_by) is loaded in
    * sg_player_units_transport(). */
@@ -5697,6 +5702,12 @@
     secfile_insert_int(saving->file, unit_transport_get(punit)
                                      ? unit_transport_get(punit)->id : -1,
                        "%s.transported_by", buf);
+    if (punit->carrying != NULL) {
+      secfile_insert_str(saving->file, goods_rule_name(punit->carrying),
+                         "%s.carrying", buf);
+    } else {
+      secfile_insert_str(saving->file, "", "%s.carrying", buf);
+    }
 
     secfile_insert_int(saving->file, punit->action_decision_want,
                        "%s.action_decision", buf);

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=33637&r1=33636&r2=33637&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Wed Aug 17 20:25:53 2016
@@ -2414,6 +2414,8 @@
     send_city_info(old_owner, old_pcity);
   }
 
+  unit_get_goods(punit);
+
   fc_assert(unit_owner(punit) == city_owner(new_pcity));
 }
 
@@ -3692,7 +3694,15 @@
                     " a trade route because it has no home city."),
                   unit_link(punit));
     return FALSE;
-   
+  }
+
+  goods = punit->carrying;
+  if (goods == NULL) {
+    notify_player(pplayer, unit_tile(punit), E_BAD_COMMAND, ftc_server,
+                  _("Sorry, your %s cannot establish"
+                    " a trade route because it's not carrying any goods."),
+                  unit_link(punit));
+    return FALSE;
   }
 
   sz_strlcpy(homecity_link, city_link(pcity_homecity));
@@ -3806,7 +3816,6 @@
 
   conn_list_do_buffer(pplayer->connections);
 
-  goods = goods_for_new_route(pcity_homecity, pcity_dest);
   goods_str = goods_name_translation(goods);
 
   if (bonus_str != NULL) {

Modified: trunk/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unittools.c?rev=33637&r1=33636&r2=33637&view=diff
==============================================================================
--- trunk/server/unittools.c    (original)
+++ trunk/server/unittools.c    Wed Aug 17 20:25:53 2016
@@ -1537,14 +1537,28 @@
 }
 
 /**************************************************************************
+  Set carried goods for unit.
+**************************************************************************/
+void unit_get_goods(struct unit *punit)
+{
+  if (punit->homecity != 0) {
+    struct city *home = game_city_by_number(punit->homecity);
+
+    if (home != NULL) {
+      punit->carrying = goods_from_city_to_unit(home, punit);
+    }
+  }
+}
+
+/**************************************************************************
   Creates a unit, and set it's initial values, and put it into the right 
   lists.
   If moves_left is less than zero, unit will get max moves.
 **************************************************************************/
 struct unit *create_unit_full(struct player *pplayer, struct tile *ptile,
-                             struct unit_type *type, int veteran_level, 
+                              struct unit_type *type, int veteran_level, 
                               int homecity_id, int moves_left, int hp_left,
-                             struct unit *ptrans)
+                              struct unit *ptrans)
 {
   struct unit *punit = unit_virtual_create(pplayer, NULL, type, veteran_level);
   struct city *pcity;
@@ -1609,6 +1623,8 @@
   /* The unit may have changed the available tiles in nearby cities. */
   city_map_update_tile_now(ptile);
   sync_cities();
+
+  unit_get_goods(punit);
 
   CALL_PLR_AI_FUNC(unit_got, pplayer, punit);
 
@@ -2438,6 +2454,11 @@
     packet->transported = TRUE;
     packet->transported_by = unit_transport_get(punit)->id;
   }
+  if (punit->carrying != NULL) {
+    packet->carrying = goods_index(punit->carrying);
+  } else {
+    packet->carrying = -1;
+  }
   packet->occupied = (get_transporter_occupancy(punit) > 0);
   packet->battlegroup = punit->battlegroup;
   packet->has_orders = punit->has_orders;

Modified: trunk/server/unittools.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unittools.h?rev=33637&r1=33636&r2=33637&view=diff
==============================================================================
--- trunk/server/unittools.h    (original)
+++ trunk/server/unittools.h    Wed Aug 17 20:25:53 2016
@@ -166,4 +166,6 @@
 
 void unit_activities_cancel_all_illegal(const struct tile *ptile);
 
+void unit_get_goods(struct unit *punit);
+
 #endif  /* FC__UNITTOOLS_H */


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

Reply via email to