abstract
| - Below is the full text to track.c from the source code of NetHack 3.1.0. To link to a particular line, write [[NetHack 3.1.0/track.c#line123]], for example. Warning! This is the source code from an old release. For the latest release, see Source code 1. /* SCCS Id: @(#)track.c 3.1 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 */ 5. 6. #include "hack.h" 7. 8. #define UTSZ 50 9. 10. STATIC_VAR int NEARDATA utcnt, NEARDATA utpnt; 11. STATIC_VAR coord NEARDATA utrack[UTSZ]; 12. 13. #ifdef OVLB 14. void 15. initrack(){ 16. utcnt = utpnt = 0; 17. } 18. #endif /* OVLB */ 19. 20. #ifdef OVL1 21. 22. /* add to track */ 23. void 24. settrack(){ 25. if(utcnt < UTSZ) utcnt++; 26. if(utpnt == UTSZ) utpnt = 0; 27. utrack[utpnt].x = u.ux; 28. utrack[utpnt].y = u.uy; 29. utpnt++; 30. } 31. 32. #endif /* OVL1 */ 33. #ifdef OVL0 34. 35. coord * 36. gettrack(x, y) 37. register int x, y; 38. { 39. register int cnt, ndist; 40. register coord *tc; 41. cnt = utcnt; 42. for(tc = &utrack[utpnt]; cnt--; ){ 43. if(tc == utrack) tc = &utrack[UTSZ-1]; 44. else tc--; 45. ndist = distmin(x,y,tc->x,tc->y); 46. 47. /* if far away, skip track entries til we're closer */ 48. if(ndist > 2) { 49. ndist -= 2; /* be careful due to extra decrement at top of loop */ 50. cnt -= ndist; 51. if(cnt <= 0) 52. return (coord *) 0; /* too far away, no matches possible */ 53. if(tc < &utrack[ndist]) 54. tc += (UTSZ-ndist); 55. else 56. tc -= ndist; 57. } else if(ndist <= 1) 58. return(ndist ? tc : 0); 59. } 60. return (coord *)0; 61. } 62. 63. #endif /* OVL0 */ 64. 65. /*track.c*/
|