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