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

 Get information about bases that cannot coexist from ruleset.


 - ML

diff -Nurd -X.diff_ignore freeciv/common/base.c freeciv/common/base.c
--- freeciv/common/base.c       2008-09-08 21:39:02.000000000 +0300
+++ freeciv/common/base.c       2008-09-08 22:56:08.000000000 +0300
@@ -300,10 +300,5 @@
     return TRUE;
   }
 
-  if (base_has_flag(base1, BF_CLAIM_TERRITORY)
-      && base_has_flag(base2, BF_CLAIM_TERRITORY)) {
-    return FALSE;
-  }
-
-  return TRUE;
+  return !BV_ISSET(base1->conflicts, base_index(base2));
 }
diff -Nurd -X.diff_ignore freeciv/common/base.h freeciv/common/base.h
--- freeciv/common/base.h       2008-09-08 21:39:02.000000000 +0300
+++ freeciv/common/base.h       2008-09-08 22:56:15.000000000 +0300
@@ -50,6 +50,7 @@
 
   bv_unit_classes native_to;
   bv_base_flags flags;
+  bv_bases conflicts;
 };
 
 
diff -Nurd -X.diff_ignore freeciv/data/civ1/terrain.ruleset 
freeciv/data/civ1/terrain.ruleset
--- freeciv/data/civ1/terrain.ruleset   2008-09-02 00:43:00.000000000 +0300
+++ freeciv/data/civ1/terrain.ruleset   2008-09-08 22:07:12.000000000 +0300
@@ -663,6 +663,7 @@
 ;                           and README.effects for help on requirements)
 ; gui_type                = How gui should handle this base. 
Fortress/Airbase/Other
 ; build_time              = How long it takes for a unit to build this base
+; conflicts               = List of bases that cannot be on the same tile
 ; flags
 ;   - "NoAggressive"      = Units inside are not considered aggressive
 ;   - "DefenseBonus"      = Units inside gain defense bonus
diff -Nurd -X.diff_ignore freeciv/data/civ2/terrain.ruleset 
freeciv/data/civ2/terrain.ruleset
--- freeciv/data/civ2/terrain.ruleset   2008-09-02 00:43:00.000000000 +0300
+++ freeciv/data/civ2/terrain.ruleset   2008-09-08 22:07:12.000000000 +0300
@@ -778,6 +778,7 @@
 ;                           and README.effects for help on requirements)
 ; gui_type                = How gui should handle this base. 
Fortress/Airbase/Other
 ; build_time              = How long it takes for a unit to build this base
+; conflicts               = List of bases that cannot be on the same tile
 ; flags
 ;   - "NoAggressive"      = Units inside are not considered aggressive
 ;   - "DefenseBonus"      = Units inside gain defense bonus
diff -Nurd -X.diff_ignore freeciv/data/default/terrain.ruleset 
freeciv/data/default/terrain.ruleset
--- freeciv/data/default/terrain.ruleset        2008-09-02 00:43:00.000000000 
+0300
+++ freeciv/data/default/terrain.ruleset        2008-09-08 22:07:12.000000000 
+0300
@@ -898,6 +898,7 @@
 ;                           and README.effects for help on requirements)
 ; gui_type                = How gui should handle this base. 
Fortress/Airbase/Other
 ; build_time              = How long it takes for a unit to build this base
+; conflicts               = List of bases that cannot be on the same tile
 ; flags
 ;   - "NoAggressive"      = Units inside are not considered aggressive
 ;   - "DefenseBonus"      = Units inside gain defense bonus
diff -Nurd -X.diff_ignore freeciv/server/ruleset.c freeciv/server/ruleset.c
--- freeciv/server/ruleset.c    2008-09-02 00:43:00.000000000 +0300
+++ freeciv/server/ruleset.c    2008-09-08 22:56:30.000000000 +0300
@@ -1960,6 +1960,9 @@
   } resource_type_iterate_end;
 
   /* base details */
+  base_type_iterate(pbase) {
+    BV_CLR_ALL(pbase->conflicts);
+  } base_type_iterate_end;
 
   base_type_iterate(pbase) {
     const char *section = &base_sections[base_index(pbase) * 
MAX_SECTION_LABEL];
@@ -2028,6 +2031,34 @@
     }
     
     free(slist);
+
+    slist = secfile_lookup_str_vec(file, &nval, "%s.conflicts", section);
+    for (j = 0; j < nval; j++) {
+      const char *sval = slist[j];
+      struct base_type *pbase2 = find_base_type_by_rule_name(sval);
+
+      if (pbase2 == NULL) {
+        ruleset_error(LOG_FATAL, "\"%s\" base \"%s\": unknown conflict base 
\"%s\".",
+                      filename,
+                      base_rule_name(pbase),
+                      sval);
+      } else {
+        BV_SET(pbase->conflicts, base_index(pbase2));
+        BV_SET(pbase2->conflicts, base_index(pbase));
+      }
+    }
+    
+    free(slist);
+
+    if (base_has_flag(pbase, BF_CLAIM_TERRITORY)) {
+      base_type_iterate(pbase2) {
+        if (pbase2 > pbase && base_has_flag(pbase2, BF_CLAIM_TERRITORY)) {
+          BV_SET(pbase->conflicts, base_index(pbase2));
+          BV_SET(pbase2->conflicts, base_index(pbase));
+        }
+      } base_type_iterate_end;
+    }
+
   } base_type_iterate_end;
 
   section_file_check_unused(file, filename);
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to