Source:NetHack 3.4.3/src/wield.c

From NetHackWiki
(Redirected from Source:Ref/welded)
Jump to: navigation, search

Below is the full text to src/wield.c from NetHack 3.4.3. To link to a particular line, write [[wield.c#line123]], for example.

Top of file

  1. /*	SCCS Id: @(#)wield.c	3.4	2003/01/29	*/
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

  1. #include "hack.h"
  2.  
  3. /* KMH -- Differences between the three weapon slots.
  4. *
  5. * The main weapon (uwep):
  6. * 1.  Is filled by the (w)ield command.
  7. * 2.  Can be filled with any type of item.
  8. * 3.  May be carried in one or both hands.
  9. * 4.  Is used as the melee weapon and as the launcher for
  10. *     ammunition.
  11. * 5.  Only conveys intrinsics when it is a weapon, weapon-tool,
  12. *     or artifact.
  13. * 6.  Certain cursed items will weld to the hand and cannot be
  14. *     unwielded or dropped.  See erodeable_wep() and will_weld()
  15. *     below for the list of which items apply.
  16. *
  17. * The secondary weapon (uswapwep):
  18. * 1.  Is filled by the e(x)change command, which swaps this slot
  19. *     with the main weapon.  If the "pushweapon" option is set,
  20. *     the (w)ield command will also store the old weapon in the
  21. *     secondary slot.
  22. * 2.  Can be field with anything that will fit in the main weapon
  23. *     slot; that is, any type of item.
  24. * 3.  Is usually NOT considered to be carried in the hands.
  25. *     That would force too many checks among the main weapon,
  26. *     second weapon, shield, gloves, and rings; and it would
  27. *     further be complicated by bimanual weapons.  A special
  28. *     exception is made for two-weapon combat.
  29. * 4.  Is used as the second weapon for two-weapon combat, and as
  30. *     a convenience to swap with the main weapon.
  31. * 5.  Never conveys intrinsics.
  32. * 6.  Cursed items never weld (see #3 for reasons), but they also
  33. *     prevent two-weapon combat.
  34. *
  35. * The quiver (uquiver):
  36. * 1.  Is filled by the (Q)uiver command.
  37. * 2.  Can be filled with any type of item.
  38. * 3.  Is considered to be carried in a special part of the pack.
  39. * 4.  Is used as the item to throw with the (f)ire command.
  40. *     This is a convenience over the normal (t)hrow command.
  41. * 5.  Never conveys intrinsics.
  42. * 6.  Cursed items never weld; their effect is handled by the normal
  43. *     throwing code.
  44. *
  45. * No item may be in more than one of these slots.
  46. */
  47.  
  48.  
  49. STATIC_DCL int FDECL(ready_weapon, (struct obj *));
  50.  
  51. /* used by will_weld() */
  52. /* probably should be renamed */
  53. #define erodeable_wep(optr)	((optr)->oclass == WEAPON_CLASS \
  54. 				|| is_weptool(optr) \
  55. 				|| (optr)->otyp == HEAVY_IRON_BALL \
  56. 				|| (optr)->otyp == IRON_CHAIN)
  57.  
  58. /* used by welded(), and also while wielding */
  59. #define will_weld(optr)		((optr)->cursed \
  60. 				&& (erodeable_wep(optr) \
  61. 				   || (optr)->otyp == TIN_OPENER))

