Source:NetHack 3.1.0/mcastu.c

Below is the full text to mcastu.c from the source code of NetHack 3.1.0. To link to a particular line, write [[NetHack 3.1.0/mcastu.c#line123 ]], for example.

Warning! This is the source code from an old release. For the latest release, see Source code

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