Source:NetHack 3.2.0/mcastu.c

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