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, freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: directional system: more magic code cleanups
From: Gregory Berkolaiko <gberkolaiko@xxxxxxxxxxx>
Date: Mon, 17 Sep 2001 11:13:03 +0100 (BST)

 --- Jason Dorje Short <jshort@xxxxxxxxxxxxx> wrote: 
[..]
> It does *not* fully fix dir_ok and straightest_direction as it should;
> I
> think Ross should provide a patch that fixes these guys properly. 
> However it is good as far as it goes.

there is a nice mathematical way to code dir_ok:
if diff_x, diff_y and dir are what they are in the current function then
the "scalar product"

        diff_x*DIR_DX[dir] + diff_y*DIR_DY[dir]

is positive whenever direction is ok.  And you don't need any switches.

However Ross' patch might be more advanced than this.

> RCS file: /home/freeciv/CVS/freeciv/server/gotohand.c,v
> retrieving revision 1.115
> diff -u -r1.115 gotohand.c
> --- server/gotohand.c 2001/09/15 15:31:26     1.115
> +++ server/gotohand.c 2001/09/17 06:52:07
> @@ -451,28 +451,28 @@
>      diff_y = 0;
>  
>    switch(dir) {
> -  case 0:
> +  case DIR8_NORTHWEST:
>      if (diff_x >= 0 && diff_y >= 0) return 0;
>      else return 1;
> -  case 1:
> +  case DIR8_NORTH:
>      if (diff_y == 1) return 0;
>      else return 1;
> -  case 2:
> +  case DIR8_NORTHEAST:
>      if (diff_x <= 0 && diff_y >= 0) return 0;
>      else return 1;
> -  case 3:
> +  case DIR8_WEST:
>      if (diff_x == 1) return 0;
>      else return 1;
> -  case 4:
> +  case DIR8_EAST:
>      if (diff_x == -1) return 0;
>      else return 1;
> -  case 5:
> +  case DIR8_SOUTHWEST:
>      if (diff_x >= 0 && diff_y <= 0) return 0;
>      else return 1;
> -  case 6:
> +  case DIR8_SOUTH:
>      if (diff_y == -1) return 0;
>      else return 1;
> -  case 7:
> +  case DIR8_SOUTHEAST:
>      if (diff_x <= 0 && diff_y <= 0) return 0;
>      else return 1;
>    default:


____________________________________________________________
Do You Yahoo!?
Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
or your free @yahoo.ie address at http://mail.yahoo.ie


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