Source:NetHack 2.2a/track.c
Jump to navigation
Jump to search
Below is the full text to track.c from the source code of NetHack 2.2a.
Warning! This is the source code from an old release. For newer releases, see Source code
Screenshots and source code from Hack are used under the CWI license.
1. /* SCCS Id: @(#)track.c 1.4 87/08/08 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /* track.c - version 1.0.2 */ 4. 5. #include "hack.h" 6. 7. #define UTSZ 50 8. 9. coord utrack[UTSZ]; 10. int utcnt = 0; 11. int utpnt = 0; 12. 13. initrack(){ 14. utcnt = utpnt = 0; 15. } 16. 17. /* add to track */ 18. settrack(){ 19. if(utcnt < UTSZ) utcnt++; 20. if(utpnt == UTSZ) utpnt = 0; 21. utrack[utpnt].x = u.ux; 22. utrack[utpnt].y = u.uy; 23. utpnt++; 24. } 25. 26. coord * 27. gettrack(x,y) register x,y; { 28. register int i,cnt,dist; 29. coord tc; 30. cnt = utcnt; 31. for(i = utpnt-1; cnt--; i--){ 32. if(i == -1) i = UTSZ-1; 33. tc = utrack[i]; 34. dist = (x-tc.x)*(x-tc.x) + (y-tc.y)*(y-tc.y); 35. if(dist < 3) 36. return(dist ? &(utrack[i]) : 0); 37. } 38. return(0); 39. }