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

[freeciv-ai] Re: (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: jdorje@xxxxxxxxxxxxxxxxxxxxx
Subject: [freeciv-ai] Re: (PR#3619) coordinate fix in find_city_to_diplomat
From: "Raimar Falke" <rf13@xxxxxxxxxxxxxxxxx>
Date: Wed, 5 Mar 2003 00:53:26 -0800
Reply-to: rt@xxxxxxxxxxxxxx

On Wed, Mar 05, 2003 at 12:09:06AM -0800, Jason Short wrote:
> 
> 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)

It is easier and safer to set it to a value which is an invalid
distance like -1 and treat this value as unset.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "We've all heard that a million monkeys banging on a million typewriters
  will eventually reproduce the entire works of Shakespeare.
  Now, thanks to the Internet, we know this is not true."




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