Fandom

Wikihack

Source:SLASH'EM 0.0.7E7F2/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 SLASH'EM 0.0.7E7F2. To link to a particular line, write [[SLASH'EM 0.0.7E7F2/artifact.c#line123]], for example.

The latest source code for vanilla NetHack is at Source code.


The NetHack General Public License applies to screenshots, source code and other content from NetHack.
1.    /*	SCCS Id: @(#)artifact.c 3.4	2003/08/11	*/
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.   
24.   STATIC_DCL int FDECL(spec_applies, (const struct artifact *,struct monst *));
25.   STATIC_DCL int FDECL(arti_invoke, (struct obj*));
26.   STATIC_DCL boolean FDECL(Mb_hit, (struct monst *magr,struct monst *mdef,
27.   				  struct obj *,int *,int,BOOLEAN_P,char *));
28.   
29.   /* The amount added to the victim's total hit points to insure that the
30.      victim will be killed even after damage bonus/penalty adjustments.
31.      Most such penalties are small, and 200 is plenty; the exception is
32.      half physical damage.  3.3.1 and previous versions tried to use a very
33.      large number to account for this case; now, we just compute the fatal
34.      damage by adding it to 2 times the total hit points instead of 1 time.
35.      Note: this will still break if they have more than about half the number
36.      of hit points that will fit in a 15 bit integer. */
37.   #define FATAL_DAMAGE_MODIFIER 200
38.   
39.   #ifndef OVLB
40.   STATIC_DCL int spec_dbon_applies;
41.   STATIC_DCL xchar artidisco[NROFARTIFACTS];
42.   #else	/* OVLB */
43.   /* coordinate effects from spec_dbon() with messages in artifact_hit() */
44.   STATIC_OVL int spec_dbon_applies = 0;
45.   
46.   /* flags including which artifacts have already been created */
47.   static boolean artiexist[1+NROFARTIFACTS+1];
48.   /* and a discovery list for them (no dummy first entry here) */
49.   
50.   STATIC_OVL xchar artidisco[NROFARTIFACTS];
51.   
52.   STATIC_DCL void NDECL(hack_artifacts);
53.   STATIC_DCL boolean FDECL(attacks, (int,struct obj *));
54.   
55.   
56.   /* handle some special cases; must be called after role_init() */
57.   STATIC_OVL void
58.   hack_artifacts()
59.   {
60.   	struct artifact *art;
61.   	int alignmnt = aligns[flags.initalign].value;
62.   
63.   	/* Fix up the alignments of "gift" artifacts */
64.   	for (art = artilist+1; art->otyp; art++)
65.   	    if (art->role == Role_switch && art->alignment != A_NONE)
66.   		art->alignment = alignmnt;
67.   
68.   	/* Excalibur can be used by any lawful character, not just knights */
69.   	if (!Role_if(PM_KNIGHT))
70.   	    artilist[ART_EXCALIBUR].role = NON_PM;
71.   
72.   #if 0
73.   	/* Fix up the gifts */
74.   	if (urole.gift1arti) {
75.   		artilist[urole.gift1arti].alignment = alignmnt;
76.   		artilist[urole.gift1arti].role = Role_switch;
77.   	}
78.   	if (urole.gift2arti) {
79.   		artilist[urole.gift2arti].alignment = alignmnt;
80.   		artilist[urole.gift2arti].role = Role_switch;
81.   	}
82.   #endif
83.   	/* Fix up the quest artifact */
84.   	if (urole.questarti) {
85.   	    artilist[urole.questarti].alignment = alignmnt;
86.   	    artilist[urole.questarti].role = Role_switch;
87.   	}
88.   	return;
89.   }
90.   
91.   /* zero out the artifact existence list */
92.   void
93.   init_artifacts()
94.   {
95.   	(void) memset((genericptr_t) artiexist, 0, sizeof artiexist);
96.   	(void) memset((genericptr_t) artidisco, 0, sizeof artidisco);
97.   	hack_artifacts();
98.   }
99.   
100.  /* Post u_init() initialization */
101.  void
102.  init_artifacts1()
103.  {
104.  #if 0
105.      /* KMH -- Should be at least skilled in first artifact gifts */
106.      if (urole.gift1arti &&
107.  	    (objects[artilist[urole.gift1arti].otyp].oc_class == WEAPON_CLASS ||
108.  	     objects[artilist[urole.gift1arti].otyp].oc_class == TOOL_CLASS)) {
109.  	int skill = objects[artilist[urole.gift1arti].otyp].oc_skill;
110.  
111.  	if (skill > P_NONE && P_SKILL(skill) < P_UNSKILLED)
112.  	    P_SKILL(skill) = P_UNSKILLED;
113.  	if (skill > P_NONE && P_MAX_SKILL(skill) < P_SKILLED) {
114.  	    pline("Warning: %s should be at least skilled.  Fixing...",
115.  		    artilist[urole.gift1arti].name);
116.  		P_MAX_SKILL(skill) = P_SKILLED;
117.  	}
118.      }
119.      if (urole.gift2arti &&
120.  	    (objects[artilist[urole.gift2arti].otyp].oc_class == WEAPON_CLASS ||
121.  	     objects[artilist[urole.gift2arti].otyp].oc_class == TOOL_CLASS)) {
122.  	int skill = objects[artilist[urole.gift2arti].otyp].oc_skill;
123.  
124.  	if (skill > P_NONE && P_SKILL(skill) < P_UNSKILLED)
125.  	    P_SKILL(skill) = P_UNSKILLED;
126.  	if (skill > P_NONE && P_MAX_SKILL(skill) < P_SKILLED) {
127.  	    pline("Warning: %s should be at least skilled.  Fixing...",
128.  		    artilist[urole.gift1arti].name);
129.  	    P_MAX_SKILL(skill) = P_SKILLED;
130.  	}
131.      }
132.  #endif 
133.      /* KMH -- Should be expert in quest artifact */
134.      if (urole.questarti &&
135.  	    (objects[artilist[urole.questarti].otyp].oc_class == WEAPON_CLASS ||
136.  	     objects[artilist[urole.questarti].otyp].oc_class == TOOL_CLASS)) {
137.  	int skill = objects[artilist[urole.questarti].otyp].oc_skill;
138.  
139.  	if (skill > P_NONE && P_SKILL(skill) < P_UNSKILLED)
140.  	    P_SKILL(skill) = P_UNSKILLED;
141.  	if (skill > P_NONE && P_MAX_SKILL(skill) < P_EXPERT) {
142.  	    pline("Warning: %s should be at least expert.  Fixing...",
143.  		    artilist[urole.questarti].name);
144.  	    P_MAX_SKILL(skill) = P_EXPERT;
145.  	}
146.      }
147.  }
148.  
149.  void
150.  save_artifacts(fd)
151.  int fd;
152.  {
153.  	bwrite(fd, (genericptr_t) artiexist, sizeof artiexist);
154.  	bwrite(fd, (genericptr_t) artidisco, sizeof artidisco);
155.  }
156.  
157.  void
158.  restore_artifacts(fd)
159.  int fd;
160.  {
161.  	mread(fd, (genericptr_t) artiexist, sizeof artiexist);
162.  	mread(fd, (genericptr_t) artidisco, sizeof artidisco);
163.  	hack_artifacts();	/* redo non-saved special cases */
164.  }
165.  
166.  const char *
167.  artiname(artinum)
168.  int artinum;
169.  {
170.  	if (artinum <= 0 || artinum > NROFARTIFACTS) return("");
171.  	return(artilist[artinum].name);
172.  }
173.  
174.  /*
175.     Make an artifact.  If a specific alignment is specified, then an object of
176.     the appropriate alignment is created from scratch, or 0 is returned if
177.     none is available.  (If at least one aligned artifact has already been
178.     given, then unaligned ones also become eligible for this.)
179.     If no alignment is given, then 'otmp' is converted
180.     into an artifact of matching type, or returned as-is if that's not possible.
181.     For the 2nd case, caller should use ``obj = mk_artifact(obj, A_NONE);
182.     for the 1st, ``obj = mk_artifact((struct obj *)0, some_alignment);.
183.   */
184.  struct obj *
185.  mk_artifact(otmp, alignment)
186.  struct obj *otmp;	/* existing object; ignored if alignment specified */
187.  aligntyp alignment;	/* target alignment, or A_NONE */
188.  {
189.  	const struct artifact *a;
190.  	int n, m;
191.  	boolean by_align = (alignment != A_NONE);
192.  	short o_typ = (by_align || !otmp) ? 0 : otmp->otyp;
193.  	boolean unique = !by_align && otmp && objects[o_typ].oc_unique;
194.  	short eligible[NROFARTIFACTS];
195.  
196.  
197.  #if 0
198.  	/* KMH, role patch -- Try first or second gift */
199.  	m = urole.gift1arti;
200.  	if (by_align && m && !artiexist[m]) {
201.  		a = (struct artifact *)&artilist[m];
202.  		goto make_artif;
203.  	}
204.  	m = urole.gift2arti;
205.  	if (by_align && m && !artiexist[m]) {
206.  		a = (struct artifact *)&artilist[m];
207.  		goto make_artif;
208.  	}
209.  #endif
210.  
211.  	/* gather eligible artifacts */
212.  	for (n = 0, a = artilist+1, m = 1; a->otyp; a++, m++)
213.  	    if ((!by_align ? a->otyp == o_typ :
214.  		    (a->alignment == alignment ||
215.  			(a->alignment == A_NONE && u.ugifts > 0))) &&
216.  		(!(a->spfx & SPFX_NOGEN) || unique) && !artiexist[m]) {
217.  		/*
218.  		 * [ALI] The determination of whether an artifact is
219.  		 * hostile to the player is a little more complex in
220.  		 * Slash'EM than Vanilla since there are artifacts
221.  		 * which are hostile to humans (eg., Deathsword) which
222.  		 * aren't aligned to any race.
223.  		 * Nevertheless, the rule remains the same: Gods don't
224.  		 * grant artifacts which would be hostile to the player
225.  		 * _in their normal form_.
226.  		 */
227.  		boolean hostile = FALSE;
228.  		if (by_align) {
229.  		    if (a->race != NON_PM && race_hostile(&mons[a->race]))
230.  			hostile = TRUE;		/* enemies' equipment */
231.  		    else if (a->spfx & SPFX_DBONUS) {
232.  			struct artifact tmp;
233.  
234.  			tmp = *a;
235.  			tmp.spfx &= SPFX_DBONUS;
236.  			if (Upolyd)
237.  			    set_mon_data(&youmonst, &upermonst, 0);
238.  			if (spec_applies(&tmp, &youmonst))
239.  			    hostile = TRUE;	/* can blast unpolyd player */
240.  			if (Upolyd)
241.  			    set_mon_data(&youmonst, &mons[u.umonnum], 0);
242.  		    }
243.  		}
244.  		if (hostile)
245.  		    continue;
246.  		if (by_align && Role_if(a->role))
247.  		    goto make_artif;	/* 'a' points to the desired one */
248.  		else
249.  		    eligible[n++] = m;
250.  	    }
251.  
252.  	if (n) {		/* found at least one candidate */
253.  	    m = eligible[rn2(n)];	/* [0..n-1] */
254.  	    a = &artilist[m];
255.  
256.  	    /* make an appropriate object if necessary, then christen it */
257.  make_artif: if (by_align) otmp = mksobj((int)a->otyp, TRUE, FALSE);
258.  	    otmp = oname(otmp, a->name);
259.  	    otmp->oartifact = m;
260.  	    artiexist[m] = TRUE;
261.  	} else {
262.  	    /* nothing appropriate could be found; return the original object */
263.  	    if (by_align) otmp = 0;	/* (there was no original object) */
264.  	}
265.  	return otmp;
266.  }
267.  
268.  /*
269.   * Returns the full name (with articles and correct capitalization) of an
270.   * artifact named "name" if one exists, or NULL, it not.
271.   * The given name must be rather close to the real name for it to match.
272.   * The object type of the artifact is returned in otyp if the return value
273.   * is non-NULL.
274.   */
275.  const char*
276.  artifact_name(name, otyp)
277.  const char *name;
278.  short *otyp;
279.  {
280.      register const struct artifact *a;
281.      register const char *aname;
282.  
283.      if(!strncmpi(name, "the ", 4)) name += 4;
284.      if(!strncmpi(name, "poisoned ", 9)) name += 9;
285.  
286.      for (a = artilist+1; a->otyp; a++) {
287.  	aname = a->name;
288.  	if(!strncmpi(aname, "the ", 4)) aname += 4;
289.  	if(!strcmpi(name, aname)) {
290.  	    *otyp = a->otyp;
291.  	    return a->name;
292.  	}
293.      }
294.  
295.      return (char *)0;
296.  }
297.  
298.  boolean
299.  exist_artifact(otyp, name)
300.  register int otyp;
301.  register const char *name;
302.  {
303.  	register const struct artifact *a;
304.  	register boolean *arex;
305.  
306.  	if (otyp && *name)
307.  	    for (a = artilist+1,arex = artiexist+1; a->otyp; a++,arex++)
308.  		if ((int) a->otyp == otyp && !strcmp(a->name, name))
309.  		    return *arex;
310.  	return FALSE;
311.  }
312.  
313.  void
314.  artifact_exists(otmp, name, mod)
315.  register struct obj *otmp;
316.  register const char *name;
317.  register boolean mod;
318.  {
319.  	register const struct artifact *a;
320.  
321.  	if (otmp && *name)
322.  	    for (a = artilist+1; a->otyp; a++)
323.  		if (a->otyp == otmp->otyp && !strcmp(a->name, name)) {
324.  		    register int m = a - artilist;
325.  /*WAC add code to automatically light up Sunsword/holy spear of light on
326.          creation*/
327.  		    /* For the check so artifact_light recognizes it */
328.  		    otmp->oartifact = m;
329.  		    if (!artiexist[m] && mod && (artifact_light(otmp) ||
330.  						 otmp->otyp == MAGIC_CANDLE)) {
331.  			begin_burn(otmp, FALSE);
332.  			/* WAC light source deletion handled in obfree */
333.  		    }
334.  		    otmp->oartifact = (char)(mod ? m : 0);
335.  		    if (mod) {
336.  			otmp->quan = 1; /* guarantee only one of this artifact */
337.  #ifdef UNPOLYPILE	/* Artifacts are immune to unpolypile --ALI */
338.  			if (is_hazy(otmp)) {
339.  			    (void) stop_timer(UNPOLY_OBJ, (genericptr_t) otmp);
340.  			    otmp->oldtyp = STRANGE_OBJECT;
341.  			}
342.  #endif
343.  		    }
344.  		    otmp->age = 0;
345.  		    if(otmp->otyp == RIN_INCREASE_DAMAGE)
346.  			otmp->spe = 0;
347.  		    artiexist[m] = mod;
348.  		    break;
349.  		}
350.  	return;
351.  }
352.  
353.  int
354.  nartifact_exist()
355.  {
356.      int a = 0;
357.      int n = SIZE(artiexist);
358.  
359.      while(n > 1)
360.  	if(artiexist[--n]) a++;
361.  
362.      return a;
363.  }
364.  #endif /* OVLB */
365.  #ifdef OVL0
366.  
367.  boolean
368.  spec_ability(otmp, abil)
369.  struct obj *otmp;
370.  unsigned long abil;
371.  {
372.  	const struct artifact *arti = get_artifact(otmp);
373.  
374.  	return((boolean)(arti && (arti->spfx & abil)));
375.  }
376.  
377.  /* used so that callers don't need to known about SPFX_ codes */
378.  boolean
379.  confers_luck(obj)
380.  struct obj *obj;
381.  {
382.      /* might as well check for this too */
383.      if (obj->otyp == LUCKSTONE) return TRUE;
384.  
385.      if (obj->otyp == FEDORA && obj == uarmh) return TRUE;
386.  
387.      return (obj->oartifact && spec_ability(obj, SPFX_LUCK));
388.  }
389.  
390.  /* used to check whether a monster is getting reflection from an artifact */
391.  boolean
392.  arti_reflects(obj)
393.  struct obj *obj;
394.  {
395.      const struct artifact *arti = get_artifact(obj);
396.  
397.      if (arti) {      
398.  	/* while being worn */
399.  	if ((obj->owornmask & ~W_ART) && (arti->spfx & SPFX_REFLECT))
400.  	    return TRUE;
401.  	/* just being carried */
402.  	if (arti->cspfx & SPFX_REFLECT) return TRUE;
403.      }
404.      return FALSE;
405.  }
406.  
407.  #endif /* OVL0 */
408.  #ifdef OVLB
409.  
410.  boolean
411.  restrict_name(otmp, name)  /* returns 1 if name is restricted for otmp->otyp */
412.  register struct obj *otmp;
413.  register const char *name;
414.  {
415.  	register const struct artifact *a;
416.  	register const char *aname;
417.  
418.  	if (!*name) return FALSE;
419.  	if (!strncmpi(name, "the ", 4)) name += 4;
420.  
421.  		/* Since almost every artifact is SPFX_RESTR, it doesn't cost
422.  		   us much to do the string comparison before the spfx check.
423.  		   Bug fix:  don't name multiple elven daggers "Sting".
424.  		 */
425.  	for (a = artilist+1; a->otyp; a++) {
426.  	    if (a->otyp != otmp->otyp) continue;
427.  	    aname = a->name;
428.  	    if (!strncmpi(aname, "the ", 4)) aname += 4;
429.  	    if (!strcmp(aname, name))
430.  		return ((boolean)((a->spfx & (SPFX_NOGEN|SPFX_RESTR)) != 0 ||
431.  			otmp->quan > 1L));
432.  	}
433.  
434.  	return FALSE;
435.  }
436.  
437.  STATIC_OVL boolean
438.  attacks(adtyp, otmp)
439.  register int adtyp;
440.  register struct obj *otmp;
441.  {
442.  	register const struct artifact *weap;
443.  
444.  	if ((weap = get_artifact(otmp)) != 0)
445.  		return((boolean)(weap->attk.adtyp == adtyp));
446.  	return FALSE;
447.  }
448.  
449.  boolean
450.  defends(adtyp, otmp)
451.  register int adtyp;
452.  register struct obj *otmp;
453.  {
454.  	register const struct artifact *weap;
455.  
456.  	if ((weap = get_artifact(otmp)) != 0)
457.  		return((boolean)(weap->defn.adtyp == adtyp));
458.  	return FALSE;
459.  }
460.  
461.  /* used for monsters */
462.  boolean
463.  protects(adtyp, otmp)
464.  int adtyp;
465.  struct obj *otmp;
466.  {
467.  	register const struct artifact *weap;
468.  
469.  	if ((weap = get_artifact(otmp)) != 0)
470.  		return (boolean)(weap->cary.adtyp == adtyp);
471.  	return FALSE;
472.  }
473.  
474.  /*
475.   * a potential artifact has just been worn/wielded/picked-up or
476.   * unworn/unwielded/dropped.  Pickup/drop only set/reset the W_ART mask.
477.   */
478.  void
479.  set_artifact_intrinsic(otmp,on,wp_mask)
480.  register struct obj *otmp;
481.  boolean on;
482.  long wp_mask;
483.  {
484.  	long *mask = 0;
485.  	register const struct artifact *oart = get_artifact(otmp);
486.  	uchar dtyp;
487.  	long spfx;
488.  
489.  	if (!oart) return;
490.  
491.  	/* effects from the defn field */
492.  	dtyp = (wp_mask != W_ART) ? oart->defn.adtyp : oart->cary.adtyp;
493.  
494.  	if (dtyp == AD_FIRE)
495.  	    mask = &EFire_resistance;
496.  	else if (dtyp == AD_COLD)
497.  	    mask = &ECold_resistance;
498.  	else if (dtyp == AD_ELEC)
499.  	    mask = &EShock_resistance;
500.  	else if (dtyp == AD_MAGM)
501.  	    mask = &EAntimagic;
502.  	else if (dtyp == AD_DISN)
503.  	    mask = &EDisint_resistance;
504.  	else if (dtyp == AD_DRST)
505.  	    mask = &EPoison_resistance;
506.  
507.  	if (mask && wp_mask == W_ART && !on) {
508.  	    /* find out if some other artifact also confers this intrinsic */
509.  	    /* if so, leave the mask alone */
510.  	    register struct obj* obj;
511.  	    for(obj = invent; obj; obj = obj->nobj)
512.  		if(obj != otmp && obj->oartifact) {
513.  		    register const struct artifact *art = get_artifact(obj);
514.  		    if(art->cary.adtyp == dtyp) {
515.  			mask = (long *) 0;
516.  			break;
517.  		    }
518.  		}
519.  	}
520.  	if(mask) {
521.  	    if (on) *mask |= wp_mask;
522.  	    else *mask &= ~wp_mask;
523.  	}
524.  
525.  	/* intrinsics from the spfx field; there could be more than one */
526.  	spfx = (wp_mask != W_ART) ? oart->spfx : oart->cspfx;
527.  	if(spfx && wp_mask == W_ART && !on) {
528.  	    /* don't change any spfx also conferred by other artifacts */
529.  	    register struct obj* obj;
530.  	    for(obj = invent; obj; obj = obj->nobj)
531.  		if(obj != otmp && obj->oartifact) {
532.  		    register const struct artifact *art = get_artifact(obj);
533.  		    spfx &= ~art->cspfx;
534.  		}
535.  	}
536.  
537.  	if (spfx & SPFX_SEARCH) {
538.  	    if(on) ESearching |= wp_mask;
539.  	    else ESearching &= ~wp_mask;
540.  	}
541.  	if (spfx & SPFX_HALRES) {
542.  	    /* make_hallucinated must (re)set the mask itself to get
543.  	     * the display right */
544.  	    /* restoring needed because this is the only artifact intrinsic
545.  	     * that can print a message--need to guard against being printed
546.  	     * when restoring a game
547.  	     */
548.  	    (void) make_hallucinated((long)!on, restoring ? FALSE : TRUE, wp_mask);
549.  	}
550.  	if (spfx & SPFX_ESP) {
551.  	    if(on) ETelepat |= wp_mask;
552.  	    else ETelepat &= ~wp_mask;
553.  	    see_monsters();
554.  	}
555.  	if (spfx & SPFX_STLTH) {
556.  	    if (on) EStealth |= wp_mask;
557.  	    else EStealth &= ~wp_mask;
558.  	}
559.  	if (spfx & SPFX_REGEN) {
560.  	    if (on) ERegeneration |= wp_mask;
561.  	    else ERegeneration &= ~wp_mask;
562.  	}
563.  	if (spfx & SPFX_TCTRL) {
564.  	    if (on) ETeleport_control |= wp_mask;
565.  	    else ETeleport_control &= ~wp_mask;
566.  	}
567.  	/* weapon warning is specially handled in mon.c */
568.  	if (spfx & SPFX_WARN) {
569.  	    if (spec_m2(otmp)) {
570.  	    	if (on) {
571.  			EWarn_of_mon |= wp_mask;
572.  			flags.warntype |= spec_m2(otmp);
573.  	    	} else {
574.  			EWarn_of_mon &= ~wp_mask;
575.  	    		flags.warntype &= ~spec_m2(otmp);
576.  		}
577.  		see_monsters();
578.  	    } else {
579.  		if (on) EWarning |= wp_mask;
580.  	    	else EWarning &= ~wp_mask;
581.  	    }
582.  	}
583.  	if (spfx & SPFX_EREGEN) {
584.  	    if (on) EEnergy_regeneration |= wp_mask;
585.  	    else EEnergy_regeneration &= ~wp_mask;
586.  	}
587.  	if (spfx & SPFX_HSPDAM) {
588.  	    if (on) EHalf_spell_damage |= wp_mask;
589.  	    else EHalf_spell_damage &= ~wp_mask;
590.  	}
591.  	if (spfx & SPFX_HPHDAM) {
592.  	    if (on) EHalf_physical_damage |= wp_mask;
593.  	    else EHalf_physical_damage &= ~wp_mask;
594.  	}
595.  	if (spfx & SPFX_XRAY) {
596.  	    /* this assumes that no one else is using xray_range */
597.  	    if (on) u.xray_range = 3;
598.  	    else u.xray_range = -1;
599.  	    vision_full_recalc = 1;
600.  	}
601.  	/* KMH -- Reflection when wielded */
602.  	if ((spfx & SPFX_REFLECT) && (wp_mask & W_WEP)) {
603.  	    if (on) EReflecting |= wp_mask;
604.  	    else EReflecting &= ~wp_mask;
605.  	}
606.  
607.  	if(wp_mask == W_ART && !on && oart->inv_prop) {
608.  	    /* might have to turn off invoked power too */
609.  	    if (oart->inv_prop <= LAST_PROP &&
610.  		(u.uprops[oart->inv_prop].extrinsic & W_ARTI))
611.  		(void) arti_invoke(otmp);
612.  	}
613.  }
614.  
615.  /*
616.   * creature (usually player) tries to touch (pick up or wield) an artifact obj.
617.   * Returns 0 if the object refuses to be touched.
618.   * This routine does not change any object chains.
619.   * Ignores such things as gauntlets, assuming the artifact is not
620.   * fooled by such trappings.
621.   */
622.  int
623.  touch_artifact(obj,mon)
624.      struct obj *obj;
625.      struct monst *mon;
626.  {
627.      register const struct artifact *oart = get_artifact(obj);
628.      boolean badclass, badalign, self_willed, yours;
629.  
630.      if(!oart) return 1;
631.  
632.      /* [ALI] Thiefbane has a special affinity with shopkeepers */
633.      if (mon->isshk && obj->oartifact == ART_THIEFBANE) return 1;
634.  
635.      yours = (mon == &youmonst);
636.      /* all quest artifacts are self-willed; it this ever changes, `badclass'
637.         will have to be extended to explicitly include quest artifacts */
638.      self_willed = ((oart->spfx & SPFX_INTEL) != 0);
639.      if (yours) {
640.  	badclass = self_willed &&
641.  		   ((oart->role != NON_PM && !Role_if(oart->role)) ||
642.  		    (oart->race != NON_PM && !Race_if(oart->race)));
643.  	badalign = (oart->spfx & SPFX_RESTR) && oart->alignment != A_NONE &&
644.  		   (oart->alignment != u.ualign.type || u.ualign.record < 0);
645.      } else if (!is_covetous(mon->data) && !is_mplayer(mon->data)) {
646.  	badclass = self_willed &&
647.  		   oart->role != NON_PM && oart != &artilist[ART_EXCALIBUR];
648.  	badalign = (oart->spfx & SPFX_RESTR) && oart->alignment != A_NONE &&
649.  		   (oart->alignment != sgn(mon->data->maligntyp));
650.      } else {    /* an M3_WANTSxxx monster or a fake player */
651.  	/* special monsters trying to take the Amulet, invocation tools or
652.  	   quest item can touch anything except for `spec_applies' artifacts */
653.  	badclass = badalign = FALSE;
654.      }
655.      /* weapons which attack specific categories of monsters are
656.         bad for them even if their alignments happen to match */
657.      if (!badalign && (oart->spfx & SPFX_DBONUS) != 0) {
658.  	struct artifact tmp;
659.  
660.  	tmp = *oart;
661.  	tmp.spfx &= SPFX_DBONUS;
662.  	badalign = !!spec_applies(&tmp, mon);
663.      }
664.  
665.      if (((badclass || badalign) && self_willed) ||
666.         (badalign && (!yours || !rn2(4))))  {
667.  	int dmg;
668.  	char buf[BUFSZ];
669.  
670.  	if (!yours) return 0;
671.  	You("are blasted by %s power!", s_suffix(the(xname(obj))));
672.  	dmg = d((Antimagic ? 6 : 8), (self_willed ? 10 : 6));
673.  	Sprintf(buf, "touching %s", oart->name);
674.  	losehp(dmg, buf, KILLED_BY);
675.  	exercise(A_WIS, FALSE);
676.      }
677.  
678.      /* can pick it up unless you're totally non-synch'd with the artifact */
679.      if (badclass && badalign && self_willed) {
680.  	if (yours) pline("%s your grasp!", Tobjnam(obj, "evade"));
681.  	return 0;
682.      }
683.  
684.      return 1;
685.  }
686.  
687.  #endif /* OVLB */
688.  #ifdef OVL1
689.  
690.  /* decide whether an artifact's special attacks apply against mtmp */
691.  STATIC_OVL int
692.  spec_applies(weap, mtmp)
693.  register const struct artifact *weap;
694.  struct monst *mtmp;
695.  {
696.  	int retval = TRUE;
697.  	struct permonst *ptr;
698.  	boolean yours;
699.  
700.  	if(!(weap->spfx & (SPFX_DBONUS | SPFX_ATTK)))
701.  	    return(weap->attk.adtyp == AD_PHYS);
702.  
703.  	yours = (mtmp == &youmonst);
704.  	ptr = mtmp->data;
705.  
706.  	/* [ALI] Modified to support multiple DBONUS and ATTK flags set.
707.  	 * Not all combinations are possible because many DBONUS flags
708.  	 * use mtype and would conflict. Where combinations are possible,
709.  	 * both checks must pass in order for the special attack to
710.  	 * apply against mtmp.
711.  	 */
712.  	if (weap->spfx & SPFX_DMONS) {
713.  	    retval &= (ptr == &mons[(int)weap->mtype]);
714.  	} else if (weap->spfx & SPFX_DCLAS) {
715.  	    retval &= (weap->mtype == (unsigned long)ptr->mlet);
716.  	} else if (weap->spfx & SPFX_DFLAG1) {
717.  	    retval &= ((ptr->mflags1 & weap->mtype) != 0L);
718.  	} else if (weap->spfx & SPFX_DFLAG2) {
719.  	    retval &= ((ptr->mflags2 & weap->mtype) || (yours &&
720.  			   ((!Upolyd && (urace.selfmask & weap->mtype)) ||
721.  			    ((weap->mtype & M2_WERE) && u.ulycn >= LOW_PM))));
722.  	}
723.  	if (weap->spfx & SPFX_DALIGN) {
724.  	    retval &= yours ? (u.ualign.type != weap->alignment) :
725.  			   (ptr->maligntyp == A_NONE ||
726.  				sgn(ptr->maligntyp) != weap->alignment);
727.  	}
728.  	if (weap->spfx & SPFX_ATTK) {
729.  	    struct obj *defending_weapon = (yours ? uwep : MON_WEP(mtmp));
730.  
731.  	    if (defending_weapon && defending_weapon->oartifact &&
732.  		    defends((int)weap->attk.adtyp, defending_weapon))
733.  		return FALSE;
734.  	    switch(weap->attk.adtyp) {
735.  		case AD_FIRE:
736.  			if (yours ? Fire_resistance : resists_fire(mtmp))
737.  			    retval = FALSE;
738.  			break;
739.  		case AD_COLD:
740.  			if (yours ? Cold_resistance : resists_cold(mtmp))
741.  			    retval = FALSE;
742.  			break;
743.  		case AD_ELEC:
744.  			if (yours ? Shock_resistance : resists_elec(mtmp))
745.  			    retval = FALSE;
746.  			break;
747.  		case AD_MAGM:
748.  		case AD_STUN:
749.  			if (yours ? Antimagic : (rn2(100) < ptr->mr))
750.  			    retval = FALSE;
751.  			break;
752.  		case AD_DRST:
753.  			if (yours ? Poison_resistance : resists_poison(mtmp))
754.  			    retval = FALSE;
755.  			break;
756.  		case AD_DRLI:
757.  			if (yours ? Drain_resistance : resists_drli(mtmp))
758.  			    retval = FALSE;
759.  			break;
760.  		case AD_STON:
761.  			if (yours ? Stone_resistance : resists_ston(mtmp))
762.  			    retval = FALSE;
763.  			break;
764.  		default:	impossible("Weird weapon special attack.");
765.  	    }
766.  	}
767.  	return retval;
768.  }
769.  
770.  /* return the M2 flags of monster that an artifact's special attacks apply against */
771.  long
772.  spec_m2(otmp)
773.  struct obj *otmp;
774.  {
775.  	register const struct artifact *artifact = get_artifact(otmp);
776.  	if (artifact)
777.  		return artifact->mtype;
778.  	return 0L;
779.  }
780.  
781.  /* special attack bonus */
782.  int
783.  spec_abon(otmp, mon)
784.  struct obj *otmp;
785.  struct monst *mon;
786.  {
787.  	register const struct artifact *weap = get_artifact(otmp);
788.  
789.  	/* no need for an extra check for `NO_ATTK' because this will
790.  	   always return 0 for any artifact which has that attribute */
791.  
792.  	if (weap && weap->attk.damn && spec_applies(weap, mon))
793.  	    return (int)weap->attk.damn;
794.  	return 0;
795.  }
796.  
797.  /* special damage bonus */
798.  int
799.  spec_dbon(otmp, mon, tmp)
800.  struct obj *otmp;
801.  struct monst *mon;
802.  int tmp;
803.  {
804.  	register const struct artifact *weap = get_artifact(otmp);
805.  
806.  	if (!weap || (weap->attk.adtyp == AD_PHYS && /* check for `NO_ATTK' */
807.  			weap->attk.damn == 0 && weap->attk.damd == 0))
808.  	    spec_dbon_applies = FALSE;
809.  	else
810.  	    spec_dbon_applies = spec_applies(weap, mon);
811.  
812.  	if (spec_dbon_applies)
813.  	    return weap->attk.damd ? (int)weap->attk.damd :
814.  		    /* [ALI] Unlike melee weapons, damd == 0 means no
815.  		     * bonus for launchers.
816.  		     */
817.  		    is_launcher(otmp) ? 0 : max(tmp,1);
818.  	return 0;
819.  }
820.  
821.  /* add identified artifact to discoveries list */
822.  void
823.  discover_artifact(m)
824.  xchar m;
825.  {
826.      int i;
827.  
828.      /* look for this artifact in the discoveries list;
829.         if we hit an empty slot then it's not present, so add it */
830.      for (i = 0; i < NROFARTIFACTS; i++)
831.  	if (artidisco[i] == 0 || artidisco[i] == m) {
832.  	    artidisco[i] = m;
833.  	    return;
834.  	}
835.      /* there is one slot per artifact, so we should never reach the
836.         end without either finding the artifact or an empty slot... */
837.      impossible("couldn't discover artifact (%d)", (int)m);
838.  }
839.  
840.  /* used to decide whether an artifact has been fully identified */
841.  boolean
842.  undiscovered_artifact(m)
843.  xchar m;
844.  {
845.      int i;
846.  
847.      /* look for this artifact in the discoveries list;
848.         if we hit an empty slot then it's undiscovered */
849.      for (i = 0; i < NROFARTIFACTS; i++)
850.  	if (artidisco[i] == m)
851.  	    return FALSE;
852.  	else if (artidisco[i] == 0)
853.  	    break;
854.      return TRUE;
855.  }
856.  
857.  /* display a list of discovered artifacts; return their count */
858.  int
859.  disp_artifact_discoveries(tmpwin)
860.  winid tmpwin;		/* supplied by dodiscover() */
861.  {
862.      int i, m, otyp;
863.      char buf[BUFSZ];
864.      anything any;
865.  
866.      any.a_void = 0;
867.      for (i = 0; i < NROFARTIFACTS; i++) {
868.  	if (artidisco[i] == 0) break;	/* empty slot implies end of list */
869.  	if (i == 0)
870.  	    add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings,
871.  	      "Artifacts", MENU_UNSELECTED);
872.  	m = artidisco[i];
873.  	otyp = artilist[m].otyp;
874.  	Sprintf(buf, "  %s [%s %s]", artiname(m),
875.  		align_str(artilist[m].alignment), simple_typename(otyp));
876.  	add_menu(tmpwin, objnum_to_glyph(otyp), &any, 0, 0, ATR_NONE,
877.  	  buf, MENU_UNSELECTED);
878.      }
879.      return i;
880.  }
881.  
882.  #endif /* OVL1 */
883.  
884.  #ifdef OVLB
885.  
886.  
887.  	/*
888.  	 * Magicbane's intrinsic magic is incompatible with normal
889.  	 * enchantment magic.  Thus, its effects have a negative
890.  	 * dependence on spe.  Against low mr victims, it typically
891.  	 * does "double athame" damage, 2d4.  Occasionally, it will
892.  	 * cast unbalancing magic which effectively averages out to
893.  	 * 4d4 damage (3d4 against high mr victims), for spe = 0.
894.  	 *
895.  	 * Prior to 3.4.1, the cancel (aka purge) effect always
896.  	 * included the scare effect too; now it's one or the other.
897.  	 * Likewise, the stun effect won't be combined with either
898.  	 * of those two; it will be chosen separately or possibly
899.  	 * used as a fallback when scare or cancel fails.
900.  	 *
901.  	 * [Historical note: a change to artifact_hit() for 3.4.0
902.  	 * unintentionally made all of Magicbane's special effects
903.  	 * be blocked if the defender successfully saved against a
904.  	 * stun attack.  As of 3.4.1, those effects can occur but
905.  	 * will be slightly less likely than they were in 3.3.x.]
906.  	 */
907.  #define MB_MAX_DIEROLL		8	/* rolls above this aren't magical */
908.  static const char * const mb_verb[2][4] = {
909.  	{ "probe", "stun", "scare", "cancel" },
910.  	{ "prod", "amaze", "tickle", "purge" },
911.  };
912.  #define MB_INDEX_PROBE		0
913.  #define MB_INDEX_STUN		1
914.  #define MB_INDEX_SCARE		2
915.  #define MB_INDEX_CANCEL		3
916.  
917.  /* called when someone is being hit by Magicbane */
918.  STATIC_OVL boolean
919.  Mb_hit(magr, mdef, mb, dmgptr, dieroll, vis, hittee)
920.  struct monst *magr, *mdef;	/* attacker and defender */
921.  struct obj *mb;			/* Magicbane */
922.  int *dmgptr;			/* extra damage target will suffer */
923.  int dieroll;			/* d20 that has already scored a hit */
924.  boolean vis;			/* whether the action can be seen */
925.  char *hittee;			/* target's name: "you" or mon_nam(mdef) */
926.  {
927.      struct permonst *old_uasmon;
928.      const char *verb;
929.      boolean youattack = (magr == &youmonst),
930.  	    youdefend = (mdef == &youmonst),
931.  	    resisted = FALSE, do_stun, do_confuse, result;
932.      int attack_indx, scare_dieroll = MB_MAX_DIEROLL / 2;
933.  
934.      result = FALSE;		/* no message given yet */
935.      /* the most severe effects are less likely at higher enchantment */
936.      if (mb->spe >= 3)
937.  	scare_dieroll /= (1 << (mb->spe / 3));
938.      /* if target successfully resisted the artifact damage bonus,
939.         reduce overall likelihood of the assorted special effects */
940.      if (!spec_dbon_applies) dieroll += 1;
941.  
942.      /* might stun even when attempting a more severe effect, but
943.         in that case it will only happen if the other effect fails;
944.         extra damage will apply regardless; 3.4.1: sometimes might
945.         just probe even when it hasn't been enchanted */
946.      do_stun = (max(mb->spe,0) < rn2(spec_dbon_applies ? 11 : 7));
947.  
948.      /* the special effects also boost physical damage; increments are
949.         generally cumulative, but since the stun effect is based on a
950.         different criterium its damage might not be included; the base
951.         damage is either 1d4 (athame) or 2d4 (athame+spec_dbon) depending
952.         on target's resistance check against AD_STUN (handled by caller)
953.         [note that a successful save against AD_STUN doesn't actually
954.         prevent the target from ending up stunned] */
955.      attack_indx = MB_INDEX_PROBE;
956.      *dmgptr += rnd(4);			/* (2..3)d4 */
957.      if (do_stun) {
958.  	attack_indx = MB_INDEX_STUN;
959.  	*dmgptr += rnd(4);		/* (3..4)d4 */
960.      }
961.      if (dieroll <= scare_dieroll) {
962.  	attack_indx = MB_INDEX_SCARE;
963.  	*dmgptr += rnd(4);		/* (3..5)d4 */
964.      }
965.      if (dieroll <= (scare_dieroll / 2)) {
966.  	attack_indx = MB_INDEX_CANCEL;
967.  	*dmgptr += rnd(4);		/* (4..6)d4 */
968.      }
969.  
970.      /* give the hit message prior to inflicting the effects */
971.      verb = mb_verb[!!Hallucination][attack_indx];
972.      if (youattack || youdefend || vis) {
973.  	result = TRUE;
974.  	pline_The("magic-absorbing blade %s %s!",
975.  		  vtense((const char *)0, verb), hittee);
976.  	/* assume probing has some sort of noticeable feedback
977.  	   even if it is being done by one monster to another */
978.  	if (attack_indx == MB_INDEX_PROBE && !canspotmon(mdef))
979.  	    map_invisible(mdef->mx, mdef->my);
980.      }
981.  
982.      /* now perform special effects */
983.      switch (attack_indx) {
984.      case MB_INDEX_CANCEL:
985.  	old_uasmon = youmonst.data;
986.  	/* No mdef->mcan check: even a cancelled monster can be polymorphed
987.  	 * into a golem, and the "cancel" effect acts as if some magical
988.  	 * energy remains in spellcasting defenders to be absorbed later.
989.  	 */
990.  	if (!cancel_monst(mdef, mb, youattack, FALSE, FALSE)) {
991.  	    resisted = TRUE;
992.  	} else {
993.  	    do_stun = FALSE;
994.  	    if (youdefend) {
995.  		if (youmonst.data != old_uasmon)
996.  		    *dmgptr = 0;    /* rehumanized, so no more damage */
997.  		if (u.uenmax > 0) {
998.  		    You("lose magical energy!");
999.  		    u.uenmax--;
1000. 		    if (u.uen > 0) u.uen--;
1001. 		    flags.botl = 1;
1002. 		}
1003. 	    } else {
1004. 		if (mdef->data == &mons[PM_CLAY_GOLEM])
1005. 		    mdef->mhp = 1;	/* cancelled clay golems will die */
1006. 		if (youattack && attacktype(mdef->data, AT_MAGC)) {
1007. 		    You("absorb magical energy!");
1008. 		    u.uenmax++;
1009. 		    u.uen++;
1010. 		    flags.botl = 1;
1011. 		}
1012. 	    }
1013. 	}
1014. 	break;
1015. 
1016.     case MB_INDEX_SCARE:
1017. 	if (youdefend) {
1018. 	    if (Antimagic) {
1019. 		resisted = TRUE;
1020. 	    } else {
1021. 		nomul(-3);
1022. 		nomovemsg = "";
1023. 		if (magr && magr == u.ustuck && sticks(youmonst.data)) {
1024. 		    setustuck((struct monst *)0);
1025. 		    You("release %s!", mon_nam(magr));
1026. 		}
1027. 	    }
1028. 	} else {
1029. 	    if (rn2(2) && resist(mdef, WEAPON_CLASS, 0, NOTELL))
1030. 		resisted = TRUE;
1031. 	    else
1032. 		monflee(mdef, 3, FALSE, (mdef->mhp > *dmgptr));
1033. 	}
1034. 	if (!resisted) do_stun = FALSE;
1035. 	break;
1036. 
1037.     case MB_INDEX_STUN:
1038. 	do_stun = TRUE;		/* (this is redundant...) */
1039. 	break;
1040. 
1041.     case MB_INDEX_PROBE:
1042. 	if (youattack && (mb->spe == 0 || !rn2(3 * abs(mb->spe)))) {
1043. 	    pline_The("%s is insightful.", verb);
1044. 	    /* pre-damage status */
1045. 	    probe_monster(mdef);
1046. 	}
1047. 	break;
1048.     }
1049.     /* stun if that was selected and a worse effect didn't occur */
1050.     if (do_stun) {
1051. 	if (youdefend)
1052. 	    make_stunned((HStun + 3), FALSE);
1053. 	else
1054. 	    mdef->mstun = 1;
1055. 	/* avoid extra stun message below if we used mb_verb["stun"] above */
1056. 	if (attack_indx == MB_INDEX_STUN) do_stun = FALSE;
1057.     }
1058.     /* lastly, all this magic can be confusing... */
1059.     do_confuse = !rn2(12);
1060.     if (do_confuse) {
1061. 	if (youdefend)
1062. 	    make_confused(HConfusion + 4, FALSE);
1063. 	else
1064. 	    mdef->mconf = 1;
1065.     }
1066. 
1067.     if (youattack || youdefend || vis) {
1068. 	(void) upstart(hittee);	/* capitalize */
1069. 	if (resisted) {
1070. 	    pline("%s %s!", hittee, vtense(hittee, "resist"));
1071. 	    shieldeff(youdefend ? u.ux : mdef->mx,
1072. 		      youdefend ? u.uy : mdef->my);
1073. 	}
1074. 	if ((do_stun || do_confuse) && flags.verbose) {
1075. 	    char buf[BUFSZ];
1076. 
1077. 	    buf[0] = '\0';
1078. 	    if (do_stun) Strcat(buf, "stunned");
1079. 	    if (do_stun && do_confuse) Strcat(buf, " and ");
1080. 	    if (do_confuse) Strcat(buf, "confused");
1081. 	    pline("%s %s %s%c", hittee, vtense(hittee, "are"),
1082. 		  buf, (do_stun && do_confuse) ? '!' : '.');
1083. 	}
1084.     }
1085. 
1086.     return result;
1087. }
1088.   
1089. /* Function used when someone attacks someone else with an artifact
1090.  * weapon.  Only adds the special (artifact) damage, and returns a 1 if it
1091.  * did something special (in which case the caller won't print the normal
1092.  * hit message).  This should be called once upon every artifact attack;
1093.  * dmgval() no longer takes artifact bonuses into account.  Possible
1094.  * extension: change the killer so that when an orc kills you with
1095.  * Stormbringer it's "killed by Stormbringer" instead of "killed by an orc".
1096.  */
1097. boolean
1098. artifact_hit(magr, mdef, otmp, dmgptr, dieroll)
1099. struct monst *magr, *mdef;
1100. struct obj *otmp;
1101. int *dmgptr;
1102. int dieroll; /* needed for Magicbane and vorpal blades */
1103. {
1104. 	boolean youattack = (magr == &youmonst);
1105. 	boolean youdefend = (mdef == &youmonst);
1106. 	boolean vis = (!youattack && magr && cansee(magr->mx, magr->my))
1107. 	    || (!youdefend && cansee(mdef->mx, mdef->my))
1108. 	    || (youattack && u.uswallow && mdef == u.ustuck && !Blind);
1109. 	boolean realizes_damage;
1110. 	const char *wepdesc;
1111. 	static const char you[] = "you";
1112. 	char hittee[BUFSIZ];
1113. 	boolean special_applies;
1114. 
1115. 	strcpy(hittee, youdefend ? you : mon_nam(mdef));
1116. 
1117. 	/* The following takes care of most of the damage, but not all--
1118. 	 * the exception being for level draining, which is specially
1119. 	 * handled.  Messages are done in this function, however.
1120. 	 */
1121. 	*dmgptr += spec_dbon(otmp, mdef, *dmgptr);
1122. 
1123. 	if (spec_dbon_applies)
1124. 	    special_applies = TRUE;
1125. 	else {
1126. 	    const struct artifact *weap = get_artifact(otmp);
1127. 	    special_applies = weap && spec_applies(weap, mdef);
1128. 	}
1129. 
1130. 	if (youattack && youdefend) {
1131. 	    impossible("attacking yourself with weapon?");
1132. 	    return FALSE;
1133. 	}
1134. 
1135. 	realizes_damage = (youdefend || vis || 
1136. 			   /* feel the effect even if not seen */
1137. 			   (youattack && mdef == u.ustuck));
1138. 
1139. 	/* the four basic attacks: fire, cold, shock and missiles */
1140. 	if (attacks(AD_FIRE, otmp)) {
1141. 	    if (realizes_damage)
1142. 		pline_The("fiery blade %s %s%c",
1143. 			!spec_dbon_applies ? "hits" :
1144. 			(mdef->data == &mons[PM_WATER_ELEMENTAL]) ?
1145. 			"vaporizes part of" : "burns",
1146. 			hittee, !spec_dbon_applies ? '.' : '!');
1147. 	    if (!rn2(4)) (void) destroy_mitem(mdef, POTION_CLASS, AD_FIRE);
1148. 	    if (!rn2(4)) (void) destroy_mitem(mdef, SCROLL_CLASS, AD_FIRE);
1149. 	    if (!rn2(7)) (void) destroy_mitem(mdef, SPBOOK_CLASS, AD_FIRE);
1150. 	    if (youdefend && Slimed) burn_away_slime();
1151. 	    return realizes_damage;
1152. 	}
1153. 	if (attacks(AD_COLD, otmp)) {
1154. 	    if (realizes_damage)
1155. 		pline_The("ice-cold blade %s %s%c",
1156. 			!spec_dbon_applies ? "hits" : "freezes",
1157. 			hittee, !spec_dbon_applies ? '.' : '!');
1158. 	    if (!rn2(4)) (void) destroy_mitem(mdef, POTION_CLASS, AD_COLD);
1159. 	    return realizes_damage;
1160. 	}
1161. 	if (attacks(AD_ELEC, otmp)) {
1162. 	    if (realizes_damage)
1163. 		pline_The("massive hammer hits%s %s%c",
1164. 			  !spec_dbon_applies ? "" : "!  Lightning strikes",
1165. 			  hittee, !spec_dbon_applies ? '.' : '!');
1166. 	    if (!rn2(5)) (void) destroy_mitem(mdef, RING_CLASS, AD_ELEC);
1167. 	    if (!rn2(5)) (void) destroy_mitem(mdef, WAND_CLASS, AD_ELEC);
1168. 	    return realizes_damage;
1169. 	}
1170. 	if (attacks(AD_MAGM, otmp)) {
1171. 	    if (realizes_damage)
1172. 		pline_The("imaginary widget hits%s %s%c",
1173. 			  !spec_dbon_applies ? "" :
1174. 				"!  A hail of magic missiles strikes",
1175. 			  hittee, !spec_dbon_applies ? '.' : '!');
1176. 	    return realizes_damage;
1177. 	}
1178. 
1179. 	if (attacks(AD_STUN, otmp) && dieroll <= MB_MAX_DIEROLL) {
1180. 	    /* Magicbane's special attacks (possibly modifies hittee[]) */
1181. 	    return Mb_hit(magr, mdef, otmp, dmgptr, dieroll, vis, hittee);
1182. 	}
1183. 
1184. 	if (!spec_dbon_applies && !spec_ability(otmp, SPFX_BEHEAD) ||
1185. 		!special_applies) {
1186. 	    /* since damage bonus didn't apply, nothing more to do;  
1187. 	       no further attacks have side-effects on inventory */
1188. 	    /* [ALI] The Tsurugi of Muramasa has no damage bonus but
1189. 	       is handled below so avoid early exit if SPFX_BEHEAD set
1190. 	       and the defender is vulnerable */
1191. 	    return FALSE;
1192. 	}
1193. 
1194. 	/* STEPHEN WHITE'S NEW CODE */
1195. 	if (otmp->oartifact == ART_SERPENT_S_TONGUE) {
1196. 	    otmp->dknown = TRUE;
1197. 	    pline_The("twisted blade poisons %s!",
1198. 		    youdefend ? "you" : mon_nam(mdef));
1199. 	    if (youdefend ? Poison_resistance : resists_poison(mdef)) {
1200. 		if (youdefend)
1201. 		    You("are not affected by the poison.");
1202. 		else
1203. 		    pline("%s seems unaffected by the poison.", Monnam(mdef));
1204. 		return TRUE;
1205. 	    }
1206. 	    switch (rnd(10)) {
1207. 		case 1:
1208. 		case 2:
1209. 		case 3:
1210. 		case 4:
1211. 		    *dmgptr += d(1,6) + 2;
1212. 		    break;
1213. 		case 5:
1214. 		case 6:
1215. 		case 7:
1216. 		    *dmgptr += d(2,6) + 4;
1217. 		    break;
1218. 		case 8:
1219. 		case 9:
1220. 		    *dmgptr += d(3,6) + 6;
1221. 		    break;
1222. 		case 10:
1223. 		    pline_The("poison was deadly...");
1224. 		    *dmgptr = 2 *
1225. 			    (youdefend ? Upolyd ? u.mh : u.uhp : mdef->mhp) +
1226. 			    FATAL_DAMAGE_MODIFIER;
1227. 		    break;
1228. 	    }
1229. 	    return TRUE;
1230. 	}
1231. 
1232.        if (otmp->oartifact == ART_DOOMBLADE && dieroll < 6) {
1233. 	    if (youattack)
1234. 		You("plunge the Doomblade deeply into %s!",
1235. 			mon_nam(mdef));
1236. 	    else
1237. 		pline("%s plunges the Doomblade deeply into %s!",
1238. 			Monnam(magr), hittee);
1239. 	    *dmgptr += rnd(4) * 5;
1240. 	    return TRUE;
1241.        }
1242.       /* END OF STEPHEN WHITE'S NEW CODE */
1243. 
1244. #if 0
1245. 	   if (otmp->oartifact == ART_SCALPEL && dieroll < 5) {
1246. 		/* faster than a speeding bullet is the Gray Mouser... */
1247. 		pline("There is a flurry of blows!");
1248. 		/* I suppose this could theoretically continue forever... */
1249. 		while (dieroll < 5) {
1250. 		   *dmgptr += rnd(8) + 1 + otmp->spe;
1251. 		   dieroll = rn2(11);
1252. 		}
1253. 	   }
1254. 	   if (otmp->oartifact == ART_HEARTSEEKER && dieroll < 3) {
1255. 		/* this weapon just sounds nasty... yuck... */
1256. 		if (!youdefend) {
1257. 		   You("plunge Heartseeker into %s!",mon_nam(mdef));
1258. 		} else {
1259. 		   pline("%s plunges Heartseeker into you!",mon_nam(mdef));
1260. 		}
1261. 		*dmgptr += rnd(6)+rnd(6)+rnd(6)+rnd(6)+4;
1262. 	   }
1263. #endif
1264. 
1265. 
1266. 	/* We really want "on a natural 20" but Nethack does it in */
1267. 	/* reverse from AD&D. */
1268. 	if (spec_ability(otmp, SPFX_BEHEAD)) {
1269. 	    if (otmp->oartifact == ART_TSURUGI_OF_MURAMASA && dieroll < 3) {
1270. 		wepdesc = "The razor-sharp blade";
1271. 		/* not really beheading, but so close, why add another SPFX */
1272. 		if (youattack && u.uswallow && mdef == u.ustuck) {
1273. 		    You("slice %s wide open!", mon_nam(mdef));
1274. 		    *dmgptr = 2 * mdef->mhp + FATAL_DAMAGE_MODIFIER;
1275. 		    return TRUE;
1276. 		}
1277. 		if (!youdefend) {
1278. 			/* allow normal cutworm() call to add extra damage */
1279. 			if(notonhead)
1280. 			    return FALSE;
1281. 
1282. 			if (bigmonst(mdef->data)) {
1283. 				if (youattack)
1284. 					You("slice deeply into %s!",
1285. 						mon_nam(mdef));
1286. 				else if (vis)
1287. 					pline("%s cuts deeply into %s!",
1288. 					      Monnam(magr), hittee);
1289. 				*dmgptr *= 2;
1290. 				return TRUE;
1291. 			}
1292. 			*dmgptr = 2 * mdef->mhp + FATAL_DAMAGE_MODIFIER;
1293. 			pline("%s cuts %s in half!", wepdesc, mon_nam(mdef));
1294. 			otmp->dknown = TRUE;
1295. 			return TRUE;
1296. 		} else {
1297. 			/* Invulnerable player won't be bisected */
1298. 			if (bigmonst(youmonst.data) || Invulnerable) {
1299. 				pline("%s cuts deeply into you!",
1300. 				      magr ? Monnam(magr) : wepdesc);
1301. 				*dmgptr *= 2;
1302. 				return TRUE;
1303. 			}
1304. 
1305. 			/* Players with negative AC's take less damage instead
1306. 			 * of just not getting hit.  We must add a large enough
1307. 			 * value to the damage so that this reduction in
1308. 			 * damage does not prevent death.
1309. 			 */
1310. 			*dmgptr = 2 * (Upolyd ? u.mh : u.uhp) + FATAL_DAMAGE_MODIFIER;
1311. 			pline("%s cuts you in half!", wepdesc);
1312. 			otmp->dknown = TRUE;
1313. 			return TRUE;
1314. 		}
1315. 	    } else if (dieroll < 3 || otmp->oartifact == ART_VORPAL_BLADE &&
1316. 				      mdef->data == &mons[PM_JABBERWOCK]) {
1317. 		static const char * const behead_msg[2] = {
1318. 		     "%s beheads %s!",
1319. 		     "%s decapitates %s!"
1320. 		};
1321. 
1322. 		if (youattack && u.uswallow && mdef == u.ustuck)
1323. 			return FALSE;
1324. 		wepdesc = artilist[otmp->oartifact].name;
1325. 		if (!youdefend) {
1326. 			if (!has_head(mdef->data) || notonhead || u.uswallow) {
1327. 				if (youattack)
1328. 					pline("Somehow, you miss %s wildly.",
1329. 						mon_nam(mdef));
1330. 				else if (vis)
1331. 					pline("Somehow, %s misses wildly.",
1332. 						mon_nam(magr));
1333. 				*dmgptr = 0;
1334. 				return ((boolean)(youattack || vis));
1335. 			}
1336. 			if (noncorporeal(mdef->data) || amorphous(mdef->data)) {
1337. 				pline("%s slices through %s %s.", wepdesc,
1338. 				      s_suffix(mon_nam(mdef)),
1339. 				      mbodypart(mdef,NECK));
1340. 				return TRUE;
1341. 			}
1342. 			*dmgptr = 2 * mdef->mhp + FATAL_DAMAGE_MODIFIER;
1343. 			pline(behead_msg[rn2(SIZE(behead_msg))],
1344. 			      wepdesc, mon_nam(mdef));
1345. 			otmp->dknown = TRUE;
1346. 			return TRUE;
1347. 		} else {
1348. 			if (!has_head(youmonst.data)) {
1349. 				pline("Somehow, %s misses you wildly.",
1350. 				      magr ? mon_nam(magr) : wepdesc);
1351. 				*dmgptr = 0;
1352. 				return TRUE;
1353. 			}
1354. 			if (noncorporeal(youmonst.data) || amorphous(youmonst.data)) {
1355. 				pline("%s slices through your %s.",
1356. 				      wepdesc, body_part(NECK));
1357. 				return TRUE;
1358. 			}
1359. 			*dmgptr = 2 * (Upolyd ? u.mh : u.uhp)
1360. 				  + FATAL_DAMAGE_MODIFIER;
1361. 			if (Invulnerable) {
1362. 				pline("%s slices into your %s.",
1363. 				      wepdesc, body_part(NECK));
1364. 				return TRUE;
1365. 			}
1366. 			pline(behead_msg[rn2(SIZE(behead_msg))],
1367. 			      wepdesc, "you");
1368. 			otmp->dknown = TRUE;
1369. 			/* Should amulets fall off? */
1370. 			return TRUE;
1371. 		}
1372. 	    }
1373. 	}
1374. 	if (spec_ability(otmp, SPFX_DRLI)) {
1375. 		if (!youdefend) {
1376. 		    if (!resists_drli(mdef)) {
1377. 			if (vis) {
1378. 			    if(otmp->oartifact == ART_STORMBRINGER)
1379. 				pline_The("%s blade draws the life from %s!",
1380. 				      hcolor(NH_BLACK),
1381. 				      mon_nam(mdef));
1382. #if 0	/* OBSOLETE */
1383. 			    else if(otmp->oartifact == ART_TENTACLE_STAFF)
1384. 				pline("The writhing tentacles draw the life from %s!",
1385. 				      mon_nam(mdef));
1386. #endif
1387. 			    else
1388. 				pline("%s draws the life from %s!",
1389. 				      The(distant_name(otmp, xname)),
1390. 				      mon_nam(mdef));
1391. 			}
1392. 			if (mdef->m_lev == 0) {
1393. 			    *dmgptr = 2 * mdef->mhp + FATAL_DAMAGE_MODIFIER;
1394. 			} else {
1395. 			    int drain = rnd(8);
1396. 			    *dmgptr += drain;
1397. 			    mdef->mhpmax -= drain;
1398. 			    mdef->m_lev--;
1399. 			    drain /= 2;
1400. 			    if (drain) healup(drain, 0, FALSE, FALSE);
1401. 			}
1402. 			return vis;
1403. 		    }
1404. 		} else if (!Drain_resistance) { /* youdefend */
1405. 			int oldhpmax = u.uhpmax;
1406. 
1407. 			if (Blind)
1408. 				You_feel("an %s drain your life!",
1409. 				    otmp->oartifact == ART_STORMBRINGER ?
1410. 				    "unholy blade" : "object");
1411. 			else if (otmp->oartifact == ART_STORMBRINGER)
1412. 				pline_The("%s blade drains your life!",
1413. 				      hcolor(NH_BLACK));
1414. 			else
1415. 				pline("%s drains your life!",
1416. 				      The(distant_name(otmp, xname)));
1417. 			losexp("life drainage", FALSE);
1418. 			if (magr && magr->mhp < magr->mhpmax) {
1419. 			    magr->mhp += (oldhpmax - u.uhpmax)/2;
1420. 			    if (magr->mhp > magr->mhpmax) magr->mhp = magr->mhpmax;
1421. 			}
1422. 			return TRUE;
1423. 		}
1424. 	}
1425. 	/* WAC -- 1/6 chance of cancellation with foobane weapons */
1426. 	if (otmp->oartifact == ART_GIANTKILLER ||
1427. 	    otmp->oartifact == ART_ORCRIST ||
1428. 	    otmp->oartifact == ART_DRAGONBANE ||
1429. 	    otmp->oartifact == ART_DEMONBANE ||
1430. 	    otmp->oartifact == ART_WEREBANE ||
1431. 	    otmp->oartifact == ART_TROLLSBANE ||
1432. #ifdef BLACKMARKET
1433. 	    otmp->oartifact == ART_THIEFBANE ||
1434. #endif
1435. 	    otmp->oartifact == ART_OGRESMASHER ||
1436. 	    otmp->oartifact == ART_ELFRIST) {
1437. 		if (dieroll < 4) {
1438. 		    if (realizes_damage) {
1439. 			pline("%s %s!", The(distant_name(otmp, xname)), Blind ?
1440. 				"roars deafeningly" : "shines brilliantly");
1441. 			pline("It strikes %s!", hittee);
1442. 		    }
1443. 		    cancel_monst(mdef, otmp, youattack, TRUE, magr == mdef);
1444. 		    return TRUE;
1445. 		}
1446. 	}
1447. 	return FALSE;
1448. }
1449. 
1450. static NEARDATA const char recharge_type[] = { ALLOW_COUNT, ALL_CLASSES, 0 };
1451. static NEARDATA const char invoke_types[] = { ALL_CLASSES, 0 };
1452. 		/* #invoke: an "ugly check" filters out most objects */
1453. 
1454. int
1455. doinvoke()
1456. {
1457.     register struct obj *obj;
1458. 
1459.     obj = getobj(invoke_types, "invoke");
1460.     if (!obj) return 0;
1461.     if (obj->oartifact && !touch_artifact(obj, &youmonst)) return 1;
1462.     return arti_invoke(obj);
1463. }
1464. 
1465. STATIC_OVL int
1466. arti_invoke(obj)
1467.     register struct obj *obj;
1468. {
1469.     register const struct artifact *oart = get_artifact(obj);
1470. 	    register struct monst *mtmp;
1471. 	    register struct monst *mtmp2;
1472. 	    register struct permonst *pm;
1473. 
1474.     int summon_loop;
1475.     int unseen;
1476. /*
1477.     int kill_loop;
1478.  */
1479. 
1480.     if(!oart || !oart->inv_prop) {
1481. 	if(obj->otyp == CRYSTAL_BALL)
1482. 	    use_crystal_ball(obj);
1483. 	else
1484. 	    pline(nothing_happens);
1485. 	return 1;
1486.     }
1487. 
1488.     if(oart->inv_prop > LAST_PROP) {
1489. 	/* It's a special power, not "just" a property */
1490. 	if(obj->age > monstermoves) {
1491. 	    /* the artifact is tired :-) */
1492. 	    You_feel("that %s %s ignoring you.",
1493. 		     the(xname(obj)), otense(obj, "are"));
1494. 	    /* and just got more so; patience is essential... */
1495. 	    obj->age += (long) d(3,10);
1496. 	    return 1;
1497. 	}
1498. 	obj->age = monstermoves + rnz(100);
1499. 
1500. 	switch(oart->inv_prop) {
1501. 	case TAMING: {
1502. 	    struct obj pseudo;
1503. 
1504. 	    pseudo = zeroobj;	/* neither cursed nor blessed */
1505. 	    pseudo.otyp = SCR_TAMING;
1506. 	    (void) seffects(&pseudo);
1507. 	    break;
1508. 	  }
1509. 	case HEALING: {
1510. 	    int healamt = (u.uhpmax + 1 - u.uhp) / 2;
1511. 	    long creamed = (long)u.ucreamed;
1512. 
1513. 	    if (Upolyd) healamt = (u.mhmax + 1 - u.mh) / 2;
1514. 	    if (healamt || Sick || Slimed || Blinded > creamed)
1515. 		You_feel("better.");
1516. 	    else
1517. 		goto nothing_special;
1518. 	    if (healamt > 0) {
1519. 		if (Upolyd) u.mh += healamt;
1520. 		else u.uhp += healamt;
1521. 	    }
1522. 	    if(Sick) make_sick(0L,(char *)0,FALSE,SICK_ALL);
1523. 	    if(Slimed) Slimed = 0L;
1524. 	    if (Blinded > creamed) make_blinded(creamed, FALSE);
1525. 	    flags.botl = 1;
1526. 	    break;
1527. 	  }
1528. 	case ENERGY_BOOST: {
1529. 	    int epboost = (u.uenmax + 1 - u.uen) / 2;
1530. 	    if (epboost > 120) epboost = 120;		/* arbitrary */
1531. 	    else if (epboost < 12) epboost = u.uenmax - u.uen;
1532. 	    if(epboost) {
1533. 		You_feel("re-energized.");
1534. 		u.uen += epboost;
1535. 		flags.botl = 1;
1536. 	    } else
1537. 		goto nothing_special;
1538. 	    break;
1539. 	  }
1540. 	case UNTRAP: {
1541. 	    if(!untrap(TRUE)) {
1542. 		obj->age = 0; /* don't charge for changing their mind */
1543. 		return 0;
1544. 	    }
1545. 	    break;
1546. 	  }
1547. 	case CHARGE_OBJ: {
1548. 	    struct obj *otmp = getobj(recharge_type, "charge");
1549. 	    boolean b_effect;
1550. 
1551. 	    if (!otmp) {
1552. 		obj->age = 0;
1553. 		return 0;
1554. 	    }
1555. 	    b_effect = obj->blessed &&
1556. 		(Role_switch == oart->role || !oart->role);
1557. 	    recharge(otmp, b_effect ? 1 : obj->cursed ? -1 : 0);
1558. 	    update_inventory();
1559. 	    break;
1560. 	  }
1561. 	case LEV_TELE:
1562. 	    level_tele();
1563. 	    break;
1564. 	/* STEPHEN WHITE'S NEW CODE */       
1565. 	case LIGHT_AREA:
1566. 	    if (!Blind)
1567. 			pline("%s shines brightly for an instant!", The(xname(obj)));
1568. 	    else
1569. 			pline("%s grows warm for a second!", The(xname(obj)));
1570. 
1571. 	    litroom(TRUE, obj); /* Light up the room */
1572. 
1573. 	    vision_recalc(0); /*clean up vision*/
1574. 
1575. 		/* WAC - added effect to self, damage is now range dependant */
1576. 		if(is_undead(youmonst.data)) {
1577. 			You("burn in the radiance!");
1578. 			
1579. 			/* This is ground zero.  Not good news ... */
1580. 			u.uhp /= 100;
1581. 
1582. 			if (u.uhp < 1) {
1583. 				u.uhp = 0;
1584. 				killer_format = KILLED_BY;
1585. 				killer = "the Holy Spear of Light";
1586. 				done(DIED);
1587. 			}
1588. 		}
1589. 
1590. 	    /* Undead and Demonics can't stand the light */
1591. 	    unseen = 0;
1592. 	    for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
1593. 			if (DEADMONSTER(mtmp)) continue;
1594. 	    	
1595. 			/* Range is 9 paces */
1596. 	    	if (distu(mtmp->mx,mtmp->my) > 81) continue;
1597. 
1598. 			if (couldsee(mtmp->mx, mtmp->my) &&
1599. 				(is_undead(mtmp->data) || is_demon(mtmp->data)) &&
1600. 				!resist(mtmp, '\0', 0, TELL)) {
1601. 					if (canseemon(mtmp))
1602. 						pline("%s burns in the radiance!", Monnam(mtmp));
1603. 					else
1604. 						unseen++;
1605. 					/* damage now depends on distance, divisor ranges from 10 to 2 */
1606. 					mtmp->mhp /= (10 - (distu(mtmp->mx,mtmp->my)/10));
1607. 					if (mtmp->mhp < 1) mtmp->mhp = 1;
1608. 			}
1609. 	    }
1610. 	    if (unseen)
1611. 			You("hear %s of intense pain!", unseen > 1 ? "cries" : "a cry");
1612. 	    break;
1613. 	case DEATH_GAZE:
1614. 	    if (u.uluck < -9) { /* uh oh... */
1615. 			pline("The Eye turns on you!");
1616. 			u.uhp = 0;
1617. 			killer_format = KILLED_BY;
1618. 			killer = "the Eye of the Beholder";
1619. 			done(DIED);
1620. 	    }
1621. 	    pline("The Eye looks around with its icy gaze!");
1622. 		for (mtmp = fmon; mtmp; mtmp = mtmp2) {
1623. 			mtmp2 = mtmp->nmon;
1624. 			/* The eye is never blind ... */
1625. 			if (couldsee(mtmp->mx, mtmp->my) && !is_undead(mtmp->data)) {
1626. 				pline("%s screams in agony!",Monnam(mtmp));
1627. 				mtmp->mhp /= 3;
1628. 				if (mtmp->mhp < 1) mtmp->mhp = 1;
1629. 			}
1630. 		}
1631. 	    /* Tsk,tsk.. */
1632. 	    adjalign(-3);
1633. 	    u.uluck -= 3;
1634. 	    break;
1635. 	case SUMMON_UNDEAD:
1636. 	    if (u.uluck < -9) { /* uh oh... */
1637. 		u.uhp -= (rn2(20)+5);
1638. 		pline("The Hand claws you with its icy nails!");
1639. 		if (u.uhp <= 0) {
1640. 		  killer_format = KILLED_BY;
1641. 		  killer="the Hand of Vecna";
1642. 		  done(DIED);
1643. 		}
1644. 	    }
1645. 	    summon_loop = rn2(4) + 4;
1646. 	    pline("Creatures from the grave surround you!");
1647. 	    do {
1648. 	      switch (rn2(6)+1) {
1649. 		case 1: mtmp = makemon(mkclass(S_VAMPIRE,0), u.ux, u.uy, NO_MM_FLAGS);
1650. 		   break;
1651. 		case 2:
1652. 		case 3: mtmp = makemon(mkclass(S_ZOMBIE,0), u.ux, u.uy, NO_MM_FLAGS);
1653. 		   break;
1654. 		case 4: mtmp = makemon(mkclass(S_MUMMY,0), u.ux, u.uy, NO_MM_FLAGS);
1655. 		   break;
1656. 		case 5: mtmp = makemon(mkclass(S_GHOST,0), u.ux, u.uy, NO_MM_FLAGS);
1657. 		   break;
1658.                default: mtmp = makemon(mkclass(S_WRAITH,0), u.ux, u.uy, NO_MM_FLAGS);
1659. 		   break;
1660. 	      }
1661. 	      if ((mtmp2 = tamedog(mtmp, (struct obj *)0)) != 0)
1662. 			mtmp = mtmp2;
1663. 	      mtmp->mtame = 30;
1664. 	      summon_loop--;
1665. 	    } while (summon_loop);
1666. 	    /* Tsk,tsk.. */
1667. 	    adjalign(-3);
1668. 	    u.uluck -= 3;
1669. 	    break;
1670. 	case PROT_POLY:
1671. 	    You("feel more observant.");
1672. 	    rescham();
1673. 	    break;
1674. 	case SUMMON_FIRE_ELEMENTAL:
1675. 	    pm = &mons[PM_FIRE_ELEMENTAL];
1676. 	    mtmp = makemon(pm, u.ux, u.uy, NO_MM_FLAGS);
1677.    
1678. 	    pline("You summon an elemental.");
1679.    
1680. 	    if ((mtmp2 = tamedog(mtmp, (struct obj *)0)) != 0)
1681. 			mtmp = mtmp2;
1682. 	    mtmp->mtame = 30;
1683. 	    break;
1684. 	case SUMMON_WATER_ELEMENTAL:
1685. 	    pm = &mons[PM_WATER_ELEMENTAL];
1686. 	    mtmp = makemon(pm, u.ux, u.uy, NO_MM_FLAGS);
1687.    
1688. 	    pline("You summon an elemental.");
1689. 	    
1690. 	    if ((mtmp2 = tamedog(mtmp, (struct obj *)0)) != 0)
1691. 			mtmp = mtmp2;
1692. 	    mtmp->mtame = 30;
1693. 	    break;
1694. 	case OBJ_DETECTION:
1695. 		(void)object_detect(obj, 0);
1696. 		break;
1697. 	case CREATE_PORTAL: {
1698. 	    int i, num_ok_dungeons, last_ok_dungeon = 0;
1699. 	    d_level newlev;
1700. 	    extern int n_dgns; /* from dungeon.c */
1701. 	    winid tmpwin = create_nhwindow(NHW_MENU);
1702. 	    anything any;
1703. 
1704. 	    any.a_void = 0;	/* set all bits to zero */
1705.  #ifdef BLACKMARKET           
1706. 	    if (Is_blackmarket(&u.uz) && *u.ushops) {
1707. 		You("feel very disoriented for a moment.");
1708. 		break;
1709. 	    }
1710.  #endif
1711. 	    start_menu(tmpwin);
1712. 	    /* use index+1 (cant use 0) as identifier */
1713. 	    for (i = num_ok_dungeons = 0; i < n_dgns; i++) {
1714. 		if (!dungeons[i].dunlev_ureached) continue;
1715. 		any.a_int = i+1;
1716. 		add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE,
1717. 			 dungeons[i].dname, MENU_UNSELECTED);
1718. 		num_ok_dungeons++;
1719. 		last_ok_dungeon = i;
1720. 	    }
1721. 	    end_menu(tmpwin, "Open a portal to which dungeon?");
1722. 	    if (num_ok_dungeons > 1) {
1723. 		/* more than one entry; display menu for choices */
1724. 		menu_item *selected;
1725. 		int n;
1726. 
1727. 		n = select_menu(tmpwin, PICK_ONE, &selected);
1728. 		if (n <= 0) {
1729. 		    destroy_nhwindow(tmpwin);
1730. 		    goto nothing_special;
1731. 		}
1732. 		i = selected[0].item.a_int - 1;
1733. 		free((genericptr_t)selected);
1734. 	    } else
1735. 		i = last_ok_dungeon;	/* also first & only OK dungeon */
1736. 	    destroy_nhwindow(tmpwin);
1737. 
1738. 	    /*
1739. 	     * i is now index into dungeon structure for the new dungeon.
1740. 	     * Find the closest level in the given dungeon, open
1741. 	     * a use-once portal to that dungeon and go there.
1742. 	     * The closest level is either the entry or dunlev_ureached.
1743. 	     */
1744. 	    newlev.dnum = i;
1745. 	    if(dungeons[i].depth_start >= depth(&u.uz))
1746. 		newlev.dlevel = dungeons[i].entry_lev;
1747. 	    else
1748. 		newlev.dlevel = dungeons[i].dunlev_ureached;
1749. 	    if(u.uhave.amulet || In_endgame(&u.uz) || In_endgame(&newlev) ||
1750. 	       newlev.dnum == u.uz.dnum) {
1751. 		You_feel("very disoriented for a moment.");
1752. 	    } else {
1753. 		if(!Blind) You("are surrounded by a shimmering sphere!");
1754. 		else You_feel("weightless for a moment.");
1755. 		goto_level(&newlev, FALSE, FALSE, FALSE);
1756. 	    }
1757. 	    break;
1758. 	  }
1759. 	case ENLIGHTENING:
1760. 	    enlightenment(0);
1761. 	    break;
1762. 	case CREATE_AMMO: {
1763. 	    struct obj *otmp = mksobj(ARROW, TRUE, FALSE);
1764. 
1765. 	    if (!otmp) goto nothing_special;
1766. 	    otmp->blessed = obj->blessed;
1767. 	    otmp->cursed = obj->cursed;
1768. 	    otmp->bknown = obj->bknown;
1769. 	    if (obj->blessed) {
1770. 		if (otmp->spe < 0) otmp->spe = 0;
1771. 		otmp->quan += rnd(10);
1772. 	    } else if (obj->cursed) {
1773. 		if (otmp->spe > 0) otmp->spe = 0;
1774. 	    } else
1775. 		otmp->quan += rnd(5);
1776. 	    otmp->owt = weight(otmp);
1777. 	    otmp = hold_another_object(otmp, "Suddenly %s out.",
1778. 				       aobjnam(otmp, "fall"), (const char *)0);
1779. 	    break;
1780. 	  }
1781. 	}
1782.     } else {
1783. 	long eprop = (u.uprops[oart->inv_prop].extrinsic ^= W_ARTI),
1784. 	     iprop = u.uprops[oart->inv_prop].intrinsic;
1785. 	boolean on = (eprop & W_ARTI) != 0; /* true if invoked prop just set */
1786. 
1787. 	if(on && obj->age > monstermoves) {
1788. 	    /* the artifact is tired :-) */
1789. 	    u.uprops[oart->inv_prop].extrinsic ^= W_ARTI;
1790. 	    You_feel("that %s %s ignoring you.",
1791. 		     the(xname(obj)), otense(obj, "are"));
1792. 	    /* can't just keep repeatedly trying */
1793. 	    obj->age += (long) d(3,10);
1794. 	    return 1;
1795. 	} else if(!on) {
1796. 	    /* when turning off property, determine downtime */
1797. 	    /* arbitrary for now until we can tune this -dlc */
1798. 	    obj->age = monstermoves + rnz(100);
1799. 	}
1800. 
1801. 	if ((eprop & ~W_ARTI) || iprop) {
1802. nothing_special:
1803. 	    /* you had the property from some other source too */
1804. 	    if (carried(obj))
1805. 		You_feel("a surge of power, but nothing seems to happen.");
1806. 	    return 1;
1807. 	}
1808. 	switch(oart->inv_prop) {
1809. 	case CONFLICT:
1810. 	    if(on) You_feel("like a rabble-rouser.");
1811. 	    else You_feel("the tension decrease around you.");
1812. 	    break;
1813. 	case LEVITATION:
1814. 	    if(on) {
1815. 		float_up();
1816. 		spoteffects(FALSE);
1817. 	    } else (void) float_down(I_SPECIAL|TIMEOUT, W_ARTI);
1818. 	    break;
1819. 	case INVIS:
1820. 	    if (BInvis || Blind) goto nothing_special;
1821. 	    newsym(u.ux, u.uy);
1822. 	    if (on)
1823. 		    Your("body takes on a %s transparency...",
1824. 			 Hallucination ? "normal" : "strange");
1825. 	    else
1826. 		    Your("body seems to unfade...");
1827. 	    break;
1828. 	}
1829.     }
1830. 
1831.     return 1;
1832. }
1833. 
1834. /*
1835.  * Artifact is dipped into water
1836.  * -1 not handled here (not used up here)
1837.  *  0 no effect but used up
1838.  *  else return
1839.  *  AD_FIRE, etc.
1840.  *  Note caller should handle what happens to the medium in these cases.
1841.  *      This only prints messages about the actual artifact.
1842.  */
1843. 
1844. int
1845. artifact_wet(obj, silent)
1846. struct obj *obj;
1847. boolean silent;
1848. {
1849. 	 if (!obj->oartifact) return (-1);
1850. 	 switch (artilist[(int) (obj)->oartifact].attk.adtyp) {
1851. 		 case AD_FIRE:
1852. 			 if (!silent) {
1853. 				pline("A cloud of steam rises.");
1854. 				pline("%s is untouched.", The(xname(obj)));
1855. 			 }
1856. 			 return (AD_FIRE);
1857. 		 case AD_COLD:
1858. 			 if (!silent) {
1859. 				pline("Icicles form and fall from the freezing %s.",
1860. 			             the(xname(obj)));
1861. 			 }
1862. 			 return (AD_COLD);
1863. 		 case AD_ELEC:
1864. 			 if (!silent) {
1865. 				pline_The("humid air crackles with electricity from %s.",
1866. 						the(xname(obj)));
1867. 			 }
1868. 			 return (AD_ELEC);
1869. 		 case AD_DRLI:
1870. 			 if (!silent) {
1871. 				pline("%s absorbs the water!", The(xname(obj)));
1872. 			 }
1873. 			 return (AD_DRLI);
1874. 		 default:
1875. 			 break;
1876. 	}
1877. 	return (-1);
1878. }
1879. 
1880. /* WAC return TRUE if artifact is always lit */
1881. boolean
1882. artifact_light(obj)
1883.     struct obj *obj;
1884. {
1885.     return get_artifact(obj) && (get_artifact(obj)->inv_prop == LIGHT_AREA
1886.         || obj->oartifact == ART_CANDLE_OF_ETERNAL_FLAME);
1887. }
1888. 
1889. /* KMH -- Talking artifacts are finally implemented */
1890. void
1891. arti_speak(obj)
1892.     struct obj *obj;
1893. {
1894. 	register const struct artifact *oart = get_artifact(obj);
1895. 	const char *line;
1896. 	char buf[BUFSZ];
1897. 
1898. 
1899. 	/* Is this a speaking artifact? */
1900. 	if (!oart || !(oart->spfx & SPFX_SPEAK))
1901. 		return;
1902. 
1903. 	line = getrumor(bcsign(obj), buf, TRUE);
1904. 	if (!*line)
1905. 		line = "Slash'EM rumors file closed for renovation.";
1906. 	pline("%s:", Tobjnam(obj, "whisper"));
1907. 	verbalize("%s", line);
1908. 	return;
1909. }
1910. 
1911. boolean
1912. artifact_has_invprop(otmp, inv_prop)
1913. struct obj *otmp;
1914. uchar inv_prop;
1915. {
1916. 	const struct artifact *arti = get_artifact(otmp);
1917. 
1918. 	return((boolean)(arti && (arti->inv_prop == inv_prop)));
1919. }
1920. 
1921. /* Return the price sold to the hero of a given artifact or unique item */
1922. long
1923. arti_cost(otmp)
1924. struct obj *otmp;
1925. {
1926. 	if (!otmp->oartifact)
1927. 	    return ((long)objects[otmp->otyp].oc_cost);
1928. 	else if (artilist[(int) otmp->oartifact].cost)
1929. 	    return (artilist[(int) otmp->oartifact].cost);
1930. 	else
1931. 	    return (100L * (long)objects[otmp->otyp].oc_cost);
1932. }
1933. 
1934. #endif /* OVLB */
1935. 
1936. /*artifact.c*/

Also on Fandom

Random Wiki