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]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: directional system: more magic code cleanups
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 17 Sep 2001 22:50:52 +0200
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Mon, Sep 17, 2001 at 01:01:51PM -0400, Jason Dorje Short wrote:
> Jason Dorje Short wrote:
> >   } else if (dest_x < src_x) {
> >     diff_x = src_x-dest_x < map.xsize/2 ? -1 : 1;
> >   } else { /* dest_x == src_x */
> >     diff_x = 0;
> >   }
> >   if (dest_y != src_y)
> >     diff_y = dest_y > src_y ? 1 : -1;
> >   else
> >     diff_y = 0;
> > 
> >   scalar_product=diff_x*DIR_DX[dir] + diff_y*DIR_DY[dir];
> >   if(only_straightest)
{
   return diff_x==DIR_DX[dir] && diff_y==DIR_DY[dir];
}
> >   else
> >         return scalar_product>=0;
> > }
> 
> This won't work, since scalar_product can sometimes be just 1 for the
> straightest direction.
> 

> 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?

> How about something like this?  It computes straightest_direction by
> finding the actual cartesian product of the travel vector with the
> normalized directional unit vector.  The largest product means the
> straightest direction.  dir_ok could then be written in terms of
> straightest_direction.  This code should give results similar to Ross's
> proposed straightest_direction.

Yes. However it looks currently to me that this isn't needed since the
code at goto_zoc_ok does not depend on the result of
straightest_direction.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "Sit, disk, sit. Good boy. Now spin up. Very good. Here's a netscape
  cookie for you. Fetch me some data. Come on, you can do it. No, not that
  data. Bad disk. Bad." 
    -- Calle Dybedahl, alt.sysadmin.recovery


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