Functions that place a given item in a slot

  1. /*** Functions that place a given item in a slot ***/
  2. /* Proper usage includes:
  3. * 1.  Initializing the slot during character generation or a
  4. *     restore.
  5. * 2.  Setting the slot due to a player's actions.
  6. * 3.  If one of the objects in the slot are split off, these
  7. *     functions can be used to put the remainder back in the slot.
  8. * 4.  Putting an item that was thrown and returned back into the slot.
  9. * 5.  Emptying the slot, by passing a null object.  NEVER pass
  10. *     zeroobj!
  11. *

setuwep

  1. * If the item is being moved from another slot, it is the caller's
  2. * responsibility to handle that.  It's also the caller's responsibility
  3. * to print the appropriate messages.
  4. */
  5. void
  6. setuwep(obj)
  7. register struct obj *obj;
  8. {
  9. 	struct obj *olduwep = uwep;
  10.  
  11. 	if (obj == uwep) return; /* necessary to not set unweapon */
  12. 	/* This message isn't printed in the caller because it happens
  13. 	 * *whenever* Sunsword is unwielded, from whatever cause.
  14. 	 */
  15. 	setworn(obj, W_WEP);
  16. 	if (uwep == obj && artifact_light(olduwep) && olduwep->lamplit) {
  17. 	    end_burn(olduwep, FALSE);
  18. 	    if (!Blind) pline("%s glowing.", Tobjnam(olduwep, "stop"));
  19. 	}
  20. 	/* Note: Explicitly wielding a pick-axe will not give a "bashing"
  21. 	 * message.  Wielding one via 'a'pplying it will.
  22. 	 * 3.2.2:  Wielding arbitrary objects will give bashing message too.
  23. 	 */
  24. 	if (obj) {
  25. 		unweapon = (obj->oclass == WEAPON_CLASS) ?
  26. 				is_launcher(obj) || is_ammo(obj) ||
  27. 				is_missile(obj) || (is_pole(obj)
  28. #ifdef STEED
  29. 				&& !u.usteed
  30. #endif
  31. 				) : !is_weptool(obj);
  32. 	} else
  33. 		unweapon = TRUE;	/* for "bare hands" message */
  34. 	update_inventory();
  35. }

ready_weapon

  1. STATIC_OVL int
  2. ready_weapon(wep)
  3. struct obj *wep;
  4. {
  5. 	/* Separated function so swapping works easily */
  6. 	int res = 0;
  7.  
  8. 	if (!wep) {
  9. 	    /* No weapon */
  10. 	    if (uwep) {
  11. 		You("are empty %s.", body_part(HANDED));
  12. 		setuwep((struct obj *) 0);
  13. 		res++;
  14. 	    } else
  15. 		You("are already empty %s.", body_part(HANDED));
  16. 	} else if (!uarmg && !Stone_resistance && wep->otyp == CORPSE
  17. 				&& touch_petrifies(&mons[wep->corpsenm])) {
  18. 	    /* Prevent wielding cockatrice when not wearing gloves --KAA */
  19. 	    char kbuf[BUFSZ];
  20.  
  21. 	    You("wield the %s corpse in your bare %s.",
  22. 		mons[wep->corpsenm].mname, makeplural(body_part(HAND)));
  23. 	    Sprintf(kbuf, "%s corpse", an(mons[wep->corpsenm].mname));
  24. 	    instapetrify(kbuf);
  25. 	} else if (uarms && bimanual(wep))
  26. 	    You("cannot wield a two-handed %s while wearing a shield.",
  27. 		is_sword(wep) ? "sword" :
  28. 		    wep->otyp == BATTLE_AXE ? "axe" : "weapon");
  29. 	else if (wep->oartifact && !touch_artifact(wep, &youmonst)) {
  30. 	    res++;	/* takes a turn even though it doesn't get wielded */
  31. 	} else {
  32. 	    /* Weapon WILL be wielded after this point */
  33. 	    res++;
  34. 	    if (will_weld(wep)) {
  35. 		const char *tmp = xname(wep), *thestr = "The ";
  36. 		if (strncmp(tmp, thestr, 4) && !strncmp(The(tmp),thestr,4))
  37. 		    tmp = thestr;
  38. 		else tmp = "";
  39. 		pline("%s%s %s to your %s!", tmp, aobjnam(wep, "weld"),
  40. 			(wep->quan == 1L) ? "itself" : "themselves", /* a3 */
  41. 			bimanual(wep) ?
  42. 				(const char *)makeplural(body_part(HAND))
  43. 				: body_part(HAND));
  44. 		wep->bknown = TRUE;
  45. 	    } else {
  46. 		/* The message must be printed before setuwep (since
  47. 		 * you might die and be revived from changing weapons),
  48. 		 * and the message must be before the death message and
  49. 		 * Lifesaved rewielding.  Yet we want the message to
  50. 		 * say "weapon in hand", thus this kludge.
  51. 		 */
  52. 		long dummy = wep->owornmask;
  53. 		wep->owornmask |= W_WEP;
  54. 		prinv((char *)0, wep, 0L);
  55. 		wep->owornmask = dummy;
  56. 	    }
  57. 	    setuwep(wep);
  58.  
  59. 	    /* KMH -- Talking artifacts are finally implemented */
  60. 	    arti_speak(wep);
  61.  
  62. 	    if (artifact_light(wep) && !wep->lamplit) {
  63. 		begin_burn(wep, FALSE);
  64. 		if (!Blind)
  65. 		    pline("%s to glow brilliantly!", Tobjnam(wep, "begin"));
  66. 	    }
  67.  
  68. #if 0
  69. 	    /* we'll get back to this someday, but it's not balanced yet */
  70. 	    if (Race_if(PM_ELF) && !wep->oartifact &&
  71. 			    objects[wep->otyp].oc_material == IRON) {
  72. 		/* Elves are averse to wielding cold iron */
  73. 		You("have an uneasy feeling about wielding cold iron.");
  74. 		change_luck(-1);
  75. 	    }
  76. #endif
  77.  
  78. 	    if (wep->unpaid) {
  79. 		struct monst *this_shkp;
  80.  
  81. 		if ((this_shkp = shop_keeper(inside_shop(u.ux, u.uy))) !=
  82. 		    (struct monst *)0) {
  83. 		    pline("%s says \"You be careful with my %s!\"",
  84. 			  shkname(this_shkp),
  85. 			  xname(wep));
  86. 		}
  87. 	    }
  88. 	}
  89. 	return(res);
  90. }

