Author: cazfi
Date: Fri Sep  9 20:59:51 2016
New Revision: 33771

URL: http://svn.gna.org/viewcvs/freeciv?rev=33771&view=rev
Log:
Added value editing for Nationality, Extra, and Style requirement types.

See patch #7655

Modified:
    trunk/common/extras.c
    trunk/common/extras.h
    trunk/common/style.c
    trunk/common/style.h
    trunk/tools/ruledit/tab_misc.cpp
    trunk/tools/ruledit/univ_value.c
    trunk/tools/ruleutil/rulesave.c

Modified: trunk/common/extras.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/extras.c?rev=33771&r1=33770&r2=33771&view=diff
==============================================================================
--- trunk/common/extras.c       (original)
+++ trunk/common/extras.c       Fri Sep  9 20:59:51 2016
@@ -66,6 +66,7 @@
     extras[i].causes = 0;
     extras[i].rmcauses = 0;
     extras[i].helptext = NULL;
+    extras[i].disabled = FALSE;
   }
 }
 

Modified: trunk/common/extras.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/extras.h?rev=33771&r1=33770&r2=33771&view=diff
==============================================================================
--- trunk/common/extras.h       (original)
+++ trunk/common/extras.h       Fri Sep  9 20:59:51 2016
@@ -82,6 +82,7 @@
 {
   int id;
   struct name_translation name;
+  bool disabled;
   enum extra_category category;
   uint16_t causes;
   uint8_t rmcauses;
@@ -261,6 +262,14 @@
   }                                               \
 }
 
+#define extra_active_type_iterate(_p)                         \
+  extra_type_iterate(_p) {                                    \
+    if (!_p->disabled) {
+
+#define extra_active_type_iterate_end                         \
+    }                                                         \
+  } extra_type_iterate_end;
+
 #define extra_type_by_cause_iterate(_cause, _extra)                 \
 {                                                                   \
   struct extra_type_list *_etl_##_extra = extra_type_list_by_cause(_cause); \

Modified: trunk/common/style.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/style.c?rev=33771&r1=33770&r2=33771&view=diff
==============================================================================
--- trunk/common/style.c        (original)
+++ trunk/common/style.c        Fri Sep  9 20:59:51 2016
@@ -41,6 +41,7 @@
 
   for (i = 0; i < count; i++) {
     styles[i].id = i;
+    styles[i].disabled = FALSE;
   }
 }
 

