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 (moved Source:Track.c to Source:NetHack 3.4.3/src/track.c: Moving src to subdirs)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
__MIXEDSYNTAXHIGHLIGHT__
 +
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 21:
 
  <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 33:
 
  <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 50:
 
  <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>

Latest revision as of 19:24, 31 January 2011

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

/*	SCCS Id: @(#)track.c	3.4	87/08/08	*/
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed.  See license for details. */
/* 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.

#include "hack.h"

#define UTSZ	50

STATIC_VAR NEARDATA int utcnt, utpnt;
STATIC_VAR NEARDATA coord utrack[UTSZ];

#ifdef OVLB

initrack

void
initrack()
{
	utcnt = utpnt = 0;
}

#endif /* OVLB */
#ifdef OVL1

settrack

/* add to track */
void
settrack()
{
	if(utcnt < UTSZ) utcnt++;
	if(utpnt == UTSZ) utpnt = 0;
	utrack[utpnt].x = u.ux;
	utrack[utpnt].y = u.uy;
	utpnt++;
}

#endif /* OVL1 */
#ifdef OVL0

gettrack

coord *
gettrack(x, y)
register int x, y;
{
register int cnt, ndist;
register coord *tc;
cnt = utcnt;
for(tc = &utrack[utpnt]; cnt--; ){
	if(tc == utrack) tc = &utrack[UTSZ-1];
	else tc--;
	ndist = distmin(x,y,tc->x,tc->y);

	/* if far away, skip track entries til we're closer */
	if(ndist > 2) {
	    ndist -= 2; /* be careful due to extra decrement at top of loop */
	    cnt -= ndist;
	    if(cnt <= 0)
		return (coord *) 0; /* too far away, no matches possible */
	    if(tc < &utrack[ndist])
		tc += (UTSZ-ndist);
	    else
		tc -= ndist;
	} else if(ndist <= 1)
	    return(ndist ? tc : 0);
}
return (coord *)0;
}

#endif /* OVL0 */

/*track.c*/