Author: cazfi
Date: Sat Aug 20 15:14:54 2016
New Revision: 33652

URL: http://svn.gna.org/viewcvs/freeciv?rev=33652&view=rev
Log:
Added support for "Bidirectional" goods flag.

See patch #7619

Modified:
    trunk/common/networking/packets.def
    trunk/common/traderoutes.c
    trunk/common/traderoutes.h
    trunk/data/alien/game.ruleset
    trunk/data/civ1/game.ruleset
    trunk/data/civ2/game.ruleset
    trunk/data/civ2civ3/game.ruleset
    trunk/data/classic/game.ruleset
    trunk/data/experimental/game.ruleset
    trunk/data/ruledit/comments.txt
    trunk/data/sandbox/game.ruleset
    trunk/data/stub/game.ruleset
    trunk/fc_version
    trunk/server/ruleset.c
    trunk/server/unithand.c

Modified: trunk/common/networking/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/networking/packets.def?rev=33652&r1=33651&r2=33652&view=diff
==============================================================================
--- trunk/common/networking/packets.def (original)
+++ trunk/common/networking/packets.def Sat Aug 20 15:14:54 2016
@@ -264,6 +264,7 @@
 type BV_ACTIONS         = bitvector(bv_actions)
 type BV_EXTRA_FLAGS     = bitvector(bv_extra_flags)
 type BV_BASE_FLAGS      = bitvector(bv_base_flags)
+type BV_GOODS_FLAGS     = bitvector(bv_goods_flags)
 type BV_EXTRAS          = bitvector(bv_extras)
 type BV_BASES           = bitvector(bv_bases)
 type BV_ROADS           = bitvector(bv_roads)
@@ -1697,6 +1698,7 @@
   STRING rule_name[MAX_LEN_NAME];
   UINT8 reqs_count;
   REQUIREMENT reqs[MAX_NUM_REQS:reqs_count];
+  BV_GOODS_FLAGS flags;
 end
 
 PACKET_RULESET_DISASTER = 224; sc, lsend

Modified: trunk/common/traderoutes.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/traderoutes.c?rev=33652&r1=33651&r2=33652&view=diff
==============================================================================
--- trunk/common/traderoutes.c  (original)
+++ trunk/common/traderoutes.c  Sat Aug 20 15:14:54 2016
@@ -504,6 +504,14 @@
 }
 
 /****************************************************************************
+  Check if goods has given flag
+****************************************************************************/
+bool goods_has_flag(const struct goods_type *pgood, enum goods_flag_id flag)
+{
+  return BV_ISSET(pgood->flags, flag);
+}
+
+/****************************************************************************
   Can the city provide goods.
 ****************************************************************************/
 bool goods_can_be_provided(struct city *pcity, struct goods_type *pgood,

Modified: trunk/common/traderoutes.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/traderoutes.h?rev=33652&r1=33651&r2=33652&view=diff
==============================================================================
--- trunk/common/traderoutes.h  (original)
+++ trunk/common/traderoutes.h  Sat Aug 20 15:14:54 2016
@@ -152,6 +152,14 @@
   } trade_routes_iterate_end;                               \
 } while (FALSE);
 
+/* Used in the network protocol. */
+#define SPECENUM_NAME goods_flag_id
+#define SPECENUM_VALUE0 GF_BIDIRECTIONAL
+#define SPECENUM_VALUE0NAME "Bidirectional"
+#define SPECENUM_COUNT GF_COUNT
+#define SPECENUM_BITVECTOR bv_goods_flags
+#include "specenum_gen.h"
+
 struct goods_type
 {
   int id;
@@ -159,6 +167,8 @@
   bool disabled; /* Does not really exist - hole in goods array */
 
   struct requirement_vector reqs;
+
+  bv_goods_flags flags;
 };
 
 void goods_init(void);
@@ -172,6 +182,8 @@
 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);
+
+bool goods_has_flag(const struct goods_type *pgood, enum goods_flag_id flag);
 
 bool goods_can_be_provided(struct city *pcity, struct goods_type *pgood,
                            struct unit *punit);

Modified: trunk/data/alien/game.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/alien/game.ruleset?rev=33652&r1=33651&r2=33652&view=diff
==============================================================================
--- trunk/data/alien/game.ruleset       (original)
+++ trunk/data/alien/game.ruleset       Sat Aug 20 15:14:54 2016
@@ -760,6 +760,9 @@
 ;                           an good after a ruleset has been released.
 ; reqs                    = requirements for a city to provide goods (see 
effects.ruleset
 ;                           and README.effects for help on requirements)
+; flags
+;   - "Bidirectional"     = Traderoute carrying the goods does not have "from" 
and "to"
+;                           ends, but both ends are considered the same.
 ;
 ; */ <-- avoid gettext warnings
 

