<URL: http://bugs.freeciv.org/Ticket/Display.html?id=38378 >

On 18/03/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
>
>  If there is no barbarian nation defined, game will assert later.
> Atatched patch adds sanity checking to ruleset load. This is for S2_1.
> Trunk will need different patch, as there land and sea barbarians use
> separate nations.

 Patches updated against svn.


 - ML

diff -Nurd -X.diff_ignore freeciv/server/ruleset.c freeciv/server/ruleset.c
--- freeciv/server/ruleset.c	2007-08-01 17:17:23.000000000 +0300
+++ freeciv/server/ruleset.c	2007-08-01 21:24:55.000000000 +0300
@@ -2441,9 +2441,23 @@
     if (mystrcasecmp(barb_type, "None") == 0) {
       pl->barb_type = NOT_A_BARBARIAN;
     } else if (mystrcasecmp(barb_type, "Land") == 0) {
+      if (pl->is_playable) {
+        /* We can't allow players to use barbarian nations, barbarians
+         * may run out of nations */
+        freelog(LOG_FATAL, "Nation %s marked both barbarian and playable.",
+                nation_rule_name(pl));
+        exit(EXIT_FAILURE);
+      }
       pl->barb_type = LAND_BARBARIAN;
       barb_land_count++;
     } else if (mystrcasecmp(barb_type, "Sea") == 0) {
+      if (pl->is_playable) {
+        /* We can't allow players to use barbarian nations, barbarians
+         * may run out of nations */
+        freelog(LOG_FATAL, "Nation %s marked both barbarian and playable.",
+                nation_rule_name(pl));
+        exit(EXIT_FAILURE);
+      }
       pl->barb_type = SEA_BARBARIAN;
       barb_sea_count++;
     } else {
diff -Nurd -X.diff_ignore freeciv/server/ruleset.c freeciv/server/ruleset.c
--- freeciv/server/ruleset.c	2007-07-04 14:04:17.000000000 +0300
+++ freeciv/server/ruleset.c	2007-08-01 21:27:33.000000000 +0300
@@ -2052,6 +2052,7 @@
   char **leaders, **sec, **civilwar_nations, **groups, **conflicts;
   char* name;
   const char *filename = secfile_filename(file);
+  int barbarians = 0;
 
   (void) check_ruleset_capabilities(file, "+1.9", filename);
   
@@ -2167,6 +2168,18 @@
     pl->is_barbarian = secfile_lookup_bool_default(file, FALSE,
 						  "%s.is_barbarian", sec[i]);
 
+    if (pl->is_barbarian) {
+      if (pl->is_playable) {
+        /* We can't allow players to use barbarian nations, barbarians
+         * may run out of nations */
+        /* TRANS: Ruleset error */
+        freelog(LOG_FATAL, "Nation %s marked both barbarian and playable.",
+                nation_rule_name(pl));
+        exit(EXIT_FAILURE);
+      }
+      barbarians++;
+    }
+
     /* Flags */
 
     sz_strlcpy(pl->flag_graphic_str,
@@ -2318,6 +2331,13 @@
   free(sec);
   section_file_check_unused(file, filename);
   section_file_free(file);
+
+  if (barbarians < 1) {
+    /* TRANS: Ruleset error */
+    freelog(LOG_FATAL,
+            _("No barbarian nation in rulesets, at least one required!"));
+    exit(EXIT_FAILURE);
+  }
 }
 
 /**************************************************************************
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to