Fandom

Wikihack

Source:NetHack 3.3.0/artifact.c

2,034pages on
this wiki
Add New Page
Talk0

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

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

Also on Fandom

Random Wiki