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: Gregory Berkolaiko <gberkolaiko@xxxxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: directional system: more magic code cleanups
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 17 Sep 2001 16:11:51 +0200
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Mon, Sep 17, 2001 at 02:26:43PM +0100, Gregory Berkolaiko wrote:
>  --- Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx> wrote: 
> [..]
> > I think the code should be changed as follow:
> > 
> > int dir_ok(int src_x, int src_y, int dest_x, int dest_y, int dir, int
> > only_straightest /* this will make only 3 dirs ok */)
> [..]
> > 
> > And remove straightest_direction.
> 
> Well, straightest_direction is used in a different context, if only once.
>  You can come up with a way to substitute it with randomly chosen
> direction (provided it's dir_ok(...., only_straightest=1) ), but it's
> kind of bother really.

*rereading server/gotohand.c* straightest_direction is similar to
get_direction_for_step and also to dir_ok.

Proposed dir_ok function:

int dir_ok(int src_x, int src_y, int dest_x, int dest_y, int dir, 
  int only_straightest /* this will make only 1 direction ok */)
{
  int diff_x, diff_y,scalar_product;

  if (dest_x > src_x) {
    diff_x = dest_x-src_x < map.xsize/2 ? 1 : -1;
  } 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 scalar_product==2;
  else
        return scalar_product>=0;
}
        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
  The trick is to keep breathing.


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