Modified: trunk/data/civ1/game.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/civ1/game.ruleset?rev=33652&r1=33651&r2=33652&view=diff
==============================================================================
--- trunk/data/civ1/game.ruleset        (original)
+++ trunk/data/civ1/game.ruleset        Sat Aug 20 15:14:54 2016
@@ -754,6 +754,9 @@
 ;                           an good after a ruleset has been released.
 ; reqs                    = requirements for a city to provide goods (see 
effects.ruleset
 ;                           and README.effects for help on requirements)
+; flags
+;   - "Bidirectional"     = Traderoute carrying the goods does not have "from" 
and "to"
+;                           ends, but both ends are considered the same.
 ;
 ; */ <-- avoid gettext warnings
 

Modified: trunk/data/civ2/game.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/civ2/game.ruleset?rev=33652&r1=33651&r2=33652&view=diff
==============================================================================
--- trunk/data/civ2/game.ruleset        (original)
+++ trunk/data/civ2/game.ruleset        Sat Aug 20 15:14:54 2016
@@ -788,6 +788,9 @@
 ;                           an good after a ruleset has been released.
 ; reqs                    = requirements for a city to provide goods (see 
effects.ruleset
 ;                           and README.effects for help on requirements)
+; flags
+;   - "Bidirectional"     = Traderoute carrying the goods does not have "from" 
and "to"
+;                           ends, but both ends are considered the same.
 ;
 ; */ <-- avoid gettext warnings
 

Modified: trunk/data/civ2civ3/game.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/civ2civ3/game.ruleset?rev=33652&r1=33651&r2=33652&view=diff
==============================================================================
--- trunk/data/civ2civ3/game.ruleset    (original)
+++ trunk/data/civ2civ3/game.ruleset    Sat Aug 20 15:14:54 2016
@@ -941,6 +941,9 @@
 ;                           an good after a ruleset has been released.
 ; reqs                    = requirements for a city to provide goods (see 
effects.ruleset
 ;                           and README.effects for help on requirements)
+; flags
+;   - "Bidirectional"     = Traderoute carrying the goods does not have "from" 
and "to"
+;                           ends, but both ends are considered the same.
 ;
 ; */ <-- avoid gettext warnings
 

Modified: trunk/data/classic/game.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/classic/game.ruleset?rev=33652&r1=33651&r2=33652&view=diff
==============================================================================
--- trunk/data/classic/game.ruleset     (original)
+++ trunk/data/classic/game.ruleset     Sat Aug 20 15:14:54 2016
@@ -822,6 +822,9 @@
 ;                           an good after a ruleset has been released.
 ; reqs                    = requirements for a city to provide goods (see 
effects.ruleset
 ;                           and README.effects for help on requirements)
+; flags
+;   - "Bidirectional"     = Traderoute carrying the goods does not have "from" 
and "to"
+;                           ends, but both ends are considered the same.
 ;
 ; */ <-- avoid gettext warnings
 

Modified: trunk/data/experimental/game.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/experimental/game.ruleset?rev=33652&r1=33651&r2=33652&view=diff
==============================================================================
--- trunk/data/experimental/game.ruleset        (original)
+++ trunk/data/experimental/game.ruleset        Sat Aug 20 15:14:54 2016
@@ -851,6 +851,9 @@
 ;                           an good after a ruleset has been released.
 ; reqs                    = requirements for a city to provide goods (see 
effects.ruleset
 ;                           and README.effects for help on requirements)
+; flags
+;   - "Bidirectional"     = Traderoute carrying the goods does not have "from" 
and "to"
+;                           ends, but both ends are considered the same.
 ;
 ; */ <-- avoid gettext warnings
 

Modified: trunk/data/ruledit/comments.txt
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/ruledit/comments.txt?rev=33652&r1=33651&r2=33652&view=diff
==============================================================================
--- trunk/data/ruledit/comments.txt     (original)
+++ trunk/data/ruledit/comments.txt     Sat Aug 20 15:14:54 2016
@@ -972,6 +972,9 @@
 ;                           an good after a ruleset has been released.\n\
 ; reqs                    = requirements for a city to provide goods (see 
effects.ruleset\n\
 ;                           and README.effects for help on requirements)\n\
+; flags\n\
+;   - \"Bidirectional\"     = Traderoute carrying the goods does not have 
"from" and "to"\n\
+;                           ends, but both ends are considered the same.\n\
 ;\n\
 ; */ <-- avoid gettext warnings\n\
 "

Modified: trunk/data/sandbox/game.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/sandbox/game.ruleset?rev=33652&r1=33651&r2=33652&view=diff
==============================================================================
--- trunk/data/sandbox/game.ruleset     (original)
+++ trunk/data/sandbox/game.ruleset     Sat Aug 20 15:14:54 2016
@@ -1028,6 +1028,9 @@
 ;                           an good after a ruleset has been released.
 ; reqs                    = requirements for a city to provide goods (see 
effects.ruleset
 ;                           and README.effects for help on requirements)
