Home | History | Annotate | Line # | Download | only in hack
hack.track.c revision 1.4
      1 /*	$NetBSD: hack.track.c,v 1.4 1997/10/19 16:59:11 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
      5  */
      6 
      7 #include <sys/cdefs.h>
      8 #ifndef lint
      9 __RCSID("$NetBSD: hack.track.c,v 1.4 1997/10/19 16:59:11 christos Exp $");
     10 #endif				/* not lint */
     11 
     12 #include "hack.h"
     13 #include "extern.h"
     14 
     15 #define	UTSZ	50
     16 
     17 coord           utrack[UTSZ];
     18 int             utcnt = 0;
     19 int             utpnt = 0;
     20 
     21 void
     22 initrack()
     23 {
     24 	utcnt = utpnt = 0;
     25 }
     26 
     27 /* add to track */
     28 void
     29 settrack()
     30 {
     31 	if (utcnt < UTSZ)
     32 		utcnt++;
     33 	if (utpnt == UTSZ)
     34 		utpnt = 0;
     35 	utrack[utpnt].x = u.ux;
     36 	utrack[utpnt].y = u.uy;
     37 	utpnt++;
     38 }
     39 
     40 coord          *
     41 gettrack(x, y)
     42 	int x, y;
     43 {
     44 	int             i, cnt, dist;
     45 	coord           tc;
     46 	cnt = utcnt;
     47 	for (i = utpnt - 1; cnt--; i--) {
     48 		if (i == -1)
     49 			i = UTSZ - 1;
     50 		tc = utrack[i];
     51 		dist = (x - tc.x) * (x - tc.x) + (y - tc.y) * (y - tc.y);
     52 		if (dist < 3)
     53 			return (dist ? &(utrack[i]) : 0);
     54 	}
     55 	return (0);
     56 }
     57