Author: cazfi
Date: Sat Jul  9 08:12:55 2016
New Revision: 33207

URL: http://svn.gna.org/viewcvs/freeciv?rev=33207&view=rev
Log:
Added tech_class iterating macros

See patch #7391

Modified:
    trunk/client/helpdata.c
    trunk/client/packhand.c
    trunk/common/networking/packets.def
    trunk/common/tech.c
    trunk/common/tech.h
    trunk/fc_version
    trunk/server/ruleset.c
    trunk/tools/ruleutil/rulesave.c

Modified: trunk/client/helpdata.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/helpdata.c?rev=33207&r1=33206&r2=33207&view=diff
==============================================================================
--- trunk/client/helpdata.c     (original)
+++ trunk/client/helpdata.c     Sat Jul  9 08:12:55 2016
@@ -4640,13 +4640,12 @@
   if (NULL != pplayer) {
     const struct research *presearch = research_get(pplayer);
 
-    if (game.info.tech_classes > 0) {
+    if (game.control.num_tech_classes > 0) {
       if (vap->tclass == NULL) {
-        cat_snprintf(buf, bufsz, _("Belongs to the default tech class 
(%s).\n\n"),
-                     Q_(game.info.tech_class_names[0]));
+        cat_snprintf(buf, bufsz, _("Belongs to the default tech class.\n\n"));
       } else {
         cat_snprintf(buf, bufsz, _("Belongs to tech class %s.\n\n"),
-                     Q_(game.info.tech_class_names[vap->tclass->idx]));
+                     tech_class_name_translation(vap->tclass));
       }
     }
 

Modified: trunk/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/packhand.c?rev=33207&r1=33206&r2=33207&view=diff
==============================================================================
--- trunk/client/packhand.c     (original)
+++ trunk/client/packhand.c     Sat Jul  9 08:12:55 2016
@@ -3420,7 +3420,7 @@
 
   i = 0;
 
-  fc_assert(game.info.tech_classes == 0 || p->tclass < game.info.tech_classes);
+  fc_assert(game.control.num_tech_classes == 0 || p->tclass < 
game.control.num_tech_classes);
   if (p->tclass >= 0) {
     a->tclass = tech_class_by_number(p->tclass);
   } else {

Modified: trunk/common/networking/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/networking/packets.def?rev=33207&r1=33206&r2=33207&view=diff
==============================================================================
--- trunk/common/networking/packets.def (original)
+++ trunk/common/networking/packets.def Sat Jul  9 08:12:55 2016
@@ -485,8 +485,6 @@
   UINT16 global_advance_count;
   BOOL global_advances[A_LAST]; diff
   BOOL global_warming;
-  UINT8 tech_classes;
-  STRING tech_class_names[255:tech_classes][MAX_LEN_NAME];
   UINT32 globalwarming;
   GOLD gold;
   GOLD_UPKEEP_STYLE gold_upkeep_style;
@@ -1775,6 +1773,7 @@
   UINT16 num_unit_classes;
   UINT16 num_unit_types;
   UINT16 num_impr_types;
+  UINT16 num_tech_classes;
   UINT16 num_tech_types;
   UINT16 num_extra_types;
   UINT16 num_base_types;

Modified: trunk/common/tech.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/tech.c?rev=33207&r1=33206&r2=33207&view=diff
==============================================================================
--- trunk/common/tech.c (original)
+++ trunk/common/tech.c Sat Jul  9 08:12:55 2016
@@ -286,6 +286,7 @@
 
   for (i = 0; i < MAX_NUM_TECH_CLASSES; i++) {
     tech_classes[i].idx = i;
+    tech_classes[i].disabled = FALSE;
   }
 }
 
@@ -294,7 +295,7 @@
 **************************************************************************/
 struct tech_class *tech_class_by_number(const int idx)
 {
-  if (idx < 0 || idx >= game.info.tech_classes) {
+  if (idx < 0 || idx >= game.control.num_tech_classes) {
     return NULL;
   }
 
@@ -328,7 +329,7 @@
   const char *qname = Qn_(name);
   int i;
 
-  for (i = 0; i < game.info.tech_classes; i++) {
+  for (i = 0; i < game.control.num_tech_classes; i++) {
     struct tech_class *ptclass = tech_class_by_number(i);
 
     if (!fc_strcasecmp(tech_class_rule_name(ptclass), qname)) {

Modified: trunk/common/tech.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/tech.h?rev=33207&r1=33206&r2=33207&view=diff
==============================================================================
--- trunk/common/tech.h (original)
+++ trunk/common/tech.h Sat Jul  9 08:12:55 2016
@@ -117,6 +117,7 @@
 struct tech_class {
   int idx;
   struct name_translation name;
+  bool disabled;
 };
 
 struct advance {
@@ -176,6 +177,24 @@
 const char *tech_class_rule_name(const struct tech_class *ptclass);
 struct tech_class *tech_class_by_rule_name(const char *name);
 
+#define tech_class_iterate(_p)                                \
+{                                                             \
+  int _i_##_p;                                                \
+  for (_i_##_p = 0; _i_##_p < game.control.num_tech_classes; _i_##_p++) {  \
+    struct tech_class *_p = tech_class_by_number(_i_##_p);
+
+#define tech_class_iterate_end                    \
+  }                                               \
+}
+
+#define tech_class_active_iterate(_p)                                  \
+  tech_class_iterate(_p) {                                             \
+    if (!_p->disabled) {
+
+#define tech_class_active_iterate_end                                  \
+    }                                                                  \
+  } tech_class_iterate_end;
+
 void user_tech_flags_init(void);
 void user_tech_flags_free(void);
 void set_user_tech_flag_name(enum tech_flag_id id, const char *name, const 
char *helptxt);

Modified: trunk/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/fc_version?rev=33207&r1=33206&r2=33207&view=diff
==============================================================================
--- trunk/fc_version    (original)
+++ trunk/fc_version    Sat Jul  9 08:12:55 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.Jul.04"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2016.Jul.09"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: trunk/server/ruleset.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/ruleset.c?rev=33207&r1=33206&r2=33207&view=diff
==============================================================================
--- trunk/server/ruleset.c      (original)
+++ trunk/server/ruleset.c      Sat Jul  9 08:12:55 2016
@@ -1196,9 +1196,9 @@
 
   slist = secfile_lookup_str_vec(file, &nval, "classes.names");
   if (slist == NULL) {
-    game.info.tech_classes = 0;
+    game.control.num_tech_classes = 0;
   } else {
-    game.info.tech_classes = nval;
+    game.control.num_tech_classes = nval;
     for (i = 0; i < nval; i++) {
       names_set(&(tech_class_by_number(i)->name), "freeciv", slist[i], 
slist[i]);
     }
@@ -1238,7 +1238,7 @@
       break;
     }
 
-    if (game.info.tech_classes == 0) {
+    if (game.control.num_tech_classes == 0) {
       a->tclass = NULL;
     } else {
       const char *classname;

Modified: trunk/tools/ruleutil/rulesave.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruleutil/rulesave.c?rev=33207&r1=33206&r2=33207&view=diff
==============================================================================
--- trunk/tools/ruleutil/rulesave.c     (original)
+++ trunk/tools/ruleutil/rulesave.c     Sat Jul  9 08:12:55 2016
@@ -1743,12 +1743,12 @@
     }
   }
 
-  if (game.info.tech_classes > 0) {
+  if (game.control.num_tech_classes > 0) {
     int ci;
-    const char *class_names[game.info.tech_classes];
-
-    for (ci = 0; ci < game.info.tech_classes; ci++) {
-      class_names[ci] = game.info.tech_class_names[ci];
+    const char *class_names[game.control.num_tech_classes];
+
+    for (ci = 0; ci < game.control.num_tech_classes; ci++) {
+      class_names[ci] = tech_class_rule_name(tech_class_by_number(ci));
     }
 
     secfile_insert_str_vec(sfile, class_names, ci,
@@ -1769,7 +1769,7 @@
 
       save_name_translation(sfile, &(pa->name), path);
 
-      if (game.info.tech_classes > 0) {
+      if (game.control.num_tech_classes > 0) {
         if (pa->tclass != NULL) {
           secfile_insert_str(sfile, tech_class_rule_name(pa->tclass),
                              "%s.class", path);


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

Reply via email to