+; flags
+;   - "Bidirectional"     = Traderoute carrying the goods does not have "from" 
and "to"
+;                           ends, but both ends are considered the same.
 ;
 ; */ <-- avoid gettext warnings
 

Modified: trunk/data/stub/game.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/stub/game.ruleset?rev=33652&r1=33651&r2=33652&view=diff
==============================================================================
--- trunk/data/stub/game.ruleset        (original)
+++ trunk/data/stub/game.ruleset        Sat Aug 20 15:14:54 2016
@@ -448,6 +448,9 @@
 ;                           an good after a ruleset has been released.
 ; reqs                    = requirements for a city to provide goods (see 
effects.ruleset
 ;                           and README.effects for help on requirements)
+; flags
+;   - "Bidirectional"     = Traderoute carrying the goods does not have "from" 
and "to"
+;                           ends, but both ends are considered the same.
 ;
 ; */ <-- avoid gettext warnings
 

Modified: trunk/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/fc_version?rev=33652&r1=33651&r2=33652&view=diff
==============================================================================
--- trunk/fc_version    (original)
+++ trunk/fc_version    Sat Aug 20 15:14:54 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.19"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2016.Aug.20"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: trunk/server/ruleset.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/ruleset.c?rev=33652&r1=33651&r2=33652&view=diff
==============================================================================
--- trunk/server/ruleset.c      (original)
+++ trunk/server/ruleset.c      Sat Aug 20 15:14:54 2016
@@ -6547,6 +6547,8 @@
       int id = goods_index(pgood);
       const char *sec_name = section_name(section_list_get(sec, id));
       struct requirement_vector *reqs;
+      const char **slist;
+      int j;
 
       reqs = lookup_req_list(file, compat, sec_name, "reqs", 
goods_rule_name(pgood));
       if (reqs == NULL) {
@@ -6554,6 +6556,26 @@
         break;
       }
       requirement_vector_copy(&pgood->reqs, reqs);
+
+      slist = secfile_lookup_str_vec(file, &nval, "%s.flags", sec_name);
+      BV_CLR_ALL(pgood->flags);
+      for (j = 0; j < nval; j++) {
+        enum goods_flag_id flag;
+
+        sval = slist[j];
+        flag = goods_flag_id_by_name(sval, fc_strcasecmp);
+        if (!goods_flag_id_is_valid(flag)) {
+          ruleset_error(LOG_ERROR, "\"%s\" good \"%s\": unknown flag \"%s\".",
+                        filename,
+                        goods_rule_name(pgood),
+                        sval);
+          ok = FALSE;
+          break;
+        } else {
+          BV_SET(pgood->flags, flag);
+        }
+      }
+      free(slist);
     } goods_type_iterate_end;
   }
 
@@ -7202,6 +7224,8 @@
     } requirement_vector_iterate_end;
     packet.reqs_count = j;
 
+    packet.flags = g->flags;
+
     lsend_packet_ruleset_goods(dest, &packet);
   } goods_type_iterate_end;
 }

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=33652&r1=33651&r2=33652&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Sat Aug 20 15:14:54 2016
@@ -3864,7 +3864,7 @@
   }
 
   if (can_establish) {
-    struct trade_route *proute;
+    struct trade_route *proute_from, *proute_to;
     struct city_list *cities_out_of_home;
     struct city_list *cities_out_of_dest;
 
@@ -3914,17 +3914,23 @@
     } trade_route_list_iterate_end;
 
     /* Actually create the new trade route */
-    proute = fc_malloc(sizeof(struct trade_route));
-    proute->partner = pcity_dest->id;
-    proute->dir = RDIR_FROM;
-    proute->goods = goods;
-    trade_route_list_append(pcity_homecity->routes, proute);
-
-    proute = fc_malloc(sizeof(struct trade_route));
-    proute->partner = pcity_homecity->id;
-    proute->dir = RDIR_TO;
-    proute->goods = goods;
-    trade_route_list_append(pcity_dest->routes, proute);
+    proute_from = fc_malloc(sizeof(struct trade_route));
+    proute_from->partner = pcity_dest->id;
+    proute_from->goods = goods;
+
+    proute_to = fc_malloc(sizeof(struct trade_route));
+    proute_to->partner = pcity_homecity->id;
+    proute_to->goods = goods;
+
+    if (goods_has_flag(goods, GF_BIDIRECTIONAL)) {
+      proute_from->dir = RDIR_BIDIRECTIONAL;
+      proute_to->dir = RDIR_BIDIRECTIONAL;
+    } else {
+      proute_from->dir = RDIR_FROM;
+      proute_to->dir = RDIR_TO;
+    }
+    trade_route_list_append(pcity_homecity->routes, proute_from);
+    trade_route_list_append(pcity_dest->routes, proute_to);
 
     /* Refresh the cities. */
     city_refresh(pcity_homecity);


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

Reply via email to