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

 This patch moves border handling from player maps (and vision sites)
to master map.


 - ML

diff -Nurd -X.diff_ignore freeciv/ai/aisettler.c freeciv/ai/aisettler.c
--- freeciv/ai/aisettler.c      2008-10-27 04:13:32.000000000 +0200
+++ freeciv/ai/aisettler.c      2009-01-06 14:17:38.000000000 +0200
@@ -116,6 +116,7 @@
   struct city *pcity = tile_city(result->tile);
   struct government *curr_govt = government_of_player(pplayer);
   struct player *saved_owner = NULL;
+  struct tile *saved_claimer = NULL;
   int sum = 0;
   bool virtual_city = FALSE;
   bool handicap = ai_handicap(pplayer, H_MAP);
@@ -134,7 +135,8 @@
   if (!pcity) {
     pcity = create_city_virtual(pplayer, result->tile, "Virtuaville");
     saved_owner = tile_owner(result->tile);
-    tile_set_owner(result->tile, pplayer); /* temporarily */
+    saved_claimer = tile_claimer(result->tile);
+    tile_set_owner(result->tile, pplayer, result->tile); /* temporarily */
     city_choose_build_default(pcity);  /* ?? */
     virtual_city = TRUE;
   }
@@ -266,7 +268,7 @@
   pplayer->government = curr_govt;
   if (virtual_city) {
     destroy_city_virtual(pcity);
-    tile_set_owner(result->tile, saved_owner);
+    tile_set_owner(result->tile, saved_owner, saved_claimer);
   }
 
   assert(result->city_center >= 0);
diff -Nurd -X.diff_ignore freeciv/client/packhand.c freeciv/client/packhand.c
--- freeciv/client/packhand.c   2008-11-11 17:38:45.000000000 +0200
+++ freeciv/client/packhand.c   2009-01-06 15:17:36.000000000 +0200
@@ -2316,7 +2316,7 @@
   tile_set_resource(ptile, presource);
 
   if (tile_owner(ptile) != powner) {
-    tile_set_owner(ptile, powner);
+    tile_set_owner(ptile, powner, NULL);
     tile_changed = TRUE;
   }
 
diff -Nurd -X.diff_ignore freeciv/common/borders.c freeciv/common/borders.c
--- freeciv/common/borders.c    1970-01-01 02:00:00.000000000 +0200
+++ freeciv/common/borders.c    2009-01-06 15:34:10.000000000 +0200
@@ -0,0 +1,78 @@
+/****************************************************************************
+ Freeciv - Copyright (C) 2004 - The Freeciv Team
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <assert.h>
+
+/* utility */
+#include "fcintl.h"
+#include "log.h"
+
+/* common */
+#include "game.h"
+#include "tile.h"
+#include "unit.h"
+
+#include "borders.h"
+
+/*************************************************************************
+  Border radius sq from given border source tile.
+*************************************************************************/
+int tile_border_radius_sq(struct tile *ptile)
+{
+  struct city *pcity;
+  int radius_sq = 0;
+
+  if (game.info.borders_sq == 0) {
+    return 0;
+  }
+
+  pcity = tile_city(ptile);
+
+  if (pcity) {
+    radius_sq = MAX(game.info.borders_sq, 2*2+1*1);
+    radius_sq += pcity->size;
+  } else {
+    base_type_iterate(pbase) {
+      if (tile_has_base(ptile, pbase) && base_has_flag(pbase, 
BF_CLAIM_TERRITORY)) {
+        radius_sq = 5;
+        break;
+      }
+    } base_type_iterate_end;
+  }
+
+  return radius_sq;
+}
+
+/*************************************************************************
+  Is given tile source to borders.
+*************************************************************************/
+bool is_border_source(struct tile *ptile)
+{
+  if (tile_city(ptile)) {
+    return TRUE;
+  }
+
+  if (tile_owner(ptile) != NULL) {
+    base_type_iterate(pbase) {
+      if (tile_has_base(ptile, pbase) && base_has_flag(pbase, 
BF_CLAIM_TERRITORY)) {
+        return TRUE;
+      }
+    } base_type_iterate_end;
+  }
+
+  return FALSE;
+}
diff -Nurd -X.diff_ignore freeciv/common/borders.h freeciv/common/borders.h
--- freeciv/common/borders.h    1970-01-01 02:00:00.000000000 +0200
+++ freeciv/common/borders.h    2009-01-06 14:41:11.000000000 +0200
@@ -0,0 +1,21 @@
+/********************************************************************** 
+ Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+#ifndef FC__BORDERS_H
+#define FC__BORDERS_H
+
+#include "fc_types.h"
+
+int tile_border_radius_sq(struct tile *ptile);
+bool is_border_source(struct tile *ptile);
+
+#endif  /* FC__BORDERS_H */
diff -Nurd -X.diff_ignore freeciv/common/Makefile.am freeciv/common/Makefile.am
--- freeciv/common/Makefile.am  2008-10-27 04:13:31.000000000 +0200
+++ freeciv/common/Makefile.am  2009-01-06 14:28:58.000000000 +0200
@@ -9,6 +9,8 @@
 libcivcommon_a_SOURCES = \
                base.c          \
                base.h          \
