Wikia

Wikihack

Source:Track.c

2,032pages on
this wiki
Talk0

Below is the full text to src/track.c from NetHack 3.4.3. To link to a particular line, write [[track.c#line123]], for example.

Top of file Edit

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 */
The NetHack General Public License applies to screenshots, source code and other content from NetHack.
5.    
6.    #include "hack.h"
7.    
8.    #define UTSZ	50
9.    
10.   STATIC_VAR NEARDATA int utcnt, utpnt;
11.   STATIC_VAR NEARDATA coord utrack[UTSZ];
12.   
13.   #ifdef OVLB
14.   

initrack Edit

15.   void
16.   initrack()
17.   {
18.   	utcnt = utpnt = 0;
19.   }
20.   
21.   #endif /* OVLB */
22.   #ifdef OVL1
23.   

settrack Edit

24.   /* add to track */
25.   void
26.   settrack()
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.   

gettrack Edit

38.   coord *
39.   gettrack(x, y)
40.   register 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*/

Around Wikia's network

Random Wiki