implement #H4305 - Quivering wielded weapon
[aNetHack.git] / src / wield.c
blob058eff434099797ffd09cc3d060c760eb2a322c6
1 /* NetHack 3.6 wield.c $NHDT-Date: 1461967849 2016/04/29 22:10:49 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.49 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /* NetHack may be freely redistributed. See license for details. */
5 #include "hack.h"
7 /* KMH -- Differences between the three weapon slots.
9 * The main weapon (uwep):
10 * 1. Is filled by the (w)ield command.
11 * 2. Can be filled with any type of item.
12 * 3. May be carried in one or both hands.
13 * 4. Is used as the melee weapon and as the launcher for
14 * ammunition.
15 * 5. Only conveys intrinsics when it is a weapon, weapon-tool,
16 * or artifact.
17 * 6. Certain cursed items will weld to the hand and cannot be
18 * unwielded or dropped. See erodeable_wep() and will_weld()
19 * below for the list of which items apply.
21 * The secondary weapon (uswapwep):
22 * 1. Is filled by the e(x)change command, which swaps this slot
23 * with the main weapon. If the "pushweapon" option is set,
24 * the (w)ield command will also store the old weapon in the
25 * secondary slot.
26 * 2. Can be filled with anything that will fit in the main weapon
27 * slot; that is, any type of item.
28 * 3. Is usually NOT considered to be carried in the hands.
29 * That would force too many checks among the main weapon,
30 * second weapon, shield, gloves, and rings; and it would
31 * further be complicated by bimanual weapons. A special
32 * exception is made for two-weapon combat.
33 * 4. Is used as the second weapon for two-weapon combat, and as
34 * a convenience to swap with the main weapon.
35 * 5. Never conveys intrinsics.
36 * 6. Cursed items never weld (see #3 for reasons), but they also
37 * prevent two-weapon combat.
39 * The quiver (uquiver):
40 * 1. Is filled by the (Q)uiver command.
41 * 2. Can be filled with any type of item.
42 * 3. Is considered to be carried in a special part of the pack.
43 * 4. Is used as the item to throw with the (f)ire command.
44 * This is a convenience over the normal (t)hrow command.
45 * 5. Never conveys intrinsics.
46 * 6. Cursed items never weld; their effect is handled by the normal
47 * throwing code.
48 * 7. The autoquiver option will fill it with something deemed
49 * suitable if (f)ire is used when it's empty.
51 * No item may be in more than one of these slots.
54 STATIC_DCL boolean FDECL(cant_wield_corpse, (struct obj *));
55 STATIC_DCL int FDECL(ready_weapon, (struct obj *));
57 /* used by will_weld() */
58 /* probably should be renamed */
59 #define erodeable_wep(optr) \
60 ((optr)->oclass == WEAPON_CLASS || is_weptool(optr) \
61 || (optr)->otyp == HEAVY_IRON_BALL || (optr)->otyp == IRON_CHAIN)
63 /* used by welded(), and also while wielding */
64 #define will_weld(optr) \
65 ((optr)->cursed && (erodeable_wep(optr) || (optr)->otyp == TIN_OPENER))
67 /*** Functions that place a given item in a slot ***/
68 /* Proper usage includes:
69 * 1. Initializing the slot during character generation or a
70 * restore.
71 * 2. Setting the slot due to a player's actions.
72 * 3. If one of the objects in the slot are split off, these
73 * functions can be used to put the remainder back in the slot.
74 * 4. Putting an item that was thrown and returned back into the slot.
75 * 5. Emptying the slot, by passing a null object. NEVER pass
76 * zeroobj!
78 * If the item is being moved from another slot, it is the caller's
79 * responsibility to handle that. It's also the caller's responsibility
80 * to print the appropriate messages.
82 void
83 setuwep(obj)
84 register struct obj *obj;
86 struct obj *olduwep = uwep;
88 if (obj == uwep)
89 return; /* necessary to not set unweapon */
90 /* This message isn't printed in the caller because it happens
91 * *whenever* Sunsword is unwielded, from whatever cause.
93 setworn(obj, W_WEP);
94 if (uwep == obj && artifact_light(olduwep) && olduwep->lamplit) {
95 end_burn(olduwep, FALSE);
96 if (!Blind)
97 pline("%s shining.", Tobjnam(olduwep, "stop"));
99 /* Note: Explicitly wielding a pick-axe will not give a "bashing"
100 * message. Wielding one via 'a'pplying it will.
101 * 3.2.2: Wielding arbitrary objects will give bashing message too.
103 if (obj) {
104 unweapon = (obj->oclass == WEAPON_CLASS)
105 ? is_launcher(obj) || is_ammo(obj) || is_missile(obj)
106 || (is_pole(obj) && !u.usteed)
107 : !is_weptool(obj) && !is_wet_towel(obj);
108 } else
109 unweapon = TRUE; /* for "bare hands" message */
110 update_inventory();
113 STATIC_OVL boolean
114 cant_wield_corpse(obj)
115 struct obj *obj;
117 char kbuf[BUFSZ];
119 if (uarmg || obj->otyp != CORPSE || !touch_petrifies(&mons[obj->corpsenm])
120 || Stone_resistance)
121 return FALSE;
123 /* Prevent wielding cockatrice when not wearing gloves --KAA */
124 You("wield %s in your bare %s.",
125 corpse_xname(obj, (const char *) 0, CXN_PFX_THE),
126 makeplural(body_part(HAND)));
127 Sprintf(kbuf, "wielding %s bare-handed", killer_xname(obj));
128 instapetrify(kbuf);
129 return TRUE;
132 STATIC_OVL int
133 ready_weapon(wep)
134 struct obj *wep;
136 /* Separated function so swapping works easily */
137 int res = 0;
139 if (!wep) {
140 /* No weapon */
141 if (uwep) {
142 You("are empty %s.", body_part(HANDED));
143 setuwep((struct obj *) 0);
144 res++;
145 } else
146 You("are already empty %s.", body_part(HANDED));
147 } else if (wep->otyp == CORPSE && cant_wield_corpse(wep)) {
148 /* hero must have been life-saved to get here; use a turn */
149 res++; /* corpse won't be wielded */
150 } else if (uarms && bimanual(wep)) {
151 You("cannot wield a two-handed %s while wearing a shield.",
152 is_sword(wep) ? "sword" : wep->otyp == BATTLE_AXE ? "axe"
153 : "weapon");
154 } else if (!retouch_object(&wep, FALSE)) {
155 res++; /* takes a turn even though it doesn't get wielded */
156 } else {
157 /* Weapon WILL be wielded after this point */
158 res++;
159 if (will_weld(wep)) {
160 const char *tmp = xname(wep), *thestr = "The ";
162 if (strncmp(tmp, thestr, 4) && !strncmp(The(tmp), thestr, 4))
163 tmp = thestr;
164 else
165 tmp = "";
166 pline("%s%s %s to your %s!", tmp, aobjnam(wep, "weld"),
167 (wep->quan == 1L) ? "itself" : "themselves", /* a3 */
168 bimanual(wep) ? (const char *) makeplural(body_part(HAND))
169 : body_part(HAND));
170 wep->bknown = TRUE;
171 } else {
172 /* The message must be printed before setuwep (since
173 * you might die and be revived from changing weapons),
174 * and the message must be before the death message and
175 * Lifesaved rewielding. Yet we want the message to
176 * say "weapon in hand", thus this kludge.
177 * [That comment is obsolete. It dates from the days (3.0)
178 * when unwielding Firebrand could cause hero to be burned
179 * to death in Hell due to loss of fire resistance.
180 * "Lifesaved re-wielding or re-wearing" is ancient history.]
182 long dummy = wep->owornmask;
184 wep->owornmask |= W_WEP;
185 prinv((char *) 0, wep, 0L);
186 wep->owornmask = dummy;
188 setuwep(wep);
190 /* KMH -- Talking artifacts are finally implemented */
191 arti_speak(wep);
193 if (artifact_light(wep) && !wep->lamplit) {
194 begin_burn(wep, FALSE);
195 if (!Blind)
196 pline("%s to shine %s!", Tobjnam(wep, "begin"),
197 arti_light_description(wep));
199 #if 0
200 /* we'll get back to this someday, but it's not balanced yet */
201 if (Race_if(PM_ELF) && !wep->oartifact
202 && objects[wep->otyp].oc_material == IRON) {
203 /* Elves are averse to wielding cold iron */
204 You("have an uneasy feeling about wielding cold iron.");
205 change_luck(-1);
207 #endif
208 if (wep->unpaid) {
209 struct monst *this_shkp;
211 if ((this_shkp = shop_keeper(inside_shop(u.ux, u.uy)))
212 != (struct monst *) 0) {
213 pline("%s says \"You be careful with my %s!\"",
214 shkname(this_shkp), xname(wep));
218 return res;
221 void
222 setuqwep(obj)
223 register struct obj *obj;
225 setworn(obj, W_QUIVER);
226 update_inventory();
229 void
230 setuswapwep(obj)
231 register struct obj *obj;
233 setworn(obj, W_SWAPWEP);
234 update_inventory();
237 /*** Commands to change particular slot(s) ***/
239 static NEARDATA const char wield_objs[] = {
240 ALL_CLASSES, ALLOW_NONE, WEAPON_CLASS, TOOL_CLASS, 0
242 static NEARDATA const char ready_objs[] = {
243 ALLOW_COUNT, COIN_CLASS, ALL_CLASSES, ALLOW_NONE, WEAPON_CLASS, 0
245 static NEARDATA const char bullets[] = { /* (note: different from dothrow.c) */
246 ALLOW_COUNT, COIN_CLASS, ALL_CLASSES, ALLOW_NONE,
247 GEM_CLASS, WEAPON_CLASS, 0
251 dowield()
253 register struct obj *wep, *oldwep;
254 int result;
256 /* May we attempt this? */
257 multi = 0;
258 if (cantwield(youmonst.data)) {
259 pline("Don't be ridiculous!");
260 return 0;
263 /* Prompt for a new weapon */
264 if (!(wep = getobj(wield_objs, "wield")))
265 /* Cancelled */
266 return 0;
267 else if (wep == uwep) {
268 You("are already wielding that!");
269 if (is_weptool(wep) || is_wet_towel(wep))
270 unweapon = FALSE; /* [see setuwep()] */
271 return 0;
272 } else if (welded(uwep)) {
273 weldmsg(uwep);
274 /* previously interrupted armor removal mustn't be resumed */
275 reset_remarm();
276 return 0;
279 /* Handle no object, or object in other slot */
280 if (wep == &zeroobj)
281 wep = (struct obj *) 0;
282 else if (wep == uswapwep)
283 return doswapweapon();
284 else if (wep == uquiver)
285 setuqwep((struct obj *) 0);
286 else if (wep->owornmask & (W_ARMOR | W_ACCESSORY | W_SADDLE)) {
287 You("cannot wield that!");
288 return 0;
291 /* Set your new primary weapon */
292 oldwep = uwep;
293 result = ready_weapon(wep);
294 if (flags.pushweapon && oldwep && uwep != oldwep)
295 setuswapwep(oldwep);
296 untwoweapon();
298 return result;
302 doswapweapon()
304 register struct obj *oldwep, *oldswap;
305 int result = 0;
307 /* May we attempt this? */
308 multi = 0;
309 if (cantwield(youmonst.data)) {
310 pline("Don't be ridiculous!");
311 return 0;
313 if (welded(uwep)) {
314 weldmsg(uwep);
315 return 0;
318 /* Unwield your current secondary weapon */
319 oldwep = uwep;
320 oldswap = uswapwep;
321 setuswapwep((struct obj *) 0);
323 /* Set your new primary weapon */
324 result = ready_weapon(oldswap);
326 /* Set your new secondary weapon */
327 if (uwep == oldwep) {
328 /* Wield failed for some reason */
329 setuswapwep(oldswap);
330 } else {
331 setuswapwep(oldwep);
332 if (uswapwep)
333 prinv((char *) 0, uswapwep, 0L);
334 else
335 You("have no secondary weapon readied.");
338 if (u.twoweap && !can_twoweapon())
339 untwoweapon();
341 return result;
345 dowieldquiver()
347 char qbuf[QBUFSZ];
348 struct obj *newquiver;
349 const char *quivee_types;
350 int res;
351 boolean finish_splitting = FALSE,
352 was_uwep = FALSE, was_twoweap = u.twoweap;
354 /* Since the quiver isn't in your hands, don't check cantwield(), */
355 /* will_weld(), touch_petrifies(), etc. */
356 multi = 0;
357 /* forget last splitobj() before calling getobj() with ALLOW_COUNT */
358 context.objsplit.child_oid = context.objsplit.parent_oid = 0;
360 /* Prompt for a new quiver: "What do you want to ready?"
361 (Include gems/stones as likely candidates if either primary
362 or secondary weapon is a sling.) */
363 quivee_types = (uslinging()
364 || (uswapwep
365 && objects[uswapwep->otyp].oc_skill == P_SLING))
366 ? bullets
367 : ready_objs;
368 newquiver = getobj(quivee_types, "ready");
370 if (!newquiver) {
371 /* Cancelled */
372 return 0;
373 } else if (newquiver == &zeroobj) { /* no object */
374 /* Explicitly nothing */
375 if (uquiver) {
376 You("now have no ammunition readied.");
377 /* skip 'quivering: prinv()' */
378 setuqwep((struct obj *) 0);
379 } else {
380 You("already have no ammunition readied!");
382 return 0;
383 } else if (newquiver->o_id == context.objsplit.child_oid) {
384 /* if newquiver is the result of supplying a count to getobj()
385 we don't want to split something already in the quiver;
386 for any other item, we need to give it its own inventory slot */
387 if (uquiver && uquiver->o_id == context.objsplit.parent_oid) {
388 unsplitobj(newquiver);
389 goto already_quivered;
391 finish_splitting = TRUE;
392 } else if (newquiver == uquiver) {
393 already_quivered:
394 pline("That ammunition is already readied!");
395 return 0;
396 } else if (newquiver->owornmask & (W_ARMOR | W_ACCESSORY | W_SADDLE)) {
397 You("cannot ready that!");
398 return 0;
399 } else if (newquiver == uwep) {
400 int weld_res = !uwep->bknown;
402 if (welded(uwep)) {
403 weldmsg(uwep);
404 reset_remarm(); /* same as dowield() */
405 return weld_res;
407 /* offer to split stack if wielding more than 1 */
408 if (uwep->quan > 1L && inv_cnt(FALSE) < 52 && splittable(uwep)) {
409 Sprintf(qbuf, "You are wielding %ld %s. Ready %ld of them?",
410 uwep->quan, simpleonames(uwep), uwep->quan - 1L);
411 switch (ynq(qbuf)) {
412 case 'q':
413 return 0;
414 case 'y':
415 /* leave 1 wielded, split rest off and put into quiver */
416 newquiver = splitobj(uwep, uwep->quan - 1L);
417 finish_splitting = TRUE;
418 goto quivering;
419 default:
420 break;
422 Strcpy(qbuf, "Ready all of them instead?");
423 } else {
424 Sprintf(qbuf, "You are wielding %s. Ready %s instead?",
425 /* uwep->quan is 1, but name might be plural ('boots') */
426 !is_plural(uwep) ? "that" : "those",
427 !is_plural(uwep) ? "it" : "them");
429 /* require confirmation to ready the main weapon */
430 if (ynq(qbuf) != 'y') {
431 (void) Shk_Your(qbuf, uwep); /* replace qbuf[] contents */
432 pline("%s%s %s wielded.", qbuf,
433 simpleonames(uwep), otense(uwep, "remain"));
434 return 0;
436 /* quivering main weapon, so no longer wielding it */
437 setuwep((struct obj *) 0);
438 untwoweapon();
439 was_uwep = TRUE;
440 } else if (newquiver == uswapwep) {
441 if (uswapwep->quan > 1L && inv_cnt(FALSE) < 52
442 && splittable(uswapwep)) {
443 Sprintf(qbuf, "%s %ld %s. Ready %ld of them?",
444 u.twoweap ? "You are dual wielding"
445 : "Your alternate weapon is",
446 uswapwep->quan, simpleonames(uswapwep),
447 uswapwep->quan - 1L);
448 switch (ynq(qbuf)) {
449 case 'q':
450 return 0;
451 case 'y':
452 /* leave 1 alt-wielded, split rest off and put into quiver */
453 newquiver = splitobj(uswapwep, uswapwep->quan - 1L);
454 finish_splitting = TRUE;
455 goto quivering;
456 default:
457 break;
459 Strcpy(qbuf, "Ready all of them instead?");
460 } else {
461 Sprintf(qbuf, "%s your %s weapon. Ready %s instead?",
462 !is_plural(uswapwep) ? "That is" : "Those are",
463 u.twoweap ? "second" : "alternate",
464 /* uswapwep->quan is 1, but name might be plural */
465 !is_plural(uswapwep) ? "it" : "them");
467 /* require confirmation to ready the alternate weapon */
468 if (ynq(qbuf) != 'y') {
469 (void) Shk_Your(qbuf, uswapwep); /* replace qbuf[] contents */
470 pline("%s%s %s %s.", qbuf,
471 simpleonames(uswapwep), otense(uswapwep, "remain"),
472 u.twoweap ? "wielded" : "as secondary weapon");
473 return 0;
475 /* quivering alternate weapon, so no more uswapwep */
476 setuswapwep((struct obj *) 0);
477 untwoweapon();
480 quivering:
481 if (finish_splitting) {
482 freeinv(newquiver);
483 newquiver->nomerge = 1;
484 addinv(newquiver);
485 newquiver->nomerge = 0;
487 /* place item in quiver before printing so that inventory feedback
488 includes "(at the ready)" */
489 setuqwep(newquiver);
490 prinv((char *) 0, newquiver, 0L);
492 /* quiver is a convenience slot and manipulating it ordinarily
493 consumes no time, but unwielding primary or secondary weapon
494 should take time (perhaps we're adjacent to a rust monster
495 or disenchanter and want to hit it immediately, but not with
496 something we're wielding that's vulnerable to its damage) */
497 res = 0;
498 if (was_uwep) {
499 You("are now empty %s.", body_part(HANDED));
500 res = 1;
501 } else if (was_twoweap && !u.twoweap) {
502 You("are no longer wielding two weapons at once.");
503 res = 1;
505 return res;
508 /* used for #rub and for applying pick-axe, whip, grappling hook or polearm */
509 boolean
510 wield_tool(obj, verb)
511 struct obj *obj;
512 const char *verb; /* "rub",&c */
514 const char *what;
515 boolean more_than_1;
517 if (obj == uwep)
518 return TRUE; /* nothing to do if already wielding it */
520 if (!verb)
521 verb = "wield";
522 what = xname(obj);
523 more_than_1 = (obj->quan > 1L || strstri(what, "pair of ") != 0
524 || strstri(what, "s of ") != 0);
526 if (obj->owornmask & (W_ARMOR | W_ACCESSORY)) {
527 You_cant("%s %s while wearing %s.", verb, yname(obj),
528 more_than_1 ? "them" : "it");
529 return FALSE;
531 if (welded(uwep)) {
532 if (flags.verbose) {
533 const char *hand = body_part(HAND);
535 if (bimanual(uwep))
536 hand = makeplural(hand);
537 if (strstri(what, "pair of ") != 0)
538 more_than_1 = FALSE;
539 pline(
540 "Since your weapon is welded to your %s, you cannot %s %s %s.",
541 hand, verb, more_than_1 ? "those" : "that", xname(obj));
542 } else {
543 You_cant("do that.");
545 return FALSE;
547 if (cantwield(youmonst.data)) {
548 You_cant("hold %s strongly enough.", more_than_1 ? "them" : "it");
549 return FALSE;
551 /* check shield */
552 if (uarms && bimanual(obj)) {
553 You("cannot %s a two-handed %s while wearing a shield.", verb,
554 (obj->oclass == WEAPON_CLASS) ? "weapon" : "tool");
555 return FALSE;
558 if (uquiver == obj)
559 setuqwep((struct obj *) 0);
560 if (uswapwep == obj) {
561 (void) doswapweapon();
562 /* doswapweapon might fail */
563 if (uswapwep == obj)
564 return FALSE;
565 } else {
566 struct obj *oldwep = uwep;
568 You("now wield %s.", doname(obj));
569 setuwep(obj);
570 if (flags.pushweapon && oldwep && uwep != oldwep)
571 setuswapwep(oldwep);
573 if (uwep != obj)
574 return FALSE; /* rewielded old object after dying */
575 /* applying weapon or tool that gets wielded ends two-weapon combat */
576 if (u.twoweap)
577 untwoweapon();
578 if (obj->oclass != WEAPON_CLASS)
579 unweapon = TRUE;
580 return TRUE;
584 can_twoweapon()
586 struct obj *otmp;
588 #define NOT_WEAPON(obj) (!is_weptool(obj) && obj->oclass != WEAPON_CLASS)
589 if (!could_twoweap(youmonst.data)) {
590 if (Upolyd)
591 You_cant("use two weapons in your current form.");
592 else
593 pline("%s aren't able to use two weapons at once.",
594 makeplural((flags.female && urole.name.f) ? urole.name.f
595 : urole.name.m));
596 } else if (!uwep || !uswapwep)
597 Your("%s%s%s empty.", uwep ? "left " : uswapwep ? "right " : "",
598 body_part(HAND), (!uwep && !uswapwep) ? "s are" : " is");
599 else if (NOT_WEAPON(uwep) || NOT_WEAPON(uswapwep)) {
600 otmp = NOT_WEAPON(uwep) ? uwep : uswapwep;
601 pline("%s %s.", Yname2(otmp),
602 is_plural(otmp) ? "aren't weapons" : "isn't a weapon");
603 } else if (bimanual(uwep) || bimanual(uswapwep)) {
604 otmp = bimanual(uwep) ? uwep : uswapwep;
605 pline("%s isn't one-handed.", Yname2(otmp));
606 } else if (uarms)
607 You_cant("use two weapons while wearing a shield.");
608 else if (uswapwep->oartifact)
609 pline("%s being held second to another weapon!",
610 Yobjnam2(uswapwep, "resist"));
611 else if (uswapwep->otyp == CORPSE && cant_wield_corpse(uswapwep)) {
612 /* [Note: NOT_WEAPON() check prevents ever getting here...] */
613 ; /* must be life-saved to reach here; return FALSE */
614 } else if (Glib || uswapwep->cursed) {
615 if (!Glib)
616 uswapwep->bknown = TRUE;
617 drop_uswapwep();
618 } else
619 return TRUE;
620 return FALSE;
623 void
624 drop_uswapwep()
626 char str[BUFSZ];
627 struct obj *obj = uswapwep;
629 /* Avoid trashing makeplural's static buffer */
630 Strcpy(str, makeplural(body_part(HAND)));
631 pline("%s from your %s!", Yobjnam2(obj, "slip"), str);
632 dropx(obj);
636 dotwoweapon()
638 /* You can always toggle it off */
639 if (u.twoweap) {
640 You("switch to your primary weapon.");
641 u.twoweap = 0;
642 update_inventory();
643 return 0;
646 /* May we use two weapons? */
647 if (can_twoweapon()) {
648 /* Success! */
649 You("begin two-weapon combat.");
650 u.twoweap = 1;
651 update_inventory();
652 return (rnd(20) > ACURR(A_DEX));
654 return 0;
657 /*** Functions to empty a given slot ***/
658 /* These should be used only when the item can't be put back in
659 * the slot by life saving. Proper usage includes:
660 * 1. The item has been eaten, stolen, burned away, or rotted away.
661 * 2. Making an item disappear for a bones pile.
663 void
664 uwepgone()
666 if (uwep) {
667 if (artifact_light(uwep) && uwep->lamplit) {
668 end_burn(uwep, FALSE);
669 if (!Blind)
670 pline("%s shining.", Tobjnam(uwep, "stop"));
672 setworn((struct obj *) 0, W_WEP);
673 unweapon = TRUE;
674 update_inventory();
678 void
679 uswapwepgone()
681 if (uswapwep) {
682 setworn((struct obj *) 0, W_SWAPWEP);
683 update_inventory();
687 void
688 uqwepgone()
690 if (uquiver) {
691 setworn((struct obj *) 0, W_QUIVER);
692 update_inventory();
696 void
697 untwoweapon()
699 if (u.twoweap) {
700 You("can no longer use two weapons at once.");
701 u.twoweap = FALSE;
702 update_inventory();
704 return;
708 chwepon(otmp, amount)
709 register struct obj *otmp;
710 register int amount;
712 const char *color = hcolor((amount < 0) ? NH_BLACK : NH_BLUE);
713 const char *xtime, *wepname = "";
714 boolean multiple;
715 int otyp = STRANGE_OBJECT;
717 if (!uwep || (uwep->oclass != WEAPON_CLASS && !is_weptool(uwep))) {
718 char buf[BUFSZ];
720 if (amount >= 0 && uwep && will_weld(uwep)) { /* cursed tin opener */
721 if (!Blind) {
722 Sprintf(buf, "%s with %s aura.",
723 Yobjnam2(uwep, "glow"), an(hcolor(NH_AMBER)));
724 uwep->bknown = !Hallucination;
725 } else {
726 /* cursed tin opener is wielded in right hand */
727 Sprintf(buf, "Your right %s tingles.", body_part(HAND));
729 uncurse(uwep);
730 update_inventory();
731 } else {
732 Sprintf(buf, "Your %s %s.", makeplural(body_part(HAND)),
733 (amount >= 0) ? "twitch" : "itch");
735 strange_feeling(otmp, buf); /* pline()+docall()+useup() */
736 exercise(A_DEX, (boolean) (amount >= 0));
737 return 0;
740 if (otmp && otmp->oclass == SCROLL_CLASS)
741 otyp = otmp->otyp;
743 if (uwep->otyp == WORM_TOOTH && amount >= 0) {
744 multiple = (uwep->quan > 1L);
745 /* order: message, transformation, shop handling */
746 Your("%s %s much sharper now.", simpleonames(uwep),
747 multiple ? "fuse, and become" : "is");
748 uwep->otyp = CRYSKNIFE;
749 uwep->oerodeproof = 0;
750 if (multiple) {
751 uwep->quan = 1L;
752 uwep->owt = weight(uwep);
754 if (uwep->cursed)
755 uncurse(uwep);
756 /* update shop bill to reflect new higher value */
757 if (uwep->unpaid)
758 alter_cost(uwep, 0L);
759 if (otyp != STRANGE_OBJECT)
760 makeknown(otyp);
761 if (multiple)
762 encumber_msg();
763 return 1;
764 } else if (uwep->otyp == CRYSKNIFE && amount < 0) {
765 multiple = (uwep->quan > 1L);
766 /* order matters: message, shop handling, transformation */
767 Your("%s %s much duller now.", simpleonames(uwep),
768 multiple ? "fuse, and become" : "is");
769 costly_alteration(uwep, COST_DEGRD); /* DECHNT? other? */
770 uwep->otyp = WORM_TOOTH;
771 uwep->oerodeproof = 0;
772 if (multiple) {
773 uwep->quan = 1L;
774 uwep->owt = weight(uwep);
776 if (otyp != STRANGE_OBJECT && otmp->bknown)
777 makeknown(otyp);
778 if (multiple)
779 encumber_msg();
780 return 1;
783 if (has_oname(uwep))
784 wepname = ONAME(uwep);
785 if (amount < 0 && uwep->oartifact && restrict_name(uwep, wepname)) {
786 if (!Blind)
787 pline("%s %s.", Yobjnam2(uwep, "faintly glow"), color);
788 return 1;
790 /* there is a (soft) upper and lower limit to uwep->spe */
791 if (((uwep->spe > 5 && amount >= 0) || (uwep->spe < -5 && amount < 0))
792 && rn2(3)) {
793 if (!Blind)
794 pline("%s %s for a while and then %s.",
795 Yobjnam2(uwep, "violently glow"), color,
796 otense(uwep, "evaporate"));
797 else
798 pline("%s.", Yobjnam2(uwep, "evaporate"));
800 useupall(uwep); /* let all of them disappear */
801 return 1;
803 if (!Blind) {
804 xtime = (amount * amount == 1) ? "moment" : "while";
805 pline("%s %s for a %s.",
806 Yobjnam2(uwep, amount == 0 ? "violently glow" : "glow"), color,
807 xtime);
808 if (otyp != STRANGE_OBJECT && uwep->known
809 && (amount > 0 || (amount < 0 && otmp->bknown)))
810 makeknown(otyp);
812 if (amount < 0)
813 costly_alteration(uwep, COST_DECHNT);
814 uwep->spe += amount;
815 if (amount > 0) {
816 if (uwep->cursed)
817 uncurse(uwep);
818 /* update shop bill to reflect new higher price */
819 if (uwep->unpaid)
820 alter_cost(uwep, 0L);
824 * Enchantment, which normally improves a weapon, has an
825 * addition adverse reaction on Magicbane whose effects are
826 * spe dependent. Give an obscure clue here.
828 if (uwep->oartifact == ART_MAGICBANE && uwep->spe >= 0) {
829 Your("right %s %sches!", body_part(HAND),
830 (((amount > 1) && (uwep->spe > 1)) ? "flin" : "it"));
833 /* an elven magic clue, cookie@keebler */
834 /* elven weapons vibrate warningly when enchanted beyond a limit */
835 if ((uwep->spe > 5)
836 && (is_elven_weapon(uwep) || uwep->oartifact || !rn2(7)))
837 pline("%s unexpectedly.", Yobjnam2(uwep, "suddenly vibrate"));
839 return 1;
843 welded(obj)
844 register struct obj *obj;
846 if (obj && obj == uwep && will_weld(obj)) {
847 obj->bknown = TRUE;
848 return 1;
850 return 0;
853 void
854 weldmsg(obj)
855 register struct obj *obj;
857 long savewornmask;
859 savewornmask = obj->owornmask;
860 pline("%s welded to your %s!", Yobjnam2(obj, "are"),
861 bimanual(obj) ? (const char *) makeplural(body_part(HAND))
862 : body_part(HAND));
863 obj->owornmask = savewornmask;
866 /* test whether monster's wielded weapon is stuck to hand/paw/whatever */
867 boolean
868 mwelded(obj)
869 struct obj *obj;
871 /* caller is responsible for making sure this is a monster's item */
872 if (obj && (obj->owornmask & W_WEP) && will_weld(obj))
873 return TRUE;
874 return FALSE;
877 /*wield.c*/