+               borders.c       \
+               borders.h       \
                capstr.c        \
                capstr.h        \
                city.c          \
diff -Nurd -X.diff_ignore freeciv/common/tile.c freeciv/common/tile.c
--- freeciv/common/tile.c       2008-12-15 21:55:49.000000000 +0200
+++ freeciv/common/tile.c       2009-01-06 14:13:40.000000000 +0200
@@ -42,10 +42,21 @@
 }
 #endif
 
+#ifndef tile_claimer
+/****************************************************************************
+  Return the player who owns this tile (or NULL if none).
+****************************************************************************/
+struct tile *tile_claimer(const struct tile *ptile)
+{
+  return ptile->claimer;
+}
+#endif
+
 /****************************************************************************
   Set the owner of a tile (may be NULL).
 ****************************************************************************/
-void tile_set_owner(struct tile *ptile, struct player *pplayer)
+void tile_set_owner(struct tile *ptile, struct player *pplayer,
+                    struct tile *claimer)
 {
   ptile->owner = pplayer;
 }
diff -Nurd -X.diff_ignore freeciv/common/tile.h freeciv/common/tile.h
--- freeciv/common/tile.h       2008-12-15 21:55:49.000000000 +0200
+++ freeciv/common/tile.h       2009-01-06 14:18:09.000000000 +0200
@@ -43,8 +43,9 @@
   struct resource *resource;           /* NULL for no resource */
   struct terrain *terrain;             /* NULL for unknown tiles */
   struct unit_list *units;
-  struct player *owner;                        /* NULL for not owned */
   struct city *worked;                 /* NULL for not worked */
+  struct player *owner;                        /* NULL for not owned */
+  struct tile *claimer;
   char *spec_sprite;
 };
 
@@ -68,7 +69,9 @@
 
 #define tile_owner(_tile) ((_tile)->owner)
 /*struct player *tile_owner(const struct tile *ptile);*/
-void tile_set_owner(struct tile *ptile, struct player *pplayer);
+void tile_set_owner(struct tile *ptile, struct player *pplayer,
+                    struct tile *claimer);
+#define tile_claimer(_tile) ((_tile)->claimer)
 
 #define tile_resource(_tile) ((_tile)->resource)
 #define tile_resource_is_valid(_tile) BV_ISSET((_tile)->special, 
S_RESOURCE_VALID)
diff -Nurd -X.diff_ignore freeciv/common/vision.c freeciv/common/vision.c
--- freeciv/common/vision.c     2008-10-27 04:13:31.000000000 +0200
+++ freeciv/common/vision.c     2009-01-06 15:00:32.000000000 +0200
@@ -135,7 +135,6 @@
 
   psite = create_vision_site(-base_number(pbase) - 1, ptile, owner);
   psite->size = 0;