setuqwep

  1. void
  2. setuqwep(obj)
  3. register struct obj *obj;
  4. {
  5. 	setworn(obj, W_QUIVER);
  6. 	update_inventory();
  7. }

setuswapwep

  1. void
  2. setuswapwep(obj)
  3. register struct obj *obj;
  4. {
  5. 	setworn(obj, W_SWAPWEP);
  6. 	update_inventory();
  7. }

Commands to change particular slots

  1. /*** Commands to change particular slot(s) ***/
  2.  
  3. static NEARDATA const char wield_objs[] =
  4. 	{ ALL_CLASSES, ALLOW_NONE, WEAPON_CLASS, TOOL_CLASS, 0 };
  5. static NEARDATA const char ready_objs[] =
  6. 	{ ALL_CLASSES, ALLOW_NONE, WEAPON_CLASS, 0 };
  7. static NEARDATA const char bullets[] =	/* (note: different from dothrow.c) */
  8. 	{ ALL_CLASSES, ALLOW_NONE, GEM_CLASS, WEAPON_CLASS, 0 };

dowield

  1. int
  2. dowield()
  3. {
  4. 	register struct obj *wep, *oldwep;
  5. 	int result;
  6.  
  7. 	/* May we attempt this? */
  8. 	multi = 0;
  9. 	if (cantwield(youmonst.data)) {
  10. 		pline("Don't be ridiculous!");
  11. 		return(0);
  12. 	}
  13.  
  14. 	/* Prompt for a new weapon */
  15. 	if (!(wep = getobj(wield_objs, "wield")))
  16. 		/* Cancelled */
  17. 		return (0);
  18. 	else if (wep == uwep) {
  19. 	    You("are already wielding that!");
  20. 	    if (is_weptool(wep)) unweapon = FALSE;	/* [see setuwep()] */
  21. 		return (0);
  22. 	} else if (welded(uwep)) {
  23. 		weldmsg(uwep);
  24. 		/* previously interrupted armor removal mustn't be resumed */
  25. 		reset_remarm();
  26. 		return (0);
  27. 	}
  28.  
  29. 	/* Handle no object, or object in other slot */
  30. 	if (wep == &zeroobj)
  31. 		wep = (struct obj *) 0;
  32. 	else if (wep == uswapwep)
  33. 		return (doswapweapon());
  34. 	else if (wep == uquiver)
  35. 		setuqwep((struct obj *) 0);
  36. 	else if (wep->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL
  37. #ifdef STEED
  38. 			| W_SADDLE
  39. #endif
  40. 			)) {
  41. 		You("cannot wield that!");
  42. 		return (0);
  43. 	}
  44.  
  45. 	/* Set your new primary weapon */
  46. 	oldwep = uwep;
  47. 	result = ready_weapon(wep);
  48. 	if (flags.pushweapon && oldwep && uwep != oldwep)
  49. 		setuswapwep(oldwep);
  50. 	untwoweapon();
  51.  
  52. 	return (result);
  53. }

