Difference between revisions of "Source:Hack 1.0/mklv.shk.c"
Jump to navigation
Jump to search
m (Automated source code upload) |
Kernigh bot (talk | contribs) m (Hack 1.0/mklv.shk.c moved to Source:Hack 1.0/mklv.shk.c: Robot: moved page) |
(No difference)
|
Latest revision as of 22:52, 3 March 2008
Below is the full text to mklv.shk.c from the source code of Hack 1.0. To link to a particular line, write [[Hack 1.0/mklv.shk.c#line123]], for example.
Warning! This is the source code from an old release. For the latest release, see Source code
Screenshots and source code from Hack are used under the CWI license.
1. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984. */ 2. 3. #ifndef QUEST 4. #include "mklev.h" 5. #include "def.eshk.h" 6. #define ESHK ((struct eshk *)(&(shk->mextra[0]))) 7. extern struct monst *makemon(); 8. 9. char shtypes[] = "=/)%?!["; /* 8 shoptypes: 7 specialised, 1 mixed */ 10. schar shprobs[] = { 3,3,5,5,10,10,14,50 }; /* their probabilities */ 11. 12. mkshop(){ 13. register struct mkroom *sroom; 14. register int sh,sx,sy,i; 15. register char let; 16. int roomno; 17. register struct monst *shk; 18. for(sroom = &rooms[0], roomno = 0; ; sroom++, roomno++){ 19. if(sroom->hx < 0) return; 20. if(sroom->lx <= xdnstair && xdnstair <= sroom->hx && 21. sroom->ly <= ydnstair && ydnstair <= sroom->hy) continue; 22. if(sroom->lx <= xupstair && xupstair <= sroom->hx && 23. sroom->ly <= yupstair && yupstair <= sroom->hy) continue; 24. if( 25. #ifdef WIZARD 26. wizard || 27. #endif WIZARD 28. sroom->doorct == 1) break; 29. } 30. #ifdef WIZARD 31. if(wizard){ 32. extern char *getenv(); 33. register char *ep = getenv("SHOPTYPE"); 34. if(ep){ 35. if(*ep == 'z' || *ep == 'Z'){ 36. mkzoo(); 37. return; 38. } 39. for(i=0; shtypes[i]; i++) 40. if(*ep == shtypes[i]) break; 41. let = i; 42. goto gotlet; 43. } 44. } 45. #endif WIZARD 46. for(i = rn2(100),let = 0; (i -= shprobs[let])>= 0; let++) 47. if(!shtypes[let]) break; /* superfluous */ 48. #ifdef WIZARD 49. gotlet: 50. #endif WIZARD 51. sroom->rtype = 8+let; 52. let = shtypes[let]; 53. sh = sroom->fdoor; 54. sx = doors[sh].x; 55. sy = doors[sh].y; 56. if(sx == sroom->lx-1) sx++; else 57. if(sx == sroom->hx+1) sx--; else 58. if(sy == sroom->ly-1) sy++; else 59. if(sy == sroom->hy+1) sy--; else { 60. printf("Where is shopdoor?"); 61. return; 62. } 63. if(!(shk = makemon(PM_SHK,sx,sy))) return; 64. shk->isshk = shk->mpeaceful = 1; 65. shk->msleep = 0; 66. shk->mtrapseen = ~0; /* we know all the traps already */ 67. ESHK->shoproom = roomno; 68. ESHK->shd = doors[sh]; 69. ESHK->shk.x = sx; 70. ESHK->shk.y = sy; 71. ESHK->robbed = 0; 72. ESHK->visitct = 0; 73. shk->mgold = 1000 + 30*rnd(100); /* initial capital */ 74. ESHK->billct = 0; 75. findname(ESHK->shknam, let); 76. for(sx = sroom->lx; sx <= sroom->hx; sx++) 77. for(sy = sroom->ly; sy <= sroom->hy; sy++){ 78. register struct monst *mtmp; 79. if((sx == sroom->lx && doors[sh].x == sx-1) || 80. (sx == sroom->hx && doors[sh].x == sx+1) || 81. (sy == sroom->ly && doors[sh].y == sy-1) || 82. (sy == sroom->hy && doors[sh].y == sy+1)) continue; 83. if(rn2(100) < dlevel && !m_at(sx,sy) && 84. (mtmp = makemon(PM_MIMIC, sx, sy))){ 85. mtmp->mimic = 86. (let && rn2(10) < dlevel) ? let : ']'; 87. continue; 88. } 89. mkobj_at(let, sx, sy); 90. } 91. #ifdef WIZARD 92. if(wizard) printf("I made a %c-shop.", let ? let : 'g'); 93. #endif WIZARD 94. } 95. 96. mkzoo(){ 97. register struct mkroom *sroom; 98. register int sh,sx,sy,i; 99. int goldlim = 500 * dlevel; 100. for(sroom = &rooms[0]; ; sroom++){ 101. if(sroom->hx < 0) return; 102. if(sroom->lx <= xdnstair && xdnstair <= sroom->hx && 103. sroom->ly <= ydnstair && ydnstair <= sroom->hy) continue; 104. if(sroom->lx <= xupstair && xupstair <= sroom->hx && 105. sroom->ly <= yupstair && yupstair <= sroom->hy) continue; 106. if(sroom->doorct == 1) break; 107. } 108. sroom->rtype = 7; 109. sh = sroom->fdoor; 110. for(sx = sroom->lx; sx <= sroom->hx; sx++) 111. for(sy = sroom->ly; sy <= sroom->hy; sy++){ 112. if((sx == sroom->lx && doors[sh].x == sx-1) || 113. (sx == sroom->hx && doors[sh].x == sx+1) || 114. (sy == sroom->ly && doors[sh].y == sy-1) || 115. (sy == sroom->hy && doors[sh].y == sy+1)) continue; 116. (void) makemon((struct permonst *) 0,sx,sy); 117. i = sq(dist2(sx,sy,doors[sh].x,doors[sh].y)); 118. if(i >= goldlim) i = 5*dlevel; 119. goldlim -= i; 120. mkgold(10 + rn2(i), sx, sy); 121. } 122. #ifdef WIZARD 123. if(wizard) printf("I made a zoo."); 124. #endif WIZARD 125. } 126. 127. dist2(x0,y0,x1,y1){ 128. return((x0-x1)*(x0-x1) + (y0-y1)*(y0-y1)); 129. } 130. 131. sq(a) int a; { 132. return(a*a); 133. } 134. #endif QUEST