xref: /dragonfly/games/hack/hack.track.c (revision 0db87cb7)
1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.track.c - version 1.0.2 */
3 /* $FreeBSD: src/games/hack/hack.track.c,v 1.4 1999/11/16 10:26:38 marcel Exp $ */
4 /* $DragonFly: src/games/hack/hack.track.c,v 1.3 2006/08/21 19:45:32 pavalos Exp $ */
5 
6 #include "hack.h"
7 
8 #define	UTSZ	50
9 
10 coord utrack[UTSZ];
11 int utcnt = 0;
12 int utpnt = 0;
13 
14 void
15 initrack(void)
16 {
17 	utcnt = utpnt = 0;
18 }
19 
20 /* add to track */
21 void
22 settrack(void)
23 {
24 	if (utcnt < UTSZ)
25 		utcnt++;
26 	if (utpnt == UTSZ)
27 		utpnt = 0;
28 	utrack[utpnt].x = u.ux;
29 	utrack[utpnt].y = u.uy;
30 	utpnt++;
31 }
32 
33 coord *
34 gettrack(int x, int y)
35 {
36 	int i, cnt, dst;
37 	coord tc;
38 
39 	cnt = utcnt;
40 	for (i = utpnt - 1; cnt--; i--) {
41 		if (i == -1)
42 			i = UTSZ - 1;
43 		tc = utrack[i];
44 		dst = (x - tc.x) * (x - tc.x) + (y - tc.y) * (y - tc.y);
45 		if (dst < 3)
46 			return (dst ? &(utrack[i]) : 0);
47 	}
48 	return (0);
49 }
50