doswapweapon

  1. int
  2. doswapweapon()
  3. {
  4. 	register struct obj *oldwep, *oldswap;
  5. 	int result = 0;
  6.  
  7.  
  8. 	/* May we attempt this? */
  9. 	multi = 0;
  10. 	if (cantwield(youmonst.data)) {
  11. 		pline("Don't be ridiculous!");
  12. 		return(0);
  13. 	}
  14. 	if (welded(uwep)) {
  15. 		weldmsg(uwep);
  16. 		return (0);
  17. 	}
  18.  
  19. 	/* Unwield your current secondary weapon */
  20. 	oldwep = uwep;
  21. 	oldswap = uswapwep;
  22. 	setuswapwep((struct obj *) 0);
  23.  
  24. 	/* Set your new primary weapon */
  25. 	result = ready_weapon(oldswap);
  26.  
  27. 	/* Set your new secondary weapon */
  28. 	if (uwep == oldwep)
  29. 		/* Wield failed for some reason */
  30. 		setuswapwep(oldswap);
  31. 	else {
  32. 		setuswapwep(oldwep);
  33. 		if (uswapwep)
  34. 			prinv((char *)0, uswapwep, 0L);
  35. 		else
  36. 			You("have no secondary weapon readied.");
  37. 	}
  38.  
  39. 	if (u.twoweap && !can_twoweapon())
  40. 		untwoweapon();
  41.  
  42. 	return (result);
  43. }

dowieldquiver

  1. int
  2. dowieldquiver()
  3. {
  4. 	register struct obj *newquiver;
  5. 	const char *quivee_types = (uslinging() ||
  6. 		  (uswapwep && objects[uswapwep->otyp].oc_skill == P_SLING)) ?
  7. 				  bullets : ready_objs;
  8.  
  9. 	/* Since the quiver isn't in your hands, don't check cantwield(), */
  10. 	/* will_weld(), touch_petrifies(), etc. */
  11. 	multi = 0;
  12.  
  13. 	/* Because 'Q' used to be quit... */
  14. 	if (flags.suppress_alert < FEATURE_NOTICE_VER(3,3,0))
  15. 		pline("Note: Please use #quit if you wish to exit the game.");
  16.  
  17. 	/* Prompt for a new quiver */
  18. 	if (!(newquiver = getobj(quivee_types, "ready")))
  19. 		/* Cancelled */
  20. 		return (0);
  21.  
  22. 	/* Handle no object, or object in other slot */
  23. 	/* Any type is okay, since we give no intrinsics anyways */
  24. 	if (newquiver == &zeroobj) {
  25. 		/* Explicitly nothing */
  26. 		if (uquiver) {
  27. 			You("now have no ammunition readied.");
  28. 			setuqwep(newquiver = (struct obj *) 0);
  29. 		} else {
  30. 			You("already have no ammunition readied!");
  31. 			return(0);
  32. 		}
  33. 	} else if (newquiver == uquiver) {
  34. 		pline("That ammunition is already readied!");
  35. 		return(0);
  36. 	} else if (newquiver == uwep) {
  37. 		/* Prevent accidentally readying the main weapon */
  38. 		pline("%s already being used as a weapon!",
  39. 		      !is_plural(uwep) ? "That is" : "They are");
  40. 		return(0);
  41. 	} else if (newquiver->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL
  42. #ifdef STEED
  43. 			| W_SADDLE
  44. #endif
  45. 			)) {
  46. 		You("cannot ready that!");
  47. 		return (0);
  48. 	} else {
  49. 		long dummy;
  50.  
  51.  
  52. 		/* Check if it's the secondary weapon */
  53. 		if (newquiver == uswapwep) {
  54. 			setuswapwep((struct obj *) 0);
  55. 			untwoweapon();
  56. 		}
  57.  
  58. 		/* Okay to put in quiver; print it */
  59. 		dummy = newquiver->owornmask;
  60. 		newquiver->owornmask |= W_QUIVER;
  61. 		prinv((char *)0, newquiver, 0L);
  62. 		newquiver->owornmask = dummy;
  63. 	}
  64.  
  65. 	/* Finally, place it in the quiver */
  66. 	setuqwep(newquiver);
  67. 	/* Take no time since this is a convenience slot */
  68. 	return (0);
  69. }