-  psite->border_radius_sq = game.info.borders_sq;
   sz_strlcpy(psite->name, base_name_translation(pbase));
 
   site_list_append(owner->sites, psite);
@@ -170,7 +169,6 @@
   dest->owner = src->owner;
   dest->identity = src->identity;
   dest->size = src->size;
-  dest->border_radius_sq = src->border_radius_sq;
   dest->occupied = src->occupied;
   dest->walls = src->walls;
   dest->happy = src->happy;
diff -Nurd -X.diff_ignore freeciv/common/vision.h freeciv/common/vision.h
--- freeciv/common/vision.h     2008-10-27 04:13:31.000000000 +0200
+++ freeciv/common/vision.h     2009-01-06 14:56:57.000000000 +0200
@@ -116,9 +116,6 @@
   int identity;                                /* city > IDENTITY_NUMBER_ZERO 
*/
   int size;                            /* city, or base pseudo-size */
 
-  /* The radius of the border source. */
-  int border_radius_sq;
-
   bool occupied;
   bool walls;
   bool happy;
diff -Nurd -X.diff_ignore freeciv/server/citytools.c freeciv/server/citytools.c
--- freeciv/server/citytools.c  2008-11-15 00:03:26.000000000 +0200
+++ freeciv/server/citytools.c  2009-01-06 15:37:31.000000000 +0200
@@ -896,10 +896,9 @@
 
   /* Has to follow the unfog call above. */
   city_list_unlink(pgiver->cities, pcity);
-  map_clear_border(pcenter, pgiver);
+  map_clear_border(pcenter);
   /* city_thaw_workers_queue() later */
 
-  pcity->owner = ptaker;
   map_claim_ownership(pcenter, ptaker, pcenter);
   city_list_prepend(ptaker->cities, pcity);
 
@@ -1026,12 +1025,13 @@
 {
   struct nation_type *nation = nation_of_player(pplayer);
   struct player *saved_owner = tile_owner(ptile);
+  struct tile *saved_claimer = tile_claimer(ptile);
   struct city *pwork = tile_worked(ptile);
   struct city *pcity = create_city_virtual(pplayer, ptile, name);
 
   freelog(LOG_DEBUG, "create_city() %s", name);
 
-  tile_set_owner(ptile, pplayer); /* temporarily */
+  tile_set_owner(ptile, pplayer, ptile); /* temporarily */
   city_choose_build_default(pcity);
   pcity->ai.trade_want = TRADE_WEIGHTING;
   pcity->id = identity_number();
@@ -1079,7 +1079,7 @@
   }
 
   /* Claim the ground we stand on */
-  tile_set_owner(ptile, saved_owner);
+  tile_set_owner(ptile, saved_owner, saved_claimer);
   map_claim_ownership(ptile, pplayer, ptile);
 
   /* Before arranging workers to show unknown land */
@@ -1242,10 +1242,9 @@
     }
   }
 
-  map_clear_border(pcenter, powner);
+  map_clear_border(pcenter);
   city_thaw_workers_queue();
   city_refresh_queue_processing();
-  map_claim_ownership(pcenter, NULL, NULL);
 
   /* idex_unregister_city() is called in game_remove_city() below */
 
