Author: cazfi
Date: Mon Dec 21 11:03:02 2015
New Revision: 31136

URL: http://svn.gna.org/viewcvs/freeciv?rev=31136&view=rev
Log:
Avoid temporary complete removal of border source when city size reduces and 
border radius might change.

See bug #24194

Modified:
    trunk/server/citytools.c
    trunk/server/cityturn.c
    trunk/server/maphand.c
    trunk/server/maphand.h

Modified: trunk/server/citytools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/citytools.c?rev=31136&r1=31135&r2=31136&view=diff
==============================================================================
--- trunk/server/citytools.c    (original)
+++ trunk/server/citytools.c    Mon Dec 21 11:03:02 2015
@@ -1264,7 +1264,7 @@
      * This could leave a border ring around the city, updated later by
      * map_calculate_borders() at the next turn.
      */
-    map_claim_border(pcenter, ptaker);
+    map_claim_border(pcenter, ptaker, -1);
     /* city_thaw_workers_queue() later */
 
     auto_arrange_workers(pcity); /* does city_map_update_all() */
@@ -1516,7 +1516,7 @@
 
   /* This is dependent on the current vision, so must be done after
    * vision is prepared and before arranging workers. */
-  map_claim_border(ptile, pplayer);
+  map_claim_border(ptile, pplayer, -1);
   /* city_thaw_workers_queue() later */
 
   /* Refresh the city.  First a city refresh is done (this shouldn't

Modified: trunk/server/cityturn.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/cityturn.c?rev=31136&r1=31135&r2=31136&view=diff
==============================================================================
--- trunk/server/cityturn.c     (original)
+++ trunk/server/cityturn.c     Mon Dec 21 11:03:02 2015
@@ -34,6 +34,7 @@
 /* common */
 #include "achievements.h"
 #include "actiontools.h"
+#include "borders.h"
 #include "calendar.h"
 #include "citizens.h"
 #include "city.h"
@@ -724,6 +725,7 @@
                       struct player *destroyer)
 {
   citizens loss_remain;
+  int old_radius_sq;
 
   if (pop_loss == 0) {
     return TRUE;
@@ -739,9 +741,10 @@
     remove_city(pcity);
     return FALSE;
   }
-  map_clear_border(pcity->tile);
+  old_radius_sq = tile_border_source_radius_sq(pcity->tile);
   city_size_add(pcity, -pop_loss);
-  map_claim_border(pcity->tile, pcity->owner);
+  map_update_border(pcity->tile, pcity->owner, old_radius_sq,
+                    tile_border_source_radius_sq(pcity->tile));
 
   /* Cap the food stock at the new granary size. */
   if (pcity->food_stock > city_granary_size(city_size_get(pcity))) {
@@ -957,7 +960,7 @@
     return city_reduce_size(pcity, city_size_get(pcity) - size, NULL);
   }
 
-  map_claim_border(pcity->tile, pcity->owner);
+  map_claim_border(pcity->tile, pcity->owner, -1);
 
   return TRUE;
 }
@@ -982,7 +985,7 @@
       pcity->food_stock = MIN(pcity->food_stock, granary_size);
     } else {
       city_increase_size(pcity, nationality);
-      map_claim_border(pcity->tile, pcity->owner);
+      map_claim_border(pcity->tile, pcity->owner, -1);
     }
   } else if (pcity->food_stock < 0) {
     /* FIXME: should this depend on units with ability to build

Modified: trunk/server/maphand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/maphand.c?rev=31136&r1=31135&r2=31136&view=diff
==============================================================================
--- trunk/server/maphand.c      (original)
+++ trunk/server/maphand.c      Mon Dec 21 11:03:02 2015
@@ -1992,12 +1992,44 @@
 }
 
 /*************************************************************************
+  Update borders for this source. Changes the radius without temporary
+  clearing.
+*************************************************************************/
+void map_update_border(struct tile *ptile, struct player *owner,
+                       int old_radius_sq, int new_radius_sq)
+{
+  if (old_radius_sq == new_radius_sq) {
+    /* No change */
+    return;
+  }
+
+  if (BORDERS_DISABLED == game.info.borders) {
+    return;
+  }
+
+  if (old_radius_sq < new_radius_sq) {
+    map_claim_border(ptile, owner, new_radius_sq);
+  } else {
+    circle_dxyr_iterate(ptile, old_radius_sq, dtile, dx, dy, dr) {
+      if (dr > new_radius_sq) {
+        struct tile *claimer = tile_claimer(dtile);
+
+        if (claimer == ptile) {
+          map_claim_ownership(dtile, NULL, NULL, FALSE);
+        }
+      }
+    } circle_dxyr_iterate_end;
+  }
+}
+
+/*************************************************************************
   Update borders for this source. Call this for each new source.
+
+  If radius_sq is -1, get value from the border source on tile.
 *************************************************************************/
-void map_claim_border(struct tile *ptile, struct player *owner)
-{
-  int radius_sq = tile_border_source_radius_sq(ptile);
-
+void map_claim_border(struct tile *ptile, struct player *owner,
+                      int radius_sq)
+{
   if (BORDERS_DISABLED == game.info.borders) {
     return;
   }
@@ -2010,8 +2042,17 @@
     return;
   }
 
+  if (radius_sq < 0) {
+    radius_sq = tile_border_source_radius_sq(ptile);
+  }
+
   circle_dxyr_iterate(ptile, radius_sq, dtile, dx, dy, dr) {
     struct tile *dclaimer = tile_claimer(dtile);
+
+    if (dclaimer == ptile) {
+      /* Already claimed by the ptile */
+      continue;
+    }
 
     if (dr != 0 && is_border_source(dtile)) {
       /* Do not claim border sources other than self */
@@ -2088,7 +2129,7 @@
 
   whole_map_iterate(ptile) {
     if (is_border_source(ptile)) {
-      map_claim_border(ptile, ptile->owner);
+      map_claim_border(ptile, ptile->owner, -1);
     }
   } whole_map_iterate_end;
 
@@ -2144,7 +2185,7 @@
      * ploser == powner and above check will abort the recursion. */
     if (powner != NULL) {
       map_claim_border_ownership(ptile, powner, ptile);
-      map_claim_border(ptile, powner);
+      map_claim_border(ptile, powner, -1);
     }
     city_thaw_workers_queue();
     city_refresh_queue_processing();

Modified: trunk/server/maphand.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/maphand.h?rev=31136&r1=31135&r2=31136&view=diff
==============================================================================
--- trunk/server/maphand.h      (original)
+++ trunk/server/maphand.h      Mon Dec 21 11:03:02 2015
@@ -106,10 +106,13 @@
 void disable_fog_of_war_player(struct player *pplayer);
 
 void map_calculate_borders(void);
-void map_claim_border(struct tile *ptile, struct player *powner);
+void map_claim_border(struct tile *ptile, struct player *powner,
+                      int radius_sq);
 void map_claim_ownership(struct tile *ptile, struct player *powner,
                          struct tile *psource, bool claim_bases);
 void map_clear_border(struct tile *ptile);
+void map_update_border(struct tile *ptile, struct player *owner,
+                       int old_radius_sq, int new_radius_sq);
 
 void tile_claim_bases(struct tile *ptile, struct player *powner);
 void map_claim_base(struct tile *ptile, struct base_type *pbase,


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

Reply via email to