1/* SCCS Id: @(#)track.c 3.4 87/08/08 */ 2/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3/* NetHack may be freely redistributed. See license for details. */ 4/* track.c - version 1.0.2 */ 5 6#include "hack.h" 7 8#define UTSZ 50 9 10STATIC_VAR NEARDATA int utcnt, utpnt; 11STATIC_VAR NEARDATA coord utrack[UTSZ]; 12 13#ifdef OVLB 14 15void 16initrack() 17{ 18 utcnt = utpnt = 0; 19} 20 21#endif /* OVLB */ 22#ifdef OVL1 23 24/* add to track */ 25void 26settrack() 27{ 28 if(utcnt < UTSZ) utcnt++; 29 if(utpnt == UTSZ) utpnt = 0; 30 utrack[utpnt].x = u.ux; 31 utrack[utpnt].y = u.uy; 32 utpnt++; 33} 34 35#endif /* OVL1 */ 36#ifdef OVL0 37 38coord * 39gettrack(x, y) 40register int x, y; 41{ 42 register int cnt, ndist; 43 register coord *tc; 44 cnt = utcnt; 45 for(tc = &utrack[utpnt]; cnt--; ){ 46 if(tc == utrack) tc = &utrack[UTSZ-1]; 47 else tc--; 48 ndist = distmin(x,y,tc->x,tc->y); 49 50 /* if far away, skip track entries til we're closer */ 51 if(ndist > 2) { 52 ndist -= 2; /* be careful due to extra decrement at top of loop */ 53 cnt -= ndist; 54 if(cnt <= 0) 55 return (coord *) 0; /* too far away, no matches possible */ 56 if(tc < &utrack[ndist]) 57 tc += (UTSZ-ndist); 58 else 59 tc -= ndist; 60 } else if(ndist <= 1) 61 return(ndist ? tc : 0); 62 } 63 return (coord *)0; 64} 65 66#endif /* OVL0 */ 67 68/*track.c*/ 69