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

On 3/18/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.

 - Even trunk can use some extra checking, so separate version for it too
 - LOG_ERROR -> LOG_FATAL
 - Error messages translatable, with TRANS comment


 - ML

diff -Nurd -X.diff_ignore freeciv/server/ruleset.c freeciv/server/ruleset.c
--- freeciv/server/ruleset.c	2007-03-18 16:59:16.000000000 +0200
+++ freeciv/server/ruleset.c	2007-03-18 17:22:29.000000000 +0200
@@ -2340,13 +2340,28 @@
       pl->barb_type = NOT_A_BARBARIAN;
     } else if (mystrcasecmp(barb_type, "Land") == 0) {
       pl->barb_type = LAND_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."),
+                pl->name);
+        exit(EXIT_FAILURE);
+      }
       barb_land_count++;
     } else if (mystrcasecmp(barb_type, "Sea") == 0) {
       pl->barb_type = SEA_BARBARIAN;
+      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."),
+                pl->name);
+        exit(EXIT_FAILURE);
+      }
       barb_sea_count++;
     } else {
       /* TRANS: Do not translate "None", "Land" or "Sea" */
-      freelog(LOG_ERROR, _("Nation %s, barbarian_type is \"%s\". Must be "
+      freelog(LOG_FATAL, _("Nation %s, barbarian_type is \"%s\". Must be "
               "\"None\" or \"Land\" or \"Sea\""), pl->name, barb_type);
       exit(EXIT_FAILURE);
     }
@@ -2491,12 +2506,14 @@
   section_file_free(file);
 
   if (barb_land_count == 0) {
-    freelog(LOG_ERROR,
+    /* TRANS: Ruleset error */
+    freelog(LOG_FATAL,
             _("No land barbarian nation defined. At least one required!"));
     exit(EXIT_FAILURE);
   }
   if (barb_sea_count == 0) {
-    freelog(LOG_ERROR,
+    /* TRANS: Ruleset error */
+    freelog(LOG_FATAL,
             _("No sea barbarian nation defined. At least one required!"));
     exit(EXIT_FAILURE);
   }
diff -Nurd -X.diff_ignore freeciv/server/ruleset.c freeciv/server/ruleset.c
--- freeciv/server/ruleset.c	2007-03-05 19:13:46.000000000 +0200
+++ freeciv/server/ruleset.c	2007-03-18 17:20:58.000000000 +0200
@@ -2004,6 +2004,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);
   
@@ -2106,6 +2107,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."),
+                pl->name);
+        exit(EXIT_FAILURE);
+      }
+      barbarians++;
+    }
+
     /* Flags */
 
     sz_strlcpy(pl->flag_graphic_str,
@@ -2244,6 +2257,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