[Freeciv-Dev] Re: directional system: more magic code cleanups
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
--- 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
- [Freeciv-Dev] directional system: more magic code cleanups, Jason Dorje Short, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Raimar Falke, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups,
Gregory Berkolaiko <=
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Raimar Falke, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Gregory Berkolaiko, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Raimar Falke, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Gregory Berkolaiko, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Raimar Falke, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Jason Dorje Short, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Raimar Falke, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Jason Dorje Short, 2001/09/17
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Raimar Falke, 2001/09/18
- [Freeciv-Dev] Re: directional system: more magic code cleanups, Jason Dorje Short, 2001/09/18
|
|