Merge from vendor branch GDB:
[games.git] / games / hack / hack.track.c
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) utcnt++;
25         if(utpnt == UTSZ) utpnt = 0;
26         utrack[utpnt].x = u.ux;
27         utrack[utpnt].y = u.uy;
28         utpnt++;
29 }
30
31 coord *
32 gettrack(int x, int y)
33 {
34 int i,cnt,dst;
35 coord tc;
36         cnt = utcnt;
37         for(i = utpnt-1; cnt--; i--){
38                 if(i == -1) i = UTSZ-1;
39                 tc = utrack[i];
40                 dst = (x-tc.x)*(x-tc.x) + (y-tc.y)*(y-tc.y);
41                 if(dst < 3)
42                         return(dst ? &(utrack[i]) : 0);
43         }
44         return(0);
45 }