Author: cazfi
Date: Fri May  6 14:44:54 2016
New Revision: 32606

URL: http://svn.gna.org/viewcvs/freeciv?rev=32606&view=rev
Log:
Automatically disable barbarians if ruleset has no barbarian units.

See patch #7192

Modified:
    branches/S2_6/data/stub/game.ruleset
    branches/S2_6/server/rssanity.c
    branches/S2_6/server/rssanity.h
    branches/S2_6/server/settings.c

Modified: branches/S2_6/data/stub/game.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/stub/game.ruleset?rev=32606&r1=32605&r2=32606&view=diff
==============================================================================
--- branches/S2_6/data/stub/game.ruleset        (original)
+++ branches/S2_6/data/stub/game.ruleset        Fri May  6 14:44:54 2016
@@ -423,6 +423,5 @@
 
 set =
     { "name", "value", "lock"
-      "barbarians", "DISABLED", TRUE
       "startunits", "c", TRUE
     }

Modified: branches/S2_6/server/rssanity.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/rssanity.c?rev=32606&r1=32605&r2=32606&view=diff
==============================================================================
--- branches/S2_6/server/rssanity.c     (original)
+++ branches/S2_6/server/rssanity.c     Fri May  6 14:44:54 2016
@@ -1,4 +1,4 @@
-/**********************************************************************
+/***********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    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
@@ -28,6 +28,7 @@
 
 /* server */
 #include "ruleset.h"
+#include "settings.h"
 
 #include "rssanity.h"
 
