[Freeciv-Dev] Re: (PR#14589) New borders, riots, and working city tiles
[Top] [All Lists]
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
 
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=14589 >
On Fri, 11 Nov 2005, Jason Short wrote:
> >>On 11/11/05, Christian Knoke <chrisk@xxxxxxxxx> wrote:
> >>>The attached PNG shows a just conquered city, with new borders code. The
> >>>cities I conquer usually go in riot for 1 or 2 turns, because they have no
> >>>tiles to work on and so no nutrition or luxus.
...
> This is why I wanted source transferral: when one of your sources (S1)
> is closer to a tile you own than the tile's source (S2) is, and S1 is
> close enough that it would be a source for the tile, then the source is
> changed to S1.
Ok. Patch attached.
 - Per
 Index: server/maphand.c
===================================================================
--- server/maphand.c    (revision 11246)
+++ server/maphand.c    (working copy)
@@ -1509,9 +1509,9 @@
 }
 
 /*************************************************************************
-  Establish range of a city's borders.
+  Establish range of a border source.
 *************************************************************************/
-static inline int tile_border_range(struct tile *ptile)
+static int tile_border_range(struct tile *ptile)
 {
   int range;
 
@@ -1558,8 +1558,33 @@
     }
   } whole_map_iterate_end;
 
-  /* Second remove undue ownership. */
+  /* Second transfer ownership to city closer than current source 
+   * but with the same owner. */
   whole_map_iterate(ptile) {
+    if (ptile->owner) {
+      city_list_iterate(ptile->owner->cities, pcity) {
+        int r_curr = sq_map_distance(ptile, ptile->owner_source);
+        int r_city = sq_map_distance(ptile, pcity->tile);
+
+        /* Repair tile ownership */
+        if (!ptile->owner_source) {
+          assert(FALSE);
+          ptile->owner_source = pcity->tile;
+        }
+        /* Transfer tile to city if closer than current source */
+        if (r_curr > r_city && tile_border_range(pcity->tile) >= r_city) {
+          freelog(LOG_DEBUG, "%s's %s(%d,%d) acquired tile (%d,%d) from "
+                  "(%d,%d)", ptile->owner->name, pcity->name, pcity->tile->x, 
+                  pcity->tile->y, ptile->x, ptile->y, ptile->owner_source->x, 
+                  ptile->owner_source->y);
+          ptile->owner_source = pcity->tile;
+        }
+      } city_list_iterate_end;
+    }
+  } whole_map_iterate_end;
+
+  /* Third remove undue ownership. */
+  whole_map_iterate(ptile) {
     if (ptile->owner
         && (ptile->owner != ptile->owner_source->owner
             || (!ptile->owner_source->city
 
- [Freeciv-Dev] Re: (PR#14589) New borders, riots, and working city tiles, Peter Schaefer, 2005/11/11
- [Freeciv-Dev] Re: (PR#14589) New borders, riots, and working city tiles, Per I. Mathisen, 2005/11/11
- [Freeciv-Dev] Re: (PR#14589) New borders, riots, and working city tiles, Jason Short, 2005/11/11
- [Freeciv-Dev] Re: (PR#14589) New borders, riots, and working city tiles, Christian Knoke, 2005/11/12
 - [Freeciv-Dev] Re: (PR#14589) New borders, riots, and working city tiles,
Per I. Mathisen <=
 - [Freeciv-Dev] Re: (PR#14589) New borders, riots, and working city tiles, Per I. Mathisen, 2005/11/19
 
  
  
 
 
 
 
 | 
 |