Author: cazfi
Date: Sat Apr 25 09:24:51 2015
New Revision: 28866

URL: http://svn.gna.org/viewcvs/freeciv?rev=28866&view=rev
Log:
Remember what goods traderoute is about

See patch #6022

Modified:
    trunk/common/city.h
    trunk/common/traderoutes.c
    trunk/common/traderoutes.h
    trunk/server/sanitycheck.c
    trunk/server/savegame.c
    trunk/server/savegame2.c
    trunk/server/savegame3.c
    trunk/server/unithand.c

Modified: trunk/common/city.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/city.h?rev=28866&r1=28865&r2=28866&view=diff
==============================================================================
--- trunk/common/city.h (original)
+++ trunk/common/city.h Sat Apr 25 09:24:51 2015
@@ -325,6 +325,7 @@
   /* trade routes */
   int trade[MAX_TRADE_ROUTES], trade_value[MAX_TRADE_ROUTES];
   enum route_direction trade_direction[MAX_TRADE_ROUTES];
+  struct goods_type *trade_goods[MAX_TRADE_ROUTES];
 
   /* Tile output, regardless of if the tile is actually worked. It is used
    * as cache for the output of the tiles within the city map.

Modified: trunk/common/traderoutes.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/traderoutes.c?rev=28866&r1=28865&r2=28866&view=diff
==============================================================================
--- trunk/common/traderoutes.c  (original)
+++ trunk/common/traderoutes.c  Sat Apr 25 09:24:51 2015
@@ -482,6 +482,29 @@
   return rule_name(&pgood->name);
 }
 
+/**************************************************************************
+  Returns goods type matching rule name or NULL if there is no goods type
+  with such name.
+**************************************************************************/
+struct goods_type *goods_by_rule_name(const char *name)
+{
+  const char *qs;
+
+  if (name == NULL) {
+    return NULL;
+  }
+
+  qs = Qn_(name);
+
+  goods_type_iterate(pgood) {
+    if (!fc_strcasecmp(goods_rule_name(pgood), qs)) {
+      return pgood;
+    }
+  } goods_type_iterate_end;
+
+  return NULL;
+}
+
 /****************************************************************************
   Return goods type for the new traderoute between given cities.
 ****************************************************************************/

Modified: trunk/common/traderoutes.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/traderoutes.h?rev=28866&r1=28865&r2=28866&view=diff
==============================================================================
--- trunk/common/traderoutes.h  (original)
+++ trunk/common/traderoutes.h  Sat Apr 25 09:24:51 2015
@@ -126,6 +126,7 @@
 
 const char *goods_name_translation(struct goods_type *pgood);
 const char *goods_rule_name(struct goods_type *pgood);
+struct goods_type *goods_by_rule_name(const char *name);
 
 struct goods_type *goods_for_new_route(struct city *src, struct city *dest);
 

Modified: trunk/server/sanitycheck.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/sanitycheck.c?rev=28866&r1=28865&r2=28866&view=diff
==============================================================================
--- trunk/server/sanitycheck.c  (original)
+++ trunk/server/sanitycheck.c  Sat Apr 25 09:24:51 2015
@@ -291,6 +291,8 @@
           SANITY_CITY(pcity, pcity->trade_direction[i] == RDIR_BIDIRECTIONAL);
           break;
         }
+
+        SANITY_CITY(pcity, pcity->trade_goods[i] == partner->trade_goods[j]);
       }
     }
   }

Modified: trunk/server/savegame.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame.c?rev=28866&r1=28865&r2=28866&view=diff
==============================================================================
--- trunk/server/savegame.c     (original)
+++ trunk/server/savegame.c     Sat Apr 25 09:24:51 2015
@@ -2306,6 +2306,7 @@
                                                    "player%d.c%d.traderoute%d",
                                                    plrno, i, j);
       pcity->trade_direction[j] = RDIR_BIDIRECTIONAL;
