abstract
| - Below is the full text to pcunix.c from the source code of NetHack 1.3d. To link to a particular line, write [[NetHack 1.3d/pcunix.c#line123]], for example. Warning! This is the source code from an old release. For the latest release, see Source code 1. /* SCCS Id: @(#)pcunix.c 1.3 87/07/14 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /* unix.c - version 1.0.3 */ 4. 5. /* This file collects some Unix dependencies; pager.c contains some more */ 6. 7. /* 8. * The time is used for: 9. * - seed for rand() 10. * - year on tombstone and yymmdd in record file 11. * - phase of the moon (various monsters react to NEW_MOON or FULL_MOON) 12. * - night and midnight (the undead are dangerous at midnight) 13. * - determination of what files are "very old" 14. */ 15. 16. #include "hack.h" /* mainly for index() which depends on BSD */ 17. 18. #include /* for time_t */ 19. #include 20. 21. extern time_t time(); 22. 23. setrandom() 24. { 25. (void) srand((int) time ((time_t *) 0)); 26. } 27. 28. struct tm * 29. getlt() 30. { 31. time_t date; 32. struct tm *localtime(); 33. 34. (void) time(&date); 35. return(localtime(&date)); 36. } 37. 38. getyear() 39. { 40. return(1900 + getlt()->tm_year); 41. } 42. 43. char * 44. getdate() 45. { 46. static char datestr[7]; 47. register struct tm *lt = getlt(); 48. 49. (void) sprintf(datestr, "%2d%2d%2d", 50. lt->tm_year, lt->tm_mon + 1, lt->tm_mday); 51. if(datestr[2] == ' ') datestr[2] = '0'; 52. if(datestr[4] == ' ') datestr[4] = '0'; 53. return(datestr); 54. } 55. 56. phase_of_the_moon() /* 0-7, with 0: new, 4: full */ 57. { /* moon period: 29.5306 days */ 58. /* year: 365.2422 days */ 59. register struct tm *lt = getlt(); 60. register int epact, diy, golden; 61. 62. diy = lt->tm_yday; 63. golden = (lt->tm_year % 19) + 1; 64. epact = (11 * golden + 18) % 30; 65. if ((epact == 25 && golden > 11) || epact == 24) 66. epact++; 67. 68. return( (((((diy + epact) * 6) + 11) % 177) / 22) & 7 ); 69. } 70. 71. night() 72. { 73. register int hour = getlt()->tm_hour; 74. 75. return(hour < 6 || hour > 21); 76. } 77. 78. midnight() 79. { 80. return(getlt()->tm_hour == 0); 81. } 82. 83. regularize(s) /* normalize file name - we don't like ..'s or /'s */ 84. register char *s; 85. { 86. register char *lp; 87. 88. while((lp = index(s, '.')) || (lp = index(s, '/'))) 89. *lp = '_'; 90. }
|