Author: cazfi
Date: Thu Jan 21 11:10:36 2016
New Revision: 31519

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

See bug #24194

Modified:
    branches/S2_5/server/citytools.c
    branches/S2_5/server/cityturn.c
    branches/S2_5/server/maphand.c
    branches/S2_5/server/maphand.h

Modified: branches/S2_5/server/citytools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/citytools.c?rev=31519&r1=31518&r2=31519&view=diff
==============================================================================
--- branches/S2_5/server/citytools.c    (original)
+++ branches/S2_5/server/citytools.c    Thu Jan 21 11:10:36 2016
@@ -1272,7 +1272,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() */
@@ -1534,7 +1534,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: branches/S2_5/server/cityturn.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/cityturn.c?rev=31519&r1=31518&r2=31519&view=diff
==============================================================================
--- branches/S2_5/server/cityturn.c     (original)
+++ branches/S2_5/server/cityturn.c     Thu Jan 21 11:10:36 2016
@@ -32,6 +32,7 @@
 #include "cm.h"
 
 /* common */
+#include "borders.h"
 #include "citizens.h"
 #include "city.h"
 #include "events.h"
@@ -664,6 +665,7 @@
                       struct player *destroyer)
 {
   citizens loss_remain;
+  int old_radius_sq;
 
   if (pop_loss == 0) {
     return TRUE;
@@ -679,9 +681,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))) {
@@ -897,7 +900,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;
 }
@@ -922,7 +925,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: branches/S2_5/server/maphand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/maphand.c?rev=31519&r1=31518&r2=31519&view=diff
==============================================================================
--- branches/S2_5/server/maphand.c      (original)
+++ branches/S2_5/server/maphand.c      Thu Jan 21 11:10:36 2016
@@ -2045,12 +2045,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);
+        }
+      }
+    } 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;
   }
@@ -2063,8 +2095,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 */
@@ -2140,7 +2181,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;
 
@@ -2196,7 +2237,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: branches/S2_5/server/maphand.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/maphand.h?rev=31519&r1=31518&r2=31519&view=diff
==============================================================================
--- branches/S2_5/server/maphand.h      (original)
+++ branches/S2_5/server/maphand.h      Thu Jan 21 11:10:36 2016
@@ -107,10 +107,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);
 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 map_claim_base(struct tile *ptile, struct base_type *pbase,
                     struct player *powner, struct player *ploser);


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

Reply via email to