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

 This patch adds check that no two bases with flag BF_CLAIM_TERRITORY
is built to same tile. If new base with that flag is built, old one is
removed.


 - ML

diff -Nurd -X.diff_ignore freeciv/common/base.c freeciv/common/base.c
--- freeciv/common/base.c       2008-08-15 15:51:24.000000000 +0300
+++ freeciv/common/base.c       2008-08-15 15:51:45.000000000 +0300
@@ -286,3 +286,20 @@
 
   return NULL;
 }
+
+/**************************************************************************
+  Can two bases coexist in same tile?
+**************************************************************************/
+bool can_bases_coexist(const struct base_type *base1, const struct base_type 
*base2)
+{
+  if (base1 == base2) {
+    return TRUE;
+  }
+
+  if (base_has_flag(base1, BF_CLAIM_TERRITORY)
+      && base_has_flag(base2, BF_CLAIM_TERRITORY)) {
+    return FALSE;
+  }
+
+  return TRUE;
+}
diff -Nurd -X.diff_ignore freeciv/common/base.h freeciv/common/base.h
--- freeciv/common/base.h       2008-08-15 15:51:24.000000000 +0300
+++ freeciv/common/base.h       2008-08-15 15:51:45.000000000 +0300
@@ -88,6 +88,8 @@
                                        const struct unit *punit,
                                        const struct tile *ptile);
 
+bool can_bases_coexist(const struct base_type *base1, const struct base_type 
*base2);
+
 /* Initialization and iteration */
 void base_types_init(void);
 void base_types_free(void);
diff -Nurd -X.diff_ignore freeciv/server/unittools.c freeciv/server/unittools.c
--- freeciv/server/unittools.c  2008-08-15 15:51:24.000000000 +0300
+++ freeciv/server/unittools.c  2008-08-15 16:12:38.000000000 +0300
@@ -791,14 +791,25 @@
   case ACTIVITY_BASE:
     if (total_activity_base(ptile, punit->activity_base)
         >= tile_activity_base_time(ptile, punit->activity_base)) {
-      tile_add_base(ptile, base_by_number(punit->activity_base));
+      struct base_type *new_base = base_by_number(punit->activity_base);
+
+      base_type_iterate(old_base) {
+        if (!can_bases_coexist(old_base, new_base)) {
+          if (base_has_flag(old_base, BF_CLAIM_TERRITORY)) {
+            map_clear_border(ptile, ptile->owner);
+          }
+          tile_remove_base(ptile, old_base);
+        }
+      } base_type_iterate_end;
+
+      tile_add_base(ptile, new_base);
 
       /* Watchtower might become effective
        * FIXME: Reqs on other specials will not be updated immediately. */
       unit_list_refresh_vision(ptile->units);
 
       /* Claim base if it has "ClaimTerritory" flag */
-      if (tile_has_base_flag(ptile, BF_CLAIM_TERRITORY)) {
+      if (base_has_flag(new_base, BF_CLAIM_TERRITORY)) {
         map_claim_ownership(ptile, unit_owner(punit), ptile);
         map_claim_border(ptile, unit_owner(punit));
         city_thaw_workers_queue();
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to