Author: cazfi
Date: Thu Sep 17 05:47:07 2015
New Revision: 29909

URL: http://svn.gna.org/viewcvs/freeciv?rev=29909&view=rev
Log:
Save allowed_govs, allowed_terrains, and allowed_styles vectors from rulesave.

See patch #5897

Modified:
    branches/S2_6/common/game.c
    branches/S2_6/common/game.h
    branches/S2_6/server/ruleset.c
    branches/S2_6/tools/ruledit/rulesave.c

Modified: branches/S2_6/common/game.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/game.c?rev=29909&r1=29908&r2=29909&view=diff
==============================================================================
--- branches/S2_6/common/game.c (original)
+++ branches/S2_6/common/game.c Thu Sep 17 05:47:07 2015
@@ -533,6 +533,12 @@
     game.server.ruledit.nationlist = NULL;
     game.server.ruledit.embedded_nations = NULL;
     game.server.ruledit.embedded_nations_count = 0;
+    game.server.ruledit.allowed_govs = NULL;
+    game.server.ruledit.allowed_terrains = NULL;
+    game.server.ruledit.allowed_styles = NULL;
+    game.server.ruledit.ag_count = 0;
+    game.server.ruledit.at_count = 0;
+    game.server.ruledit.as_count = 0;
   }
 }
 
@@ -597,6 +603,18 @@
       free(game.server.ruledit.embedded_nations);
       game.server.ruledit.embedded_nations = NULL;
       game.server.ruledit.embedded_nations_count = 0;
+      if (game.server.ruledit.allowed_govs != NULL) {
+        free(game.server.ruledit.allowed_govs);
+        game.server.ruledit.allowed_govs = NULL;
+      }
+      if (game.server.ruledit.allowed_terrains != NULL) {
+        free(game.server.ruledit.allowed_terrains);
+        game.server.ruledit.allowed_terrains = NULL;
+      }
+      if (game.server.ruledit.allowed_styles != NULL) {
+        free(game.server.ruledit.allowed_styles);
+        game.server.ruledit.allowed_styles = NULL;
+      }
     }
   }
 

Modified: branches/S2_6/common/game.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/game.h?rev=29909&r1=29908&r2=29909&view=diff
==============================================================================
--- branches/S2_6/common/game.h (original)
+++ branches/S2_6/common/game.h Thu Sep 17 05:47:07 2015
@@ -254,6 +254,12 @@
         char *nationlist;
         char **embedded_nations;
         size_t embedded_nations_count;
+        const char **allowed_govs;
+        size_t ag_count;
+        const char **allowed_terrains;
+        size_t at_count;
+        const char **allowed_styles;
+        size_t as_count;
       } ruledit;
     } server;
   };

