Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2005:
[Freeciv-Dev] Re: (PR#14589) New borders, riots, and working city tiles
Home

[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]
To: chrisk@xxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#14589) New borders, riots, and working city tiles
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Sat, 19 Nov 2005 01:50:00 -0800
Reply-to: bugs@xxxxxxxxxxx

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

On Sat, 19 Nov 2005, Per I. Mathisen wrote:
> Ok. Patch attached.

I forgot to take into account that borders range is a normal, not squared,
value. Fixed 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,35 @@
     }
   } 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, r_city = sq_map_distance(ptile, pcity->tile);
+        int max_range = tile_border_range(pcity->tile);
+
+        /* Repair tile ownership */
+        if (!ptile->owner_source) {
+          assert(FALSE);
+          ptile->owner_source = pcity->tile;
+        }
+        r_curr = sq_map_distance(ptile, ptile->owner_source);
+        max_range *= max_range; /* we are dealing with square distances */
+        /* Transfer tile to city if closer than current source */
+        if (r_curr > r_city && max_range >= r_city) {
+          freelog(LOG_NORMAL, "%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

[Prev in Thread] Current Thread [Next in Thread]