@@ -2291,38 +2290,8 @@
 ****************************************************************************/
 void city_refresh_vision(struct city *pcity)
 {
-  struct tile *pcenter = city_tile(pcity);
-  struct player *powner = city_owner(pcity);
-  struct vision_site *psite = map_get_player_site(pcenter, powner);
   int radius_sq = get_city_bonus(pcity, EFT_CITY_VISION_RADIUS_SQ);
 
-  if (NULL != psite) {
-    int old_radius = psite->border_radius_sq;
-    int new_radius;
-
-    /* Exact behavior could be ruleset defined. */
-    if (game.info.borders_sq) {
-      new_radius = game.info.borders_sq;
-      if (psite->identity > 0) {
-        /* City */
-        new_radius = MAX(new_radius, 2*2+1*1);
-      }
-      new_radius += psite->size;
-    } else {
-      new_radius = 0;
-    }
-
-    if (old_radius > new_radius) {
-      map_clear_border(pcity->tile, pcity->owner);
-    }
-
-    psite->border_radius_sq = new_radius;
-
-    if (old_radius != new_radius) {
-      map_claim_border(pcity->tile, pcity->owner);
-    }
-  }
-
   vision_change_sight(pcity->server.vision, V_MAIN, radius_sq);
   vision_change_sight(pcity->server.vision, V_INVIS, 2);
 
diff -Nurd -X.diff_ignore freeciv/server/cityturn.c freeciv/server/cityturn.c
--- freeciv/server/cityturn.c   2008-11-04 16:19:12.000000000 +0200
+++ freeciv/server/cityturn.c   2009-01-06 15:40:20.000000000 +0200
@@ -498,9 +498,9 @@
     remove_city(pcity);
     return FALSE;
   }
+  map_clear_border(pcity->tile);
   pcity->size -= pop_loss;
-
-  city_refresh_vision(pcity);
+  map_claim_border(pcity->tile, pcity->owner);
 
   /* Cap the food stock at the new granary size. */
   if (pcity->food_stock > city_granary_size(pcity->size)) {
@@ -697,7 +697,7 @@
     return city_reduce_size(pcity, pcity->size - size, NULL);
   }
 
-  city_refresh_vision(pcity);
+  map_claim_border(pcity->tile, pcity->owner);
 
   return TRUE;
 }
@@ -714,7 +714,7 @@
   if (pcity->food_stock >= city_granary_size(pcity->size) 
      || city_rapture_grow(pcity)) {
     city_increase_size(pcity);
-    city_refresh_vision(pcity);
+    map_claim_border(pcity->tile, pcity->owner);
   } else if (pcity->food_stock < 0) {
     /* FIXME: should this depend on units with ability to build
      * cities or on units that require food in uppkeep?
diff -Nurd -X.diff_ignore freeciv/server/edithand.c freeciv/server/edithand.c
--- freeciv/server/edithand.c   2008-12-16 16:56:39.000000000 +0200
+++ freeciv/server/edithand.c   2009-01-06 14:21:16.000000000 +0200
@@ -1221,7 +1221,7 @@
     }
     /* FIXME: This does not play well with border code
      * once edit mode is exited. */
-    tile_set_owner(ptile, pplayer);
+    tile_set_owner(ptile, pplayer, ptile /*??*/ );
     send_tile_info(NULL, ptile, FALSE);
   } square_iterate_end;
   conn_list_do_unbuffer(game.est_connections);
diff -Nurd -X.diff_ignore freeciv/server/generator/mapgen.c 
freeciv/server/generator/mapgen.c
--- freeciv/server/generator/mapgen.c   2008-12-27 15:51:21.000000000 +0200
+++ freeciv/server/generator/mapgen.c   2009-01-06 14:18:50.000000000 +0200
@@ -1918,7 +1918,7 @@
     tile_set_continent(ptile, 0);
     map_set_placed(ptile); /* not a land tile */
     tile_clear_all_specials(ptile);
