Source:NetHack 3.4.3/src/track.c

From NetHackWiki
(Redirected from Source:Ref/gettrack)
Jump to: navigation, search

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.

  1. #include "hack.h"
  2.  
  3. #define UTSZ	50
  4.  
  5. STATIC_VAR NEARDATA int utcnt, utpnt;
  6. STATIC_VAR NEARDATA coord utrack[UTSZ];
  7.  
  8. #ifdef OVLB

initrack

  1. void
  2. initrack()
  3. {
  4. 	utcnt = utpnt = 0;
  5. }
  6.  
  7. #endif /* OVLB */
  8. #ifdef OVL1

settrack

  1. /* add to track */
  2. void
  3. settrack()
  4. {
  5. 	if(utcnt < UTSZ) utcnt++;
  6. 	if(utpnt == UTSZ) utpnt = 0;
  7. 	utrack[utpnt].x = u.ux;
  8. 	utrack[utpnt].y = u.uy;
  9. 	utpnt++;
  10. }
  11.  
  12. #endif /* OVL1 */
  13. #ifdef OVL0

gettrack

  1. coord *
  2. gettrack(x, y)
  3. register int x, y;
  4. {
  5. register int cnt, ndist;
  6. register coord *tc;
  7. cnt = utcnt;
  8. for(tc = &utrack[utpnt]; cnt--; ){
  9. 	if(tc == utrack) tc = &utrack[UTSZ-1];
  10. 	else tc--;
  11. 	ndist = distmin(x,y,tc->x,tc->y);
  12.  
  13. 	/* if far away, skip track entries til we're closer */
  14. 	if(ndist > 2) {
  15. 	    ndist -= 2; /* be careful due to extra decrement at top of loop */
  16. 	    cnt -= ndist;
  17. 	    if(cnt <= 0)
  18. 		return (coord *) 0; /* too far away, no matches possible */
  19. 	    if(tc < &utrack[ndist])
  20. 		tc += (UTSZ-ndist);
  21. 	    else
  22. 		tc -= ndist;
  23. 	} else if(ndist <= 1)
  24. 	    return(ndist ? tc : 0);
  25. }
  26. return (coord *)0;
  27. }
  28.  
  29. #endif /* OVL0 */
  30.  
  31. /*track.c*/