wield_tool

  1. /* used for #rub and for applying pick-axe, whip, grappling hook, or polearm */
  2. /* (moved from apply.c) */
  3. boolean
  4. wield_tool(obj, verb)
  5. struct obj *obj;
  6. const char *verb;	/* "rub",&c */
  7. {
  8. const char *what;
  9. boolean more_than_1;
  10.  
  11. if (obj == uwep) return TRUE;   /* nothing to do if already wielding it */
  12.  
  13. if (!verb) verb = "wield";
  14. what = xname(obj);
  15. more_than_1 = (obj->quan > 1L ||
  16. 		   strstri(what, "pair of ") != 0 ||
  17. 		   strstri(what, "s of ") != 0);
  18.  
  19. if (obj->owornmask & (W_ARMOR|W_RING|W_AMUL|W_TOOL)) {
  20. 	char yourbuf[BUFSZ];
  21.  
  22. 	You_cant("%s %s %s while wearing %s.",
  23. 		 verb, shk_your(yourbuf, obj), what,
  24. 		 more_than_1 ? "them" : "it");
  25. 	return FALSE;
  26. }
  27. if (welded(uwep)) {
  28. 	if (flags.verbose) {
  29. 	    const char *hand = body_part(HAND);
  30.  
  31. 	    if (bimanual(uwep)) hand = makeplural(hand);
  32. 	    if (strstri(what, "pair of ") != 0) more_than_1 = FALSE;
  33. 	    pline(
  34. 	     "Since your weapon is welded to your %s, you cannot %s %s %s.",
  35. 		  hand, verb, more_than_1 ? "those" : "that", xname(obj));
  36. 	} else {
  37. 	    You_cant("do that.");
  38. 	}
  39. 	return FALSE;
  40. }
  41. if (cantwield(youmonst.data)) {
  42. 	You_cant("hold %s strongly enough.", more_than_1 ? "them" : "it");
  43. 	return FALSE;
  44. }
  45. /* check shield */
  46. if (uarms && bimanual(obj)) {
  47. 	You("cannot %s a two-handed %s while wearing a shield.",
  48. 	    verb, (obj->oclass == WEAPON_CLASS) ? "weapon" : "tool");
  49. 	return FALSE;
  50. }
  51. if (uquiver == obj) setuqwep((struct obj *)0);
  52. if (uswapwep == obj) {
  53. 	(void) doswapweapon();
  54. 	/* doswapweapon might fail */
  55. 	if (uswapwep == obj) return FALSE;
  56. } else {
  57. 	You("now wield %s.", doname(obj));
  58. 	setuwep(obj);
  59. }
  60. if (uwep != obj) return FALSE;	/* rewielded old object after dying */
  61. /* applying weapon or tool that gets wielded ends two-weapon combat */
  62. if (u.twoweap)
  63. 	untwoweapon();
  64. if (obj->oclass != WEAPON_CLASS)
  65. 	unweapon = TRUE;
  66. return TRUE;
  67. }

can_twoweapon

  1. int
  2. can_twoweapon()
  3. {
  4. 	struct obj *otmp;
  5.  
  6. #define NOT_WEAPON(obj) (!is_weptool(obj) && obj->oclass != WEAPON_CLASS)
  7. 	if (!could_twoweap(youmonst.data)) {
  8. 		if (Upolyd)
  9. 		    You_cant("use two weapons in your current form.");
  10. 		else
  11. 		    pline("%s aren't able to use two weapons at once.",
  12. 			  makeplural((flags.female && urole.name.f) ?
  13. 				     urole.name.f : urole.name.m));
  14. 	} else if (!uwep || !uswapwep)
  15. 		Your("%s%s%s empty.", uwep ? "left " : uswapwep ? "right " : "",
  16. 			body_part(HAND), (!uwep && !uswapwep) ? "s are" : " is");
  17. 	else if (NOT_WEAPON(uwep) || NOT_WEAPON(uswapwep)) {
  18. 		otmp = NOT_WEAPON(uwep) ? uwep : uswapwep;
  19. 		pline("%s %s.", Yname2(otmp),
  20. 		    is_plural(otmp) ? "aren't weapons" : "isn't a weapon");
  21. 	} else if (bimanual(uwep) || bimanual(uswapwep)) {
  22. 		otmp = bimanual(uwep) ? uwep : uswapwep;
  23. 		pline("%s isn't one-handed.", Yname2(otmp));
  24. 	} else if (uarms)
  25. 		You_cant("use two weapons while wearing a shield.");
  26. 	else if (uswapwep->oartifact)
  27. 		pline("%s %s being held second to another weapon!",
  28. 			Yname2(uswapwep), otense(uswapwep, "resist"));
  29. 	else if (!uarmg && !Stone_resistance && (uswapwep->otyp == CORPSE &&
  30. 		    touch_petrifies(&mons[uswapwep->corpsenm]))) {
  31. 		char kbuf[BUFSZ];
  32.  
  33. 		You("wield the %s corpse with your bare %s.",
  34. 		    mons[uswapwep->corpsenm].mname, body_part(HAND));
  35. 		Sprintf(kbuf, "%s corpse", an(mons[uswapwep->corpsenm].mname));
  36. 		instapetrify(kbuf);
  37. 	} else if (Glib || uswapwep->cursed) {
  38. 		if (!Glib)
  39. 			uswapwep->bknown = TRUE;
  40. 		drop_uswapwep();
  41. 	} else
  42. 		return (TRUE);
  43. 	return (FALSE);
  44. }