Modified: branches/S2_6/server/ruleset.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/ruleset.c?rev=29909&r1=29908&r2=29909&view=diff
==============================================================================
--- branches/S2_6/server/ruleset.c      (original)
+++ branches/S2_6/server/ruleset.c      Thu Sep 17 05:47:07 2015
@@ -3660,7 +3660,8 @@
 **************************************************************************/
 static bool is_on_allowed_list(const char *name, const char **list, size_t len)
 {
-  int i;
+  int i;  
+
   for (i = 0; i < len; i++) {
     if (!fc_strcasecmp(name, list[i])) {
       return TRUE;
@@ -3758,8 +3759,9 @@
         }
 
         if (0 == fc_strcasecmp(p, "river")) {
-          if (allowed_terrains
-              && !is_on_allowed_list(p, allowed_terrains, atcount)) {
+          if (game.server.ruledit.allowed_terrains != NULL
+              && !is_on_allowed_list(p,
+                                     game.server.ruledit.allowed_terrains, 
atcount)) {
             ruleset_error(LOG_ERROR, "\"%s\" [%s] %s: city \"%s\" "
                           "has terrain hint \"%s\" not in allowed_terrains.",
                           secfile_name(file), secfile_str1, secfile_str2,
@@ -3786,8 +3788,9 @@
            * (a) quietly ignore any hints mentioned that don't happen to be in
            * the current ruleset, (b) enforce that terrains mentioned by 
nations
            * must be on the list */
-          if (pterrain && allowed_terrains) {
-            if (!is_on_allowed_list(p, allowed_terrains, atcount)) {
+          if (pterrain != NULL && game.server.ruledit.allowed_terrains != 
NULL) {
+            if (!is_on_allowed_list(p,
+                                    game.server.ruledit.allowed_terrains, 
atcount)) {
               /* Terrain exists, but not intended for these nations */
               ruleset_error(LOG_ERROR, "\"%s\" [%s] %s: city \"%s\" "
                             "has terrain hint \"%s\" not in allowed_terrains.",
@@ -3798,8 +3801,9 @@
             }
           } else if (!pterrain) {
             /* Terrain doesn't exist; only complain if it's not on any list */
-            if (!allowed_terrains
-                || !is_on_allowed_list(p, allowed_terrains, atcount)) {
+            if (game.server.ruledit.allowed_terrains == NULL
+                || !is_on_allowed_list(p,
+                                       game.server.ruledit.allowed_terrains, 
atcount)) {
               ruleset_error(LOG_ERROR, "\"%s\" [%s] %s: city \"%s\" "
                             "has unknown terrain hint \"%s\".",
                             secfile_name(file), secfile_str1, secfile_str2,
@@ -3841,10 +3845,6 @@
   const char *filename = secfile_name(file);
   struct section_list *sec;
   enum trait tr;
-  const char **allowed_govs = NULL;
-  const char **allowed_terrains = NULL;
-  const char **allowed_styles = NULL;
-  size_t agcount, atcount, ascount;
   bool ok = TRUE;
 
   if (check_ruleset_capabilities(file, RULESET_CAPABILITIES, filename) == 
NULL) {
@@ -3889,12 +3889,47 @@
   }
 
   if (ok) {
-    allowed_govs = secfile_lookup_str_vec(file, &agcount,
-                                          "compatibility.allowed_govs");
-    allowed_terrains = secfile_lookup_str_vec(file, &atcount,
-                                              
"compatibility.allowed_terrains");
-    allowed_styles = secfile_lookup_str_vec(file, &ascount,
-                                            "compatibility.allowed_styles");
+    vec = secfile_lookup_str_vec(file, &game.server.ruledit.ag_count,
+                                 "compatibility.allowed_govs");
+    if (vec != NULL) {
+      /* Copy to persistent vector */
+      game.server.ruledit.allowed_govs
+        = fc_malloc(game.server.ruledit.ag_count * sizeof(char *));
+
+      for (j = 0; j < game.server.ruledit.ag_count; j++) {
+        game.server.ruledit.allowed_govs[j] = fc_strdup(vec[j]);
+      }
+
+      free(vec);
+    }
+
+    vec = secfile_lookup_str_vec(file, &game.server.ruledit.at_count,
+                                 "compatibility.allowed_terrains");
+    if (vec != NULL) {
+      /* Copy to persistent vector */
+      game.server.ruledit.allowed_terrains
+        = fc_malloc(game.server.ruledit.at_count * sizeof(char *));
+
+      for (j = 0; j < game.server.ruledit.at_count; j++) {
+        game.server.ruledit.allowed_terrains[j] = fc_strdup(vec[j]);
+      }
+
+      free(vec);
+    }
+
+    vec = secfile_lookup_str_vec(file, &game.server.ruledit.as_count,
+                                 "compatibility.allowed_styles");
+    if (vec != NULL) {
+      /* Copy to persistent vector */
+      game.server.ruledit.allowed_styles
+        = fc_malloc(game.server.ruledit.as_count * sizeof(char *));
+
+      for (j = 0; j < game.server.ruledit.as_count; j++) {
+        game.server.ruledit.allowed_styles[j] = fc_strdup(vec[j]);
+      }
+
+      free(vec);
+    }
 
     sval = secfile_lookup_str_default(file, NULL,
                                       "compatibility.default_government");
@@ -4226,8 +4261,10 @@
          * (a) quietly ignore any govs mentioned that don't happen to be in
          * the current ruleset, (b) enforce that govs mentioned by nations
          * must be on the list */
-        if (gov && allowed_govs) {
-          if (!is_on_allowed_list(name, allowed_govs, agcount)) {
+        if (gov != NULL && game.server.ruledit.allowed_govs != NULL) {
+          if (!is_on_allowed_list(name,
+                                  game.server.ruledit.allowed_govs,
+                                  game.server.ruledit.ag_count)) {
             /* Gov exists, but not intended for these nations */
             gov = NULL;
             ruleset_error(LOG_ERROR,
@@ -4238,8 +4275,10 @@
           }
         } else if (!gov) {
           /* Gov doesn't exist; only complain if it's not on any list */
-          if (!allowed_govs
-              || !is_on_allowed_list(name, allowed_govs, agcount)) {
+          if (game.server.ruledit.allowed_govs == NULL
+              || !is_on_allowed_list(name,
+                                     game.server.ruledit.allowed_govs,
+                                     game.server.ruledit.ag_count)) {
             ruleset_error(LOG_ERROR, "Nation %s: government \"%s\" not found.",
                           nation_rule_name(pnation), name);
             ok = FALSE;
@@ -4269,8 +4308,10 @@
       }
       pnation->style = style_by_rule_name(name);
       if (pnation->style == NULL) {
-        if (!allowed_styles
-            || !is_on_allowed_list(name, allowed_styles, ascount)) {
+        if (game.server.ruledit.allowed_styles == NULL
+            || !is_on_allowed_list(name,
+                                   game.server.ruledit.allowed_styles,
+                                   game.server.ruledit.as_count)) {
           ruleset_error(LOG_ERROR, "Nation %s: Illegal style \"%s\"",
                         nation_rule_name(pnation), name);
           ok = FALSE;
@@ -4344,9 +4385,10 @@
       }
       /* ...but if a list of govs has been specified, enforce that this
        * nation's init_government is on the list. */
-      if (allowed_govs
+      if (game.server.ruledit.allowed_govs != NULL
           && 
!is_on_allowed_list(government_rule_name(pnation->init_government),
-                                 allowed_govs, agcount)) {
+                                 game.server.ruledit.allowed_govs,
+                                 game.server.ruledit.ag_count)) {
         ruleset_error(LOG_ERROR,
                       "Nation %s: init_government \"%s\" not allowed.",
                       nation_rule_name(pnation),
@@ -4357,7 +4399,8 @@
 
       /* Read default city names. */
       if (!load_city_name_list(file, pnation, sec_name, "cities",
-                               allowed_terrains, atcount)) {
+                               game.server.ruledit.allowed_terrains,
+                               game.server.ruledit.at_count)) {
         ok = FALSE;
         break;
       }
@@ -4385,10 +4428,6 @@
     section_list_destroy(sec);
   }
 
-  FC_FREE(allowed_govs);
-  FC_FREE(allowed_terrains);
-  FC_FREE(allowed_styles);
-
   if (ok) {
     secfile_check_unused(file);
   }
@@ -4396,7 +4435,7 @@
   if (ok) {
     /* Update cached number of playable nations in the current set */
     count_playable_nations();
-    
+
     /* Sanity checks on all sets */
     nation_sets_iterate(pset) {
       int num_playable = 0, barb_land_count = 0, barb_sea_count = 0;

Modified: branches/S2_6/tools/ruledit/rulesave.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/tools/ruledit/rulesave.c?rev=29909&r1=29908&r2=29909&view=diff
==============================================================================
--- branches/S2_6/tools/ruledit/rulesave.c      (original)
+++ branches/S2_6/tools/ruledit/rulesave.c      Thu Sep 17 05:47:07 2015
@@ -1383,7 +1383,18 @@
   save_traits(game.server.default_traits, NULL, sfile,
               "default_traits", "");
 
-  /* TODO: allowed_govs, allowed_terrains, allowed_cstyles */
+  if (game.server.ruledit.allowed_govs != NULL) {
+    secfile_insert_str_vec(sfile, game.server.ruledit.allowed_govs, 
game.server.ruledit.ag_count,
+                           "compatibility.allowed_govs");
+  }
+  if (game.server.ruledit.allowed_terrains != NULL) {
+    secfile_insert_str_vec(sfile, game.server.ruledit.allowed_terrains, 
game.server.ruledit.at_count,
+                           "compatibility.allowed_terrains");
+  }
+  if (game.server.ruledit.allowed_styles != NULL) {
+    secfile_insert_str_vec(sfile, game.server.ruledit.allowed_styles, 
game.server.ruledit.as_count,
+                           "compatibility.allowed_styles");
+  }
 
   if (game.server.default_government != NULL) {
     secfile_insert_str(sfile, 
government_rule_name(game.server.default_government),


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

Reply via email to