Difference between revisions of "Source:NetHack 3.4.3/src/track.c"

From NetHackWiki
Jump to navigation Jump to search
(Automated source code upload)
 
m (add headers)
Line 1: Line 1:
 +
Below is the full text to src/track.c from NetHack 3.4.3. To link to a particular line, write [[track.c#line123|<nowiki>[[track.c#line123]]</nowiki>]], for example.
 +
 +
== Top of file ==
  
Below is the full text to src/track.c from NetHack 3.4.3. To link to a particular line, write [[track.c#line123|<nowiki>[[track.c#line123]]</nowiki>]], for example.
 
 
  <span id="line1">1.    /* SCCS Id: @(#)track.c 3.4 87/08/08 */</span>
 
  <span id="line1">1.    /* SCCS Id: @(#)track.c 3.4 87/08/08 */</span>
 
  <span id="line2">2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */</span>
 
  <span id="line2">2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */</span>
Line 18: Line 20:
 
  <span id="line13">13.  #ifdef OVLB</span>
 
  <span id="line13">13.  #ifdef OVLB</span>
 
  <span id="line14">14.  </span>
 
  <span id="line14">14.  </span>
 +
 +
== initrack ==
 +
 
  <span id="line15">15.  void</span>
 
  <span id="line15">15.  void</span>
 
  <span id="line16">16.  initrack()</span>
 
  <span id="line16">16.  initrack()</span>
Line 27: Line 32:
 
  <span id="line22">22.  #ifdef OVL1</span>
 
  <span id="line22">22.  #ifdef OVL1</span>
 
  <span id="line23">23.  </span>
 
  <span id="line23">23.  </span>
 +
 +
== settrack ==
 +
 
  <span id="line24">24.  /* add to track */</span>
 
  <span id="line24">24.  /* add to track */</span>
 
  <span id="line25">25.  void</span>
 
  <span id="line25">25.  void</span>
Line 41: Line 49:
 
  <span id="line36">36.  #ifdef OVL0</span>
 
  <span id="line36">36.  #ifdef OVL0</span>
 
  <span id="line37">37.  </span>
 
  <span id="line37">37.  </span>
 +
 +
== gettrack ==
 +
 
  <span id="line38">38.  coord *</span>
 
  <span id="line38">38.  coord *</span>
 
  <span id="line39">39.  gettrack(x, y)</span>
 
  <span id="line39">39.  gettrack(x, y)</span>

Revision as of 12:26, 29 August 2006

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

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.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

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

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

settrack

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

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*/