drop_uswapwep

  1. void
  2. drop_uswapwep()
  3. {
  4. 	char str[BUFSZ];
  5. 	struct obj *obj = uswapwep;
  6.  
  7. 	/* Avoid trashing makeplural's static buffer */
  8. 	Strcpy(str, makeplural(body_part(HAND)));
  9. 	Your("%s from your %s!",  aobjnam(obj, "slip"), str);
  10. 	dropx(obj);
  11. }

dotwoweapon

  1. int
  2. dotwoweapon()
  3. {
  4. 	/* You can always toggle it off */
  5. 	if (u.twoweap) {
  6. 		You("switch to your primary weapon.");
  7. 		u.twoweap = 0;
  8. 		update_inventory();
  9. 		return (0);
  10. 	}
  11.  
  12. 	/* May we use two weapons? */
  13. 	if (can_twoweapon()) {
  14. 		/* Success! */
  15. 		You("begin two-weapon combat.");
  16. 		u.twoweap = 1;
  17. 		update_inventory();
  18. 		return (rnd(20) > ACURR(A_DEX));
  19. 	}
  20. 	return (0);
  21. }

Functions to empty a given slot

  1. /*** Functions to empty a given slot ***/
  2. /* These should be used only when the item can't be put back in
  3. * the slot by life saving.  Proper usage includes:
  4. * 1.  The item has been eaten, stolen, burned away, or rotted away.
  5. * 2.  Making an item disappear for a bones pile.
  6. */

uwepgone

  1. void
  2. uwepgone()
  3. {
  4. 	if (uwep) {
  5. 		if (artifact_light(uwep) && uwep->lamplit) {
  6. 		    end_burn(uwep, FALSE);
  7. 		    if (!Blind) pline("%s glowing.", Tobjnam(uwep, "stop"));
  8. 		}
  9. 		setworn((struct obj *)0, W_WEP);
  10. 		unweapon = TRUE;
  11. 		update_inventory();
  12. 	}
  13. }

uswapwepgone

  1. void
  2. uswapwepgone()
  3. {
  4. 	if (uswapwep) {
  5. 		setworn((struct obj *)0, W_SWAPWEP);
  6. 		update_inventory();
  7. 	}
  8. }

uqwepgone

  1. void
  2. uqwepgone()
  3. {
  4. 	if (uquiver) {
  5. 		setworn((struct obj *)0, W_QUIVER);
  6. 		update_inventory();
  7. 	}
  8. }

untwoweapon

  1. void
  2. untwoweapon()
  3. {
  4. 	if (u.twoweap) {
  5. 		You("can no longer use two weapons at once.");
  6. 		u.twoweap = FALSE;
  7. 		update_inventory();
  8. 	}
  9. 	return;
  10. }

