Merge from vendor branch OPENSSH:
[dragonfly.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.2 2003/06/17 04:25:24 dillon 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 initrack(){
15         utcnt = utpnt = 0;
16 }
17
18 /* add to track */
19 settrack(){
20         if(utcnt < UTSZ) utcnt++;
21         if(utpnt == UTSZ) utpnt = 0;
22         utrack[utpnt].x = u.ux;
23         utrack[utpnt].y = u.uy;
24         utpnt++;
25 }
26
27 coord *
28 gettrack(x,y) int x,y; {
29 int i,cnt,dist;
30 coord tc;
31         cnt = utcnt;
32         for(i = utpnt-1; cnt--; i--){
33                 if(i == -1) i = UTSZ-1;
34                 tc = utrack[i];
35                 dist = (x-tc.x)*(x-tc.x) + (y-tc.y)*(y-tc.y);
36                 if(dist < 3)
37                         return(dist ? &(utrack[i]) : 0);
38         }
39         return(0);
40 }