Complete.Org: Mailing Lists: Archives: freeciv-ai: March 2003:
[freeciv-ai] (PR#3619) coordinate fix in find_city_to_diplomat
Home

[freeciv-ai] (PR#3619) coordinate fix in find_city_to_diplomat

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [freeciv-ai] (PR#3619) coordinate fix in find_city_to_diplomat
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 5 Mar 2003 00:09:06 -0800
Reply-to: rt@xxxxxxxxxxxxxx

In find_city_to_diplomat, there is an initializer:

  int best_dist = MAX(map.xsize, map.ysize);

this is no good under gen-topologies, because it is possible for a
distance to be larger than this (map.xsize and map.ysize are the
_native_ dimensions of the map, while the distance is in _map_ coordinates).

It's easy to fix it to simply be a larger value.  But how large?  The
most obviously correct thing to me is just to use MAXINT.  But I'm not
sure if this is portable (Raimar?).  Aside from that, its correctness
should be obvious.

An alternative is to have a MAP_MAX_X or MAP_MAX_DISTANCE macro defined
in map.h.  But this is unnecessary clutter if it can be avoided:

  /* Upper bounds for iso and non-iso maps. */
  /* (this is from memory; it may be off-by-one) */
  #define MAP_MAX_X (MAP_MAX_WIDTH + MAP_MAX_HEIGHT / 2)
  #define MAP_MAX_Y (MAP_MAX_WIDTH + (MAP_MAX_HEIGHT - 1) / 2)
  #define MAP_MAX_REAL_DISTANCE (MAP_MAX_WIDTH + MAP_MAX_HEIGHT / 2)

jason

Index: ai/aidiplomat.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aidiplomat.c,v
retrieving revision 1.14
diff -u -r1.14 aidiplomat.c
--- ai/aidiplomat.c     2003/02/27 22:14:37     1.14
+++ ai/aidiplomat.c     2003/03/05 07:32:32
@@ -19,6 +19,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
+#include <values.h>
 
 #include "city.h"
 #include "combat.h"
@@ -312,7 +313,7 @@
   bool has_embassy;
   int incite_cost = 0; /* incite cost */
   int move_cost = 0; /* move cost */
-  int best_dist = MAX(map.xsize, map.ysize);
+  int best_dist = MAXINT;
   int continent = map_get_continent(x, y);
   bool dipldef; /* whether target is protected by diplomats */
   bool handicap = ai_handicap(pplayer, H_TARGETS);

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