-    tile_set_owner(ptile, NULL);
+    tile_set_owner(ptile, NULL, NULL);
   } whole_map_iterate_end;
   
   if (HAS_POLES) {
diff -Nurd -X.diff_ignore freeciv/server/maphand.c freeciv/server/maphand.c
--- freeciv/server/maphand.c    2008-11-11 17:38:45.000000000 +0200
+++ freeciv/server/maphand.c    2009-01-06 15:13:39.000000000 +0200
@@ -24,6 +24,7 @@
 #include "support.h"
 
 #include "base.h"
+#include "borders.h"
 #include "events.h"
 #include "game.h"
 #include "map.h"
@@ -1529,66 +1530,13 @@
 
 /*************************************************************************
   Claim ownership of a single tile.
-
-  This is called for two reasons:
-  (1) Set a base or city.  The tile_owner() MUST be any previous owner.
-      Before city_refresh_vision() as that now depends on the vision_site.
-      The city SHOULD NOT be in the cities list yet.
-  (2) map_claim_border(), only after (1) has setup the vision_site.
 *************************************************************************/
 void map_claim_ownership(struct tile *ptile, struct player *powner,
                          struct tile *psource)
 {
-  struct city *pcity = tile_city(ptile);
   struct player *ploser = tile_owner(ptile);
 
-  if (NULL != ploser) {
-    struct player_tile *playtile = map_get_player_tile(ptile, ploser);
-
-    /* cleverly uses return that is NULL for non-site tile */
-    change_playertile_site(playtile, map_get_player_base(ptile, ploser));
-
-    if (NULL != playtile->site && ptile == psource) {
-      /* has new owner */
-      playtile->site->owner = powner;
-    }
-  }
-
-  if (NULL != powner && NULL != psource) {
-    struct player_tile *playsite = map_get_player_tile(psource, powner);
-    struct vision_site *psite = playsite->site;
-
-    if (NULL != psite) {
-      if (ptile != psource) {
-        struct player_tile *playtile = map_get_player_tile(ptile, powner);
-        assert(NULL == playtile->site);
-        change_playertile_site(playtile, psite);
-      } else if (NULL != pcity) {
-        update_vision_site_from_city(psite, pcity);
-      } else {
-        /* has new owner */
-        psite->owner = powner;
-      }
-    } else {
-      assert(ptile == psource);
-
-      if (NULL != pcity) {
-        psite = create_vision_site_from_city(pcity);
-      } else {
-        base_type_iterate(pbase) {
-          if (tile_has_base(ptile, pbase)
-              && base_has_flag(pbase, BF_CLAIM_TERRITORY)) {
-            psite = create_vision_site_from_base(ptile, pbase, powner);
-          }
-        } base_type_iterate_end;
-      }
-      change_playertile_site(playsite, psite);
-    }
-  } else {
-    assert(NULL == powner && NULL == psource);
-  }
-
-  tile_set_owner(ptile, powner);
+  tile_set_owner(ptile, powner, psource);
 
   if (ploser != powner) {
     if (S_S_RUNNING == server_state() && game.info.happyborders > 0) {
@@ -1604,184 +1552,97 @@
 /*************************************************************************
   Remove border for this source.
 *************************************************************************/
-void map_clear_border(struct tile *ptile, struct player *powner)
+void map_clear_border(struct tile *ptile)
 {
-  struct city *pcity = tile_city(ptile);
-  struct vision_site *psite = map_get_player_site(ptile, powner);
-
-  if (0 == game.info.borders_sq) {
-    /* no borders */
-    return;
-  }
-
-  if (NULL == psite) {
-    /* should never happen! call map_claim_ownership() first! */
-    freelog(LOG_ERROR, "(%2d,%2d) border has NULL source for %s",
-            TILE_XY(ptile),
-            nation_rule_name(nation_of_player(powner)));
-    return;
-  }
-
-  if (IDENTITY_NUMBER_ZERO == psite->identity) {
-    /* TODO: maybe someday, but currently should never be called! */
-    freelog(LOG_ERROR, "(%2d,%2d) border has zero identity for %s",
-            TILE_XY(ptile),
-            nation_rule_name(nation_of_player(powner)));
-    return;
-  }
-
-  if (NULL != pcity) {
-    freelog(LOG_VERBOSE, "(%2d,%2d) clear border %2d \"%s\"[%d]",
-            TILE_XY(ptile),
-            psite->border_radius_sq,
-            city_name(pcity), pcity->size);
-  } else {
-    freelog(LOG_VERBOSE, "(%2d,%2d) clear border %2d",
-            TILE_XY(ptile),
-            psite->border_radius_sq);
-  }
+  int radius_sq = tile_border_radius_sq(ptile);
 
-  circle_dxyr_iterate(ptile, psite->border_radius_sq, dtile, dx, dy, dr) {
+  circle_dxyr_iterate(ptile, radius_sq, dtile, dx, dy, dr) {
     struct city *dcity = tile_city(dtile);
-    struct player *downer = tile_owner(dtile);
+    struct tile *claimer = tile_claimer(dtile);
     bool source_tile = FALSE;
 
     if (NULL != dcity) {
-      /* cannot affect existing cities (including self) */
-      continue;
+      source_tile = TRUE;
     }
 
-    base_type_iterate(dbase) {
-      if (tile_has_base(dtile, dbase) && base_has_flag(dbase, 
BF_CLAIM_TERRITORY)) {
-        /* Cannot affect territory claiming bases */
-        source_tile = TRUE;
-        break;
-      }
-    } base_type_iterate_end;
-
-    if (source_tile) {
-      continue;
+    if (!source_tile) {
+      base_type_iterate(dbase) {
+        if (tile_has_base(dtile, dbase) && base_has_flag(dbase, 
BF_CLAIM_TERRITORY)) {
+          /* Cannot affect territory claiming bases */
+          source_tile = TRUE;
+          break;
+        }
+      } base_type_iterate_end;
     }
 
-    if (downer == powner) {
-      struct vision_site *dsite = map_get_player_site(dtile, downer);
-
-      if (dsite == psite) {
-        map_claim_ownership(dtile, NULL, NULL);
-      }
+    if (!source_tile && claimer == ptile) {
+      map_claim_ownership(dtile, NULL, NULL);
     }
   } circle_dxyr_iterate_end;
 }
 
 /*************************************************************************
-  Update borders for this source.  Call this for each new source.
-
-  This is dependent on the current vision, so must be done after
-  city_refresh_vision() and before (re-)arranging workers.
+  Update borders for this source. Call this for each new source.
 *************************************************************************/
-void map_claim_border(struct tile *ptile, struct player *powner)
+void map_claim_border(struct tile *ptile, struct player *owner)
 {
-  struct city *pcity = tile_city(ptile);
-  struct vision_site *psite = map_get_player_site(ptile, powner);
-
-  if (0 == game.info.borders_sq) {
-    /* no borders */
-    return;
-  }
-
-  if (NULL == psite) {
-    /* should never happen! call map_claim_ownership() first! */
-    freelog(LOG_ERROR, "(%2d,%2d) border has NULL source for %s",
-            TILE_XY(ptile),
-            nation_rule_name(nation_of_player(powner)));
-    return;
-  }
-
-  if (IDENTITY_NUMBER_ZERO == psite->identity) {
-    /* TODO: maybe someday, but currently should never be called! */
-    freelog(LOG_ERROR, "(%2d,%2d) border has zero identity for %s",
-            TILE_XY(ptile),
-            nation_rule_name(nation_of_player(powner)));
-    return;
-  }
-
-  if (NULL != pcity) {
-    freelog(LOG_VERBOSE, "(%2d,%2d) claim border %2d \"%s\"[%d]",
-            TILE_XY(ptile),
-            psite->border_radius_sq,
-            city_name(pcity), pcity->size);
-  } else {
-    freelog(LOG_VERBOSE, "(%2d,%2d) claim border %2d",
-            TILE_XY(ptile),
-            psite->border_radius_sq);
-  }
+  int radius_sq = tile_border_radius_sq(ptile);
 
-  circle_dxyr_iterate(ptile, psite->border_radius_sq, dtile, dx, dy, dr) {
+  circle_dxyr_iterate(ptile, radius_sq, dtile, dx, dy, dr) {
     struct city *dcity = tile_city(dtile);
-    struct player *downer = tile_owner(dtile);
+    struct tile *dclaimer = tile_claimer(dtile);
     bool source_tile = FALSE;
 
     if (NULL != dcity) {
       /* cannot affect existing cities (including self) */
-      continue;
+      source_tile = TRUE;
     }
 
-    base_type_iterate(dbase) {
-      if (tile_has_base(dtile, dbase) && base_has_flag(dbase, 
BF_CLAIM_TERRITORY)) {
-        /* Cannot affect territory claiming bases */
-        source_tile = TRUE;
-        break;
-      }
-    } base_type_iterate_end;
+    if (!source_tile) {
+      base_type_iterate(dbase) {
+        if (tile_has_base(dtile, dbase) && base_has_flag(dbase, 
BF_CLAIM_TERRITORY)) {
+          /* Cannot affect territory claiming bases */
+          source_tile = TRUE;
+          break;
+        }
+      } base_type_iterate_end;
+    }
 
     if (source_tile) {
       continue;
     }
 
-    if (!map_is_known(dtile, powner)) {
+    if (!map_is_known(dtile, owner)) {
       /* without city_reveal_tiles option */
       continue;
     }
 
-    if (NULL != downer && downer != powner) {
-      struct vision_site *dsite = map_get_player_site(dtile, downer);
-      int r = sq_map_distance(dsite->location, dtile);
+    if (NULL != dclaimer && dclaimer != ptile) {
+      int r = sq_map_distance(dclaimer, dtile);
 
-      /* border tile claimed by another */
-      if (IDENTITY_NUMBER_ZERO == dsite->identity) {
-        /* ruins don't keep their borders */
-        dsite->owner = powner;
-        tile_set_owner(dtile, powner);
-        continue;
-      } else if (r < dr) {
+      if (r < dr) {
         /* nearest shall prevail */
         continue;
       } else if (r == dr) {
-        if (dsite->identity < psite->identity) {
-          /* lower shall prevail: airport/fortress/city */
-          continue;
-        } else if (dsite->identity == psite->identity) {
-          /* neither shall prevail */
-          map_claim_ownership(dtile, NULL, NULL);
-          continue;
-        }
+        /* older shall prevail */
+        continue;
       }
     }
 
     if (is_ocean_tile(dtile)) {
       if (is_claimable_ocean(dtile, ptile)) {
-        map_claim_ownership(dtile, powner, ptile);
+        map_claim_ownership(dtile, owner, ptile);
       }
     } else {
       if (tile_continent(dtile) == tile_continent(ptile)) {
-        map_claim_ownership(dtile, powner, ptile);
+        map_claim_ownership(dtile, owner, ptile);
       }
     }
   } circle_dxyr_iterate_end;
 }
 
 /*************************************************************************
-  Update borders for all sources.  Call this on turn end.
+  Update borders for all sources. Call this on turn end.
 *************************************************************************/
 void map_calculate_borders(void)
 {
@@ -1789,16 +1650,13 @@
     return;
   }
 
-  freelog(LOG_VERBOSE,"map_calculate_borders() sites");
-  /* base sites are done first, as they may be thorn in city side. */
-  sites_iterate(psite) {
-    map_claim_border(psite->location, vision_owner(psite));
-  } sites_iterate_end;
+  freelog(LOG_VERBOSE,"map_calculate_borders()");
 
-  freelog(LOG_VERBOSE,"map_calculate_borders() cities");
-  cities_iterate(pcity) {
-    map_claim_border(pcity->tile, city_owner(pcity));
-  } cities_iterate_end;
+  whole_map_iterate(ptile) {
+    if (is_border_source(ptile)) {
+      map_claim_border(ptile, ptile->owner);
+    }
+  } whole_map_iterate_end;
 
   freelog(LOG_VERBOSE,"map_calculate_borders() workers");
   city_thaw_workers_queue();
diff -Nurd -X.diff_ignore freeciv/server/maphand.h freeciv/server/maphand.h
--- freeciv/server/maphand.h    2008-10-27 04:13:36.000000000 +0200
+++ freeciv/server/maphand.h    2009-01-06 14:54:29.000000000 +0200
@@ -101,7 +101,7 @@
 void map_claim_border(struct tile *ptile, struct player *powner);
 void map_claim_ownership(struct tile *ptile, struct player *powner,
                          struct tile *psource);
-void map_clear_border(struct tile *ptile, struct player *powner);
+void map_clear_border(struct tile *ptile);
 
 void check_terrain_change(struct tile *ptile, struct terrain *oldter);
 bool need_to_fix_terrain_change(const struct terrain *oldter,
diff -Nurd -X.diff_ignore freeciv/server/sanitycheck.c 
freeciv/server/sanitycheck.c
--- freeciv/server/sanitycheck.c        2008-10-27 04:13:36.000000000 +0200
+++ freeciv/server/sanitycheck.c        2009-01-06 15:20:42.000000000 +0200
@@ -185,9 +185,6 @@
       SANITY_TILE(ptile, same_pos(pcity->tile, ptile));
       SANITY_TILE(ptile, tile_owner(ptile) != NULL);
     }
-    if (tile_owner(ptile) != NULL) {
-      SANITY_TILE(ptile, map_get_player_site(ptile, tile_owner(ptile)) != 
NULL);
-    }
 
     index_to_map_pos(&x, &y, tile_index(ptile));
     SANITY_TILE(ptile, x == ptile->x && y == ptile->y);
diff -Nurd -X.diff_ignore freeciv/server/savegame.c freeciv/server/savegame.c
--- freeciv/server/savegame.c   2009-01-05 18:32:09.000000000 +0200
+++ freeciv/server/savegame.c   2009-01-06 15:12:28.000000000 +0200
@@ -2391,7 +2391,7 @@
       pcity->original = past;
     }
     past = tile_owner(pcenter);
-    tile_set_owner(pcenter, plr); /* for city_owner(), just in case? */
+    tile_set_owner(pcenter, plr, pcenter); /* for city_owner(), just in case? 
*/
     /* no city_choose_build_default(), values loaded below! */
 
     pcity->size = secfile_lookup_int(file, "player%d.c%d.size", plrno, i);
@@ -2830,7 +2830,6 @@
                                   plrno, i);
 
     /* After everything is loaded, but before vision. */
-    tile_set_owner(pcenter, past);
     map_claim_ownership(pcenter, plr, pcenter);
 
     /* adding the city contribution to fog-of-war */
diff -Nurd -X.diff_ignore freeciv/server/unittools.c freeciv/server/unittools.c
--- freeciv/server/unittools.c  2009-01-05 18:32:09.000000000 +0200
+++ freeciv/server/unittools.c  2009-01-06 15:14:23.000000000 +0200
@@ -730,7 +730,7 @@
        if (what != S_LAST) {
           if (what == S_PILLAGE_BASE) {
             if (base_has_flag(first_base, BF_CLAIM_TERRITORY)) {
-              map_clear_border(ptile, ptile->owner);
+              map_clear_border(ptile);
               map_claim_ownership(ptile, NULL, NULL);
             }
             tile_remove_base(ptile, first_base);
@@ -800,7 +800,7 @@
         if (tile_has_base(ptile, old_base)
             && !can_bases_coexist(old_base, new_base)) {
           if (base_has_flag(old_base, BF_CLAIM_TERRITORY)) {
-            map_clear_border(ptile, ptile->owner);
+            map_clear_border(ptile);
             map_claim_ownership(ptile, NULL, NULL);
           }
           tile_remove_base(ptile, old_base);
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to