@@ -325,76 +326,69 @@
 **************************************************************************/
 static bool rs_barbarian_units(void)
 {
-  if (num_role_units(L_BARBARIAN) == 0
-      && BARBS_DISABLED != game.server.barbarianrate) {
-    ruleset_error(LOG_ERROR, "No role barbarian units");
-    return FALSE;
-  }
-  if (num_role_units(L_BARBARIAN_LEADER) == 0
-      && BARBS_DISABLED != game.server.barbarianrate) {
-    ruleset_error(LOG_ERROR, "No role barbarian leader units");
-    return FALSE;
-  }
-  if (num_role_units(L_BARBARIAN_BUILD) == 0
-      && BARBS_DISABLED != game.server.barbarianrate) {
-    ruleset_error(LOG_ERROR, "No role barbarian build units");
-    return FALSE;
-  }
-  if (num_role_units(L_BARBARIAN_BOAT) == 0
-      && BARBS_DISABLED != game.server.barbarianrate) {
-    ruleset_error(LOG_ERROR, "No role barbarian ship units");
-    return FALSE;
-  } else if (num_role_units(L_BARBARIAN_BOAT) > 0) {
-    bool sea_capable = FALSE;
-    struct unit_type *u = get_role_unit(L_BARBARIAN_BOAT, 0);
-
-    terrain_type_iterate(pterr) {
-      if(is_ocean(pterr)
-         && BV_ISSET(pterr->native_to, uclass_index(utype_class(u)))) {
-        sea_capable = TRUE;
-        break;
-      }
-    } terrain_type_iterate_end;
-
-    if (!sea_capable) {
-      ruleset_error(LOG_ERROR,
-                    "Barbarian boat (%s) needs to be able to move at sea.",
-                    utype_rule_name(u));
+  if (num_role_units(L_BARBARIAN) > 0) {
+    if (num_role_units(L_BARBARIAN_LEADER) == 0) {
+      ruleset_error(LOG_ERROR, "No role barbarian leader units");
       return FALSE;
     }
-  }
-  if (num_role_units(L_BARBARIAN_SEA) == 0
-      && BARBS_DISABLED != game.server.barbarianrate) {
-    ruleset_error(LOG_ERROR, "No role sea raider barbarian units");
-    return FALSE;
-  }
-
-  unit_type_iterate(ptype) {
-    if (utype_has_role(ptype, L_BARBARIAN_BOAT)) {
-      if (ptype->transport_capacity <= 1) {
-        ruleset_error(LOG_ERROR,
-                      "Barbarian boat %s has no capacity for both "
-                      "leader and at least one man.",
-                      utype_rule_name(ptype));
+    if (num_role_units(L_BARBARIAN_BUILD) == 0) {
+      ruleset_error(LOG_ERROR, "No role barbarian build units");
+      return FALSE;
+    }
+    if (num_role_units(L_BARBARIAN_BOAT) == 0) {
+      ruleset_error(LOG_ERROR, "No role barbarian ship units");
+      return FALSE;
+    } else if (num_role_units(L_BARBARIAN_BOAT) > 0) {
+      bool sea_capable = FALSE;
+      struct unit_type *u = get_role_unit(L_BARBARIAN_BOAT, 0);
+
+      terrain_type_iterate(pterr) {
+        if (is_ocean(pterr)
+            && BV_ISSET(pterr->native_to, uclass_index(utype_class(u)))) {
+          sea_capable = TRUE;
+          break;
+        }
+      } terrain_type_iterate_end;
+
+      if (!sea_capable) {
+        ruleset_error(LOG_ERROR,
+                      "Barbarian boat (%s) needs to be able to move at sea.",
+                      utype_rule_name(u));
         return FALSE;
       }
-
-      unit_type_iterate(pbarb) {
-        if (utype_has_role(pbarb, L_BARBARIAN_SEA)
-            || utype_has_role(pbarb, L_BARBARIAN_SEA_TECH)
-            || utype_has_role(pbarb, L_BARBARIAN_LEADER)) {
-          if (!can_unit_type_transport(ptype, utype_class(pbarb))) {
-            ruleset_error(LOG_ERROR,
-                          "Barbarian boat %s cannot transport "
-                          "barbarian cargo %s.",
-                          utype_rule_name(ptype),
-                          utype_rule_name(pbarb));
-            return FALSE;
+    }
+    if (num_role_units(L_BARBARIAN_SEA) == 0) {
+      ruleset_error(LOG_ERROR, "No role sea raider barbarian units");
+      return FALSE;
+    }
+
+    unit_type_iterate(ptype) {
+      if (utype_has_role(ptype, L_BARBARIAN_BOAT)) {
+        if (ptype->transport_capacity <= 1) {
+          ruleset_error(LOG_ERROR,
+                        "Barbarian boat %s has no capacity for both "
+                        "leader and at least one man.",
+                        utype_rule_name(ptype));
+          return FALSE;
+        }
+
+        unit_type_iterate(pbarb) {
+          if (utype_has_role(pbarb, L_BARBARIAN_SEA)
+              || utype_has_role(pbarb, L_BARBARIAN_SEA_TECH)
+              || utype_has_role(pbarb, L_BARBARIAN_LEADER)) {
+            if (!can_unit_type_transport(ptype, utype_class(pbarb))) {
+              ruleset_error(LOG_ERROR,
+                            "Barbarian boat %s cannot transport "
+                            "barbarian cargo %s.",
+                            utype_rule_name(ptype),
+                            utype_rule_name(pbarb));
+              return FALSE;
+            }
           }
-        }
-      } unit_type_iterate_end;
-    }
-  } unit_type_iterate_end;
+        } unit_type_iterate_end;
+      }
+    } unit_type_iterate_end;
+  }
 
   return TRUE;
 }
@@ -963,3 +957,24 @@
 
   return ok;
 }
+
+/**************************************************************************
+  Set and lock settings that must have certain value.
+**************************************************************************/
+bool autolock_settings(void)
+{
+  bool ok = TRUE;
+
+  if (num_role_units(L_BARBARIAN) == 0) {
+    struct setting *pset = setting_by_name("barbarians");
+
+    log_normal(_("Disabling barbarians in lack of suitable unit types."));
+    setting_lock_set(pset, FALSE);
+    if (!setting_enum_set(pset, "DISABLED", NULL, NULL, 0)) {
+      ok = FALSE;
+    }
+    setting_lock_set(pset, TRUE);
+  }
+
+  return ok;
+}

Modified: branches/S2_6/server/rssanity.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/rssanity.h?rev=32606&r1=32605&r2=32606&view=diff
==============================================================================
--- branches/S2_6/server/rssanity.h     (original)
+++ branches/S2_6/server/rssanity.h     Fri May  6 14:44:54 2016
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/***********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    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
@@ -18,6 +18,7 @@
 #endif /* __cplusplus */
 
 bool sanity_check_ruleset_data(void);
+bool autolock_settings(void);
 
 #ifdef __cplusplus
 }

Modified: branches/S2_6/server/settings.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/settings.c?rev=32606&r1=32605&r2=32606&view=diff
==============================================================================
--- branches/S2_6/server/settings.c     (original)
+++ branches/S2_6/server/settings.c     Fri May  6 14:44:54 2016
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/***********************************************************************
  Freeciv - Copyright (C) 1996-2004 - 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
@@ -34,6 +34,7 @@
 #include "notify.h"
 #include "plrhand.h"
 #include "report.h"
+#include "rssanity.h"
 #include "settings.h"
 #include "srv_main.h"
 #include "stdinhand.h"
@@ -3833,6 +3834,8 @@
       setting_action(pset);
     } settings_iterate_end;
   }
+
+  autolock_settings();
 
   /* send game settings */
   send_server_settings(NULL);


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

Reply via email to