Source:NetHack 3.0.0/mcastu.c
Jump to navigation
Jump to search
Below is the full text to mcastu.c from the source code of NetHack 3.0.0. To link to a particular line, write [[NetHack 3.0.0/mcastu.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: @(#)mcastu.c 3.0 88/04/13 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. const char *spelltyp[] = { 8. "shower of missiles", 9. "fireball", 10. "sleep ray", 11. "cone of cold", 12. "finger of death", 13. "bolt of lightning", 14. "", 15. "", 16. "", 17. "" 18. }; 19. 20. static 21. void 22. cursetxt(mtmp) 23. register struct monst *mtmp; 24. { 25. if(canseemon(mtmp)) 26. pline("%s points at you, then curses.", Monnam(mtmp)); 27. else if((!(moves%4) || !rn2(4)) && flags.soundok) 28. You("hear a mumbled curse."); 29. } 30. 31. int 32. castmu(mtmp, mattk) /* monster casts spell at you */ 33. register struct monst *mtmp; 34. register struct attack *mattk; 35. { 36. int dmg = 0, ml = mtmp->m_lev; 37. 38. if(mtmp->mcan || mtmp->mspec_used) { /* could not attack */ 39. cursetxt(mtmp); 40. return(0); 41. } else { 42. nomul(0); 43. if(rn2(ml*10) < (mtmp->mconf ? 100 : 20)) { /* fumbled attack */ 44. if(canseemon(mtmp)) 45. pline("The air crackles around %s.", mon_nam(mtmp)); 46. return(0); 47. } 48. } 49. /* 50. * As these are spells, the damage is related to the level 51. * of the monster casting the spell. 52. */ 53. if (mattk->damd) 54. dmg = d((int)((ml/3) + mattk->damn), (int)mattk->damd); 55. else dmg = d((int)((ml/3) + 1), 6); 56. 57. switch(mattk->adtyp) { 58. 59. case AD_FIRE: 60. pline("You're enveloped in flames."); 61. if(Fire_resistance) { 62. shieldeff(u.ux, u.uy); 63. pline("But you resist the effects."); 64. dmg = 0; 65. } 66. break; 67. case AD_COLD: 68. pline("You're covered in frost."); 69. if(Cold_resistance) { 70. shieldeff(u.ux, u.uy); 71. pline("But you resist the effects."); 72. dmg = 0; 73. } 74. break; 75. #ifdef HARD 76. case AD_MAGM: 77. You("are hit by a shower of missiles!"); 78. if(Antimagic) { 79. shieldeff(u.ux, u.uy); 80. pline("The missiles bounce off!"); 81. dmg = 0; 82. } else dmg = d((int)mtmp->m_lev/2 + 1,6); 83. break; 84. #endif 85. case AD_SPEL: /* random spell */ 86. 87. mtmp->mspec_used = 10 - mtmp->m_lev; 88. if (mtmp->mspec_used < 2) mtmp->mspec_used = 2; 89. switch(rn2((int)mtmp->m_lev)) { 90. case 22: 91. case 21: 92. case 20: 93. pline("Oh no, %s's using the touch of death!", 94. is_female(mtmp) ? "she" : 95. is_human(mtmp->data) ? "he" : "it" 96. ); 97. #ifdef POLYSELF 98. if (is_undead(uasmon)) 99. You("seem no deader than before."); 100. else 101. #endif 102. if(!Antimagic && rn2(ml) > 12) { 103. 104. if(Hallucination) 105. You("have an out of body experience."); 106. else { 107. killer = "touch of death"; 108. done("died"); 109. } 110. } else { 111. if(Antimagic) shieldeff(u.ux, u.uy); 112. pline("Lucky for you, it didn't work!"); 113. } 114. dmg = 0; 115. break; 116. case 19: 117. case 18: 118. if(mtmp->iswiz && flags.no_of_wizards == 1) { 119. pline("Double Trouble..."); 120. clonewiz(); 121. dmg = 0; 122. break; 123. } /* else fall into the next case */ 124. case 17: 125. case 16: 126. case 15: 127. if(mtmp->iswiz && flags.soundok) 128. pline("\"Destroy the thief, my pets!\""); 129. #ifdef HARD 130. nasty(); /* summon something nasty */ 131. #endif 132. /* fall into the next case */ 133. case 14: /* aggravate all monsters */ 134. case 13: 135. aggravate(); 136. dmg = 0; 137. break; 138. case 12: /* curse random items */ 139. case 11: 140. case 10: 141. rndcurse(); 142. dmg = 0; 143. break; 144. case 9: 145. case 8: /* destroy armor */ 146. if(Antimagic) { 147. shieldeff(u.ux, u.uy); 148. pline("A field of force surrounds you!"); 149. } else if(!destroy_arm(some_armor())) 150. Your("skin itches."); 151. dmg = 0; 152. break; 153. case 7: 154. case 6: /* drain strength */ 155. if(Antimagic) { 156. shieldeff(u.ux, u.uy); 157. You("feel momentarily weakened."); 158. } else { 159. You("suddenly feel weaker!"); 160. losestr(rnd(ml - 6)); 161. if(u.uhp < 1) 162. done_in_by(mtmp); 163. } 164. dmg = 0; 165. break; 166. case 5: /* make invisible if not */ 167. case 4: 168. if(!mtmp->minvis) { 169. if(canseemon(mtmp) && !See_invisible) 170. pline("%s suddenly disappears!", 171. Monnam(mtmp)); 172. mtmp->minvis = 1; 173. unpmon(mtmp); 174. dmg = 0; 175. break; 176. } /* else fall into the next case */ 177. case 3: /* stun */ 178. if(Antimagic) { 179. shieldeff(u.ux, u.uy); 180. if(!Stunned) 181. You("feel momentarily disoriented."); 182. make_stunned(1L, FALSE); 183. } else { 184. if (Stunned) You("struggle to keep your balance."); 185. else You("reel..."); 186. make_stunned(HStun + d(ACURR(A_DEX) < 12 ? 6 : 4, 4), FALSE); 187. } 188. dmg = 0; 189. break; 190. case 2: /* haste self */ 191. if(mtmp->mspeed == MSLOW) mtmp->mspeed = 0; 192. else mtmp->mspeed = MFAST; 193. dmg = 0; 194. break; 195. case 1: /* cure self */ 196. if(mtmp->mhp < mtmp->mhpmax) { 197. if((mtmp->mhp += rnd(8)) > mtmp->mhpmax) 198. mtmp->mhp = mtmp->mhpmax; 199. dmg = 0; 200. break; 201. } /* else fall through to default case */ 202. default: /* psi bolt */ 203. if(Antimagic) { 204. shieldeff(u.ux, u.uy); 205. You("get a slight %sache.",body_part(HEAD)); 206. dmg = 1; 207. } else { 208. if (dmg <= 10) 209. Your("brain is on fire!"); 210. else Your("%s suddenly aches!", body_part(HEAD)); 211. } 212. break; 213. } 214. break; 215. 216. case AD_CLRC: /* clerical spell */ 217. 218. mtmp->mspec_used = 10 - mtmp->m_lev; 219. if (mtmp->mspec_used < 2) mtmp->mspec_used = 2; 220. switch(rn2((int)mtmp->m_lev)) { 221. /* Other ideas: lightning bolts, towers of flame, 222. gush of water -3. */ 223. 224. default: /* confuse */ 225. if(Antimagic) { 226. shieldeff(u.ux, u.uy); 227. You("feel momentarily dizzy."); 228. } else { 229. make_confused(HConfusion + (long)mtmp->m_lev, TRUE); 230. } 231. dmg = 0; 232. break; 233. case 12: /* curse random items */ 234. case 11: 235. case 10: 236. rndcurse(); 237. dmg = 0; 238. break; 239. case 9: 240. case 8: /* insects */ 241. /* Try for insects, and if there are none 242. left, go for (sticks to) snakes. -3. */ 243. { 244. int i; 245. struct permonst *pm = mkclass(S_ANT); 246. struct monst *mtmp2; 247. char let = (pm ? S_ANT : S_SNAKE); 248. 249. for (i = 0; i <= mtmp->m_lev; i++) 250. if ((pm = mkclass(let)) && 251. (mtmp2 = makemon(pm, u.ux, u.uy))) 252. mtmp2->msleep = mtmp2->mpeaceful = 253. mtmp2->mtame = 0; 254. } 255. dmg = 0; 256. break; 257. case 6: 258. case 7: /* blindness */ 259. if (!Blinded) { 260. pline("Scales cover your eyes!"); 261. make_blinded(200L, FALSE); 262. dmg = 0; 263. break; 264. } 265. case 4: 266. case 5: /* wound */ 267. if(Antimagic) { 268. shieldeff(u.ux, u.uy); 269. Your("skin itches badly for a moment."); 270. dmg = 0; 271. } else { 272. pline("Wounds appear on your body!"); 273. dmg = d(2,8) + 1; 274. } 275. break; 276. case 3: /* hold */ 277. if(Antimagic) { 278. shieldeff(u.ux, u.uy); 279. if(multi >= 0) 280. You("stiffen briefly."); 281. nomul(-1); 282. } else { 283. if (multi >= 0) 284. You("are frozen in place!"); 285. nomul(-4 - (int)mtmp->m_lev); 286. } 287. dmg = 0; 288. break; 289. case 2: 290. case 1: /* cure self */ 291. if(mtmp->mhp < mtmp->mhpmax) { 292. if((mtmp->mhp += rnd(8)) > mtmp->mhpmax) 293. mtmp->mhp = mtmp->mhpmax; 294. dmg = 0; 295. break; 296. } /* else fall through to default case */ 297. } 298. } 299. if(dmg) mdamageu(mtmp, dmg); 300. return(1); 301. } 302. 303. int 304. buzzmu(mtmp, mattk) /* monster uses spell (ranged) */ 305. register struct monst *mtmp; 306. register struct attack *mattk; 307. { 308. if(mtmp->mcan || mattk->adtyp > AD_SPC2) { 309. cursetxt(mtmp); 310. return(0); 311. } 312. if(lined_up(mtmp) && rn2(3)) { 313. nomul(0); 314. if(mattk->adtyp && (mattk->adtyp < 11)) { /* no cf unsigned >0 */ 315. if(canseemon(mtmp)) 316. pline("%s zaps you with a %s!", Monnam(mtmp), 317. spelltyp[mattk->adtyp-1]); 318. buzz((int) (-10 - (mattk->adtyp-1)), (int)mattk->damn, 319. mtmp->mx, mtmp->my, sgn(tbx), sgn(tby)); 320. } else impossible("Monster spell %d cast", mattk->adtyp-1); 321. } 322. return(1); 323. } 324.