Modified: trunk/common/style.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/style.h?rev=33771&r1=33770&r2=33771&view=diff
==============================================================================
--- trunk/common/style.h        (original)
+++ trunk/common/style.h        Fri Sep  9 20:59:51 2016
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/***********************************************************************
  Freeciv - Copyright (C) 2005 - The Freeciv Project
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -22,6 +22,7 @@
 {
   int id;
   struct name_translation name;
+  bool disabled;
 };
 
 struct music_style
@@ -51,6 +52,14 @@
 #define styles_iterate_end                               \
   }                                                      \
 }
+
+#define styles_active_iterate(_p)                         \
+  styles_iterate(_p) {                                    \
+    if (!_p->disabled) {
+
+#define styles_active_iterate_end                         \
+    }                                                     \
+  } styles_iterate_end;
 
 void music_styles_alloc(int count);
 void music_styles_free(void);

Modified: trunk/tools/ruledit/tab_misc.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/tab_misc.cpp?rev=33771&r1=33770&r2=33771&view=diff
==============================================================================
--- trunk/tools/ruledit/tab_misc.cpp    (original)
+++ trunk/tools/ruledit/tab_misc.cpp    Fri Sep  9 20:59:51 2016
@@ -236,6 +236,8 @@
 {
   int row = 0;
   int count;
+  int base_count;
+  int road_count;
 
   count = 0;
   terrain_active_iterate(pterr) {
@@ -278,7 +280,13 @@
   stats->item(row++, 4)->setText(QString::number(count));
 
   stats->item(row++, 4)->setText(QString::number(game.control.nation_count));
-  stats->item(row++, 4)->setText(QString::number(game.control.styles_count));
+
+  count = 0;
+  styles_active_iterate(pstyle) {
+    count++;
+  } styles_active_iterate_end;
+  stats->item(row++, 4)->setText(QString::number(count));
+
   stats->item(row++, 
4)->setText(QString::number(game.control.num_specialist_types));
 
   count = 0;
@@ -292,9 +300,23 @@
   // Third column
   row = 0;
   stats->item(row++, 
7)->setText(QString::number(game.control.num_achievement_types));
-  stats->item(row++, 
7)->setText(QString::number(game.control.num_extra_types));
-  stats->item(row++, 7)->setText(QString::number(game.control.num_base_types));
-  stats->item(row++, 7)->setText(QString::number(game.control.num_road_types));
+
+  count = 0;
+  base_count = 0;
+  road_count = 0;
+  extra_active_type_iterate(pextra) {
+    count++;
+    if (is_extra_caused_by(pextra, EC_BASE)) {
+      base_count++;
+    }
+    if (is_extra_caused_by(pextra, EC_ROAD)) {
+      road_count++;
+    }
+  } extra_active_type_iterate_end;
+  stats->item(row++, 7)->setText(QString::number(count));
+  stats->item(row++, 7)->setText(QString::number(base_count));
+  stats->item(row++, 7)->setText(QString::number(road_count));
+
   count = 0;
   goods_active_type_iterate(pg) {
     count++;

Modified: trunk/tools/ruledit/univ_value.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/univ_value.c?rev=33771&r1=33770&r2=33771&view=diff
==============================================================================
--- trunk/tools/ruledit/univ_value.c    (original)
+++ trunk/tools/ruledit/univ_value.c    Fri Sep  9 20:59:51 2016
@@ -256,6 +256,21 @@
       cb(goods_rule_name(pgood), univ->value.good == pgood, data);
     } goods_active_type_iterate_end;
     break;
+  case VUT_NATIONALITY:
+    nations_iterate(pnat) {
+      cb(nation_rule_name(pnat), univ->value.nationality == pnat, data);
+    } nations_iterate_end;
+    break;
+  case VUT_EXTRA:
+    extra_active_type_iterate(pextra) {
+      cb(extra_rule_name(pextra), univ->value.extra == pextra, data);
+    } extra_active_type_iterate_end;
+    break;
+  case VUT_STYLE:
+    styles_active_iterate(pstyle) {
+      cb(style_rule_name(pstyle), univ->value.style == pstyle, data);
+    } styles_active_iterate_end;
+    break;
   case VUT_UTFLAG:
   case VUT_UCFLAG:
   case VUT_SPECIALIST:
@@ -264,14 +279,11 @@
   case VUT_TERRAINALTER:
   case VUT_CITYTILE:
   case VUT_TERRFLAG:
-  case VUT_NATIONALITY:
   case VUT_BASEFLAG:
   case VUT_ROADFLAG:
-  case VUT_EXTRA:
   case VUT_TECHFLAG:
   case VUT_ACHIEVEMENT:
   case VUT_DIPLREL:
-  case VUT_STYLE:
   case VUT_UNITSTATE:
   case VUT_NATIONGROUP:
   case VUT_TOPO:
@@ -289,6 +301,7 @@
   case VUT_MINHP:
   case VUT_AGE:
   case VUT_MINTECHS:
+    /* Requirement types having numerical value */
     cb(NULL, FALSE, data);
     break;
   case VUT_COUNT:

Modified: trunk/tools/ruleutil/rulesave.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruleutil/rulesave.c?rev=33771&r1=33770&r2=33771&view=diff
==============================================================================
--- trunk/tools/ruleutil/rulesave.c     (original)
+++ trunk/tools/ruleutil/rulesave.c     Fri Sep  9 20:59:51 2016
@@ -455,13 +455,13 @@
   comment_styles(sfile);
 
   sect_idx = 0;
-  styles_iterate(pstyle) {
+  styles_active_iterate(pstyle) {
     char path[512];
 
     fc_snprintf(path, sizeof(path), "style_%d", sect_idx++);
 
     save_name_translation(sfile, &(pstyle->name), path);
-  } styles_iterate_end;
+  } styles_active_iterate_end;
 
   comment_citystyles(sfile);
 