+      pcity->trade_goods[j] = goods_by_number(0); /* First good */
     }
 
     fc_assert_exit_msg(secfile_lookup_int(file, &pcity->food_stock,

Modified: trunk/server/savegame2.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame2.c?rev=28866&r1=28865&r2=28866&view=diff
==============================================================================
--- trunk/server/savegame2.c    (original)
+++ trunk/server/savegame2.c    Sat Apr 25 09:24:51 2015
@@ -2955,6 +2955,7 @@
     pcity->trade[i] = secfile_lookup_int_default(loading->file, 0,
                                                  "%s.traderoute%d", citystr, 
i);
     pcity->trade_direction[i] = RDIR_BIDIRECTIONAL;
+    pcity->trade_goods[i] = goods_by_number(0); /* First good */
   }
 
   sg_warn_ret_val(secfile_lookup_int(loading->file, &pcity->food_stock,

Modified: trunk/server/savegame3.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame3.c?rev=28866&r1=28865&r2=28866&view=diff
==============================================================================
--- trunk/server/savegame3.c    (original)
+++ trunk/server/savegame3.c    Sat Apr 25 09:24:51 2015
@@ -4155,18 +4155,25 @@
   }
 
   for (i = 0; i < MAX_TRADE_ROUTES; i++) {
-    const char *dir;
-
     pcity->trade[i] = secfile_lookup_int_default(loading->file, 0,
                                                  "%s.traderoute%d", citystr, 
i);
 
     if (pcity->trade[i] != 0) {
+      const char *dir;
+      const char *good_str;
+
       dir = secfile_lookup_str(loading->file, "%s.route_direction%d", citystr, 
i);
       sg_warn_ret_val(dir != NULL, FALSE,
                       "No traderoute direction found for %s", citystr);
       pcity->trade_direction[i] = route_direction_by_name(dir, fc_strcasecmp);
       sg_warn_ret_val(route_direction_is_valid(pcity->trade_direction[i]), 
FALSE,
                       "Illegal route direction %s", dir);
+      good_str = secfile_lookup_str(loading->file, "%s.route_good%d", citystr, 
i);
+      sg_warn_ret_val(dir != NULL, FALSE,
+                      "No good found for %s", citystr);
+      pcity->trade_goods[i] = goods_by_rule_name(good_str);
+      sg_warn_ret_val(pcity->trade_goods[i] != NULL, FALSE,
+                      "Illegal good %s", good_str);
     }
   }
 
@@ -4518,6 +4525,8 @@
                          buf, j);
       secfile_insert_str(saving->file, 
route_direction_name(pcity->trade_direction[i]),
                          "%s.route_direction%d", buf, j);
+      secfile_insert_str(saving->file, goods_rule_name(pcity->trade_goods[i]),
+                         "%s.route_good%d", buf, j);
     }
 
     secfile_insert_int(saving->file, pcity->food_stock, "%s.food_stock",

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=28866&r1=28865&r2=28866&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Sat Apr 25 09:24:51 2015
@@ -2451,6 +2451,7 @@
   struct city_list *cities_out_of_home, *cities_out_of_dest;
   enum traderoute_bonus_type bonus_type;
   const char *bonus_str;
+  struct goods_type *goods;
   const char *goods_str;
 
   if (NULL == punit) {
@@ -2594,8 +2595,8 @@
 
   conn_list_do_buffer(pplayer->connections);
 
-  /* Get name from the first (and currently only) goods type there is */
-  goods_str = goods_name_translation(goods_for_new_route(pcity_homecity, 
pcity_dest));
+  goods = goods_for_new_route(pcity_homecity, pcity_dest);
+  goods_str = goods_name_translation(goods);
 
   if (bonus_str != NULL) {
     notify_player(pplayer, city_tile(pcity_dest),
@@ -2674,6 +2675,7 @@
     for (i = 0; i < MAX_TRADE_ROUTES; i++) {
       if (pcity_homecity->trade[i] == 0) {
         pcity_homecity->trade[i] = pcity_dest->id;
+        pcity_homecity->trade_goods[i] = goods;
         break;
       }
     }
@@ -2682,6 +2684,7 @@
     for (i = 0; i < MAX_TRADE_ROUTES; i++) {
       if (pcity_dest->trade[i] == 0) {
         pcity_dest->trade[i] = pcity_homecity->id;
+        pcity_dest->trade_goods[i] = goods;
         break;
       }
     }


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

Reply via email to