1997-10-19 20:56:41 +04:00
|
|
|
/* $NetBSD: hack.track.c,v 1.4 1997/10/19 16:59:11 christos Exp $ */
|
|
|
|
|
1993-08-02 21:18:41 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
|
|
|
|
*/
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-08-02 21:18:41 +04:00
|
|
|
#ifndef lint
|
1997-10-19 20:56:41 +04:00
|
|
|
__RCSID("$NetBSD: hack.track.c,v 1.4 1997/10/19 16:59:11 christos Exp $");
|
|
|
|
#endif /* not lint */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
#include "hack.h"
|
1997-10-19 20:56:41 +04:00
|
|
|
#include "extern.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
#define UTSZ 50
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
coord utrack[UTSZ];
|
|
|
|
int utcnt = 0;
|
|
|
|
int utpnt = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
|
|
|
initrack()
|
|
|
|
{
|
1993-03-21 12:45:37 +03:00
|
|
|
utcnt = utpnt = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add to track */
|
1997-10-19 20:56:41 +04:00
|
|
|
void
|
|
|
|
settrack()
|
|
|
|
{
|
|
|
|
if (utcnt < UTSZ)
|
|
|
|
utcnt++;
|
|
|
|
if (utpnt == UTSZ)
|
|
|
|
utpnt = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
utrack[utpnt].x = u.ux;
|
|
|
|
utrack[utpnt].y = u.uy;
|
|
|
|
utpnt++;
|
|
|
|
}
|
|
|
|
|
1997-10-19 20:56:41 +04:00
|
|
|
coord *
|
|
|
|
gettrack(x, y)
|
|
|
|
int x, y;
|
|
|
|
{
|
|
|
|
int i, cnt, dist;
|
|
|
|
coord tc;
|
1993-03-21 12:45:37 +03:00
|
|
|
cnt = utcnt;
|
1997-10-19 20:56:41 +04:00
|
|
|
for (i = utpnt - 1; cnt--; i--) {
|
|
|
|
if (i == -1)
|
|
|
|
i = UTSZ - 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
tc = utrack[i];
|
1997-10-19 20:56:41 +04:00
|
|
|
dist = (x - tc.x) * (x - tc.x) + (y - tc.y) * (y - tc.y);
|
|
|
|
if (dist < 3)
|
|
|
|
return (dist ? &(utrack[i]) : 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-19 20:56:41 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|