erode_obj

  1. /* Maybe rust object, or corrode it if acid damage is called for */
  2. void
  3. erode_obj(target, acid_dmg, fade_scrolls)
  4. struct obj *target;		/* object (e.g. weapon or armor) to erode */
  5. boolean acid_dmg;
  6. boolean fade_scrolls;
  7. {
  8. 	int erosion;
  9. 	struct monst *victim;
  10. 	boolean vismon;
  11. 	boolean visobj;
  12.  
  13. 	if (!target)
  14. 	    return;
  15. 	victim = carried(target) ? &youmonst :
  16. 	    mcarried(target) ? target->ocarry : (struct monst *)0;
  17. 	vismon = victim && (victim != &youmonst) && canseemon(victim);
  18. 	visobj = !victim && cansee(bhitpos.x, bhitpos.y); /* assume thrown */
  19.  
  20. 	erosion = acid_dmg ? target->oeroded2 : target->oeroded;
  21.  
  22. 	if (target->greased) {
  23. 	    grease_protect(target,(char *)0,victim);
  24. 	} else if (target->oclass == SCROLL_CLASS) {
  25. 	    if(fade_scrolls && target->otyp != SCR_BLANK_PAPER
  26. #ifdef MAIL
  27. 	    && target->otyp != SCR_MAIL
  28. #endif
  29. 					)
  30. 	    {
  31. 		if (!Blind) {
  32. 		    if (victim == &youmonst)
  33. 			Your("%s.", aobjnam(target, "fade"));
  34. 		    else if (vismon)
  35. 			pline("%s's %s.", Monnam(victim),
  36. 			      aobjnam(target, "fade"));
  37. 		    else if (visobj)
  38. 			pline_The("%s.", aobjnam(target, "fade"));
  39. 		}
  40. 		target->otyp = SCR_BLANK_PAPER;
  41. 		target->spe = 0;
  42. 	    }
  43. 	} else if (target->oerodeproof ||
  44. 		(acid_dmg ? !is_corrodeable(target) : !is_rustprone(target))) {
  45. 	    if (flags.verbose || !(target->oerodeproof && target->rknown)) {
  46. 		if (victim == &youmonst)
  47. 		    Your("%s not affected.", aobjnam(target, "are"));
  48. 		else if (vismon)
  49. 		    pline("%s's %s not affected.", Monnam(victim),
  50. 			aobjnam(target, "are"));
  51. 		/* no message if not carried */
  52. 	    }
  53. 	    if (target->oerodeproof) target->rknown = TRUE;
  54. 	} else if (erosion < MAX_ERODE) {
  55. 	    if (victim == &youmonst)
  56. 		Your("%s%s!", aobjnam(target, acid_dmg ? "corrode" : "rust"),
  57. 		    erosion+1 == MAX_ERODE ? " completely" :
  58. 		    erosion ? " further" : "");
  59. 	    else if (vismon)
  60. 		pline("%s's %s%s!", Monnam(victim),
  61. 		    aobjnam(target, acid_dmg ? "corrode" : "rust"),
  62. 		    erosion+1 == MAX_ERODE ? " completely" :
  63. 		    erosion ? " further" : "");
  64. 	    else if (visobj)
  65. 		pline_The("%s%s!",
  66. 		    aobjnam(target, acid_dmg ? "corrode" : "rust"),
  67. 		    erosion+1 == MAX_ERODE ? " completely" :
  68. 		    erosion ? " further" : "");
  69. 	    if (acid_dmg)
  70. 		target->oeroded2++;
  71. 	    else
  72. 		target->oeroded++;
  73. 	} else {
  74. 	    if (flags.verbose) {
  75. 		if (victim == &youmonst)
  76. 		    Your("%s completely %s.",
  77. 			aobjnam(target, Blind ? "feel" : "look"),
  78. 			acid_dmg ? "corroded" : "rusty");
  79. 		else if (vismon)
  80. 		    pline("%s's %s completely %s.", Monnam(victim),
  81. 			aobjnam(target, "look"),
  82. 			acid_dmg ? "corroded" : "rusty");
  83. 		else if (visobj)
  84. 		    pline_The("%s completely %s.",
  85. 			aobjnam(target, "look"),
  86. 			acid_dmg ? "corroded" : "rusty");
  87. 	    }
  88. 	}
  89. }

