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

From NetHackWiki
Jump to navigation Jump to search
 
Line 18: Line 18:
 
  <span id="line11">11. STATIC_VAR NEARDATA coord utrack[UTSZ];</span>
 
  <span id="line11">11. STATIC_VAR NEARDATA coord utrack[UTSZ];</span>
 
  <span id="line12">12. </span>
 
  <span id="line12">12. </span>
 +
 +
== initrack ==
 +
   
 
  <span id="line13">13. void</span>
 
  <span id="line13">13. void</span>
 
  <span id="line14">14. initrack()</span>
 
  <span id="line14">14. initrack()</span>
Line 24: Line 27:
 
  <span id="line17">17. }</span>
 
  <span id="line17">17. }</span>
 
  <span id="line18">18. </span>
 
  <span id="line18">18. </span>
 +
 +
== settrack ==
 +
   
 
  <span id="line19">19. /* add to track */</span>
 
  <span id="line19">19. /* add to track */</span>
 
  <span id="line20">20. void</span>
 
  <span id="line20">20. void</span>
Line 37: Line 43:
 
  <span id="line30">30. }</span>
 
  <span id="line30">30. }</span>
 
  <span id="line31">31. </span>
 
  <span id="line31">31. </span>
 +
 +
== gettrack ==
 +
   
 
  <span id="line32">32. coord *</span>
 
  <span id="line32">32. coord *</span>
 
  <span id="line33">33. gettrack(x, y)</span>
 
  <span id="line33">33. gettrack(x, y)</span>

Latest revision as of 22:16, 3 January 2016

Below is the full text to track.c from the source code of NetHack 3.6.0. To link to a particular line, write [[Source:NetHack 3.6.0/src/track.c#line123]], for example.

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.

Top of file

 /* NetHack 3.6	track.c	$NHDT-Date: 1432512769 2015/05/25 00:12:49 $  $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 /* track.c - version 1.0.2 */
 
 #include "hack.h"
 
 #define UTSZ 50
 
 STATIC_VAR NEARDATA int utcnt, utpnt;
 STATIC_VAR NEARDATA coord utrack[UTSZ];
 

initrack

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

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++;
 }
 

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;
 }
 
 /*track.c*/