@@ -2061,24 +2061,26 @@
 
   sect_idx = 0;
   extra_type_by_cause_iterate(EC_RESOURCE, pres) {
-    char path[512];
-    char identifier[2];
-
-    fc_snprintf(path, sizeof(path), "resource_%d", sect_idx++);
-
-    secfile_insert_str(sfile, extra_rule_name(pres),
-                       "%s.extra", path);
-
-    output_type_iterate(o) {
-      if (pres->data.resource->output[o] != 0) {
-        secfile_insert_int(sfile, pres->data.resource->output[o], "%s.%s",
-                           path, get_output_identifier(o));
-      }
-    } output_type_iterate_end;
-
-    identifier[0] = pres->data.resource->id_old_save;
-    identifier[1] = '\0';
-    secfile_insert_str(sfile, identifier, "%s.identifier", path);
+    if (!pres->disabled) {
+      char path[512];
+      char identifier[2];
+
+      fc_snprintf(path, sizeof(path), "resource_%d", sect_idx++);
+
+      secfile_insert_str(sfile, extra_rule_name(pres),
+                         "%s.extra", path);
+
+      output_type_iterate(o) {
+        if (pres->data.resource->output[o] != 0) {
+          secfile_insert_int(sfile, pres->data.resource->output[o], "%s.%s",
+                             path, get_output_identifier(o));
+        }
+      } output_type_iterate_end;
+
+      identifier[0] = pres->data.resource->id_old_save;
+      identifier[1] = '\0';
+      secfile_insert_str(sfile, identifier, "%s.identifier", path);
+    }
   } extra_type_by_cause_iterate_end;
 
   secfile_insert_str(sfile, terrain_control.gui_type_base0,
@@ -2089,7 +2091,7 @@
   comment_extras(sfile);
 
   sect_idx = 0;
-  extra_type_iterate(pextra) {
+  extra_active_type_iterate(pextra) {
     char path[512];
     const char *flag_names[EF_COUNT];
     const char *cause_names[EC_COUNT];
@@ -2231,43 +2233,45 @@
 
     save_strvec(sfile, pextra->helptext, path, "helptext");
 
-  } extra_type_iterate_end;
+  } extra_active_type_iterate_end;
 
   comment_bases(sfile);
 
   sect_idx = 0;
   extra_type_by_cause_iterate(EC_BASE, pextra) {
-    char path[512];
-    struct base_type *pbase = extra_base_get(pextra);
-    const char *flag_names[BF_COUNT];
-    int flagi;
-    int set_count;
-
-    fc_snprintf(path, sizeof(path), "base_%d", sect_idx++);
-
-    secfile_insert_str(sfile, extra_rule_name(pextra),
-                       "%s.extra", path);
-
-    secfile_insert_str(sfile, base_gui_type_name(pbase->gui_type),
-                       "%s.gui_type", path);
-
-    if (pbase->border_sq >= 0) {
-      secfile_insert_int(sfile, pbase->border_sq, "%s.border_sq", path);
-    }
-    if (pbase->vision_main_sq >= 0) {
-      secfile_insert_int(sfile, pbase->vision_main_sq, "%s.vision_main_sq", 
path);
-    }
-
-    set_count = 0;
-    for (flagi = 0; flagi < BF_COUNT; flagi++) {
-      if (base_has_flag(pbase, flagi)) {
-        flag_names[set_count++] = base_flag_id_name(flagi);
-      }
-    }
-
-    if (set_count > 0) {
-      secfile_insert_str_vec(sfile, flag_names, set_count,
-                             "%s.flags", path);
+    if (!pextra->disabled) {
+      char path[512];
+      struct base_type *pbase = extra_base_get(pextra);
+      const char *flag_names[BF_COUNT];
+      int flagi;
+      int set_count;
+
+      fc_snprintf(path, sizeof(path), "base_%d", sect_idx++);
+
+      secfile_insert_str(sfile, extra_rule_name(pextra),
+                         "%s.extra", path);
+
+      secfile_insert_str(sfile, base_gui_type_name(pbase->gui_type),
+                         "%s.gui_type", path);
+
+      if (pbase->border_sq >= 0) {
+        secfile_insert_int(sfile, pbase->border_sq, "%s.border_sq", path);
+      }
+      if (pbase->vision_main_sq >= 0) {
+        secfile_insert_int(sfile, pbase->vision_main_sq, "%s.vision_main_sq", 
path);
+      }
+
+      set_count = 0;
+      for (flagi = 0; flagi < BF_COUNT; flagi++) {
+        if (base_has_flag(pbase, flagi)) {
+          flag_names[set_count++] = base_flag_id_name(flagi);
+        }
+      }
+
+      if (set_count > 0) {
+        secfile_insert_str_vec(sfile, flag_names, set_count,
+                               "%s.flags", path);
+      }
     }
   } extra_type_by_cause_iterate_end;
 
@@ -2275,64 +2279,66 @@
 
   sect_idx = 0;
   extra_type_by_cause_iterate(EC_ROAD, pextra) {
-    struct road_type *proad = extra_road_get(pextra);
-    char path[512];
-    const char *flag_names[RF_COUNT];
-    int flagi;
-    int set_count;
-
-    fc_snprintf(path, sizeof(path), "road_%d", sect_idx++);
-
-    secfile_insert_str(sfile, extra_rule_name(pextra),
-                       "%s.extra", path);
-
-    secfile_insert_int(sfile, proad->move_cost, "%s.move_cost", path);
-
-    if (proad->move_mode != RMM_FAST_ALWAYS) {
-      secfile_insert_str(sfile, road_move_mode_name(proad->move_mode),
-                         "%s.move_mode", path);
-    }
-
-    output_type_iterate(o) {
-      if (proad->tile_incr_const[o] != 0) {
-        secfile_insert_int(sfile, proad->tile_incr_const[o],
-                           "%s.%s_incr_const", path, get_output_identifier(o));
-      }
-      if (proad->tile_incr[o] != 0) {
-        secfile_insert_int(sfile, proad->tile_incr[o],
-                           "%s.%s_incr", path, get_output_identifier(o));
-      }
-      if (proad->tile_bonus[o] != 0) {
-        secfile_insert_int(sfile, proad->tile_bonus[o],
-                           "%s.%s_bonus", path, get_output_identifier(o));
-      }
-    } output_type_iterate_end;
-
-    switch (proad->compat) {
-    case ROCO_ROAD:
-      secfile_insert_str(sfile, "Road", "%s.compat_special", path);
-      break;
-    case ROCO_RAILROAD:
-      secfile_insert_str(sfile, "Railroad", "%s.compat_special", path);
-      break;
-    case ROCO_RIVER:
-      secfile_insert_str(sfile, "River", "%s.compat_special", path);
-      break;
-    case ROCO_NONE:
-      secfile_insert_str(sfile, "None", "%s.compat_special", path);
-      break;
-    }
-
-    set_count = 0;
-    for (flagi = 0; flagi < RF_COUNT; flagi++) {
-      if (road_has_flag(proad, flagi)) {
-        flag_names[set_count++] = road_flag_id_name(flagi);
-      }
-    }
-
-    if (set_count > 0) {
-      secfile_insert_str_vec(sfile, flag_names, set_count,
-                             "%s.flags", path);
+    if (!pextra->disabled) {
+      struct road_type *proad = extra_road_get(pextra);
+      char path[512];
+      const char *flag_names[RF_COUNT];
+      int flagi;
+      int set_count;
+
+      fc_snprintf(path, sizeof(path), "road_%d", sect_idx++);
+
+      secfile_insert_str(sfile, extra_rule_name(pextra),
+                         "%s.extra", path);
+
+      secfile_insert_int(sfile, proad->move_cost, "%s.move_cost", path);
+
+      if (proad->move_mode != RMM_FAST_ALWAYS) {
+        secfile_insert_str(sfile, road_move_mode_name(proad->move_mode),
+                           "%s.move_mode", path);
+      }
+
+      output_type_iterate(o) {
+        if (proad->tile_incr_const[o] != 0) {
+          secfile_insert_int(sfile, proad->tile_incr_const[o],
+                             "%s.%s_incr_const", path, 
get_output_identifier(o));
+        }
+        if (proad->tile_incr[o] != 0) {
+          secfile_insert_int(sfile, proad->tile_incr[o],
+                             "%s.%s_incr", path, get_output_identifier(o));
+        }
+        if (proad->tile_bonus[o] != 0) {
+          secfile_insert_int(sfile, proad->tile_bonus[o],
+                             "%s.%s_bonus", path, get_output_identifier(o));
+        }
+      } output_type_iterate_end;
+
+      switch (proad->compat) {
+      case ROCO_ROAD:
+        secfile_insert_str(sfile, "Road", "%s.compat_special", path);
+        break;
+      case ROCO_RAILROAD:
+        secfile_insert_str(sfile, "Railroad", "%s.compat_special", path);
+        break;
+      case ROCO_RIVER:
+        secfile_insert_str(sfile, "River", "%s.compat_special", path);
+        break;
+      case ROCO_NONE:
+        secfile_insert_str(sfile, "None", "%s.compat_special", path);
+        break;
+      }
+
+      set_count = 0;
+      for (flagi = 0; flagi < RF_COUNT; flagi++) {
+        if (road_has_flag(proad, flagi)) {
+          flag_names[set_count++] = road_flag_id_name(flagi);
+        }
+      }
+
+      if (set_count > 0) {
+        secfile_insert_str_vec(sfile, flag_names, set_count,
+                               "%s.flags", path);
+      }
     }
   } extra_type_by_cause_iterate_end;
 


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

Reply via email to