chwepon

  1. int
  2. chwepon(otmp, amount)
  3. register struct obj *otmp;
  4. register int amount;
  5. {
  6. 	const char *color = hcolor((amount < 0) ? NH_BLACK : NH_BLUE);
  7. 	const char *xtime;
  8. 	int otyp = STRANGE_OBJECT;
  9.  
  10. 	if(!uwep || (uwep->oclass != WEAPON_CLASS && !is_weptool(uwep))) {
  11. 		char buf[BUFSZ];
  12.  
  13. 		Sprintf(buf, "Your %s %s.", makeplural(body_part(HAND)),
  14. 			(amount >= 0) ? "twitch" : "itch");
  15. 		strange_feeling(otmp, buf);
  16. 		exercise(A_DEX, (boolean) (amount >= 0));
  17. 		return(0);
  18. 	}
  19.  
  20. 	if (otmp && otmp->oclass == SCROLL_CLASS) otyp = otmp->otyp;
  21.  
  22. 	if(uwep->otyp == WORM_TOOTH && amount >= 0) {
  23. 		uwep->otyp = CRYSKNIFE;
  24. 		uwep->oerodeproof = 0;
  25. 		Your("weapon seems sharper now.");
  26. 		uwep->cursed = 0;
  27. 		if (otyp != STRANGE_OBJECT) makeknown(otyp);
  28. 		return(1);
  29. 	}
  30.  
  31. 	if(uwep->otyp == CRYSKNIFE && amount < 0) {
  32. 		uwep->otyp = WORM_TOOTH;
  33. 		uwep->oerodeproof = 0;
  34. 		Your("weapon seems duller now.");
  35. 		if (otyp != STRANGE_OBJECT && otmp->bknown) makeknown(otyp);
  36. 		return(1);
  37. 	}
  38.  
  39. 	if (amount < 0 && uwep->oartifact && restrict_name(uwep, ONAME(uwep))) {
  40. 	    if (!Blind)
  41. 		Your("%s %s.", aobjnam(uwep, "faintly glow"), color);
  42. 	    return(1);
  43. 	}
  44. 	/* there is a (soft) upper and lower limit to uwep->spe */
  45. 	if(((uwep->spe > 5 && amount >= 0) || (uwep->spe < -5 && amount < 0))
  46. 								&& rn2(3)) {
  47. 	    if (!Blind)
  48. 	    Your("%s %s for a while and then %s.",
  49. 		 aobjnam(uwep, "violently glow"), color,
  50. 		 otense(uwep, "evaporate"));
  51. 	    else
  52. 		Your("%s.", aobjnam(uwep, "evaporate"));
  53.  
  54. 	    useupall(uwep);	/* let all of them disappear */
  55. 	    return(1);
  56. 	}
  57. 	if (!Blind) {
  58. 	    xtime = (amount*amount == 1) ? "moment" : "while";
  59. 	    Your("%s %s for a %s.",
  60. 		 aobjnam(uwep, amount == 0 ? "violently glow" : "glow"),
  61. 		 color, xtime);
  62. 	    if (otyp != STRANGE_OBJECT && uwep->known &&
  63. 		    (amount > 0 || (amount < 0 && otmp->bknown)))
  64. 		makeknown(otyp);
  65. 	}
  66. 	uwep->spe += amount;
  67. 	if(amount > 0) uwep->cursed = 0;
  68.  
  69. 	/*
  70. 	 * Enchantment, which normally improves a weapon, has an
  71. 	 * addition adverse reaction on Magicbane whose effects are
  72. 	 * spe dependent.  Give an obscure clue here.
  73. 	 */
  74. 	if (uwep->oartifact == ART_MAGICBANE && uwep->spe >= 0) {
  75. 		Your("right %s %sches!",
  76. 			body_part(HAND),
  77. 			(((amount > 1) && (uwep->spe > 1)) ? "flin" : "it"));
  78. 	}
  79.  
  80. 	/* an elven magic clue, cookie@keebler */
  81. 	/* elven weapons vibrate warningly when enchanted beyond a limit */
  82. 	if ((uwep->spe > 5)
  83. 		&& (is_elven_weapon(uwep) || uwep->oartifact || !rn2(7)))
  84. 	    Your("%s unexpectedly.",
  85. 		aobjnam(uwep, "suddenly vibrate"));
  86.  
  87. 	return(1);
  88. }

welded

  1. int
  2. welded(obj)
  3. register struct obj *obj;
  4. {
  5. 	if (obj && obj == uwep && will_weld(obj)) {
  6. 		obj->bknown = TRUE;
  7. 		return 1;
  8. 	}
  9. 	return 0;
  10. }

weldmsg

  1. void
  2. weldmsg(obj)
  3. register struct obj *obj;
  4. {
  5. 	long savewornmask;
  6.  
  7. 	savewornmask = obj->owornmask;
  8. 	Your("%s %s welded to your %s!",
  9. 		xname(obj), otense(obj, "are"),
  10. 		bimanual(obj) ? (const char *)makeplural(body_part(HAND))
  11. 				: body_part(HAND));
  12. 	obj->owornmask = savewornmask;
  13. }
  14.  
  15. /*wield.c*/