Source:NetHack 3.4.0/artifact.c

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

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

1.   /*	SCCS Id: @(#)artifact.c 3.4	2002/02/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.    #include "artifact.h"  7.    #ifdef OVLB 8.   #include "artilist.h"  9.    #else 10.  STATIC_DCL struct artifact artilist[]; 11.  #endif 12.  /*  13.    * Note:  both artilist[] and artiexist[] have a dummy element #0, 14.   *	  so loops over them should normally start at #1. The primary 15.   *	  exception is the save & restore code, which doesn't care about 16.   *	  the contents, just the total size. 17.   */  18.    19.   extern boolean notonhead;	/* for long worms */ 20.   21.   #define get_artifact(o) \ 22.  		(((o)&&(o)->oartifact) ? &artilist[(int) (o)->oartifact] : 0) 23.  STATIC_DCL int FDECL(spec_applies, (const struct artifact *,struct monst *)); 24.  STATIC_DCL int FDECL(arti_invoke, (struct obj*)); 25.   26.   /* The amount added to the victim's total hit points to insure that the 27.     victim will be killed even after damage bonus/penalty adjustments. 28.     Most such penalties are small, and 200 is plenty; the exception is  29. half physical damage. 3.3.1 and previous versions tried to use a very 30.     large number to account for this case; now, we just compute the fatal 31.     damage by adding it to 2 times the total hit points instead of 1 time. 32.     Note: this will still break if they have more than about half the number 33.     of hit points that will fit in a 15 bit integer. */ 34.   #define FATAL_DAMAGE_MODIFIER 200 35.   36.   #ifndef OVLB 37.  STATIC_DCL int spec_dbon_applies; 38.  STATIC_DCL xchar artidisco[NROFARTIFACTS]; 39.  #else	/* OVLB */ 40.  /* coordinate effects from spec_dbon with messages in artifact_hit */ 41.  STATIC_OVL int spec_dbon_applies = 0; 42.   43.   /* flags including which artifacts have already been created */ 44.  static boolean artiexist[1+NROFARTIFACTS+1]; 45.  /* and a discovery list for them (no dummy first entry here) */ 46.  STATIC_OVL xchar artidisco[NROFARTIFACTS]; 47.   48.   STATIC_DCL void NDECL(hack_artifacts); 49.  STATIC_DCL boolean FDECL(attacks, (int,struct obj *)); 50.   51.   /* handle some special cases; must be called after u_init */ 52.  STATIC_OVL void 53.  hack_artifacts 54.  {  55.   	struct artifact *art; 56.  	int alignmnt = aligns[flags.initalign].value; 57.   58.   	/* Fix up the alignments of "gift" artifacts */ 59.  	for (art = artilist+1; art->otyp; art++) 60.  	    if (art->role == Role_switch && art->alignment != A_NONE) 61.  		art->alignment = alignmnt; 62.   63.   	/* Excalibur can be used by any lawful character, not just knights */ 64.  	if (!Role_if(PM_KNIGHT)) 65.  	    artilist[ART_EXCALIBUR].role = NON_PM; 66.   67.   	/* Fix up the quest artifact */ 68.  	if (urole.questarti) { 69.  	    artilist[urole.questarti].alignment = alignmnt; 70.  	    artilist[urole.questarti].role = Role_switch; 71.  	}  72.   	return; 73.  }  74.    75.   /* zero out the artifact existence list */ 76.  void 77.  init_artifacts 78.  {  79.   	(void) memset((genericptr_t) artiexist, 0, sizeof artiexist); 80.  	(void) memset((genericptr_t) artidisco, 0, sizeof artidisco); 81.  	hack_artifacts; 82.  }  83.    84.   void 85.  save_artifacts(fd) 86.  int fd; 87.  {  88.   	bwrite(fd, (genericptr_t) artiexist, sizeof artiexist); 89.  	bwrite(fd, (genericptr_t) artidisco, sizeof artidisco); 90.  }  91.    92.   void 93.  restore_artifacts(fd) 94.  int fd; 95.  {  96.   	mread(fd, (genericptr_t) artiexist, sizeof artiexist); 97.  	mread(fd, (genericptr_t) artidisco, sizeof artidisco); 98.  	hack_artifacts;	/* redo non-saved special cases */ 99.  }  100.   101.  const char * 102. artiname(artinum) 103. int artinum; 104. {  105.  	if (artinum <= 0 || artinum > NROFARTIFACTS) return(""); 106. 	return(artilist[artinum].name); 107. }  108.   109.  /*  110.     Make an artifact. If a specific alignment is specified, then an object of 111. the appropriate alignment is created from scratch, or 0 is returned if 112. none is available. (If at least one aligned artifact has already been 113.     given, then unaligned ones also become eligible for this.) 114.    If no alignment is given, then 'otmp' is converted 115.    into an artifact of matching type, or returned as-is if that's not possible. 116.    For the 2nd case, caller should use ``obj = mk_artifact(obj, A_NONE);'' 117.    for the 1st, ``obj = mk_artifact((struct obj *)0, some_alignment);''. 118.  */  119.  struct obj * 120. mk_artifact(otmp, alignment) 121. struct obj *otmp;	/* existing object; ignored if alignment specified */ 122. aligntyp alignment;	/* target alignment, or A_NONE */ 123. {  124.  	const struct artifact *a; 125. 	int n, m;  126. boolean by_align = (alignment != A_NONE); 127. 	short o_typ = (by_align || !otmp) ? 0 : otmp->otyp; 128. 	boolean unique = !by_align && otmp && objects[o_typ].oc_unique; 129. 	short eligible[NROFARTIFACTS]; 130.  131.  	/* gather eligible artifacts */ 132. 	for (n = 0, a = artilist+1, m = 1; a->otyp; a++, m++) 133. 	    if ((!by_align ? a->otyp == o_typ : 134. 		    (a->alignment == alignment ||  135.  			(a->alignment == A_NONE && u.ugifts > 0))) &&  136.  		(!(a->spfx & SPFX_NOGEN) || unique) && !artiexist[m]) { 137. 		if (by_align && a->race != NON_PM && race_hostile(&mons[a->race])) 138. 		    continue;	/* skip enemies' equipment */ 139. 		else if (by_align && Role_if(a->role)) 140. 		    goto make_artif;	/* 'a' points to the desired one */ 141. 		else 142. 		    eligible[n++] = m;  143. } 144.   145.  	if (n) {		/* found at least one candidate */ 146. 	    m = eligible[rn2(n)];	/* [0..n-1] */ 147. 	    a = &artilist[m]; 148.  149.  	    /* make an appropriate object if necessary, then christen it */ 150. make_artif: if (by_align) otmp = mksobj((int)a->otyp, TRUE, FALSE); 151. 	    otmp = oname(otmp, a->name); 152. 	    otmp->oartifact = m;  153. artiexist[m] = TRUE; 154. 	} else { 155. 	    /* nothing appropriate could be found; return the original object */ 156. 	    if (by_align) otmp = 0;	/* (there was no original object) */ 157. 	}  158.  	return otmp; 159. }  160.   161.  /*  162.   * Returns the full name (with articles and correct capitalization) of an  163. * artifact named "name" if one exists, or NULL, it not. 164.  * The given name must be rather close to the real name for it to match. 165.  * The object type of the artifact is returned in otyp if the return value 166.  * is non-NULL. 167.  */  168.  const char* 169. artifact_name(name, otyp) 170. const char *name; 171. short *otyp; 172. {  173.      register const struct artifact *a; 174.     register const char *aname; 175.  176.      if(!strncmpi(name, "the ", 4)) name += 4; 177.  178.      for (a = artilist+1; a->otyp; a++) { 179. 	aname = a->name; 180. 	if(!strncmpi(aname, "the ", 4)) aname += 4; 181. 	if(!strcmpi(name, aname)) { 182. 	    *otyp = a->otyp; 183. 	    return a->name; 184. 	}  185.      }  186.   187.      return (char *)0; 188. }  189.   190.  boolean 191. exist_artifact(otyp, name) 192. register int otyp; 193. register const char *name; 194. {  195.  	register const struct artifact *a; 196. 	register boolean *arex; 197.  198.  	if (otyp && *name) 199. 	    for (a = artilist+1,arex = artiexist+1; a->otyp; a++,arex++) 200. 		if ((int) a->otyp == otyp && !strcmp(a->name, name)) 201. 		    return *arex; 202. 	return FALSE; 203. }  204.   205.  void 206. artifact_exists(otmp, name, mod) 207. register struct obj *otmp; 208. register const char *name; 209. register boolean mod; 210. {  211.  	register const struct artifact *a; 212.  213.  	if (otmp && *name) 214. 	    for (a = artilist+1; a->otyp; a++) 215. 		if (a->otyp == otmp->otyp && !strcmp(a->name, name)) { 216. 		    register int m = a - artilist; 217. 		    otmp->oartifact = (char)(mod ? m : 0); 218. 		    otmp->age = 0; 219. 		    if(otmp->otyp == RIN_INCREASE_DAMAGE) 220. 			otmp->spe = 0; 221. 		    artiexist[m] = mod; 222. 		    break; 223. 		}  224.  	return; 225. }  226.   227.  int 228. nartifact_exist 229. {  230.      int a = 0; 231.     int n = SIZE(artiexist); 232.  233.      while(n > 1) 234. 	if(artiexist[--n]) a++; 235.  236.      return a;  237. } 238.  #endif /* OVLB */ 239. #ifdef OVL0 240.  241.  boolean 242. spec_ability(otmp, abil) 243. struct obj *otmp; 244. unsigned long abil; 245. {  246.  	const struct artifact *arti = get_artifact(otmp); 247.  248.  	return((boolean)(arti && (arti->spfx & abil))); 249. }  250.   251.  #endif /* OVL0 */ 252. #ifdef OVLB 253.  254.  boolean 255. restrict_name(otmp, name)  /* returns 1 if name is restricted for otmp->otyp */ 256. register struct obj *otmp; 257. register const char *name; 258. {  259.  	register const struct artifact *a; 260. 	register const char *aname; 261.  262.  	if (!*name) return FALSE; 263. 	if (!strncmpi(name, "the ", 4)) name += 4; 264.  265.  		/* Since almost every artifact is SPFX_RESTR, it doesn't cost 266. 		   us much to do the string comparison before the spfx check. 267. 		   Bug fix:  don't name multiple elven daggers "Sting". 268. 		 */  269.  	for (a = artilist+1; a->otyp; a++) { 270. 	    if (a->otyp != otmp->otyp) continue; 271. 	    aname = a->name; 272. 	    if (!strncmpi(aname, "the ", 4)) aname += 4; 273. 	    if (!strcmp(aname, name)) 274. 		return ((boolean)((a->spfx & (SPFX_NOGEN|SPFX_RESTR)) != 0 || 275. 			otmp->quan > 1L)); 276. 	}  277.   278.  	return FALSE; 279. }  280.   281.  STATIC_OVL boolean 282. attacks(adtyp, otmp) 283. register int adtyp; 284. register struct obj *otmp; 285. {  286.  	register const struct artifact *weap; 287.  288.  	if ((weap = get_artifact(otmp)) != 0) 289. 		return((boolean)(weap->attk.adtyp == adtyp)); 290. 	return FALSE; 291. }  292.   293.  boolean 294. defends(adtyp, otmp) 295. register int adtyp; 296. register struct obj *otmp; 297. {  298.  	register const struct artifact *weap; 299.  300.  	if ((weap = get_artifact(otmp)) != 0) 301. 		return((boolean)(weap->defn.adtyp == adtyp)); 302. 	return FALSE; 303. }  304.   305.  /* used for monsters */ 306. boolean 307. protects(adtyp, otmp) 308. int adtyp; 309. struct obj *otmp; 310. {  311.  	register const struct artifact *weap; 312.  313.  	if ((weap = get_artifact(otmp)) != 0) 314. 		return (boolean)(weap->cary.adtyp == adtyp); 315. 	return FALSE; 316. }  317.   318.  /*  319.   * a potential artifact has just been worn/wielded/picked-up or  320. * unworn/unwielded/dropped. Pickup/drop only set/reset the W_ART mask. 321.  */  322.  void 323. set_artifact_intrinsic(otmp,on,wp_mask) 324. register struct obj *otmp; 325. boolean on; 326. long wp_mask; 327. {  328.  	long *mask = 0; 329. 	register const struct artifact *oart = get_artifact(otmp); 330. 	uchar dtyp; 331. 	long spfx; 332.  333.  	if (!oart) return; 334.  335.  	/* effects from the defn field */ 336. 	dtyp = (wp_mask != W_ART) ? oart->defn.adtyp : oart->cary.adtyp; 337.  338.  	if (dtyp == AD_FIRE) 339. 	    mask = &EFire_resistance; 340. 	else if (dtyp == AD_COLD) 341. 	    mask = &ECold_resistance; 342. 	else if (dtyp == AD_ELEC) 343. 	    mask = &EShock_resistance; 344. 	else if (dtyp == AD_MAGM) 345. 	    mask = &EAntimagic; 346. 	else if (dtyp == AD_DISN) 347. 	    mask = &EDisint_resistance; 348. 	else if (dtyp == AD_DRST) 349. 	    mask = &EPoison_resistance; 350.  351.  	if (mask && wp_mask == W_ART && !on) { 352. 	    /* find out if some other artifact also confers this intrinsic */ 353. 	    /* if so, leave the mask alone */ 354. 	    register struct obj* obj; 355. 	    for(obj = invent; obj; obj = obj->nobj) 356. 		if(obj != otmp && obj->oartifact) { 357. 		    register const struct artifact *art = get_artifact(obj); 358. 		    if(art->cary.adtyp == dtyp) { 359. 			mask = (long *) 0; 360. 			break; 361. 		    }  362.  		}  363.  	}  364.  	if (mask) { 365. 	    if (on) *mask |= wp_mask; 366. 	    else *mask &= ~wp_mask; 367. 	}  368.   369.  	/* intrinsics from the spfx field; there could be more than one */ 370. 	spfx = (wp_mask != W_ART) ? oart->spfx : oart->cspfx; 371. 	if(spfx && wp_mask == W_ART && !on) { 372. 	    /* don't change any spfx also conferred by other artifacts */ 373. 	    register struct obj* obj; 374. 	    for(obj = invent; obj; obj = obj->nobj) 375. 		if(obj != otmp && obj->oartifact) { 376. 		    register const struct artifact *art = get_artifact(obj); 377. 		    spfx &= ~art->cspfx; 378. 		}  379.  	}  380.   381.  	if (spfx & SPFX_SEARCH) { 382. 	    if(on) ESearching |= wp_mask; 383. 	    else ESearching &= ~wp_mask; 384. 	}  385.  	if (spfx & SPFX_HALRES) { 386. 	    /* make_hallucinated must (re)set the mask itself to get 387. 	     * the display right */ 388. 	    /* restoring needed because this is the only artifact intrinsic 389. 	     * that can print a message--need to guard against being printed 390. 	     * when restoring a game 391. 	     */  392.  	    make_hallucinated((long)!on, restoring ? FALSE : TRUE, wp_mask); 393. 	}  394.  	if (spfx & SPFX_ESP) { 395. 	    if(on) ETelepat |= wp_mask; 396. 	    else ETelepat &= ~wp_mask; 397. 	    see_monsters; 398. 	}  399.  	if (spfx & SPFX_STLTH) { 400. 	    if (on) EStealth |= wp_mask; 401. 	    else EStealth &= ~wp_mask; 402. 	}  403.  	if (spfx & SPFX_REGEN) { 404. 	    if (on) ERegeneration |= wp_mask; 405. 	    else ERegeneration &= ~wp_mask; 406. 	}  407.  	if (spfx & SPFX_TCTRL) { 408. 	    if (on) ETeleport_control |= wp_mask; 409. 	    else ETeleport_control &= ~wp_mask; 410. 	}  411.  	if (spfx & SPFX_WARN) { 412. 	    if (spec_m2(otmp)) { 413. 	    	if (on) { 414. 			EWarn_of_mon |= wp_mask; 415. 			flags.warntype |= spec_m2(otmp); 416. 	    	} else { 417. 			EWarn_of_mon &= ~wp_mask; 418. 	    		flags.warntype &= ~spec_m2(otmp); 419. 		}  420.  		see_monsters; 421. 	    } else { 422. 		if (on) EWarning |= wp_mask; 423. 	    	else EWarning &= ~wp_mask; 424. 	    }  425.  	}  426.  	if (spfx & SPFX_EREGEN) { 427. 	    if (on) EEnergy_regeneration |= wp_mask; 428. 	    else EEnergy_regeneration &= ~wp_mask; 429. 	}  430.  	if (spfx & SPFX_HSPDAM) { 431. 	    if (on) EHalf_spell_damage |= wp_mask; 432. 	    else EHalf_spell_damage &= ~wp_mask; 433. 	}  434.  	if (spfx & SPFX_HPHDAM) { 435. 	    if (on) EHalf_physical_damage |= wp_mask; 436. 	    else EHalf_physical_damage &= ~wp_mask; 437. 	}  438.  	if (spfx & SPFX_XRAY) { 439. 	    /* this assumes that no one else is using xray_range */ 440. 	    if (on) u.xray_range = 3; 441. 	    else u.xray_range = -1; 442. 	}  443.  	if ((spfx & SPFX_REFLECT) && (wp_mask & W_WEP)) { 444. 	    if (on) EReflecting |= wp_mask; 445. 	    else EReflecting &= ~wp_mask; 446. 	}  447.   448.  	if(wp_mask == W_ART && !on && oart->inv_prop) { 449. 	    /* might have to turn off invoked power too */ 450. 	    if (oart->inv_prop <= LAST_PROP &&  451.  		(u.uprops[oart->inv_prop].extrinsic & W_ARTI)) 452. 		(void) arti_invoke(otmp); 453. 	}  454.  }  455.   456.  /*  457.   * creature (usually player) tries to touch (pick up or wield) an artifact obj. 458.  * Returns 0 if the object refuses to be touched. 459.  * This routine does not change any object chains. 460.  * Ignores such things as gauntlets, assuming the artifact is not 461.  * fooled by such trappings. 462.  */  463.  int 464. touch_artifact(obj,mon) 465.     struct obj *obj; 466.     struct monst *mon; 467. {  468.      register const struct artifact *oart = get_artifact(obj); 469.     boolean badclass, badalign, self_willed, yours; 470.  471.      if(!oart) return 1; 472.  473.      yours = (mon == &youmonst); 474.     /* all quest artifacts are self-willed; it this ever changes, `badclass' 475.        will have to be extended to explicitly include quest artifacts */ 476.     self_willed = ((oart->spfx & SPFX_INTEL) != 0); 477.     if (yours) { 478. 	badclass = self_willed && 479. 		   ((oart->role != NON_PM && !Role_if(oart->role)) ||  480.  		    (oart->race != NON_PM && !Race_if(oart->race))); 481. 	badalign = (oart->spfx & SPFX_RESTR) && oart->alignment != A_NONE && 482. 		   (oart->alignment != u.ualign.type || u.ualign.record < 0); 483.     } else if (!is_covetous(mon->data) && !is_mplayer(mon->data)) { 484. 	badclass = self_willed && 485. 		   oart->role != NON_PM && oart != &artilist[ART_EXCALIBUR]; 486. 	badalign = (oart->spfx & SPFX_RESTR) && oart->alignment != A_NONE && 487. 		   (oart->alignment != sgn(mon->data->maligntyp)); 488.     } else {    /* an M3_WANTSxxx monster or a fake player */ 489. 	/* special monsters trying to take the Amulet, invocation tools or  490. quest item can touch anything except for `spec_applies' artifacts */ 491. 	badclass = badalign = FALSE; 492.     }  493.      /* weapons which attack specific categories of monsters are 494.        bad for them even if their alignments happen to match */ 495.     if (!badalign && (oart->spfx & SPFX_DBONUS) != 0) { 496. 	struct artifact tmp; 497.  498.  	tmp = *oart; 499. 	tmp.spfx &= SPFX_DBONUS; 500. 	badalign = !!spec_applies(&tmp, mon); 501.     }  502.   503.      if (((badclass || badalign) && self_willed) ||  504.         (badalign && (!yours || !rn2(4))))  { 505. 	int dmg; 506. 	char buf[BUFSZ]; 507.  508.  	if (!yours) return 0; 509. 	You("are blasted by %s power!", s_suffix(the(xname(obj)))); 510. 	dmg = d((Antimagic ? 2 : 4), (self_willed ? 10 : 4)); 511.  	Sprintf(buf, "touching %s", oart->name); 512. 	losehp(dmg, buf, KILLED_BY); 513. 	exercise(A_WIS, FALSE); 514.     }  515.   516.      /* can pick it up unless you're totally non-synch'd with the artifact */ 517.     if (badclass && badalign && self_willed) { 518. 	if (yours) pline("%s your grasp!", Tobjnam(obj, "evade")); 519. 	return 0; 520.     }  521.   522.      return 1; 523. }  524.   525.  #endif /* OVLB */ 526. #ifdef OVL1 527.  528.  /* decide whether an artifact's special attacks apply against mtmp */ 529. STATIC_OVL int 530. spec_applies(weap, mtmp) 531. register const struct artifact *weap; 532. struct monst *mtmp; 533. {  534.  	struct permonst *ptr; 535. 	boolean yours; 536.  537.  	if(!(weap->spfx & (SPFX_DBONUS | SPFX_ATTK))) 538. 	    return(weap->attk.adtyp == AD_PHYS); 539.  540.  	yours = (mtmp == &youmonst); 541. 	ptr = mtmp->data; 542.  543.  	if (weap->spfx & SPFX_DMONS) { 544. 	    return (ptr == &mons[(int)weap->mtype]); 545. 	} else if (weap->spfx & SPFX_DCLAS) { 546. 	    return (weap->mtype == (unsigned long)ptr->mlet); 547. 	} else if (weap->spfx & SPFX_DFLAG1) { 548. 	    return ((ptr->mflags1 & weap->mtype) != 0L); 549. 	} else if (weap->spfx & SPFX_DFLAG2) { 550. 	    return ((ptr->mflags2 & weap->mtype) ||  551.  		(yours && !Upolyd && (urace.selfmask & weap->mtype))); 552. 	} else if (weap->spfx & SPFX_DALIGN) { 553. 	    return yours ? (u.ualign.type != weap->alignment) : 554. 			   (ptr->maligntyp == A_NONE ||  555.  				sgn(ptr->maligntyp) != weap->alignment); 556. 	} else if (weap->spfx & SPFX_ATTK) { 557. 	    struct obj *defending_weapon = (yours ? uwep : MON_WEP(mtmp)); 558.  559.  	    if (defending_weapon && defending_weapon->oartifact &&  560.  		    defends((int)weap->attk.adtyp, defending_weapon)) 561. 		return FALSE; 562. 	    switch(weap->attk.adtyp) { 563. 		case AD_FIRE: 564. 			return !(yours ? Fire_resistance : resists_fire(mtmp)); 565. 		case AD_COLD: 566. 			return !(yours ? Cold_resistance : resists_cold(mtmp)); 567. 		case AD_ELEC: 568. 			return !(yours ? Shock_resistance : resists_elec(mtmp)); 569. 		case AD_MAGM: 570. 		case AD_STUN: 571. 			return !(yours ? Antimagic : (rn2(100) < ptr->mr)); 572. 		case AD_DRST: 573. 			return !(yours ? Poison_resistance : resists_poison(mtmp)); 574. 		case AD_DRLI: 575. 			return !(yours ? Drain_resistance : resists_drli(mtmp)); 576. 		case AD_STON: 577. 			return !(yours ? Stone_resistance : resists_ston(mtmp)); 578. 		default:	impossible("Weird weapon special attack."); 579. 	    }  580.  	}  581.  	return(0); 582. }  583.   584.  /* return the M2 flags of monster that an artifact's special attacks apply against */ 585. long 586. spec_m2(otmp) 587. struct obj *otmp; 588. {  589.  	register const struct artifact *artifact = get_artifact(otmp); 590. 	if (artifact) 591. 		return artifact->mtype; 592. 	return 0L; 593. }  594.   595.  /* special attack bonus */ 596. int 597. spec_abon(otmp, mon) 598. struct obj *otmp; 599. struct monst *mon; 600. {  601.  	register const struct artifact *weap = get_artifact(otmp); 602.  603.  	/* no need for an extra check for `NO_ATTK' because this will 604. 	   always return 0 for any artifact which has that attribute */ 605.  606.  	if (weap && weap->attk.damn && spec_applies(weap, mon)) 607. 	    return rnd((int)weap->attk.damn); 608. 	return 0; 609. }  610.   611.  /* special damage bonus */ 612. int 613. spec_dbon(otmp, mon, tmp) 614. struct obj *otmp; 615. struct monst *mon; 616. int tmp; 617. {  618.  	register const struct artifact *weap = get_artifact(otmp); 619.  620.  	if (!weap || (weap->attk.adtyp == AD_PHYS && /* check for `NO_ATTK' */ 621. 			weap->attk.damn == 0 && weap->attk.damd == 0)) 622. 	    spec_dbon_applies = FALSE; 623. 	else 624. 	    spec_dbon_applies = spec_applies(weap, mon); 625.  626.  	if (spec_dbon_applies) 627. 	    return weap->attk.damd ? rnd((int)weap->attk.damd) : max(tmp,1); 628. 	return 0; 629. }  630.   631.  /* add identified artifact to discoveries list */ 632. void 633. discover_artifact(m) 634. xchar m;  635. { 636.      int i;  637. 638.     /* look for this artifact in the discoveries list; 639.        if we hit an empty slot then it's not present, so add it */ 640.     for (i = 0; i < NROFARTIFACTS; i++) 641. 	if (artidisco[i] == 0 || artidisco[i] == m) { 642. 	    artidisco[i] = m;  643. return; 644. 	}  645.      /* there is one slot per artifact, so we should never reach the 646.        end without either finding the artifact or an empty slot... */ 647.      impossible("couldn't discover artifact (%d)", (int)m); 648. }  649.   650.  /* used to decide whether an artifact has been fully identified */ 651. boolean 652. undiscovered_artifact(m) 653. xchar m;  654. { 655.      int i;  656. 657.     /* look for this artifact in the discoveries list; 658.        if we hit an empty slot then it's undiscovered */ 659.     for (i = 0; i < NROFARTIFACTS; i++) 660. 	if (artidisco[i] == m)  661. return FALSE; 662. 	else if (artidisco[i] == 0) 663. 	    break; 664.     return TRUE; 665. }  666.   667.  /* display a list of discovered artifacts; return their count */ 668. int 669. disp_artifact_discoveries(tmpwin) 670. winid tmpwin;		/* supplied by dodiscover */ 671. {  672.      int i, m, otyp; 673.     char buf[BUFSZ]; 674.  675.      for (i = 0; i < NROFARTIFACTS; i++) { 676. 	if (artidisco[i] == 0) break;	/* empty slot implies end of list */ 677. 	if (i == 0) putstr(tmpwin, ATR_INVERSE, "Artifacts"); 678. 	m = artidisco[i]; 679. 	otyp = artilist[m].otyp; 680. 	Sprintf(buf, "  %s [%s %s]", artiname(m),  681.  		align_str(artilist[m].alignment), simple_typename(otyp)); 682. 	putstr(tmpwin, 0, buf); 683.     }  684.      return i;  685. } 686.   687.  #endif /* OVL1 */ 688.  689.  #ifdef OVLB 690.  691.  /* Function used when someone attacks someone else with an artifact 692.  * weapon. Only adds the special (artifact) damage, and returns a 1 if it 693. * did something special (in which case the caller won't print the normal 694.   * hit message). This should be called once upon every artifact attack; 695.  * dmgval no longer takes artifact bonuses into account. Possible 696.  * extension: change the killer so that when an orc kills you with 697.  * Stormbringer it's "killed by Stormbringer" instead of "killed by an orc". 698.  */  699.  boolean 700. artifact_hit(magr, mdef, otmp, dmgptr, dieroll) 701. struct monst *magr, *mdef; 702. struct obj *otmp; 703. int *dmgptr; 704. int dieroll; /* needed for Magicbane and vorpal blades */ 705. {  706.  	boolean youattack = (magr == &youmonst); 707. 	boolean youdefend = (mdef == &youmonst); 708. 	boolean vis = (!youattack && magr && cansee(magr->mx, magr->my)) 709. 		|| (!youdefend && cansee(mdef->mx, mdef->my)); 710. 	boolean realizes_damage; 711. 	const char *wepdesc; 712. 	static const char you[] = "you"; 713. 	char hittee[BUFSZ]; 714.  715.  	Strcpy(hittee, youdefend ? you : mon_nam(mdef)); 716.  717.  	/* The following takes care of most of the damage, but not all-- 718. 	 * the exception being for level draining, which is specially 719. 	 * handled. Messages are done in this function, however. 720. 	 */  721.  	*dmgptr += spec_dbon(otmp, mdef, *dmgptr); 722.  723.  	if (youattack && youdefend) { 724. 	    impossible("attacking yourself with weapon?"); 725. 	    return FALSE; 726. 	}  727.   728.  	realizes_damage = (youdefend || vis); 729.  730.  	/* the four basic attacks: fire, cold, shock and missiles */ 731. 	if (attacks(AD_FIRE, otmp)) { 732. 	    if (realizes_damage) 733. 		pline_The("fiery blade %s %s%c",  734.  			!spec_dbon_applies ? "hits" :  735.  			(mdef->data == &mons[PM_WATER_ELEMENTAL]) ?  736.  			"vaporizes part of" : "burns",  737.  			hittee, !spec_dbon_applies ? '.' : '!'); 738. 	    if (!rn2(4)) (void) destroy_mitem(mdef, POTION_CLASS, AD_FIRE); 739. 	    if (!rn2(4)) (void) destroy_mitem(mdef, SCROLL_CLASS, AD_FIRE); 740. 	    if (!rn2(7)) (void) destroy_mitem(mdef, SPBOOK_CLASS, AD_FIRE); 741. 	    if (youdefend && Slimed) burn_away_slime; 742. 	    return realizes_damage; 743. 	}  744.  	if (attacks(AD_COLD, otmp)) { 745. 	    if (realizes_damage) 746. 		pline_The("ice-cold blade %s %s%c",  747.  			!spec_dbon_applies ? "hits" : "freezes",  748.  			hittee, !spec_dbon_applies ? '.' : '!'); 749. 	    if (!rn2(4)) (void) destroy_mitem(mdef, POTION_CLASS, AD_COLD); 750. 	    return realizes_damage; 751. 	}  752.  	if (attacks(AD_ELEC, otmp)) { 753. 	    if (realizes_damage) { 754. 		if (youattack ? otmp != uwep : !spec_dbon_applies) 755. 		    pline("%s %s%c", Tobjnam(otmp, "hit"),  756.  			  hittee, !spec_dbon_applies ? '.' : '!'); 757. 		if (spec_dbon_applies) 758. 		    pline("Lightning strikes %s!", hittee); 759. 	    }  760.  	    if (!rn2(5)) (void) destroy_mitem(mdef, RING_CLASS, AD_ELEC); 761. 	    if (!rn2(5)) (void) destroy_mitem(mdef, WAND_CLASS, AD_ELEC); 762. 	    return realizes_damage; 763. 	}  764.  	if (attacks(AD_MAGM, otmp)) { 765. 	    if (realizes_damage) { 766. 		if (youattack ? otmp != uwep : !spec_dbon_applies) 767. 		    pline("%s %s%c", Tobjnam(otmp, "hit"),  768.  			  hittee, !spec_dbon_applies ? '.' : '!'); 769. 		if (spec_dbon_applies) 770. 		    pline("A hail of magic missiles strikes %s!", hittee); 771. 	    }  772.  	    return realizes_damage; 773. 	}  774.   775.  	if (!spec_dbon_applies) { 776. 	    /* since damage bonus didn't apply, nothing more to do; 777. 	       no further attacks have side-effects on inventory */ 778. 	    return FALSE; 779. 	}  780.   781.  	/*  782.  	 * Magicbane's intrinsic magic is incompatible with normal 783. 	 * enchantment magic. Thus, its effects have a negative 784. 	 * dependence on spe. Against low mr victims, it typically 785. 	 * does "double athame" damage, 2d4. Occasionally, it will 786. 	 * cast unbalancing magic which effectively averages out to  787. * 4d4 damage (2.5d4 against high mr victims), for spe = 0. 788. 	 */  789.   790.  #define MB_MAX_DIEROLL		8    /* rolls above this aren't magical */ 791. #define MB_INDEX_INIT		(-1) 792. #define MB_INDEX_PROBE		0 793. #define MB_INDEX_STUN		1 794. #define MB_INDEX_SCARE		2 795. #define MB_INDEX_PURGE		3 796. #define MB_RESIST_ATTACK	(resist_index = attack_index) 797. #define MB_RESISTED_ATTACK	(resist_index == attack_index) 798. #define MB_UWEP_ATTACK		(youattack && (otmp == uwep)) 799.  800.  	if (attacks(AD_STUN, otmp) && (dieroll <= MB_MAX_DIEROLL)) { 801. 		int attack_index = MB_INDEX_INIT; 802. 		int resist_index = MB_INDEX_INIT; 803. 		int scare_dieroll = MB_MAX_DIEROLL / 2; 804.  805.  		if (otmp->spe >= 3) 806. 			scare_dieroll /= (1 << (otmp->spe / 3)); 807.  808.  		*dmgptr += rnd(4);			/* 3d4 */ 809.  810.  		if (otmp->spe > rn2(10))		/* probe */ 811. 			attack_index = MB_INDEX_PROBE; 812. 		else {					/* stun */ 813. 			attack_index = MB_INDEX_STUN; 814. 			*dmgptr += rnd(4);		/* 4d4 */ 815.  816.  			if (youdefend) 817. 				make_stunned((HStun + 3), FALSE); 818. 			else 819. 				mdef->mstun = 1; 820. 		}  821.  		if (dieroll <= scare_dieroll) {		/* scare */ 822. 			attack_index = MB_INDEX_SCARE; 823. 			*dmgptr += rnd(4);		/* 5d4 */ 824.  825.  			if (youdefend) { 826. 				if (Antimagic) 827. 					MB_RESIST_ATTACK; 828. 				else { 829. 					nomul(-3); 830. 					nomovemsg = ""; 831. 					if (magr && magr == u.ustuck  832.  						&& sticks(youmonst.data)) { 833. 					    u.ustuck = (struct monst *)0; 834. 					    You("release %s!", mon_nam(magr)); 835. 					}  836.  				}  837.  			} else if (youattack) { 838. 				if (rn2(2) && resist(mdef,SPBOOK_CLASS,0,0)) { 839. 				    MB_RESIST_ATTACK; 840. 				} else { 841. 				    monflee(mdef, 3, FALSE, TRUE); 842. 				}  843.  			}  844.  		}  845.  		if (dieroll <= (scare_dieroll / 2)) {	/* purge */ 846. 			struct obj *ospell; 847. 			struct permonst *old_uasmon = youmonst.data; 848.  849.  			attack_index = MB_INDEX_PURGE; 850. 			*dmgptr += rnd(4);		/* 6d4 */ 851.  852.  			/* Create a fake spell object, ala spell.c */ 853. 			ospell = mksobj(SPE_CANCELLATION, FALSE, FALSE); 854. 			ospell->blessed = ospell->cursed = 0; 855. 			ospell->quan = 20L; 856.  857.  			cancel_monst(mdef, ospell, youattack, FALSE, FALSE); 858.  859.  			if (youdefend) { 860. 				if (old_uasmon != youmonst.data) 861. 					/* rehumanized, no more damage */ 862. 					*dmgptr = 0; 863. 				if (Antimagic) 864. 					MB_RESIST_ATTACK; 865. 			} else { 866. 				if (!mdef->mcan) 867. 					MB_RESIST_ATTACK; 868.  869.  				/* cancelled clay golems will die ... */ 870.  				else if (mdef->data == &mons[PM_CLAY_GOLEM]) 871. 					mdef->mhp = 1; 872. 			}  873.   874.  			obfree(ospell, (struct obj *)0); 875. 		}  876.   877.  		if (youdefend || mdef->mhp > 0) {  /* ??? -dkh- */ 878. 			static const char *mb_verb[4] = 879. 				{"probe", "stun", "scare", "purge"}; 880.  881.  			if (youattack || youdefend || vis) { 882. 				pline_The("magic-absorbing blade %ss %s!",  883.  					mb_verb[attack_index], hittee); 884.  885.  				if (MB_RESISTED_ATTACK) { 886. 					pline("%s resist%s!",  887.  					youdefend ? "You" : Monnam(mdef),  888.  					youdefend ? "" : "s"); 889.  890.  					shieldeff(youdefend ? u.ux : mdef->mx,  891.  						youdefend ? u.uy : mdef->my); 892. 				}  893.  			}  894.   895.  			/* Much ado about nothing. More magic fanfare! */ 896.  			if (MB_UWEP_ATTACK) { 897. 				if (attack_index == MB_INDEX_PURGE) { 898. 				    if (!MB_RESISTED_ATTACK &&  899.  					attacktype(mdef->data, AT_MAGC)) { 900. 					You("absorb magical energy!"); 901. 					u.uenmax++; 902. 					u.uen++; 903. 					flags.botl = 1; 904. 				    }  905.  				} else if (attack_index == MB_INDEX_PROBE) { 906. 				    if (!rn2(4 * otmp->spe)) { 907. 					pline_The("probe is insightful!"); 908. 					if (!canspotmon(mdef)) 909. 					    map_invisible(u.ux+u.dx,u.uy+u.dy); 910. 					/* pre-damage status */ 911. 					probe_monster(mdef); 912. 				    }  913.  				}  914.  			} else if (youdefend && !MB_RESISTED_ATTACK  915.  				   && (attack_index == MB_INDEX_PURGE)) { 916. 				You("lose magical energy!"); 917. 				if (u.uenmax > 0) u.uenmax--; 918. 				if (u.uen > 0) u.uen--; 919. 					flags.botl = 1; 920. 			}  921.   922.  			/* all this magic is confusing ... */ 923.  			if (!rn2(12)) { 924. 			    if (youdefend) 925. 				make_confused((HConfusion + 4), FALSE); 926. 			    else 927. 				mdef->mconf = 1; 928.  929.  			    if (youattack || youdefend || vis) 930. 				pline("%s %s confused.",  931.  				      youdefend ? "You" : Monnam(mdef),  932.  				      youdefend ? "are" : "is"); 933. 			}  934.  		}  935.  		return TRUE; 936. 	}  937.  	/* end of Magicbane code */ 938.  939.  	/* We really want "on a natural 20" but Nethack does it in */ 940. 	/* reverse from AD&D. */ 941.  	if (spec_ability(otmp, SPFX_BEHEAD)) { 942. 	    if (otmp->oartifact == ART_TSURUGI_OF_MURAMASA && dieroll == 1) { 943. 		wepdesc = "The razor-sharp blade"; 944. 		/* not really beheading, but so close, why add another SPFX */ 945. 		if (youattack && u.uswallow && mdef == u.ustuck) { 946. 		    You("slice %s wide open!", mon_nam(mdef)); 947. 		    *dmgptr = 2 * mdef->mhp + FATAL_DAMAGE_MODIFIER; 948. 		    return TRUE; 949. 		}  950.  		if (!youdefend) { 951. 			/* allow normal cutworm call to add extra damage */ 952. 			if(notonhead) 953. 			    return FALSE; 954.  955.  			if (bigmonst(mdef->data)) { 956. 				if (youattack) 957. 					You("slice deeply into %s!",  958.  						mon_nam(mdef)); 959. 				else if (vis) 960. 					pline("%s cuts deeply into %s!",  961.  					      Monnam(magr), hittee); 962. 				*dmgptr *= 2; 963. 				return TRUE; 964. 			}  965.  			*dmgptr = 2 * mdef->mhp + FATAL_DAMAGE_MODIFIER; 966. 			pline("%s cuts %s in half!", wepdesc, mon_nam(mdef)); 967. 			otmp->dknown = TRUE; 968. 			return TRUE; 969. 		} else { 970. 			if (bigmonst(youmonst.data)) { 971. 				pline("%s cuts deeply into you!",  972.  				      magr ? Monnam(magr) : wepdesc); 973. 				*dmgptr *= 2; 974. 				return TRUE; 975. 			}  976.   977.  			/* Players with negative AC's take less damage instead 978. 			 * of just not getting hit. We must add a large enough 979. 			 * value to the damage so that this reduction in  980. * damage does not prevent death. 981. 			 */  982.  			*dmgptr = 2 * (Upolyd ? u.mh : u.uhp) + FATAL_DAMAGE_MODIFIER; 983. 			pline("%s cuts you in half!", wepdesc); 984. 			otmp->dknown = TRUE; 985. 			return TRUE; 986. 		}  987.  	    } else if (otmp->oartifact == ART_VORPAL_BLADE &&  988.  			(dieroll == 1 || mdef->data == &mons[PM_JABBERWOCK])) { 989. 		static const char *behead_msg[2] = { 990. 		     "%s beheads %s!", 991. 		     "%s decapitates %s!" 992. 		};  993.   994.  		if (youattack && u.uswallow && mdef == u.ustuck) 995. 			return FALSE; 996. 		wepdesc = artilist[ART_VORPAL_BLADE].name; 997. 		if (!youdefend) { 998. 			if (!has_head(mdef->data) || notonhead || u.uswallow) { 999. 				if (youattack) 1000. 					pline("Somehow, you miss %s wildly.", 1001. 						mon_nam(mdef)); 1002. 				else if (vis) 1003. 					pline("Somehow, %s misses wildly.", 1004. 						mon_nam(magr)); 1005. 				*dmgptr = 0; 1006. 				return ((boolean)(youattack || vis)); 1007. 			} 1008. 			if (noncorporeal(mdef->data) || amorphous(mdef->data)) { 1009. 				pline("%s slices through %s %s.", wepdesc, 1010. 				      s_suffix(mon_nam(mdef)),  1011. 				      mbodypart(mdef,NECK)); 1012. 				return TRUE; 1013. 			} 1014. 			*dmgptr = 2 * mdef->mhp + FATAL_DAMAGE_MODIFIER; 1015. 			pline(behead_msg[rn2(SIZE(behead_msg))], 1016. 			      wepdesc, mon_nam(mdef)); 1017. 			otmp->dknown = TRUE; 1018. 			return TRUE; 1019. 		} else { 1020. 			if (!has_head(youmonst.data)) { 1021. 				pline("Somehow, %s misses you wildly.", 1022. 				      magr ? mon_nam(magr) : wepdesc); 1023. 				*dmgptr = 0; 1024. 				return TRUE; 1025. 			} 1026. 			if (noncorporeal(youmonst.data) || amorphous(youmonst.data)) { 1027. 				pline("%s slices through your %s.", 1028. 				      wepdesc, body_part(NECK)); 1029. 				return TRUE; 1030. 			} 1031. 			*dmgptr = 2 * (Upolyd ? u.mh : u.uhp) 1032. 				 + FATAL_DAMAGE_MODIFIER; 1033. 			pline(behead_msg[rn2(SIZE(behead_msg))], 1034. 			      wepdesc, "you"); 1035. 			otmp->dknown = TRUE; 1036. 			/* Should amulets fall off? */ 1037. 			return TRUE; 1038. 		} 1039. 	    }  1040. 	}  1041. 	if (spec_ability(otmp, SPFX_DRLI)) { 1042. 		if (!youdefend) { 1043. 			if (vis) { 1044. 			   if(otmp->oartifact == ART_STORMBRINGER) 1045. 				pline_The("%s blade draws the life from %s!", 1046. 				      hcolor(Black),  1047. 				      mon_nam(mdef)); 1048. 			   else 1049. 				pline("%s draws the life from %s!", 1050. 				      The(distant_name(otmp, xname)),  1051. 				      mon_nam(mdef)); 1052. 			} 1053. 			if (mdef->m_lev == 0) { 1054. 			   *dmgptr = 2 * mdef->mhp + FATAL_DAMAGE_MODIFIER; 1055. 			} else { 1056. 			   int drain = rnd(8); 1057. 			   *dmgptr += drain; 1058. 			   mdef->mhpmax -= drain; 1059. 			   mdef->m_lev--; 1060. 			   drain /= 2; 1061. 			   if (drain) healup(drain, 0, FALSE, FALSE); 1062. 			} 1063. 			return vis; 1064. 		} else { /* youdefend */ 1065. 			int oldhpmax = u.uhpmax; 1066. 1067. 			if (Blind) 1068. 				You_feel("an %s drain your life!", 1069. 				    otmp->oartifact == ART_STORMBRINGER ?  1070. 				    "unholy blade" : "object"); 1071. 			else if (otmp->oartifact == ART_STORMBRINGER) 1072. 				pline_The("%s blade drains your life!", 1073. 				      hcolor(Black)); 1074. 			else 1075. 				pline("%s drains your life!", 1076. 				      The(distant_name(otmp, xname))); 1077. 			losexp("life drainage"); 1078. 			if (magr && magr->mhp < magr->mhpmax) { 1079. 			   magr->mhp += (u.uhpmax - oldhpmax)/2; 1080. 			   if (magr->mhp > magr->mhpmax) magr->mhp = magr->mhpmax; 1081. 			} 1082. 			return TRUE; 1083. 		} 1084. 	}  1085. 	return FALSE; 1086. } 1087.  1088. static NEARDATA const char recharge_type[] = { ALLOW_COUNT, ALL_CLASSES, 0 }; 1089. static NEARDATA const char invoke_types[] = { ALL_CLASSES, 0 }; 1090. 		/* #invoke: an "ugly check" filters out most objects */ 1091. 1092. int 1093. doinvoke 1094. { 1095.     register struct obj *obj; 1096. 1097.     obj = getobj(invoke_types, "invoke"); 1098.    if(!obj) return 0; 1099.    return arti_invoke(obj); 1100. } 1101.  1102. STATIC_OVL int 1103. arti_invoke(obj) 1104.    register struct obj *obj; 1105. { 1106.     register const struct artifact *oart = get_artifact(obj); 1107. 1108.     if(!oart || !oart->inv_prop) { 1109. 	if(obj->otyp == CRYSTAL_BALL) 1110. 	   use_crystal_ball(obj); 1111. 	else 1112. 	   pline(nothing_happens); 1113. 	return 1; 1114.    }  1115.  1116.     if(oart->inv_prop > LAST_PROP) { 1117. 	/* It's a special power, not "just" a property */ 1118. 	if(obj->age > monstermoves) { 1119. 	   /* the artifact is tired :-) */  1120. 	    You_feel("that %s is ignoring you.", the(xname(obj)));  1121. 	    /* and just got more so; patience is essential... */  1122. 	    obj->age += (long) d(3,10);  1123. 	    return 1;  1124. 	}  1125. 	obj->age = monstermoves + rnz(100);  1126.  1127. 	switch(oart->inv_prop) {  1128. 	case TAMING: {  1129. 	    struct obj pseudo;  1130.  1131. 	    pseudo = zeroobj;	/* neither cursed nor blessed */  1132. 	    pseudo.otyp = SCR_TAMING;  1133. 	    (void) seffects(&pseudo);  1134. 	    break;  1135. 	  }  1136. 	case HEALING: {  1137. 	    int healamt = (u.uhpmax + 1 - u.uhp) / 2;  1138. 	    long creamed = (long)u.ucreamed;  1139.  1140. 	    if (Upolyd) healamt = (u.mhmax + 1 - u.mh) / 2;  1141. 	    if (healamt || Sick || Blinded > creamed)  1142. 		You_feel("better.");  1143. 	    else  1144. 		goto nothing_special;  1145. 	    if (healamt > 0) { 1146. 		if (Upolyd) u.mh += healamt; 1147. 		else u.uhp += healamt; 1148. 	   }  1149. 	    if(Sick) make_sick(0L,(char *)0,FALSE,SICK_ALL); 1150. 	   if(Slimed) Slimed = 0L; 1151. 	   if (Blinded > creamed) make_blinded(creamed, FALSE); 1152. 	   flags.botl = 1; 1153. 	   break; 1154. 	 }  1155. 	case ENERGY_BOOST: { 1156. 	   int epboost = (u.uenmax + 1 - u.uen) / 2; 1157. 	   if (epboost > 120) epboost = 120;		/* arbitrary */ 1158. 	   else if (epboost < 12) epboost = u.uenmax - u.uen; 1159. 	   if(epboost) { 1160. 		You_feel("re-energized."); 1161. 		u.uen += epboost; 1162. 		flags.botl = 1; 1163. 	   } else 1164. 		goto nothing_special; 1165. 	   break; 1166. 	 }  1167. 	case UNTRAP: { 1168. 	   if(!untrap(TRUE)) { 1169. 		obj->age = 0; /* don't charge for changing their mind */ 1170. 		return 0; 1171. 	   }  1172. 	    break; 1173. 	 }  1174. 	case CHARGE_OBJ: { 1175. 	   struct obj *otmp = getobj(recharge_type, "charge"); 1176. 	   boolean b_effect; 1177. 1178. 	    if (!otmp) { 1179. 		obj->age = 0; 1180. 		return 0; 1181. 	   }  1182. 	    b_effect = obj->blessed && 1183. 		(Role_switch == oart->role || !oart->role); 1184. 	   recharge(otmp, b_effect ? 1 : obj->cursed ? -1 : 0); 1185. 	   update_inventory; 1186. 	   break; 1187. 	 }  1188. 	case LEV_TELE: 1189. 	   level_tele; 1190. 	   break; 1191. 	case CREATE_PORTAL: { 1192. 	   int i, num_ok_dungeons, last_ok_dungeon = 0; 1193. 	   d_level newlev; 1194. 	   extern int n_dgns; /* from dungeon.c */ 1195. 	   winid tmpwin = create_nhwindow(NHW_MENU); 1196. 	   anything any; 1197. 1198. 	    any.a_void = 0;	/* set all bits to zero */ 1199. 	   start_menu(tmpwin); 1200. 	   /* use index+1 (cant use 0) as identifier */ 1201. 	   for (i = num_ok_dungeons = 0; i < n_dgns; i++) { 1202. 		if (!dungeons[i].dunlev_ureached) continue; 1203. 		any.a_int = i+1; 1204. 		add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, 1205. 			 dungeons[i].dname, MENU_UNSELECTED); 1206. 		num_ok_dungeons++; 1207. 		last_ok_dungeon = i; 1208. } 1209. 	    end_menu(tmpwin, "Open a portal to which dungeon?"); 1210. 	   if (num_ok_dungeons > 1) { 1211. 		/* more than one entry; display menu for choices */ 1212. 		menu_item *selected; 1213. 		int n; 1214. 1215. 		n = select_menu(tmpwin, PICK_ONE, &selected); 1216. 		if (n <= 0) { 1217. 		   destroy_nhwindow(tmpwin); 1218. 		   goto nothing_special; 1219. 		} 1220. 		i = selected[0].item.a_int - 1; 1221. 		free((genericptr_t)selected); 1222. 	   } else 1223. 		i = last_ok_dungeon;	/* also first & only OK dungeon */ 1224. 	   destroy_nhwindow(tmpwin); 1225. 1226. 	    /*  1227. 	     * i is now index into dungeon structure for the new dungeon. 1228. 	    * Find the closest level in the given dungeon, open 1229. 	    * a use-once portal to that dungeon and go there. 1230. 	    * The closest level is either the entry or dunlev_ureached. 1231. 	    */  1232. 	    newlev.dnum = i;  1233. if(dungeons[i].depth_start >= depth(&u.uz)) 1234. 		newlev.dlevel = dungeons[i].entry_lev; 1235. 	   else 1236. 		newlev.dlevel = dungeons[i].dunlev_ureached; 1237. 	   if(u.uhave.amulet || In_endgame(&u.uz) || In_endgame(&newlev) ||  1238. 	       newlev.dnum == u.uz.dnum) { 1239. 		You_feel("very disoriented for a moment."); 1240. 	   } else { 1241. 		if(!Blind) You("are surrounded by a shimmering sphere!"); 1242. 		else You_feel("weightless for a moment."); 1243. 		goto_level(&newlev, FALSE, FALSE, FALSE); 1244. 	   }  1245. 	    break; 1246. 	 }  1247. 	case ENLIGHTENING: 1248. 	   enlightenment(0); 1249. 	   break; 1250. 	case CREATE_AMMO: { 1251. 	   struct obj *otmp = mksobj(ARROW, TRUE, FALSE); 1252. 1253. 	    if (!otmp) goto nothing_special; 1254. 	   otmp->blessed = obj->blessed; 1255. 	   otmp->cursed = obj->cursed; 1256. 	   otmp->bknown = obj->bknown; 1257. 	   if (obj->blessed) { 1258. 		if (otmp->spe < 0) otmp->spe = 0; 1259. 		otmp->quan += rnd(10); 1260. 	   } else if (obj->cursed) { 1261. 		if (otmp->spe > 0) otmp->spe = 0; 1262. 	   } else 1263. 		otmp->quan += rnd(5); 1264. 	   otmp->owt = weight(otmp); 1265. 	   otmp = hold_another_object(otmp, "Suddenly %s out.",  1266. 				       aobjnam(otmp, "fall"), (const char *)0); 1267. 	   break; 1268. 	 }  1269. 	}  1270.     } else { 1271. 	long cprop = (u.uprops[oart->inv_prop].extrinsic ^= W_ARTI); 1272. 	boolean on = (cprop & W_ARTI) != 0; /* true if invoked prop just set */ 1273. 1274. 	if(on && obj->age > monstermoves) { 1275. 	   /* the artifact is tired :-) */  1276. 	    u.uprops[oart->inv_prop].extrinsic ^= W_ARTI;  1277. 	    You_feel("that %s is ignoring you.", the(xname(obj)));  1278. 	    return 1;  1279. 	} else if(!on) {  1280. 	    /* when turning off property, determine downtime */  1281. 	    /* arbitrary for now until we can tune this -dlc */  1282. 	    obj->age = monstermoves + rnz(100);  1283. 	}  1284.  1285. 	if(cprop & ~W_ARTI) {  1286. nothing_special:  1287. 	    /* you had the property from some other source too */  1288. 	    if (carried(obj))  1289. 		You_feel("a surge of power, but nothing seems to happen.");  1290. 	    return 1;  1291. 	}  1292. 	switch(oart->inv_prop) {  1293. 	case CONFLICT:  1294. 	    if(on) You_feel("like a rabble-rouser.");  1295. 	    else You_feel("the tension decrease around you.");  1296. 	    break;  1297. 	case LEVITATION:  1298. 	    if(on) {  1299. float_up; 1300. 		spoteffects(FALSE); 1301. 	   } else (void) float_down(I_SPECIAL|TIMEOUT, W_ARTI); 1302. 	   break; 1303. 	case INVIS: 1304. 	   if (!See_invisible && !Blind) { 1305. 		newsym(u.ux,u.uy); 1306. 		if (on) { 1307. 		   Your("body takes on a %s transparency...",  1308. 			 Hallucination ? "normal" : "strange"); 1309. 		} else { 1310. 		   Your("body seems to unfade..."); 1311. 		} 1312. 	    } else goto nothing_special; 1313. 	   break; 1314. 	} 1315.     }  1316.  1317.     return 1; 1318. } 1319.  1320.  1321. /* WAC return TRUE if artifact is always lit */ 1322. boolean 1323. artifact_light(obj) 1324.    struct obj *obj; 1325. { 1326.     return (get_artifact(obj) && obj->oartifact == ART_SUNSWORD); 1327. } 1328.  1329. /* KMH -- Talking artifacts are finally implemented */ 1330. void arti_speak(obj) 1331.    struct obj *obj; 1332. { 1333. 	register const struct artifact *oart = get_artifact(obj); 1334. 	const char *line; 1335. 	char buf[BUFSZ]; 1336. 1337.  1338. 	/* Is this a speaking artifact? */ 1339. 	if (!oart || !(oart->spfx & SPFX_SPEAK)) 1340. 		return; 1341. 1342. 	line = getrumor(bcsign(obj), buf, TRUE); 1343. 	if (!*line) 1344. 		line = "NetHack rumors file closed for renovation."; 1345. 	pline("%s:", Tobjnam(obj, "whisper")); 1346. 	verbalize("%s", line); 1347. 	return; 1348. } 1349.  1350. boolean 1351. artifact_has_invprop(otmp, inv_prop) 1352. struct obj *otmp; 1353. uchar inv_prop; 1354. { 1355. 	const struct artifact *arti = get_artifact(otmp); 1356. 1357. 	return((boolean)(arti && (arti->inv_prop == inv_prop))); 1358. } 1359.  1360. /* Return the price sold to the hero of a given artifact or unique item */ 1361. long 1362. arti_cost(otmp) 1363. struct obj *otmp; 1364. { 1365. 	if (!otmp->oartifact) 1366. 	   return ((long)objects[otmp->otyp].oc_cost); 1367. 	else if (artilist[(int) otmp->oartifact].cost) 1368. 	   return (artilist[(int) otmp->oartifact].cost); 1369. 	else 1370. 	   return (100L * (long)objects[otmp->otyp].oc_cost); 1371. } 1372.  1373. #endif /* OVLB */ 1374. 1375. /*artifact.c*/