Source:NetHack 3.0.0/demon.c
Revision as of 04:26, 4 March 2008 by Kernigh bot (talk | contribs) (NetHack 3.0.0/demon.c moved to Source:NetHack 3.0.0/demon.c: Robot: moved page)
Below is the full text to demon.c from the source code of NetHack 3.0.0. To link to a particular line, write [[NetHack 3.0.0/demon.c#line123]], for example.
Warning! This is the source code from an old release. For the latest release, see Source code
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. /* SCCS Id: @(#)demon.c 3.0 88/11/14 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /* NetHack may be freely redistributed. See license for details. */ 4. 5. #include "hack.h" 6. 7. void 8. dsummon(ptr) /* summon demon */ 9. register struct permonst *ptr; 10. { 11. register int dtype, cnt = 0; 12. 13. if(is_dprince(ptr) || (ptr == &mons[PM_WIZARD_OF_YENDOR])) { 14. 15. dtype = (!rn2(20)) ? dprince() : (!rn2(4)) ? dlord() : ndemon(); 16. cnt = (!rn2(4) && !is_dprince(&mons[dtype])) ? 2 : 1; 17. 18. } else if(is_dlord(ptr)) { 19. 20. dtype = (!rn2(50)) ? dprince() : (!rn2(20)) ? dlord() : ndemon(); 21. cnt = (!rn2(4) && is_ndemon(&mons[dtype])) ? 2 : 1; 22. 23. } else if(is_ndemon(ptr)) { 24. 25. dtype = (!rn2(20)) ? dlord() : ndemon(); 26. cnt = 1; 27. } 28. 29. if(!dtype) return; 30. 31. while(cnt > 0) { 32. 33. (void)makemon(&mons[dtype], u.ux, u.uy); 34. cnt--; 35. } 36. return; 37. } 38. 39. #ifdef HARD 40. #define Athome (Inhell && !mtmp->cham) 41. 42. int 43. demon_talk(mtmp) /* returns 1 if he won't attack. */ 44. register struct monst *mtmp; 45. { 46. char *x_monnam(), *Xmonnam(); 47. long demand, offer; 48. 49. #ifdef NAMED_ITEMS 50. if(uwep && is_artifact(uwep) && !strcmp(ONAME(uwep), "Excalibur")) { 51. 52. pline("%s looks very angry.", Xmonnam(mtmp)); 53. return mtmp->mpeaceful = mtmp->mtame = 0; 54. } 55. #endif /* NAMED_ITEMS */ 56. 57. if(is_ndemon(mtmp->data)) { /* not for regular '&'s */ 58. 59. pline("%s mutters something about awful working conditions.", 60. Xmonnam(mtmp)); 61. return(0); 62. } 63. 64. /* Slight advantage given. */ 65. if(is_dprince(mtmp->data) && mtmp->minvis) { 66. mtmp->minvis = 0; 67. if (!Blind) pline("%s appears before you.", Xmonnam(mtmp)); 68. pmon(mtmp); 69. } 70. if(u.usym == S_DEMON) { /* Won't blackmail their own. */ 71. 72. pline("%s says, \"Good hunting %s.\" and vanishes.", 73. Xmonnam(mtmp), flags.female ? "Sister" : "Brother"); 74. rloc(mtmp); 75. return(1); 76. } 77. demand = (u.ugold * (rnd(80) + 20 * Athome)) / 100; 78. if(!demand) /* you have no gold */ 79. return mtmp->mpeaceful = 0; 80. else { 81. 82. pline("%s demands %ld Zorkmids for safe passage.", 83. Xmonnam(mtmp), demand); 84. 85. if((offer = bribe(mtmp)) >= demand) { 86. pline("%s vanishes laughing about cowardly mortals.", 87. Xmonnam(mtmp)); 88. } else { 89. if((long)rnd(40) > (demand - offer)) { 90. pline("%s scowls at you menacingly, then vanishes.", 91. Xmonnam(mtmp)); 92. } else { 93. pline("%s gets angry...", Xmonnam(mtmp)); 94. return mtmp->mpeaceful = 0; 95. } 96. } 97. } 98. mongone(mtmp); 99. return(1); 100. } 101. #endif 102. 103. #if defined(HARD) || (defined(ALTARS) && defined(SOUNDS)) 104. long 105. bribe(mtmp) 106. 107. struct monst *mtmp; 108. { 109. char buf[80]; 110. long offer; 111. 112. pline("How much will you offer? "); 113. getlin(buf); 114. (void) sscanf(buf, "%ld", &offer); 115. 116. /*Michael Paddon -- fix for negative offer to monster*/ /*JAR880815 - */ 117. if(offer < 0L) { 118. You("try to shortchange %s, but fumble.", 119. x_monnam(mtmp, 0)); 120. offer = 0L; 121. } else if(offer >= u.ugold) { 122. You("give %s all your gold.", x_monnam(mtmp, 0)); 123. offer = u.ugold; 124. } else You("give %s %ld Zorkmids.", x_monnam(mtmp, 0), offer); 125. 126. u.ugold -= offer; 127. return(offer); 128. } 129. #endif 130. 131. int 132. dprince() { 133. #ifdef HARD 134. int tryct; 135. struct permonst *ptr; 136. 137. for(tryct = 0; tryct < 20; tryct++) 138. if(is_dprince((ptr = mkclass(S_DEMON)))) 139. return(monsndx(ptr)); 140. 141. #endif 142. return(dlord()); 143. } 144. 145. int 146. dlord() { 147. #ifdef HARD 148. int tryct; 149. struct permonst *ptr; 150. 151. for(tryct = 0; tryct < 20; tryct++) 152. if(is_dlord((ptr = mkclass(S_DEMON)))) 153. return(monsndx(ptr)); 154. 155. #endif 156. return(ndemon()); 157. } 158. 159. int 160. ndemon() { 161. #ifndef HARD 162. return(PM_DEMON); 163. #else 164. int tryct; 165. struct permonst *ptr; 166. 167. for(tryct = 0; tryct < 20; tryct++) 168. if(is_ndemon((ptr = mkclass(S_DEMON)))) 169. return(monsndx(ptr)); 170. 171. return(0); 172. #endif 173. }