Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2001:
[Freeciv-Dev] Re: directional system: more magic code cleanups
Home

[Freeciv-Dev] Re: directional system: more magic code cleanups

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: directional system: more magic code cleanups
From: Jason Dorje Short <jshort@xxxxxxxxxxxxx>
Date: Mon, 17 Sep 2001 18:39:03 -0400
Reply-to: jdorje@xxxxxxxxxxxxxxxxxxxxx

Raimar Falke wrote:
> 
> On Mon, Sep 17, 2001 at 01:01:51PM -0400, Jason Dorje Short wrote:

> > Another point of note is that the code to determine diff_x and diff_y is
> > topology-dependent, and so should be moved into a macro/function
> > somewhere in map.[ch].
> 
> What about a normalize_map_pos call or two?

Unfortunately, normalize_map_pos won't work in this case.  The problem
is very similar to the wrapping problems the GUI code has.

And yet, I cannot think of a single function specification that will
work for both of them and work in all topologies.  So, the best I can
come up with is this:

void map_pos_difference(int *x, *y, src_x, src_y, dest_x, dest_y)
{
  *x = dest_x - src_x;
  *y = dest_y - src_y;

  /* wrap as appropriate for the current topology */
  if (*x <= -map.xsize / 2) x += map.xsize;
  if (*x > map.xsize / 2) x += map.xsize;
}

jason


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