Source:NetHack 3.6.2/src/apply.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to apply.c from the source code of NetHack 3.6.2. To link to a particular line, write [[Source:NetHack 3.6.2/src/apply.c#line12]], for example.

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. /* NetHack 3.6	apply.c	$NHDT-Date: 1553363415 2019/03/23 17:50:15 $  $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.272 $ */
2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3. /*-Copyright (c) Robert Patrick Rankin, 2012. */
4. /* NetHack may be freely redistributed.  See license for details. */
5. 
6. #include "hack.h"
7. 
8. extern boolean notonhead; /* for long worms */
9. 
10. STATIC_DCL int FDECL(use_camera, (struct obj *));
11. STATIC_DCL int FDECL(use_towel, (struct obj *));
12. STATIC_DCL boolean FDECL(its_dead, (int, int, int *));
13. STATIC_DCL int FDECL(use_stethoscope, (struct obj *));
14. STATIC_DCL void FDECL(use_whistle, (struct obj *));
15. STATIC_DCL void FDECL(use_magic_whistle, (struct obj *));
16. STATIC_DCL int FDECL(use_leash, (struct obj *));
17. STATIC_DCL int FDECL(use_mirror, (struct obj *));
18. STATIC_DCL void FDECL(use_bell, (struct obj **));
19. STATIC_DCL void FDECL(use_candelabrum, (struct obj *));
20. STATIC_DCL void FDECL(use_candle, (struct obj **));
21. STATIC_DCL void FDECL(use_lamp, (struct obj *));
22. STATIC_DCL void FDECL(light_cocktail, (struct obj **));
23. STATIC_PTR void FDECL(display_jump_positions, (int));
24. STATIC_DCL void FDECL(use_tinning_kit, (struct obj *));
25. STATIC_DCL void FDECL(use_figurine, (struct obj **));
26. STATIC_DCL void FDECL(use_grease, (struct obj *));
27. STATIC_DCL void FDECL(use_trap, (struct obj *));
28. STATIC_DCL void FDECL(use_stone, (struct obj *));
29. STATIC_PTR int NDECL(set_trap); /* occupation callback */
30. STATIC_DCL int FDECL(use_whip, (struct obj *));
31. STATIC_PTR void FDECL(display_polearm_positions, (int));
32. STATIC_DCL int FDECL(use_pole, (struct obj *));
33. STATIC_DCL int FDECL(use_cream_pie, (struct obj *));
34. STATIC_DCL int FDECL(use_grapple, (struct obj *));
35. STATIC_DCL int FDECL(do_break_wand, (struct obj *));
36. STATIC_DCL boolean FDECL(figurine_location_checks, (struct obj *,
37.                                                     coord *, BOOLEAN_P));
38. STATIC_DCL void FDECL(add_class, (char *, CHAR_P));
39. STATIC_DCL void FDECL(setapplyclasses, (char *));
40. STATIC_PTR boolean FDECL(check_jump, (genericptr_t, int, int));
41. STATIC_DCL boolean FDECL(is_valid_jump_pos, (int, int, int, BOOLEAN_P));
42. STATIC_DCL boolean FDECL(get_valid_jump_position, (int, int));
43. STATIC_DCL boolean FDECL(get_valid_polearm_position, (int, int));
44. STATIC_DCL boolean FDECL(find_poleable_mon, (coord *, int, int));
45. 
46. #ifdef AMIGA
47. void FDECL(amii_speaker, (struct obj *, char *, int));
48. #endif
49. 
50. static const char no_elbow_room[] =
51.     "don't have enough elbow-room to maneuver.";
52. 
53. STATIC_OVL int
54. use_camera(obj)
55. struct obj *obj;
56. {
57.     struct monst *mtmp;
58. 
59.     if (Underwater) {
60.         pline("Using your camera underwater would void the warranty.");
61.         return 0;
62.     }
63.     if (!getdir((char *) 0))
64.         return 0;
65. 
66.     if (obj->spe <= 0) {
67.         pline1(nothing_happens);
68.         return 1;
69.     }
70.     consume_obj_charge(obj, TRUE);
71. 
72.     if (obj->cursed && !rn2(2)) {
73.         (void) zapyourself(obj, TRUE);
74.     } else if (u.uswallow) {
75.         You("take a picture of %s %s.", s_suffix(mon_nam(u.ustuck)),
76.             mbodypart(u.ustuck, STOMACH));
77.     } else if (u.dz) {
78.         You("take a picture of the %s.",
79.             (u.dz > 0) ? surface(u.ux, u.uy) : ceiling(u.ux, u.uy));
80.     } else if (!u.dx && !u.dy) {
81.         (void) zapyourself(obj, TRUE);
82.     } else if ((mtmp = bhit(u.dx, u.dy, COLNO, FLASHED_LIGHT,
83.                             (int FDECL((*), (MONST_P, OBJ_P))) 0,
84.                             (int FDECL((*), (OBJ_P, OBJ_P))) 0, &obj)) != 0) {
85.         obj->ox = u.ux, obj->oy = u.uy;
86.         (void) flash_hits_mon(mtmp, obj);
87.     }
88.     return 1;
89. }
90. 
91. STATIC_OVL int
92. use_towel(obj)
93. struct obj *obj;
94. {
95.     boolean drying_feedback = (obj == uwep);
96. 
97.     if (!freehand()) {
98.         You("have no free %s!", body_part(HAND));
99.         return 0;
100.     } else if (obj == ublindf) {
101.         You("cannot use it while you're wearing it!");
102.         return 0;
103.     } else if (obj->cursed) {
104.         long old;
105. 
106.         switch (rn2(3)) {
107.         case 2:
108.             old = Glib;
109.             incr_itimeout(&Glib, rn1(10, 3));
110.             Your("%s %s!", makeplural(body_part(HAND)),
111.                  (old ? "are filthier than ever" : "get slimy"));
112.             if (is_wet_towel(obj))
113.                 dry_a_towel(obj, -1, drying_feedback);
114.             return 1;
115.         case 1:
116.             if (!ublindf) {
117.                 old = u.ucreamed;
118.                 u.ucreamed += rn1(10, 3);
119.                 pline("Yecch!  Your %s %s gunk on it!", body_part(FACE),
120.                       (old ? "has more" : "now has"));
121.                 make_blinded(Blinded + (long) u.ucreamed - old, TRUE);
122.             } else {
123.                 const char *what;
124. 
125.                 what = (ublindf->otyp == LENSES)
126.                            ? "lenses"
127.                            : (obj->otyp == ublindf->otyp) ? "other towel"
128.                                                           : "blindfold";
129.                 if (ublindf->cursed) {
130.                     You("push your %s %s.", what,
131.                         rn2(2) ? "cock-eyed" : "crooked");
132.                 } else {
133.                     struct obj *saved_ublindf = ublindf;
134.                     You("push your %s off.", what);
135.                     Blindf_off(ublindf);
136.                     dropx(saved_ublindf);
137.                 }
138.             }
139.             if (is_wet_towel(obj))
140.                 dry_a_towel(obj, -1, drying_feedback);
141.             return 1;
142.         case 0:
143.             break;
144.         }
145.     }
146. 
147.     if (Glib) {
148.         Glib = 0;
149.         You("wipe off your %s.", makeplural(body_part(HAND)));
150.         if (is_wet_towel(obj))
151.             dry_a_towel(obj, -1, drying_feedback);
152.         return 1;
153.     } else if (u.ucreamed) {
154.         Blinded -= u.ucreamed;
155.         u.ucreamed = 0;
156.         if (!Blinded) {
157.             pline("You've got the glop off.");
158.             if (!gulp_blnd_check()) {
159.                 Blinded = 1;
160.                 make_blinded(0L, TRUE);
161.             }
162.         } else {
163.             Your("%s feels clean now.", body_part(FACE));
164.         }
165.         if (is_wet_towel(obj))
166.             dry_a_towel(obj, -1, drying_feedback);
167.         return 1;
168.     }
169. 
170.     Your("%s and %s are already clean.", body_part(FACE),
171.          makeplural(body_part(HAND)));
172. 
173.     return 0;
174. }
175. 
176. /* maybe give a stethoscope message based on floor objects */
177. STATIC_OVL boolean
178. its_dead(rx, ry, resp)
179. int rx, ry, *resp;
180. {
181.     char buf[BUFSZ];
182.     boolean more_corpses;
183.     struct permonst *mptr;
184.     struct obj *corpse = sobj_at(CORPSE, rx, ry),
185.                *statue = sobj_at(STATUE, rx, ry);
186. 
187.     if (!can_reach_floor(TRUE)) { /* levitation or unskilled riding */
188.         corpse = 0;               /* can't reach corpse on floor */
189.         /* you can't reach tiny statues (even though you can fight
190.            tiny monsters while levitating--consistency, what's that?) */
191.         while (statue && mons[statue->corpsenm].msize == MZ_TINY)
192.             statue = nxtobj(statue, STATUE, TRUE);
193.     }
194.     /* when both corpse and statue are present, pick the uppermost one */
195.     if (corpse && statue) {
196.         if (nxtobj(statue, CORPSE, TRUE) == corpse)
197.             corpse = 0; /* corpse follows statue; ignore it */
198.         else
199.             statue = 0; /* corpse precedes statue; ignore statue */
200.     }
201.     more_corpses = (corpse && nxtobj(corpse, CORPSE, TRUE));
202. 
203.     /* additional stethoscope messages from jyoung@apanix.apana.org.au */
204.     if (!corpse && !statue) {
205.         ; /* nothing to do */
206. 
207.     } else if (Hallucination) {
208.         if (!corpse) {
209.             /* it's a statue */
210.             Strcpy(buf, "You're both stoned");
211.         } else if (corpse->quan == 1L && !more_corpses) {
212.             int gndr = 2; /* neuter: "it" */
213.             struct monst *mtmp = get_mtraits(corpse, FALSE);
214. 
215.             /* (most corpses don't retain the monster's sex, so
216.                we're usually forced to use generic pronoun here) */
217.             if (mtmp) {
218.                 mptr = mtmp->data = &mons[mtmp->mnum];
219.                 /* TRUE: override visibility check--it's not on the map */
220.                 gndr = pronoun_gender(mtmp, TRUE);
221.             } else {
222.                 mptr = &mons[corpse->corpsenm];
223.                 if (is_female(mptr))
224.                     gndr = 1;
225.                 else if (is_male(mptr))
226.                     gndr = 0;
227.             }
228.             Sprintf(buf, "%s's dead", genders[gndr].he); /* "he"/"she"/"it" */
229.             buf[0] = highc(buf[0]);
230.         } else { /* plural */
231.             Strcpy(buf, "They're dead");
232.         }
233.         /* variations on "He's dead, Jim." (Star Trek's Dr McCoy) */
234.         You_hear("a voice say, \"%s, Jim.\"", buf);
235.         *resp = 1;
236.         return TRUE;
237. 
238.     } else if (corpse) {
239.         boolean here = (rx == u.ux && ry == u.uy),
240.                 one = (corpse->quan == 1L && !more_corpses), reviver = FALSE;
241.         int visglyph, corpseglyph;
242. 
243.         visglyph = glyph_at(rx, ry);
244.         corpseglyph = obj_to_glyph(corpse, rn2);
245. 
246.         if (Blind && (visglyph != corpseglyph))
247.             map_object(corpse, TRUE);
248. 
249.         if (Role_if(PM_HEALER)) {
250.             /* ok to reset `corpse' here; we're done with it */
251.             do {
252.                 if (obj_has_timer(corpse, REVIVE_MON))
253.                     reviver = TRUE;
254.                 else
255.                     corpse = nxtobj(corpse, CORPSE, TRUE);
256.             } while (corpse && !reviver);
257.         }
258.         You("determine that %s unfortunate being%s %s%s dead.",
259.             one ? (here ? "this" : "that") : (here ? "these" : "those"),
260.             one ? "" : "s", one ? "is" : "are", reviver ? " mostly" : "");
261.         return TRUE;
262. 
263.     } else { /* statue */
264.         const char *what, *how;
265. 
266.         mptr = &mons[statue->corpsenm];
267.         if (Blind) { /* ignore statue->dknown; it'll always be set */
268.             Sprintf(buf, "%s %s",
269.                     (rx == u.ux && ry == u.uy) ? "This" : "That",
270.                     humanoid(mptr) ? "person" : "creature");
271.             what = buf;
272.         } else {
273.             what = mptr->mname;
274.             if (!type_is_pname(mptr))
275.                 what = The(what);
276.         }
277.         how = "fine";
278.         if (Role_if(PM_HEALER)) {
279.             struct trap *ttmp = t_at(rx, ry);
280. 
281.             if (ttmp && ttmp->ttyp == STATUE_TRAP)
282.                 how = "extraordinary";
283.             else if (Has_contents(statue))
284.                 how = "remarkable";
285.         }
286. 
287.         pline("%s is in %s health for a statue.", what, how);
288.         return TRUE;
289.     }
290.     return FALSE; /* no corpse or statue */
291. }
292. 
293. static const char hollow_str[] = "a hollow sound.  This must be a secret %s!";
294. 
295. /* Strictly speaking it makes no sense for usage of a stethoscope to
296.    not take any time; however, unless it did, the stethoscope would be
297.    almost useless.  As a compromise, one use per turn is free, another
298.    uses up the turn; this makes curse status have a tangible effect. */
299. STATIC_OVL int
300. use_stethoscope(obj)
301. register struct obj *obj;
302. {
303.     struct monst *mtmp;
304.     struct rm *lev;
305.     int rx, ry, res;
306.     boolean interference = (u.uswallow && is_whirly(u.ustuck->data)
307.                             && !rn2(Role_if(PM_HEALER) ? 10 : 3));
308. 
309.     if (nohands(youmonst.data)) {
310.         You("have no hands!"); /* not `body_part(HAND)' */
311.         return 0;
312.     } else if (Deaf) {
313.         You_cant("hear anything!");
314.         return 0;
315.     } else if (!freehand()) {
316.         You("have no free %s.", body_part(HAND));
317.         return 0;
318.     }
319.     if (!getdir((char *) 0))
320.         return 0;
321. 
322.     res = (moves == context.stethoscope_move)
323.           && (youmonst.movement == context.stethoscope_movement);
324.     context.stethoscope_move = moves;
325.     context.stethoscope_movement = youmonst.movement;
326. 
327.     bhitpos.x = u.ux, bhitpos.y = u.uy; /* tentative, reset below */
328.     notonhead = u.uswallow;
329.     if (u.usteed && u.dz > 0) {
330.         if (interference) {
331.             pline("%s interferes.", Monnam(u.ustuck));
332.             mstatusline(u.ustuck);
333.         } else
334.             mstatusline(u.usteed);
335.         return res;
336.     } else if (u.uswallow && (u.dx || u.dy || u.dz)) {
337.         mstatusline(u.ustuck);
338.         return res;
339.     } else if (u.uswallow && interference) {
340.         pline("%s interferes.", Monnam(u.ustuck));
341.         mstatusline(u.ustuck);
342.         return res;
343.     } else if (u.dz) {
344.         if (Underwater)
345.             You_hear("faint splashing.");
346.         else if (u.dz < 0 || !can_reach_floor(TRUE))
347.             cant_reach_floor(u.ux, u.uy, (u.dz < 0), TRUE);
348.         else if (its_dead(u.ux, u.uy, &res))
349.             ; /* message already given */
350.         else if (Is_stronghold(&u.uz))
351.             You_hear("the crackling of hellfire.");
352.         else
353.             pline_The("%s seems healthy enough.", surface(u.ux, u.uy));
354.         return res;
355.     } else if (obj->cursed && !rn2(2)) {
356.         You_hear("your heart beat.");
357.         return res;
358.     }
359.     if (Stunned || (Confusion && !rn2(5)))
360.         confdir();
361.     if (!u.dx && !u.dy) {
362.         ustatusline();
363.         return res;
364.     }
365.     rx = u.ux + u.dx;
366.     ry = u.uy + u.dy;
367.     if (!isok(rx, ry)) {
368.         You_hear("a faint typing noise.");
369.         return 0;
370.     }
371.     if ((mtmp = m_at(rx, ry)) != 0) {
372.         const char *mnm = x_monnam(mtmp, ARTICLE_A, (const char *) 0,
373.                                    SUPPRESS_IT | SUPPRESS_INVISIBLE, FALSE);
374. 
375.         /* bhitpos needed by mstatusline() iff mtmp is a long worm */
376.         bhitpos.x = rx, bhitpos.y = ry;
377.         notonhead = (mtmp->mx != rx || mtmp->my != ry);
378. 
379.         if (mtmp->mundetected) {
380.             if (!canspotmon(mtmp))
381.                 There("is %s hidden there.", mnm);
382.             mtmp->mundetected = 0;
383.             newsym(mtmp->mx, mtmp->my);
384.         } else if (mtmp->mappearance) {
385.             const char *what = "thing";
386. 
387.             switch (M_AP_TYPE(mtmp)) {
388.             case M_AP_OBJECT:
389.                 what = simple_typename(mtmp->mappearance);
390.                 break;
391.             case M_AP_MONSTER: /* ignore Hallucination here */
392.                 what = mons[mtmp->mappearance].mname;
393.                 break;
394.             case M_AP_FURNITURE:
395.                 what = defsyms[mtmp->mappearance].explanation;
396.                 break;
397.             }
398.             seemimic(mtmp);
399.             pline("That %s is really %s.", what, mnm);
400.         } else if (flags.verbose && !canspotmon(mtmp)) {
401.             There("is %s there.", mnm);
402.         }
403. 
404.         mstatusline(mtmp);
405.         if (!canspotmon(mtmp))
406.             map_invisible(rx, ry);
407.         return res;
408.     }
409.     if (unmap_invisible(rx,ry))
410.         pline_The("invisible monster must have moved.");
411. 
412.     lev = &levl[rx][ry];
413.     switch (lev->typ) {
414.     case SDOOR:
415.         You_hear(hollow_str, "door");
416.         cvt_sdoor_to_door(lev); /* ->typ = DOOR */
417.         feel_newsym(rx, ry);
418.         return res;
419.     case SCORR:
420.         You_hear(hollow_str, "passage");
421.         lev->typ = CORR, lev->flags = 0;
422.         unblock_point(rx, ry);
423.         feel_newsym(rx, ry);
424.         return res;
425.     }
426. 
427.     if (!its_dead(rx, ry, &res))
428.         You("hear nothing special."); /* not You_hear()  */
429.     return res;
430. }
431. 
432. static const char whistle_str[] = "produce a %s whistling sound.";
433. 
434. STATIC_OVL void
435. use_whistle(obj)
436. struct obj *obj;
437. {
438.     if (!can_blow(&youmonst)) {
439.         You("are incapable of using the whistle.");
440.     } else if (Underwater) {
441.         You("blow bubbles through %s.", yname(obj));
442.     } else {
443.         if (Deaf)
444.             You_feel("rushing air tickle your %s.",
445.                         body_part(NOSE));
446.         else
447.             You(whistle_str, obj->cursed ? "shrill" : "high");
448.         wake_nearby();
449.         if (obj->cursed)
450.             vault_summon_gd();
451.     }
452. }
453. 
454. STATIC_OVL void
455. use_magic_whistle(obj)
456. struct obj *obj;
457. {
458.     register struct monst *mtmp, *nextmon;
459. 
460.     if (!can_blow(&youmonst)) {
461.         You("are incapable of using the whistle.");
462.     } else if (obj->cursed && !rn2(2)) {
463.         You("produce a %shigh-pitched humming noise.",
464.             Underwater ? "very " : "");
465.         wake_nearby();
466.     } else {
467.         int pet_cnt = 0, omx, omy;
468. 
469.         /* it's magic!  it works underwater too (at a higher pitch) */
470.         You(whistle_str,
471.             Hallucination ? "normal" : Underwater ? "strange, high-pitched"
472.                                                   : "strange");
473.         for (mtmp = fmon; mtmp; mtmp = nextmon) {
474.             nextmon = mtmp->nmon; /* trap might kill mon */
475.             if (DEADMONSTER(mtmp))
476.                 continue;
477.             /* steed is already at your location, so not affected;
478.                this avoids trap issues if you're on a trap location */
479.             if (mtmp == u.usteed)
480.                 continue;
481.             if (mtmp->mtame) {
482.                 if (mtmp->mtrapped) {
483.                     /* no longer in previous trap (affects mintrap) */
484.                     mtmp->mtrapped = 0;
485.                     fill_pit(mtmp->mx, mtmp->my);
486.                 }
487.                 /* mimic must be revealed before we know whether it
488.                    actually moves because line-of-sight may change */
489.                 if (M_AP_TYPE(mtmp))
490.                     seemimic(mtmp);
491.                 omx = mtmp->mx, omy = mtmp->my;
492.                 mnexto(mtmp);
493.                 if (mtmp->mx != omx || mtmp->my != omy) {
494.                     mtmp->mundetected = 0; /* reveal non-mimic hider */
495.                     if (canspotmon(mtmp))
496.                         ++pet_cnt;
497.                     if (mintrap(mtmp) == 2)
498.                         change_luck(-1);
499.                 }
500.             }
501.         }
502.         if (pet_cnt > 0)
503.             makeknown(obj->otyp);
504.     }
505. }
506. 
507. boolean
508. um_dist(x, y, n)
509. xchar x, y, n;
510. {
511.     return (boolean) (abs(u.ux - x) > n || abs(u.uy - y) > n);
512. }
513. 
514. int
515. number_leashed()
516. {
517.     int i = 0;
518.     struct obj *obj;
519. 
520.     for (obj = invent; obj; obj = obj->nobj)
521.         if (obj->otyp == LEASH && obj->leashmon != 0)
522.             i++;
523.     return i;
524. }
525. 
526. /* otmp is about to be destroyed or stolen */
527. void
528. o_unleash(otmp)
529. register struct obj *otmp;
530. {
531.     register struct monst *mtmp;
532. 
533.     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
534.         if (mtmp->m_id == (unsigned) otmp->leashmon)
535.             mtmp->mleashed = 0;
536.     otmp->leashmon = 0;
537. }
538. 
539. /* mtmp is about to die, or become untame */
540. void
541. m_unleash(mtmp, feedback)
542. register struct monst *mtmp;
543. boolean feedback;
544. {
545.     register struct obj *otmp;
546. 
547.     if (feedback) {
548.         if (canseemon(mtmp))
549.             pline("%s pulls free of %s leash!", Monnam(mtmp), mhis(mtmp));
550.         else
551.             Your("leash falls slack.");
552.     }
553.     for (otmp = invent; otmp; otmp = otmp->nobj)
554.         if (otmp->otyp == LEASH && otmp->leashmon == (int) mtmp->m_id)
555.             otmp->leashmon = 0;
556.     mtmp->mleashed = 0;
557. }
558. 
559. /* player is about to die (for bones) */
560. void
561. unleash_all()
562. {
563.     register struct obj *otmp;
564.     register struct monst *mtmp;
565. 
566.     for (otmp = invent; otmp; otmp = otmp->nobj)
567.         if (otmp->otyp == LEASH)
568.             otmp->leashmon = 0;
569.     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
570.         mtmp->mleashed = 0;
571. }
572. 
573. #define MAXLEASHED 2
574. 
575. /* TODO:
576.  *  This ought to exclude various other things, such as lights and gas
577.  *  spore, is_whirly() critters, ethereal creatures, possibly others.
578.  */
579. static boolean
580. leashable(mtmp)
581. struct monst *mtmp;
582. {
583.     return (boolean) (mtmp->mnum != PM_LONG_WORM);
584. }
585. 
586. /* ARGSUSED */
587. STATIC_OVL int
588. use_leash(obj)
589. struct obj *obj;
590. {
591.     coord cc;
592.     struct monst *mtmp;
593.     int spotmon;
594. 
595.     if (u.uswallow) {
596.         /* if the leash isn't in use, assume we're trying to leash
597.            the engulfer; if it is use, distinguish between removing
598.            it from the engulfer versus from some other creature
599.            (note: the two in-use cases can't actually occur; all
600.            leashes are released when the hero gets engulfed) */
601.         You_cant((!obj->leashmon
602.                   ? "leash %s from inside."
603.                   : (obj->leashmon == (int) u.ustuck->m_id)
604.                     ? "unleash %s from inside."
605.                     : "unleash anything from inside %s."),
606.                  noit_mon_nam(u.ustuck));
607.         return 0;
608.     }
609.     if (!obj->leashmon && number_leashed() >= MAXLEASHED) {
610.         You("cannot leash any more pets.");
611.         return 0;
612.     }
613. 
614.     if (!get_adjacent_loc((char *) 0, (char *) 0, u.ux, u.uy, &cc))
615.         return 0;
616. 
617.     if (cc.x == u.ux && cc.y == u.uy) {
618.         if (u.usteed && u.dz > 0) {
619.             mtmp = u.usteed;
620.             spotmon = 1;
621.             goto got_target;
622.         }
623.         pline("Leash yourself?  Very funny...");
624.         return 0;
625.     }
626. 
627.     /*
628.      * From here on out, return value is 1 == a move is used.
629.      */
630. 
631.     if (!(mtmp = m_at(cc.x, cc.y))) {
632.         There("is no creature there.");
633.         (void) unmap_invisible(cc.x, cc.y);
634.         return 1;
635.     }
636. 
637.     spotmon = canspotmon(mtmp);
638.  got_target:
639. 
640.     if (!spotmon && !glyph_is_invisible(levl[cc.x][cc.y].glyph)) {
641.         /* for the unleash case, we don't verify whether this unseen
642.            monster is the creature attached to the current leash */
643.         You("fail to %sleash something.", obj->leashmon ? "un" : "");
644.         /* trying again will work provided the monster is tame
645.            (and also that it doesn't change location by retry time) */
646.         map_invisible(cc.x, cc.y);
647.     } else if (!mtmp->mtame) {
648.         pline("%s %s leashed!", Monnam(mtmp),
649.               (!obj->leashmon) ? "cannot be" : "is not");
650.     } else if (!obj->leashmon) {
651.         /* applying a leash which isn't currently in use */
652.         if (mtmp->mleashed) {
653.             pline("This %s is already leashed.",
654.                   spotmon ? l_monnam(mtmp) : "creature");
655.         } else if (!leashable(mtmp)) {
656.             pline("The leash won't fit onto %s%s.", spotmon ? "your " : "",
657.                   l_monnam(mtmp));
658.         } else {
659.             You("slip the leash around %s%s.", spotmon ? "your " : "",
660.                 l_monnam(mtmp));
661.             mtmp->mleashed = 1;
662.             obj->leashmon = (int) mtmp->m_id;
663.             mtmp->msleeping = 0;
664.         }
665.     } else {
666.         /* applying a leash which is currently in use */
667.         if (obj->leashmon != (int) mtmp->m_id) {
668.             pline("This leash is not attached to that creature.");
669.         } else if (obj->cursed) {
670.             pline_The("leash would not come off!");
671.             obj->bknown = 1;
672.         } else {
673.             mtmp->mleashed = 0;
674.             obj->leashmon = 0;
675.             You("remove the leash from %s%s.",
676.                 spotmon ? "your " : "", l_monnam(mtmp));
677.         }
678.     }
679.     return 1;
680. }
681. 
682. /* assuming mtmp->mleashed has been checked */
683. struct obj *
684. get_mleash(mtmp)
685. struct monst *mtmp;
686. {
687.     struct obj *otmp;
688. 
689.     otmp = invent;
690.     while (otmp) {
691.         if (otmp->otyp == LEASH && otmp->leashmon == (int) mtmp->m_id)
692.             return otmp;
693.         otmp = otmp->nobj;
694.     }
695.     return (struct obj *) 0;
696. }
697. 
698. boolean
699. next_to_u()
700. {
701.     register struct monst *mtmp;
702.     register struct obj *otmp;
703. 
704.     for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
705.         if (DEADMONSTER(mtmp))
706.             continue;
707.         if (mtmp->mleashed) {
708.             if (distu(mtmp->mx, mtmp->my) > 2)
709.                 mnexto(mtmp);
710.             if (distu(mtmp->mx, mtmp->my) > 2) {
711.                 for (otmp = invent; otmp; otmp = otmp->nobj)
712.                     if (otmp->otyp == LEASH
713.                         && otmp->leashmon == (int) mtmp->m_id) {
714.                         if (otmp->cursed)
715.                             return FALSE;
716.                         You_feel("%s leash go slack.",
717.                                  (number_leashed() > 1) ? "a" : "the");
718.                         mtmp->mleashed = 0;
719.                         otmp->leashmon = 0;
720.                     }
721.             }
722.         }
723.     }
724.     /* no pack mules for the Amulet */
725.     if (u.usteed && mon_has_amulet(u.usteed))
726.         return FALSE;
727.     return TRUE;
728. }
729. 
730. void
731. check_leash(x, y)
732. register xchar x, y;
733. {
734.     register struct obj *otmp;
735.     register struct monst *mtmp;
736. 
737.     for (otmp = invent; otmp; otmp = otmp->nobj) {
738.         if (otmp->otyp != LEASH || otmp->leashmon == 0)
739.             continue;
740.         for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
741.             if (DEADMONSTER(mtmp))
742.                 continue;
743.             if ((int) mtmp->m_id == otmp->leashmon)
744.                 break;
745.         }
746.         if (!mtmp) {
747.             impossible("leash in use isn't attached to anything?");
748.             otmp->leashmon = 0;
749.             continue;
750.         }
751.         if (dist2(u.ux, u.uy, mtmp->mx, mtmp->my)
752.             > dist2(x, y, mtmp->mx, mtmp->my)) {
753.             if (!um_dist(mtmp->mx, mtmp->my, 3)) {
754.                 ; /* still close enough */
755.             } else if (otmp->cursed && !breathless(mtmp->data)) {
756.                 if (um_dist(mtmp->mx, mtmp->my, 5)
757.                     || (mtmp->mhp -= rnd(2)) <= 0) {
758.                     long save_pacifism = u.uconduct.killer;
759. 
760.                     Your("leash chokes %s to death!", mon_nam(mtmp));
761.                     /* hero might not have intended to kill pet, but
762.                        that's the result of his actions; gain experience,
763.                        lose pacifism, take alignment and luck hit, make
764.                        corpse less likely to remain tame after revival */
765.                     xkilled(mtmp, XKILL_NOMSG);
766.                     /* life-saving doesn't ordinarily reset this */
767.                     if (!DEADMONSTER(mtmp))
768.                         u.uconduct.killer = save_pacifism;
769.                 } else {
770.                     pline("%s is choked by the leash!", Monnam(mtmp));
771.                     /* tameness eventually drops to 1 here (never 0) */
772.                     if (mtmp->mtame && rn2(mtmp->mtame))
773.                         mtmp->mtame--;
774.                 }
775.             } else {
776.                 if (um_dist(mtmp->mx, mtmp->my, 5)) {
777.                     pline("%s leash snaps loose!", s_suffix(Monnam(mtmp)));
778.                     m_unleash(mtmp, FALSE);
779.                 } else {
780.                     You("pull on the leash.");
781.                     if (mtmp->data->msound != MS_SILENT)
782.                         switch (rn2(3)) {
783.                         case 0:
784.                             growl(mtmp);
785.                             break;
786.                         case 1:
787.                             yelp(mtmp);
788.                             break;
789.                         default:
790.                             whimper(mtmp);
791.                             break;
792.                         }
793.                 }
794.             }
795.         }
796.     }
797. }
798. 
799. const char *
800. beautiful()
801. {
802.     return ((ACURR(A_CHA) > 14)
803.                ? ((poly_gender() == 1)
804.                      ? "beautiful"
805.                      : "handsome")
806.                : "ugly");
807. }
808. 
809. static const char look_str[] = "look %s.";
810. 
811. STATIC_OVL int
812. use_mirror(obj)
813. struct obj *obj;
814. {
815.     const char *mirror, *uvisage;
816.     struct monst *mtmp;
817.     unsigned how_seen;
818.     char mlet;
819.     boolean vis, invis_mirror, useeit, monable;
820. 
821.     if (!getdir((char *) 0))
822.         return 0;
823.     invis_mirror = Invis;
824.     useeit = !Blind && (!invis_mirror || See_invisible);
825.     uvisage = beautiful();
826.     mirror = simpleonames(obj); /* "mirror" or "looking glass" */
827.     if (obj->cursed && !rn2(2)) {
828.         if (!Blind)
829.             pline_The("%s fogs up and doesn't reflect!", mirror);
830.         return 1;
831.     }
832.     if (!u.dx && !u.dy && !u.dz) {
833.         if (!useeit) {
834.             You_cant("see your %s %s.", uvisage, body_part(FACE));
835.         } else {
836.             if (u.umonnum == PM_FLOATING_EYE) {
837.                 if (Free_action) {
838.                     You("stiffen momentarily under your gaze.");
839.                 } else {
840.                     if (Hallucination)
841.                         pline("Yow!  The %s stares back!", mirror);
842.                     else
843.                         pline("Yikes!  You've frozen yourself!");
844.                     if (!Hallucination || !rn2(4)) {
845.                         nomul(-rnd(MAXULEV + 6 - u.ulevel));
846.                         multi_reason = "gazing into a mirror";
847.                     }
848.                     nomovemsg = 0; /* default, "you can move again" */
849.                 }
850.             } else if (youmonst.data->mlet == S_VAMPIRE)
851.                 You("don't have a reflection.");
852.             else if (u.umonnum == PM_UMBER_HULK) {
853.                 pline("Huh?  That doesn't look like you!");
854.                 make_confused(HConfusion + d(3, 4), FALSE);
855.             } else if (Hallucination)
856.                 You(look_str, hcolor((char *) 0));
857.             else if (Sick)
858.                 You(look_str, "peaked");
859.             else if (u.uhs >= WEAK)
860.                 You(look_str, "undernourished");
861.             else
862.                 You("look as %s as ever.", uvisage);
863.         }
864.         return 1;
865.     }
866.     if (u.uswallow) {
867.         if (useeit)
868.             You("reflect %s %s.", s_suffix(mon_nam(u.ustuck)),
869.                 mbodypart(u.ustuck, STOMACH));
870.         return 1;
871.     }
872.     if (Underwater) {
873.         if (useeit)
874.             You(Hallucination ? "give the fish a chance to fix their makeup."
875.                               : "reflect the murky water.");
876.         return 1;
877.     }
878.     if (u.dz) {
879.         if (useeit)
880.             You("reflect the %s.",
881.                 (u.dz > 0) ? surface(u.ux, u.uy) : ceiling(u.ux, u.uy));
882.         return 1;
883.     }
884.     mtmp = bhit(u.dx, u.dy, COLNO, INVIS_BEAM,
885.                 (int FDECL((*), (MONST_P, OBJ_P))) 0,
886.                 (int FDECL((*), (OBJ_P, OBJ_P))) 0, &obj);
887.     if (!mtmp || !haseyes(mtmp->data) || notonhead)
888.         return 1;
889. 
890.     /* couldsee(mtmp->mx, mtmp->my) is implied by the fact that bhit()
891.        targetted it, so we can ignore possibility of X-ray vision */
892.     vis = canseemon(mtmp);
893. /* ways to directly see monster (excludes X-ray vision, telepathy,
894.    extended detection, type-specific warning) */
895. #define SEENMON (MONSEEN_NORMAL | MONSEEN_SEEINVIS | MONSEEN_INFRAVIS)
896.     how_seen = vis ? howmonseen(mtmp) : 0;
897.     /* whether monster is able to use its vision-based capabilities */
898.     monable = !mtmp->mcan && (!mtmp->minvis || perceives(mtmp->data));
899.     mlet = mtmp->data->mlet;
900.     if (mtmp->msleeping) {
901.         if (vis)
902.             pline("%s is too tired to look at your %s.", Monnam(mtmp),
903.                   mirror);
904.     } else if (!mtmp->mcansee) {
905.         if (vis)
906.             pline("%s can't see anything right now.", Monnam(mtmp));
907.     } else if (invis_mirror && !perceives(mtmp->data)) {
908.         if (vis)
909.             pline("%s fails to notice your %s.", Monnam(mtmp), mirror);
910.         /* infravision doesn't produce an image in the mirror */
911.     } else if ((how_seen & SEENMON) == MONSEEN_INFRAVIS) {
912.         if (vis) /* (redundant) */
913.             pline("%s is too far away to see %sself in the dark.",
914.                   Monnam(mtmp), mhim(mtmp));
915.         /* some monsters do special things */
916.     } else if (mlet == S_VAMPIRE || mlet == S_GHOST || is_vampshifter(mtmp)) {
917.         if (vis)
918.             pline("%s doesn't have a reflection.", Monnam(mtmp));
919.     } else if (monable && mtmp->data == &mons[PM_MEDUSA]) {
920.         if (mon_reflects(mtmp, "The gaze is reflected away by %s %s!"))
921.             return 1;
922.         if (vis)
923.             pline("%s is turned to stone!", Monnam(mtmp));
924.         stoned = TRUE;
925.         killed(mtmp);
926.     } else if (monable && mtmp->data == &mons[PM_FLOATING_EYE]) {
927.         int tmp = d((int) mtmp->m_lev, (int) mtmp->data->mattk[0].damd);
928.         if (!rn2(4))
929.             tmp = 120;
930.         if (vis)
931.             pline("%s is frozen by its reflection.", Monnam(mtmp));
932.         else
933.             You_hear("%s stop moving.", something);
934.         paralyze_monst(mtmp, (int) mtmp->mfrozen + tmp);
935.     } else if (monable && mtmp->data == &mons[PM_UMBER_HULK]) {
936.         if (vis)
937.             pline("%s confuses itself!", Monnam(mtmp));
938.         mtmp->mconf = 1;
939.     } else if (monable && (mlet == S_NYMPH || mtmp->data == &mons[PM_SUCCUBUS]
940.                            || mtmp->data == &mons[PM_INCUBUS])) {
941.         if (vis) {
942.             char buf[BUFSZ]; /* "She" or "He" */
943. 
944.             pline("%s admires %sself in your %s.", Monnam(mtmp), mhim(mtmp),
945.                   mirror);
946.             pline("%s takes it!", upstart(strcpy(buf, mhe(mtmp))));
947.         } else
948.             pline("It steals your %s!", mirror);
949.         setnotworn(obj); /* in case mirror was wielded */
950.         freeinv(obj);
951.         (void) mpickobj(mtmp, obj);
952.         if (!tele_restrict(mtmp))
953.             (void) rloc(mtmp, TRUE);
954.     } else if (!is_unicorn(mtmp->data) && !humanoid(mtmp->data)
955.                && (!mtmp->minvis || perceives(mtmp->data)) && rn2(5)) {
956.         boolean do_react = TRUE;
957. 
958.         if (mtmp->mfrozen) {
959.             if (vis)
960.                 You("discern no obvious reaction from %s.", mon_nam(mtmp));
961.             else
962.                 You_feel("a bit silly gesturing the mirror in that direction.");
963.             do_react = FALSE;
964.         }
965.         if (do_react) {
966.             if (vis)
967.                 pline("%s is frightened by its reflection.", Monnam(mtmp));
968.             monflee(mtmp, d(2, 4), FALSE, FALSE);
969.         }
970.     } else if (!Blind) {
971.         if (mtmp->minvis && !See_invisible)
972.             ;
973.         else if ((mtmp->minvis && !perceives(mtmp->data))
974.                  /* redundant: can't get here if these are true */
975.                  || !haseyes(mtmp->data) || notonhead || !mtmp->mcansee)
976.             pline("%s doesn't seem to notice %s reflection.", Monnam(mtmp),
977.                   mhis(mtmp));
978.         else
979.             pline("%s ignores %s reflection.", Monnam(mtmp), mhis(mtmp));
980.     }
981.     return 1;
982. }
983. 
984. STATIC_OVL void
985. use_bell(optr)
986. struct obj **optr;
987. {
988.     register struct obj *obj = *optr;
989.     struct monst *mtmp;
990.     boolean wakem = FALSE, learno = FALSE,
991.             ordinary = (obj->otyp != BELL_OF_OPENING || !obj->spe),
992.             invoking =
993.                 (obj->otyp == BELL_OF_OPENING && invocation_pos(u.ux, u.uy)
994.                  && !On_stairs(u.ux, u.uy));
995. 
996.     You("ring %s.", the(xname(obj)));
997. 
998.     if (Underwater || (u.uswallow && ordinary)) {
999. #ifdef AMIGA
1000.         amii_speaker(obj, "AhDhGqEqDhEhAqDqFhGw", AMII_MUFFLED_VOLUME);
1001. #endif
1002.         pline("But the sound is muffled.");
1003. 
1004.     } else if (invoking && ordinary) {
1005.         /* needs to be recharged... */
1006.         pline("But it makes no sound.");
1007.         learno = TRUE; /* help player figure out why */
1008. 
1009.     } else if (ordinary) {
1010. #ifdef AMIGA
1011.         amii_speaker(obj, "ahdhgqeqdhehaqdqfhgw", AMII_MUFFLED_VOLUME);
1012. #endif
1013.         if (obj->cursed && !rn2(4)
1014.             /* note: once any of them are gone, we stop all of them */
1015.             && !(mvitals[PM_WOOD_NYMPH].mvflags & G_GONE)
1016.             && !(mvitals[PM_WATER_NYMPH].mvflags & G_GONE)
1017.             && !(mvitals[PM_MOUNTAIN_NYMPH].mvflags & G_GONE)
1018.             && (mtmp = makemon(mkclass(S_NYMPH, 0), u.ux, u.uy, NO_MINVENT))
1019.                    != 0) {
1020.             You("summon %s!", a_monnam(mtmp));
1021.             if (!obj_resists(obj, 93, 100)) {
1022.                 pline("%s shattered!", Tobjnam(obj, "have"));
1023.                 useup(obj);
1024.                 *optr = 0;
1025.             } else
1026.                 switch (rn2(3)) {
1027.                 default:
1028.                     break;
1029.                 case 1:
1030.                     mon_adjust_speed(mtmp, 2, (struct obj *) 0);
1031.                     break;
1032.                 case 2: /* no explanation; it just happens... */
1033.                     nomovemsg = "";
1034.                     multi_reason = NULL;
1035.                     nomul(-rnd(2));
1036.                     break;
1037.                 }
1038.         }
1039.         wakem = TRUE;
1040. 
1041.     } else {
1042.         /* charged Bell of Opening */
1043.         consume_obj_charge(obj, TRUE);
1044. 
1045.         if (u.uswallow) {
1046.             if (!obj->cursed)
1047.                 (void) openit();
1048.             else
1049.                 pline1(nothing_happens);
1050. 
1051.         } else if (obj->cursed) {
1052.             coord mm;
1053. 
1054.             mm.x = u.ux;
1055.             mm.y = u.uy;
1056.             mkundead(&mm, FALSE, NO_MINVENT);
1057.             wakem = TRUE;
1058. 
1059.         } else if (invoking) {
1060.             pline("%s an unsettling shrill sound...", Tobjnam(obj, "issue"));
1061. #ifdef AMIGA
1062.             amii_speaker(obj, "aefeaefeaefeaefeaefe", AMII_LOUDER_VOLUME);
1063. #endif
1064.             obj->age = moves;
1065.             learno = TRUE;
1066.             wakem = TRUE;
1067. 
1068.         } else if (obj->blessed) {
1069.             int res = 0;
1070. 
1071. #ifdef AMIGA
1072.             amii_speaker(obj, "ahahahDhEhCw", AMII_SOFT_VOLUME);
1073. #endif
1074.             if (uchain) {
1075.                 unpunish();
1076.                 res = 1;
1077.             } else if (u.utrap && u.utraptype == TT_BURIEDBALL) {
1078.                 buried_ball_to_freedom();
1079.                 res = 1;
1080.             }
1081.             res += openit();
1082.             switch (res) {
1083.             case 0:
1084.                 pline1(nothing_happens);
1085.                 break;
1086.             case 1:
1087.                 pline("%s opens...", Something);
1088.                 learno = TRUE;
1089.                 break;
1090.             default:
1091.                 pline("Things open around you...");
1092.                 learno = TRUE;
1093.                 break;
1094.             }
1095. 
1096.         } else { /* uncursed */
1097. #ifdef AMIGA
1098.             amii_speaker(obj, "AeFeaeFeAefegw", AMII_OKAY_VOLUME);
1099. #endif
1100.             if (findit() != 0)
1101.                 learno = TRUE;
1102.             else
1103.                 pline1(nothing_happens);
1104.         }
1105. 
1106.     } /* charged BofO */
1107. 
1108.     if (learno) {
1109.         makeknown(BELL_OF_OPENING);
1110.         obj->known = 1;
1111.     }
1112.     if (wakem)
1113.         wake_nearby();
1114. }
1115. 
1116. STATIC_OVL void
1117. use_candelabrum(obj)
1118. register struct obj *obj;
1119. {
1120.     const char *s = (obj->spe != 1) ? "candles" : "candle";
1121. 
1122.     if (obj->lamplit) {
1123.         You("snuff the %s.", s);
1124.         end_burn(obj, TRUE);
1125.         return;
1126.     }
1127.     if (obj->spe <= 0) {
1128.         pline("This %s has no %s.", xname(obj), s);
1129.         return;
1130.     }
1131.     if (Underwater) {
1132.         You("cannot make fire under water.");
1133.         return;
1134.     }
1135.     if (u.uswallow || obj->cursed) {
1136.         if (!Blind)
1137.             pline_The("%s %s for a moment, then %s.", s, vtense(s, "flicker"),
1138.                       vtense(s, "die"));
1139.         return;
1140.     }
1141.     if (obj->spe < 7) {
1142.         There("%s only %d %s in %s.", vtense(s, "are"), obj->spe, s,
1143.               the(xname(obj)));
1144.         if (!Blind)
1145.             pline("%s lit.  %s dimly.", obj->spe == 1 ? "It is" : "They are",
1146.                   Tobjnam(obj, "shine"));
1147.     } else {
1148.         pline("%s's %s burn%s", The(xname(obj)), s,
1149.               (Blind ? "." : " brightly!"));
1150.     }
1151.     if (!invocation_pos(u.ux, u.uy) || On_stairs(u.ux, u.uy)) {
1152.         pline_The("%s %s being rapidly consumed!", s, vtense(s, "are"));
1153.         /* this used to be obj->age /= 2, rounding down; an age of
1154.            1 would yield 0, confusing begin_burn() and producing an
1155.            unlightable, unrefillable candelabrum; round up instead */
1156.         obj->age = (obj->age + 1L) / 2L;
1157.     } else {
1158.         if (obj->spe == 7) {
1159.             if (Blind)
1160.                 pline("%s a strange warmth!", Tobjnam(obj, "radiate"));
1161.             else
1162.                 pline("%s with a strange light!", Tobjnam(obj, "glow"));
1163.         }
1164.         obj->known = 1;
1165.     }
1166.     begin_burn(obj, FALSE);
1167. }
1168. 
1169. STATIC_OVL void
1170. use_candle(optr)
1171. struct obj **optr;
1172. {
1173.     register struct obj *obj = *optr;
1174.     register struct obj *otmp;
1175.     const char *s = (obj->quan != 1) ? "candles" : "candle";
1176.     char qbuf[QBUFSZ], qsfx[QBUFSZ], *q;
1177. 
1178.     if (u.uswallow) {
1179.         You(no_elbow_room);
1180.         return;
1181.     }
1182. 
1183.     otmp = carrying(CANDELABRUM_OF_INVOCATION);
1184.     if (!otmp || otmp->spe == 7) {
1185.         use_lamp(obj);
1186.         return;
1187.     }
1188. 
1189.     /* first, minimal candelabrum suffix for formatting candles */
1190.     Sprintf(qsfx, " to\033%s?", thesimpleoname(otmp));
1191.     /* next, format the candles as a prefix for the candelabrum */
1192.     (void) safe_qbuf(qbuf, "Attach ", qsfx, obj, yname, thesimpleoname, s);
1193.     /* strip temporary candelabrum suffix */
1194.     if ((q = strstri(qbuf, " to\033")) != 0)
1195.         Strcpy(q, " to ");
1196.     /* last, format final "attach candles to candelabrum?" query */
1197.     if (yn(safe_qbuf(qbuf, qbuf, "?", otmp, yname, thesimpleoname, "it"))
1198.         == 'n') {
1199.         use_lamp(obj);
1200.         return;
1201.     } else {
1202.         if ((long) otmp->spe + obj->quan > 7L) {
1203.             obj = splitobj(obj, 7L - (long) otmp->spe);
1204.             /* avoid a grammatical error if obj->quan gets
1205.                reduced to 1 candle from more than one */
1206.             s = (obj->quan != 1) ? "candles" : "candle";
1207.         } else
1208.             *optr = 0;
1209.         You("attach %ld%s %s to %s.", obj->quan, !otmp->spe ? "" : " more", s,
1210.             the(xname(otmp)));
1211.         if (!otmp->spe || otmp->age > obj->age)
1212.             otmp->age = obj->age;
1213.         otmp->spe += (int) obj->quan;
1214.         if (otmp->lamplit && !obj->lamplit)
1215.             pline_The("new %s magically %s!", s, vtense(s, "ignite"));
1216.         else if (!otmp->lamplit && obj->lamplit)
1217.             pline("%s out.", (obj->quan > 1L) ? "They go" : "It goes");
1218.         if (obj->unpaid)
1219.             verbalize("You %s %s, you bought %s!",
1220.                       otmp->lamplit ? "burn" : "use",
1221.                       (obj->quan > 1L) ? "them" : "it",
1222.                       (obj->quan > 1L) ? "them" : "it");
1223.         if (obj->quan < 7L && otmp->spe == 7)
1224.             pline("%s now has seven%s candles attached.", The(xname(otmp)),
1225.                   otmp->lamplit ? " lit" : "");
1226.         /* candelabrum's light range might increase */
1227.         if (otmp->lamplit)
1228.             obj_merge_light_sources(otmp, otmp);
1229.         /* candles are no longer a separate light source */
1230.         if (obj->lamplit)
1231.             end_burn(obj, TRUE);
1232.         /* candles are now gone */
1233.         useupall(obj);
1234.         /* candelabrum's weight is changing */
1235.         otmp->owt = weight(otmp);
1236.         update_inventory();
1237.     }
1238. }
1239. 
1240. /* call in drop, throw, and put in box, etc. */
1241. boolean
1242. snuff_candle(otmp)
1243. struct obj *otmp;
1244. {
1245.     boolean candle = Is_candle(otmp);
1246. 
1247.     if ((candle || otmp->otyp == CANDELABRUM_OF_INVOCATION)
1248.         && otmp->lamplit) {
1249.         char buf[BUFSZ];
1250.         xchar x, y;
1251.         boolean many = candle ? (otmp->quan > 1L) : (otmp->spe > 1);
1252. 
1253.         (void) get_obj_location(otmp, &x, &y, 0);
1254.         if (otmp->where == OBJ_MINVENT ? cansee(x, y) : !Blind)
1255.             pline("%s%scandle%s flame%s extinguished.", Shk_Your(buf, otmp),
1256.                   (candle ? "" : "candelabrum's "), (many ? "s'" : "'s"),
1257.                   (many ? "s are" : " is"));
1258.         end_burn(otmp, TRUE);
1259.         return TRUE;
1260.     }
1261.     return FALSE;
1262. }
1263. 
1264. /* called when lit lamp is hit by water or put into a container or
1265.    you've been swallowed by a monster; obj might be in transit while
1266.    being thrown or dropped so don't assume that its location is valid */
1267. boolean
1268. snuff_lit(obj)
1269. struct obj *obj;
1270. {
1271.     xchar x, y;
1272. 
1273.     if (obj->lamplit) {
1274.         if (obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP
1275.             || obj->otyp == BRASS_LANTERN || obj->otyp == POT_OIL) {
1276.             (void) get_obj_location(obj, &x, &y, 0);
1277.             if (obj->where == OBJ_MINVENT ? cansee(x, y) : !Blind)
1278.                 pline("%s %s out!", Yname2(obj), otense(obj, "go"));
1279.             end_burn(obj, TRUE);
1280.             return TRUE;
1281.         }
1282.         if (snuff_candle(obj))
1283.             return TRUE;
1284.     }
1285.     return FALSE;
1286. }
1287. 
1288. /* Called when potentially lightable object is affected by fire_damage().
1289.    Return TRUE if object was lit and FALSE otherwise --ALI */
1290. boolean
1291. catch_lit(obj)
1292. struct obj *obj;
1293. {
1294.     xchar x, y;
1295. 
1296.     if (!obj->lamplit && (obj->otyp == MAGIC_LAMP || ignitable(obj))) {
1297.         if ((obj->otyp == MAGIC_LAMP
1298.              || obj->otyp == CANDELABRUM_OF_INVOCATION) && obj->spe == 0)
1299.             return FALSE;
1300.         else if (obj->otyp != MAGIC_LAMP && obj->age == 0)
1301.             return FALSE;
1302.         if (!get_obj_location(obj, &x, &y, 0))
1303.             return FALSE;
1304.         if (obj->otyp == CANDELABRUM_OF_INVOCATION && obj->cursed)
1305.             return FALSE;
1306.         if ((obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP
1307.              || obj->otyp == BRASS_LANTERN) && obj->cursed && !rn2(2))
1308.             return FALSE;
1309.         if (obj->where == OBJ_MINVENT ? cansee(x, y) : !Blind)
1310.             pline("%s %s light!", Yname2(obj), otense(obj, "catch"));
1311.         if (obj->otyp == POT_OIL)
1312.             makeknown(obj->otyp);
1313.         if (carried(obj) && obj->unpaid && costly_spot(u.ux, u.uy)) {
1314.             /* if it catches while you have it, then it's your tough luck */
1315.             check_unpaid(obj);
1316.             verbalize("That's in addition to the cost of %s %s, of course.",
1317.                       yname(obj), obj->quan == 1L ? "itself" : "themselves");
1318.             bill_dummy_object(obj);
1319.         }
1320.         begin_burn(obj, FALSE);
1321.         return TRUE;
1322.     }
1323.     return FALSE;
1324. }
1325. 
1326. STATIC_OVL void
1327. use_lamp(obj)
1328. struct obj *obj;
1329. {
1330.     char buf[BUFSZ];
1331. 
1332.     if (obj->lamplit) {
1333.         if (obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP
1334.             || obj->otyp == BRASS_LANTERN)
1335.             pline("%slamp is now off.", Shk_Your(buf, obj));
1336.         else
1337.             You("snuff out %s.", yname(obj));
1338.         end_burn(obj, TRUE);
1339.         return;
1340.     }
1341.     if (Underwater) {
1342.         pline(!Is_candle(obj) ? "This is not a diving lamp"
1343.                               : "Sorry, fire and water don't mix.");
1344.         return;
1345.     }
1346.     /* magic lamps with an spe == 0 (wished for) cannot be lit */
1347.     if ((!Is_candle(obj) && obj->age == 0)
1348.         || (obj->otyp == MAGIC_LAMP && obj->spe == 0)) {
1349.         if (obj->otyp == BRASS_LANTERN)
1350.             Your("lamp has run out of power.");
1351.         else
1352.             pline("This %s has no oil.", xname(obj));
1353.         return;
1354.     }
1355.     if (obj->cursed && !rn2(2)) {
1356.         if (!Blind)
1357.             pline("%s for a moment, then %s.", Tobjnam(obj, "flicker"),
1358.                   otense(obj, "die"));
1359.     } else {
1360.         if (obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP
1361.             || obj->otyp == BRASS_LANTERN) {
1362.             check_unpaid(obj);
1363.             pline("%slamp is now on.", Shk_Your(buf, obj));
1364.         } else { /* candle(s) */
1365.             pline("%s flame%s %s%s", s_suffix(Yname2(obj)), plur(obj->quan),
1366.                   otense(obj, "burn"), Blind ? "." : " brightly!");
1367.             if (obj->unpaid && costly_spot(u.ux, u.uy)
1368.                 && obj->age == 20L * (long) objects[obj->otyp].oc_cost) {
1369.                 const char *ithem = (obj->quan > 1L) ? "them" : "it";
1370. 
1371.                 verbalize("You burn %s, you bought %s!", ithem, ithem);
1372.                 bill_dummy_object(obj);
1373.             }
1374.         }
1375.         begin_burn(obj, FALSE);
1376.     }
1377. }
1378. 
1379. STATIC_OVL void
1380. light_cocktail(optr)
1381. struct obj **optr;
1382. {
1383.     struct obj *obj = *optr; /* obj is a potion of oil */
1384.     char buf[BUFSZ];
1385.     boolean split1off;
1386. 
1387.     if (u.uswallow) {
1388.         You(no_elbow_room);
1389.         return;
1390.     }
1391. 
1392.     if (obj->lamplit) {
1393.         You("snuff the lit potion.");
1394.         end_burn(obj, TRUE);
1395.         /*
1396.          * Free & add to re-merge potion.  This will average the
1397.          * age of the potions.  Not exactly the best solution,
1398.          * but its easy.
1399.          */
1400.         freeinv(obj);
1401.         *optr = addinv(obj);
1402.         return;
1403.     } else if (Underwater) {
1404.         There("is not enough oxygen to sustain a fire.");
1405.         return;
1406.     }
1407. 
1408.     split1off = (obj->quan > 1L);
1409.     if (split1off)
1410.         obj = splitobj(obj, 1L);
1411. 
1412.     You("light %spotion.%s", shk_your(buf, obj),
1413.         Blind ? "" : "  It gives off a dim light.");
1414. 
1415.     if (obj->unpaid && costly_spot(u.ux, u.uy)) {
1416.         /* Normally, we shouldn't both partially and fully charge
1417.          * for an item, but (Yendorian Fuel) Taxes are inevitable...
1418.          */
1419.         check_unpaid(obj);
1420.         verbalize("That's in addition to the cost of the potion, of course.");
1421.         bill_dummy_object(obj);
1422.     }
1423.     makeknown(obj->otyp);
1424. 
1425.     begin_burn(obj, FALSE); /* after shop billing */
1426.     if (split1off) {
1427.         obj_extract_self(obj); /* free from inv */
1428.         obj->nomerge = 1;
1429.         obj = hold_another_object(obj, "You drop %s!", doname(obj),
1430.                                   (const char *) 0);
1431.         if (obj)
1432.             obj->nomerge = 0;
1433.     }
1434.     *optr = obj;
1435. }
1436. 
1437. static NEARDATA const char cuddly[] = { TOOL_CLASS, GEM_CLASS, 0 };
1438. 
1439. int
1440. dorub()
1441. {
1442.     struct obj *obj = getobj(cuddly, "rub");
1443. 
1444.     if (obj && obj->oclass == GEM_CLASS) {
1445.         if (is_graystone(obj)) {
1446.             use_stone(obj);
1447.             return 1;
1448.         } else {
1449.             pline("Sorry, I don't know how to use that.");
1450.             return 0;
1451.         }
1452.     }
1453. 
1454.     if (!obj || !wield_tool(obj, "rub"))
1455.         return 0;
1456. 
1457.     /* now uwep is obj */
1458.     if (uwep->otyp == MAGIC_LAMP) {
1459.         if (uwep->spe > 0 && !rn2(3)) {
1460.             check_unpaid_usage(uwep, TRUE); /* unusual item use */
1461.             /* bones preparation:  perform the lamp transformation
1462.                before releasing the djinni in case the latter turns out
1463.                to be fatal (a hostile djinni has no chance to attack yet,
1464.                but an indebted one who grants a wish might bestow an
1465.                artifact which blasts the hero with lethal results) */
1466.             uwep->otyp = OIL_LAMP;
1467.             uwep->spe = 0; /* for safety */
1468.             uwep->age = rn1(500, 1000);
1469.             if (uwep->lamplit)
1470.                 begin_burn(uwep, TRUE);
1471.             djinni_from_bottle(uwep);
1472.             makeknown(MAGIC_LAMP);
1473.             update_inventory();
1474.         } else if (rn2(2)) {
1475.             You("%s smoke.", !Blind ? "see a puff of" : "smell");
1476.         } else
1477.             pline1(nothing_happens);
1478.     } else if (obj->otyp == BRASS_LANTERN) {
1479.         /* message from Adventure */
1480.         pline("Rubbing the electric lamp is not particularly rewarding.");
1481.         pline("Anyway, nothing exciting happens.");
1482.     } else
1483.         pline1(nothing_happens);
1484.     return 1;
1485. }
1486. 
1487. int
1488. dojump()
1489. {
1490.     /* Physical jump */
1491.     return jump(0);
1492. }
1493. 
1494. enum jump_trajectory {
1495.     jAny  = 0, /* any direction => magical jump */
1496.     jHorz = 1,
1497.     jVert = 2,
1498.     jDiag = 3  /* jHorz|jVert */
1499. };
1500. 
1501. /* callback routine for walk_path() */
1502. STATIC_PTR boolean
1503. check_jump(arg, x, y)
1504. genericptr arg;
1505. int x, y;
1506. {
1507.     int traj = *(int *) arg;
1508.     struct rm *lev = &levl[x][y];
1509. 
1510.     if (Passes_walls)
1511.         return TRUE;
1512.     if (IS_STWALL(lev->typ))
1513.         return FALSE;
1514.     if (IS_DOOR(lev->typ)) {
1515.         if (closed_door(x, y))
1516.             return FALSE;
1517.         if ((lev->doormask & D_ISOPEN) != 0 && traj != jAny
1518.             /* reject diagonal jump into or out-of or through open door */
1519.             && (traj == jDiag
1520.                 /* reject horizontal jump through horizontal open door
1521.                    and non-horizontal (ie, vertical) jump through
1522.                    non-horizontal (vertical) open door */
1523.                 || ((traj & jHorz) != 0) == (lev->horizontal != 0)))
1524.             return FALSE;
1525.         /* empty doorways aren't restricted */
1526.     }
1527.     /* let giants jump over boulders (what about Flying?
1528.        and is there really enough head room for giants to jump
1529.        at all, let alone over something tall?) */
1530.     if (sobj_at(BOULDER, x, y) && !throws_rocks(youmonst.data))
1531.         return FALSE;
1532.     return TRUE;
1533. }
1534. 
1535. STATIC_OVL boolean
1536. is_valid_jump_pos(x, y, magic, showmsg)
1537. int x, y, magic;
1538. boolean showmsg;
1539. {
1540.     if (!magic && !(HJumping & ~INTRINSIC) && !EJumping && distu(x, y) != 5) {
1541.         /* The Knight jumping restriction still applies when riding a
1542.          * horse.  After all, what shape is the knight piece in chess?
1543.          */
1544.         if (showmsg)
1545.             pline("Illegal move!");
1546.         return FALSE;
1547.     } else if (distu(x, y) > (magic ? 6 + magic * 3 : 9)) {
1548.         if (showmsg)
1549.             pline("Too far!");
1550.         return FALSE;
1551.     } else if (!isok(x, y)) {
1552.         if (showmsg)
1553.             You("cannot jump there!");
1554.         return FALSE;
1555.     } else if (!cansee(x, y)) {
1556.         if (showmsg)
1557.             You("cannot see where to land!");
1558.         return FALSE;
1559.     } else {
1560.         coord uc, tc;
1561.         struct rm *lev = &levl[u.ux][u.uy];
1562.         /* we want to categorize trajectory for use in determining
1563.            passage through doorways: horizonal, vertical, or diagonal;
1564.            since knight's jump and other irregular directions are
1565.            possible, we flatten those out to simplify door checks */
1566.         int diag, traj,
1567.             dx = x - u.ux, dy = y - u.uy,
1568.             ax = abs(dx), ay = abs(dy);
1569. 
1570.         /* diag: any non-orthogonal destination classifed as diagonal */
1571.         diag = (magic || Passes_walls || (!dx && !dy)) ? jAny
1572.                : !dy ? jHorz : !dx ? jVert : jDiag;
1573.         /* traj: flatten out the trajectory => some diagonals re-classified */
1574.         if (ax >= 2 * ay)
1575.             ay = 0;
1576.         else if (ay >= 2 * ax)
1577.             ax = 0;
1578.         traj = (magic || Passes_walls || (!ax && !ay)) ? jAny
1579.                : !ay ? jHorz : !ax ? jVert : jDiag;
1580.         /* walk_path doesn't process the starting spot;
1581.            this is iffy:  if you're starting on a closed door spot,
1582.            you _can_ jump diagonally from doorway (without needing
1583.            Passes_walls); that's intentional but is it correct? */
1584.         if (diag == jDiag && IS_DOOR(lev->typ)
1585.             && (lev->doormask & D_ISOPEN) != 0
1586.             && (traj == jDiag
1587.                 || ((traj & jHorz) != 0) == (lev->horizontal != 0))) {
1588.             if (showmsg)
1589.                 You_cant("jump diagonally out of a doorway.");
1590.             return FALSE;
1591.         }
1592.         uc.x = u.ux, uc.y = u.uy;
1593.         tc.x = x, tc.y = y; /* target */
1594.         if (!walk_path(&uc, &tc, check_jump, (genericptr_t) &traj)) {
1595.             if (showmsg)
1596.                 There("is an obstacle preventing that jump.");
1597.             return FALSE;
1598.         }
1599.     }
1600.     return TRUE;
1601. }
1602. 
1603. static int jumping_is_magic;
1604. 
1605. STATIC_OVL boolean
1606. get_valid_jump_position(x,y)
1607. int x,y;
1608. {
1609.     return (isok(x, y)
1610.             && (ACCESSIBLE(levl[x][y].typ) || Passes_walls)
1611.             && is_valid_jump_pos(x, y, jumping_is_magic, FALSE));
1612. }
1613. 
1614. void
1615. display_jump_positions(state)
1616. int state;
1617. {
1618.     if (state == 0) {
1619.         tmp_at(DISP_BEAM, cmap_to_glyph(S_goodpos));
1620.     } else if (state == 1) {
1621.         int x, y, dx, dy;
1622. 
1623.         for (dx = -4; dx <= 4; dx++)
1624.             for (dy = -4; dy <= 4; dy++) {
1625.                 x = dx + (int) u.ux;
1626.                 y = dy + (int) u.uy;
1627.                 if (get_valid_jump_position(x, y))
1628.                     tmp_at(x, y);
1629.             }
1630.     } else {
1631.         tmp_at(DISP_END, 0);
1632.     }
1633. }
1634. 
1635. int
1636. jump(magic)
1637. int magic; /* 0=Physical, otherwise skill level */
1638. {
1639.     coord cc;
1640. 
1641.     /* attempt "jumping" spell if hero has no innate jumping ability */
1642.     if (!magic && !Jumping) {
1643.         int sp_no;
1644. 
1645.         for (sp_no = 0; sp_no < MAXSPELL; ++sp_no)
1646.             if (spl_book[sp_no].sp_id == NO_SPELL)
1647.                 break;
1648.             else if (spl_book[sp_no].sp_id == SPE_JUMPING)
1649.                 return spelleffects(sp_no, FALSE);
1650.     }
1651. 
1652.     if (!magic && (nolimbs(youmonst.data) || slithy(youmonst.data))) {
1653.         /* normally (nolimbs || slithy) implies !Jumping,
1654.            but that isn't necessarily the case for knights */
1655.         You_cant("jump; you have no legs!");
1656.         return 0;
1657.     } else if (!magic && !Jumping) {
1658.         You_cant("jump very far.");
1659.         return 0;
1660.     /* if steed is immobile, can't do physical jump but can do spell one */
1661.     } else if (!magic && u.usteed && stucksteed(FALSE)) {
1662.         /* stucksteed gave "<steed> won't move" message */
1663.         return 0;
1664.     } else if (u.uswallow) {
1665.         if (magic) {
1666.             You("bounce around a little.");
1667.             return 1;
1668.         }
1669.         pline("You've got to be kidding!");
1670.         return 0;
1671.     } else if (u.uinwater) {
1672.         if (magic) {
1673.             You("swish around a little.");
1674.             return 1;
1675.         }
1676.         pline("This calls for swimming, not jumping!");
1677.         return 0;
1678.     } else if (u.ustuck) {
1679.         if (u.ustuck->mtame && !Conflict && !u.ustuck->mconf) {
1680.             You("pull free from %s.", mon_nam(u.ustuck));
1681.             u.ustuck = 0;
1682.             return 1;
1683.         }
1684.         if (magic) {
1685.             You("writhe a little in the grasp of %s!", mon_nam(u.ustuck));
1686.             return 1;
1687.         }
1688.         You("cannot escape from %s!", mon_nam(u.ustuck));
1689.         return 0;
1690.     } else if (Levitation || Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) {
1691.         if (magic) {
1692.             You("flail around a little.");
1693.             return 1;
1694.         }
1695.         You("don't have enough traction to jump.");
1696.         return 0;
1697.     } else if (!magic && near_capacity() > UNENCUMBERED) {
1698.         You("are carrying too much to jump!");
1699.         return 0;
1700.     } else if (!magic && (u.uhunger <= 100 || ACURR(A_STR) < 6)) {
1701.         You("lack the strength to jump!");
1702.         return 0;
1703.     } else if (!magic && Wounded_legs) {
1704.         long wl = (Wounded_legs & BOTH_SIDES);
1705.         const char *bp = body_part(LEG);
1706. 
1707.         if (wl == BOTH_SIDES)
1708.             bp = makeplural(bp);
1709.         if (u.usteed)
1710.             pline("%s is in no shape for jumping.", Monnam(u.usteed));
1711.         else
1712.             Your("%s%s %s in no shape for jumping.",
1713.                  (wl == LEFT_SIDE) ? "left " : (wl == RIGHT_SIDE) ? "right "
1714.                                                                   : "",
1715.                  bp, (wl == BOTH_SIDES) ? "are" : "is");
1716.         return 0;
1717.     } else if (u.usteed && u.utrap) {
1718.         pline("%s is stuck in a trap.", Monnam(u.usteed));
1719.         return 0;
1720.     }
1721. 
1722.     pline("Where do you want to jump?");
1723.     cc.x = u.ux;
1724.     cc.y = u.uy;
1725.     jumping_is_magic = magic;
1726.     getpos_sethilite(display_jump_positions, get_valid_jump_position);
1727.     if (getpos(&cc, TRUE, "the desired position") < 0)
1728.         return 0; /* user pressed ESC */
1729.     if (!is_valid_jump_pos(cc.x, cc.y, magic, TRUE)) {
1730.         return 0;
1731.     } else {
1732.         coord uc;
1733.         int range, temp;
1734. 
1735.         if (u.utrap)
1736.             switch (u.utraptype) {
1737.             case TT_BEARTRAP: {
1738.                 long side = rn2(3) ? LEFT_SIDE : RIGHT_SIDE;
1739. 
1740.                 You("rip yourself free of the bear trap!  Ouch!");
1741.                 losehp(Maybe_Half_Phys(rnd(10)), "jumping out of a bear trap",
1742.                        KILLED_BY);
1743.                 set_wounded_legs(side, rn1(1000, 500));
1744.                 break;
1745.             }
1746.             case TT_PIT:
1747.                 You("leap from the pit!");
1748.                 break;
1749.             case TT_WEB:
1750.                 You("tear the web apart as you pull yourself free!");
1751.                 deltrap(t_at(u.ux, u.uy));
1752.                 break;
1753.             case TT_LAVA:
1754.                 You("pull yourself above the %s!", hliquid("lava"));
1755.                 reset_utrap(TRUE);
1756.                 return 1;
1757.             case TT_BURIEDBALL:
1758.             case TT_INFLOOR:
1759.                 You("strain your %s, but you're still %s.",
1760.                     makeplural(body_part(LEG)),
1761.                     (u.utraptype == TT_INFLOOR)
1762.                         ? "stuck in the floor"
1763.                         : "attached to the buried ball");
1764.                 set_wounded_legs(LEFT_SIDE, rn1(10, 11));
1765.                 set_wounded_legs(RIGHT_SIDE, rn1(10, 11));
1766.                 return 1;
1767.             }
1768. 
1769.         /*
1770.          * Check the path from uc to cc, calling hurtle_step at each
1771.          * location.  The final position actually reached will be
1772.          * in cc.
1773.          */
1774.         uc.x = u.ux;
1775.         uc.y = u.uy;
1776.         /* calculate max(abs(dx), abs(dy)) as the range */
1777.         range = cc.x - uc.x;
1778.         if (range < 0)
1779.             range = -range;
1780.         temp = cc.y - uc.y;
1781.         if (temp < 0)
1782.             temp = -temp;
1783.         if (range < temp)
1784.             range = temp;
1785.         (void) walk_path(&uc, &cc, hurtle_jump, (genericptr_t) &range);
1786.         /* hurtle_jump -> hurtle_step results in <u.ux,u.uy> == <cc.x,cc.y>
1787.          * and usually moves the ball if punished, but does not handle all
1788.          * the effects of landing on the final position.
1789.          */
1790.         teleds(cc.x, cc.y, FALSE);
1791.         sokoban_guilt();
1792.         nomul(-1);
1793.         multi_reason = "jumping around";
1794.         nomovemsg = "";
1795.         morehungry(rnd(25));
1796.         return 1;
1797.     }
1798. }
1799. 
1800. boolean
1801. tinnable(corpse)
1802. struct obj *corpse;
1803. {
1804.     if (corpse->oeaten)
1805.         return 0;
1806.     if (!mons[corpse->corpsenm].cnutrit)
1807.         return 0;
1808.     return 1;
1809. }
1810. 
1811. STATIC_OVL void
1812. use_tinning_kit(obj)
1813. struct obj *obj;
1814. {
1815.     struct obj *corpse, *can;
1816. 
1817.     /* This takes only 1 move.  If this is to be changed to take many
1818.      * moves, we've got to deal with decaying corpses...
1819.      */
1820.     if (obj->spe <= 0) {
1821.         You("seem to be out of tins.");
1822.         return;
1823.     }
1824.     if (!(corpse = floorfood("tin", 2)))
1825.         return;
1826.     if (corpse->oeaten) {
1827.         You("cannot tin %s which is partly eaten.", something);
1828.         return;
1829.     }
1830.     if (touch_petrifies(&mons[corpse->corpsenm]) && !Stone_resistance
1831.         && !uarmg) {
1832.         char kbuf[BUFSZ];
1833. 
1834.         if (poly_when_stoned(youmonst.data))
1835.             You("tin %s without wearing gloves.",
1836.                 an(mons[corpse->corpsenm].mname));
1837.         else {
1838.             pline("Tinning %s without wearing gloves is a fatal mistake...",
1839.                   an(mons[corpse->corpsenm].mname));
1840.             Sprintf(kbuf, "trying to tin %s without gloves",
1841.                     an(mons[corpse->corpsenm].mname));
1842.         }
1843.         instapetrify(kbuf);
1844.     }
1845.     if (is_rider(&mons[corpse->corpsenm])) {
1846.         if (revive_corpse(corpse))
1847.             verbalize("Yes...  But War does not preserve its enemies...");
1848.         else
1849.             pline_The("corpse evades your grasp.");
1850.         return;
1851.     }
1852.     if (mons[corpse->corpsenm].cnutrit == 0) {
1853.         pline("That's too insubstantial to tin.");
1854.         return;
1855.     }
1856.     consume_obj_charge(obj, TRUE);
1857. 
1858.     if ((can = mksobj(TIN, FALSE, FALSE)) != 0) {
1859.         static const char you_buy_it[] = "You tin it, you bought it!";
1860. 
1861.         can->corpsenm = corpse->corpsenm;
1862.         can->cursed = obj->cursed;
1863.         can->blessed = obj->blessed;
1864.         can->owt = weight(can);
1865.         can->known = 1;
1866.         /* Mark tinned tins. No spinach allowed... */
1867.         set_tin_variety(can, HOMEMADE_TIN);
1868.         if (carried(corpse)) {
1869.             if (corpse->unpaid)
1870.                 verbalize(you_buy_it);
1871.             useup(corpse);
1872.         } else {
1873.             if (costly_spot(corpse->ox, corpse->oy) && !corpse->no_charge)
1874.                 verbalize(you_buy_it);
1875.             useupf(corpse, 1L);
1876.         }
1877.         (void) hold_another_object(can, "You make, but cannot pick up, %s.",
1878.                                    doname(can), (const char *) 0);
1879.     } else
1880.         impossible("Tinning failed.");
1881. }
1882. 
1883. void
1884. use_unicorn_horn(obj)
1885. struct obj *obj;
1886. {
1887. #define PROP_COUNT 7           /* number of properties we're dealing with */
1888. #define ATTR_COUNT (A_MAX * 3) /* number of attribute points we might fix */
1889.     int idx, val, val_limit, trouble_count, unfixable_trbl, did_prop,
1890.         did_attr;
1891.     int trouble_list[PROP_COUNT + ATTR_COUNT];
1892. 
1893.     if (obj && obj->cursed) {
1894.         long lcount = (long) rn1(90, 10);
1895. 
1896.         switch (rn2(13) / 2) { /* case 6 is half as likely as the others */
1897.         case 0:
1898.             make_sick((Sick & TIMEOUT) ? (Sick & TIMEOUT) / 3L + 1L
1899.                                        : (long) rn1(ACURR(A_CON), 20),
1900.                       xname(obj), TRUE, SICK_NONVOMITABLE);
1901.             break;
1902.         case 1:
1903.             make_blinded((Blinded & TIMEOUT) + lcount, TRUE);
1904.             break;
1905.         case 2:
1906.             if (!Confusion)
1907.                 You("suddenly feel %s.",
1908.                     Hallucination ? "trippy" : "confused");
1909.             make_confused((HConfusion & TIMEOUT) + lcount, TRUE);
1910.             break;
1911.         case 3:
1912.             make_stunned((HStun & TIMEOUT) + lcount, TRUE);
1913.             break;
1914.         case 4:
1915.             (void) adjattrib(rn2(A_MAX), -1, FALSE);
1916.             break;
1917.         case 5:
1918.             (void) make_hallucinated((HHallucination & TIMEOUT) + lcount,
1919.                                      TRUE, 0L);
1920.             break;
1921.         case 6:
1922.             if (Deaf) /* make_deaf() won't give feedback when already deaf */
1923.                 pline("Nothing seems to happen.");
1924.             make_deaf((HDeaf & TIMEOUT) + lcount, TRUE);
1925.             break;
1926.         }
1927.         return;
1928.     }
1929. 
1930. /*
1931.  * Entries in the trouble list use a very simple encoding scheme.
1932.  */
1933. #define prop2trbl(X) ((X) + A_MAX)
1934. #define attr2trbl(Y) (Y)
1935. #define prop_trouble(X) trouble_list[trouble_count++] = prop2trbl(X)
1936. #define attr_trouble(Y) trouble_list[trouble_count++] = attr2trbl(Y)
1937. #define TimedTrouble(P) (((P) && !((P) & ~TIMEOUT)) ? ((P) & TIMEOUT) : 0L)
1938. 
1939.     trouble_count = unfixable_trbl = did_prop = did_attr = 0;
1940. 
1941.     /* collect property troubles */
1942.     if (TimedTrouble(Sick))
1943.         prop_trouble(SICK);
1944.     if (TimedTrouble(Blinded) > (long) u.ucreamed
1945.         && !(u.uswallow
1946.              && attacktype_fordmg(u.ustuck->data, AT_ENGL, AD_BLND)))
1947.         prop_trouble(BLINDED);
1948.     if (TimedTrouble(HHallucination))
1949.         prop_trouble(HALLUC);
1950.     if (TimedTrouble(Vomiting))
1951.         prop_trouble(VOMITING);
1952.     if (TimedTrouble(HConfusion))
1953.         prop_trouble(CONFUSION);
1954.     if (TimedTrouble(HStun))
1955.         prop_trouble(STUNNED);
1956.     if (TimedTrouble(HDeaf))
1957.         prop_trouble(DEAF);
1958. 
1959.     unfixable_trbl = unfixable_trouble_count(TRUE);
1960. 
1961.     /* collect attribute troubles */
1962.     for (idx = 0; idx < A_MAX; idx++) {
1963.         if (ABASE(idx) >= AMAX(idx))
1964.             continue;
1965.         val_limit = AMAX(idx);
1966.         /* this used to adjust 'val_limit' for A_STR when u.uhs was
1967.            WEAK or worse, but that's handled via ATEMP(A_STR) now */
1968.         if (Fixed_abil) {
1969.             /* potion/spell of restore ability override sustain ability
1970.                intrinsic but unicorn horn usage doesn't */
1971.             unfixable_trbl += val_limit - ABASE(idx);
1972.             continue;
1973.         }
1974.         /* don't recover more than 3 points worth of any attribute */
1975.         if (val_limit > ABASE(idx) + 3)
1976.             val_limit = ABASE(idx) + 3;
1977. 
1978.         for (val = ABASE(idx); val < val_limit; val++)
1979.             attr_trouble(idx);
1980.         /* keep track of unfixed trouble, for message adjustment below */
1981.         unfixable_trbl += (AMAX(idx) - val_limit);
1982.     }
1983. 
1984.     if (trouble_count == 0) {
1985.         pline1(nothing_happens);
1986.         return;
1987.     } else if (trouble_count > 1) { /* shuffle */
1988.         int i, j, k;
1989. 
1990.         for (i = trouble_count - 1; i > 0; i--)
1991.             if ((j = rn2(i + 1)) != i) {
1992.                 k = trouble_list[j];
1993.                 trouble_list[j] = trouble_list[i];
1994.                 trouble_list[i] = k;
1995.             }
1996.     }
1997. 
1998.     /*
1999.      *  Chances for number of troubles to be fixed
2000.      *               0      1      2      3      4      5      6      7
2001.      *   blessed:  22.7%  22.7%  19.5%  15.4%  10.7%   5.7%   2.6%   0.8%
2002.      *  uncursed:  35.4%  35.4%  22.9%   6.3%    0      0      0      0
2003.      */
2004.     val_limit = rn2(d(2, (obj && obj->blessed) ? 4 : 2));
2005.     if (val_limit > trouble_count)
2006.         val_limit = trouble_count;
2007. 
2008.     /* fix [some of] the troubles */
2009.     for (val = 0; val < val_limit; val++) {
2010.         idx = trouble_list[val];
2011. 
2012.         switch (idx) {
2013.         case prop2trbl(SICK):
2014.             make_sick(0L, (char *) 0, TRUE, SICK_ALL);
2015.             did_prop++;
2016.             break;
2017.         case prop2trbl(BLINDED):
2018.             make_blinded((long) u.ucreamed, TRUE);
2019.             did_prop++;
2020.             break;
2021.         case prop2trbl(HALLUC):
2022.             (void) make_hallucinated(0L, TRUE, 0L);
2023.             did_prop++;
2024.             break;
2025.         case prop2trbl(VOMITING):
2026.             make_vomiting(0L, TRUE);
2027.             did_prop++;
2028.             break;
2029.         case prop2trbl(CONFUSION):
2030.             make_confused(0L, TRUE);
2031.             did_prop++;
2032.             break;
2033.         case prop2trbl(STUNNED):
2034.             make_stunned(0L, TRUE);
2035.             did_prop++;
2036.             break;
2037.         case prop2trbl(DEAF):
2038.             make_deaf(0L, TRUE);
2039.             did_prop++;
2040.             break;
2041.         default:
2042.             if (idx >= 0 && idx < A_MAX) {
2043.                 ABASE(idx) += 1;
2044.                 did_attr++;
2045.             } else
2046.                 panic("use_unicorn_horn: bad trouble? (%d)", idx);
2047.             break;
2048.         }
2049.     }
2050. 
2051.     if (did_attr || did_prop)
2052.         context.botl = TRUE;
2053.     if (did_attr)
2054.         pline("This makes you feel %s!",
2055.               (did_prop + did_attr) == (trouble_count + unfixable_trbl)
2056.                   ? "great"
2057.                   : "better");
2058.     else if (!did_prop)
2059.         pline("Nothing seems to happen.");
2060. 
2061. #undef PROP_COUNT
2062. #undef ATTR_COUNT
2063. #undef prop2trbl
2064. #undef attr2trbl
2065. #undef prop_trouble
2066. #undef attr_trouble
2067. #undef TimedTrouble
2068. }
2069. 
2070. /*
2071.  * Timer callback routine: turn figurine into monster
2072.  */
2073. void
2074. fig_transform(arg, timeout)
2075. anything *arg;
2076. long timeout;
2077. {
2078.     struct obj *figurine = arg->a_obj;
2079.     struct monst *mtmp;
2080.     coord cc;
2081.     boolean cansee_spot, silent, okay_spot;
2082.     boolean redraw = FALSE;
2083.     boolean suppress_see = FALSE;
2084.     char monnambuf[BUFSZ], carriedby[BUFSZ];
2085. 
2086.     if (!figurine) {
2087.         debugpline0("null figurine in fig_transform()");
2088.         return;
2089.     }
2090.     silent = (timeout != monstermoves); /* happened while away */
2091.     okay_spot = get_obj_location(figurine, &cc.x, &cc.y, 0);
2092.     if (figurine->where == OBJ_INVENT || figurine->where == OBJ_MINVENT)
2093.         okay_spot = enexto(&cc, cc.x, cc.y, &mons[figurine->corpsenm]);
2094.     if (!okay_spot || !figurine_location_checks(figurine, &cc, TRUE)) {
2095.         /* reset the timer to try again later */
2096.         (void) start_timer((long) rnd(5000), TIMER_OBJECT, FIG_TRANSFORM,
2097.                            obj_to_any(figurine));
2098.         return;
2099.     }
2100. 
2101.     cansee_spot = cansee(cc.x, cc.y);
2102.     mtmp = make_familiar(figurine, cc.x, cc.y, TRUE);
2103.     if (mtmp) {
2104.         char and_vanish[BUFSZ];
2105.         struct obj *mshelter = level.objects[mtmp->mx][mtmp->my];
2106. 
2107.         /* [m_monnam() yields accurate mon type, overriding hallucination] */
2108.         Sprintf(monnambuf, "%s", an(m_monnam(mtmp)));
2109.         and_vanish[0] = '\0';
2110.         if ((mtmp->minvis && !See_invisible)
2111.             || (mtmp->data->mlet == S_MIMIC
2112.                 && M_AP_TYPE(mtmp) != M_AP_NOTHING))
2113.             suppress_see = TRUE;
2114. 
2115.         if (mtmp->mundetected) {
2116.             if (hides_under(mtmp->data) && mshelter) {
2117.                 Sprintf(and_vanish, " and %s under %s",
2118.                         locomotion(mtmp->data, "crawl"), doname(mshelter));
2119.             } else if (mtmp->data->mlet == S_MIMIC
2120.                        || mtmp->data->mlet == S_EEL) {
2121.                 suppress_see = TRUE;
2122.             } else
2123.                 Strcpy(and_vanish, " and vanish");
2124.         }
2125. 
2126.         switch (figurine->where) {
2127.         case OBJ_INVENT:
2128.             if (Blind || suppress_see)
2129.                 You_feel("%s %s from your pack!", something,
2130.                          locomotion(mtmp->data, "drop"));
2131.             else
2132.                 You_see("%s %s out of your pack%s!", monnambuf,
2133.                         locomotion(mtmp->data, "drop"), and_vanish);
2134.             break;
2135. 
2136.         case OBJ_FLOOR:
2137.             if (cansee_spot && !silent) {
2138.                 if (suppress_see)
2139.                     pline("%s suddenly vanishes!", an(xname(figurine)));
2140.                 else
2141.                     You_see("a figurine transform into %s%s!", monnambuf,
2142.                             and_vanish);
2143.                 redraw = TRUE; /* update figurine's map location */
2144.             }
2145.             break;
2146. 
2147.         case OBJ_MINVENT:
2148.             if (cansee_spot && !silent && !suppress_see) {
2149.                 struct monst *mon;
2150. 
2151.                 mon = figurine->ocarry;
2152.                 /* figurine carrying monster might be invisible */
2153.                 if (canseemon(figurine->ocarry)
2154.                     && (!mon->wormno || cansee(mon->mx, mon->my)))
2155.                     Sprintf(carriedby, "%s pack", s_suffix(a_monnam(mon)));
2156.                 else if (is_pool(mon->mx, mon->my))
2157.                     Strcpy(carriedby, "empty water");
2158.                 else
2159.                     Strcpy(carriedby, "thin air");
2160.                 You_see("%s %s out of %s%s!", monnambuf,
2161.                         locomotion(mtmp->data, "drop"), carriedby,
2162.                         and_vanish);
2163.             }
2164.             break;
2165. #if 0
2166.         case OBJ_MIGRATING:
2167.             break;
2168. #endif
2169. 
2170.         default:
2171.             impossible("figurine came to life where? (%d)",
2172.                        (int) figurine->where);
2173.             break;
2174.         }
2175.     }
2176.     /* free figurine now */
2177.     if (carried(figurine)) {
2178.         useup(figurine);
2179.     } else {
2180.         obj_extract_self(figurine);
2181.         obfree(figurine, (struct obj *) 0);
2182.     }
2183.     if (redraw)
2184.         newsym(cc.x, cc.y);
2185. }
2186. 
2187. STATIC_OVL boolean
2188. figurine_location_checks(obj, cc, quietly)
2189. struct obj *obj;
2190. coord *cc;
2191. boolean quietly;
2192. {
2193.     xchar x, y;
2194. 
2195.     if (carried(obj) && u.uswallow) {
2196.         if (!quietly)
2197.             You("don't have enough room in here.");
2198.         return FALSE;
2199.     }
2200.     x = cc ? cc->x : u.ux;
2201.     y = cc ? cc->y : u.uy;
2202.     if (!isok(x, y)) {
2203.         if (!quietly)
2204.             You("cannot put the figurine there.");
2205.         return FALSE;
2206.     }
2207.     if (IS_ROCK(levl[x][y].typ)
2208.         && !(passes_walls(&mons[obj->corpsenm]) && may_passwall(x, y))) {
2209.         if (!quietly)
2210.             You("cannot place a figurine in %s!",
2211.                 IS_TREE(levl[x][y].typ) ? "a tree" : "solid rock");
2212.         return FALSE;
2213.     }
2214.     if (sobj_at(BOULDER, x, y) && !passes_walls(&mons[obj->corpsenm])
2215.         && !throws_rocks(&mons[obj->corpsenm])) {
2216.         if (!quietly)
2217.             You("cannot fit the figurine on the boulder.");
2218.         return FALSE;
2219.     }
2220.     return TRUE;
2221. }
2222. 
2223. STATIC_OVL void
2224. use_figurine(optr)
2225. struct obj **optr;
2226. {
2227.     register struct obj *obj = *optr;
2228.     xchar x, y;
2229.     coord cc;
2230. 
2231.     if (u.uswallow) {
2232.         /* can't activate a figurine while swallowed */
2233.         if (!figurine_location_checks(obj, (coord *) 0, FALSE))
2234.             return;
2235.     }
2236.     if (!getdir((char *) 0)) {
2237.         context.move = multi = 0;
2238.         return;
2239.     }
2240.     x = u.ux + u.dx;
2241.     y = u.uy + u.dy;
2242.     cc.x = x;
2243.     cc.y = y;
2244.     /* Passing FALSE arg here will result in messages displayed */
2245.     if (!figurine_location_checks(obj, &cc, FALSE))
2246.         return;
2247.     You("%s and it %stransforms.",
2248.         (u.dx || u.dy) ? "set the figurine beside you"
2249.                        : (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)
2250.                           || is_pool(cc.x, cc.y))
2251.                              ? "release the figurine"
2252.                              : (u.dz < 0 ? "toss the figurine into the air"
2253.                                          : "set the figurine on the ground"),
2254.         Blind ? "supposedly " : "");
2255.     (void) make_familiar(obj, cc.x, cc.y, FALSE);
2256.     (void) stop_timer(FIG_TRANSFORM, obj_to_any(obj));
2257.     useup(obj);
2258.     if (Blind)
2259.         map_invisible(cc.x, cc.y);
2260.     *optr = 0;
2261. }
2262. 
2263. static NEARDATA const char lubricables[] = { ALL_CLASSES, ALLOW_NONE, 0 };
2264. 
2265. STATIC_OVL void
2266. use_grease(obj)
2267. struct obj *obj;
2268. {
2269.     struct obj *otmp;
2270. 
2271.     if (Glib) {
2272.         pline("%s from your %s.", Tobjnam(obj, "slip"),
2273.               makeplural(body_part(FINGER)));
2274.         dropx(obj);
2275.         return;
2276.     }
2277. 
2278.     if (obj->spe > 0) {
2279.         if ((obj->cursed || Fumbling) && !rn2(2)) {
2280.             consume_obj_charge(obj, TRUE);
2281. 
2282.             pline("%s from your %s.", Tobjnam(obj, "slip"),
2283.                   makeplural(body_part(FINGER)));
2284.             dropx(obj);
2285.             return;
2286.         }
2287.         otmp = getobj(lubricables, "grease");
2288.         if (!otmp)
2289.             return;
2290.         if (inaccessible_equipment(otmp, "grease", FALSE))
2291.             return;
2292.         consume_obj_charge(obj, TRUE);
2293. 
2294.         if (otmp != &zeroobj) {
2295.             You("cover %s with a thick layer of grease.", yname(otmp));
2296.             otmp->greased = 1;
2297.             if (obj->cursed && !nohands(youmonst.data)) {
2298.                 incr_itimeout(&Glib, rnd(15));
2299.                 pline("Some of the grease gets all over your %s.",
2300.                       makeplural(body_part(HAND)));
2301.             }
2302.         } else {
2303.             incr_itimeout(&Glib, rnd(15));
2304.             You("coat your %s with grease.", makeplural(body_part(FINGER)));
2305.         }
2306.     } else {
2307.         if (obj->known)
2308.             pline("%s empty.", Tobjnam(obj, "are"));
2309.         else
2310.             pline("%s to be empty.", Tobjnam(obj, "seem"));
2311.     }
2312.     update_inventory();
2313. }
2314. 
2315. /* touchstones - by Ken Arnold */
2316. STATIC_OVL void
2317. use_stone(tstone)
2318. struct obj *tstone;
2319. {
2320.     struct obj *obj;
2321.     boolean do_scratch;
2322.     const char *streak_color, *choices;
2323.     char stonebuf[QBUFSZ];
2324.     static const char scritch[] = "\"scritch, scritch\"";
2325.     static const char allowall[3] = { COIN_CLASS, ALL_CLASSES, 0 };
2326.     static const char coins_gems[3] = { COIN_CLASS, GEM_CLASS, 0 };
2327. 
2328.     /* in case it was acquired while blinded */
2329.     if (!Blind)
2330.         tstone->dknown = 1;
2331.     /* when the touchstone is fully known, don't bother listing extra
2332.        junk as likely candidates for rubbing */
2333.     choices = (tstone->otyp == TOUCHSTONE && tstone->dknown
2334.                && objects[TOUCHSTONE].oc_name_known)
2335.                   ? coins_gems
2336.                   : allowall;
2337.     Sprintf(stonebuf, "rub on the stone%s", plur(tstone->quan));
2338.     if ((obj = getobj(choices, stonebuf)) == 0)
2339.         return;
2340. 
2341.     if (obj == tstone && obj->quan == 1L) {
2342.         You_cant("rub %s on itself.", the(xname(obj)));
2343.         return;
2344.     }
2345. 
2346.     if (tstone->otyp == TOUCHSTONE && tstone->cursed
2347.         && obj->oclass == GEM_CLASS && !is_graystone(obj)
2348.         && !obj_resists(obj, 80, 100)) {
2349.         if (Blind)
2350.             pline("You feel something shatter.");
2351.         else if (Hallucination)
2352.             pline("Oh, wow, look at the pretty shards.");
2353.         else
2354.             pline("A sharp crack shatters %s%s.",
2355.                   (obj->quan > 1L) ? "one of " : "", the(xname(obj)));
2356.         useup(obj);
2357.         return;
2358.     }
2359. 
2360.     if (Blind) {
2361.         pline(scritch);
2362.         return;
2363.     } else if (Hallucination) {
2364.         pline("Oh wow, man: Fractals!");
2365.         return;
2366.     }
2367. 
2368.     do_scratch = FALSE;
2369.     streak_color = 0;
2370. 
2371.     switch (obj->oclass) {
2372.     case GEM_CLASS: /* these have class-specific handling below */
2373.     case RING_CLASS:
2374.         if (tstone->otyp != TOUCHSTONE) {
2375.             do_scratch = TRUE;
2376.         } else if (obj->oclass == GEM_CLASS
2377.                    && (tstone->blessed
2378.                        || (!tstone->cursed && (Role_if(PM_ARCHEOLOGIST)
2379.                                                || Race_if(PM_GNOME))))) {
2380.             makeknown(TOUCHSTONE);
2381.             makeknown(obj->otyp);
2382.             prinv((char *) 0, obj, 0L);
2383.             return;
2384.         } else {
2385.             /* either a ring or the touchstone was not effective */
2386.             if (objects[obj->otyp].oc_material == GLASS) {
2387.                 do_scratch = TRUE;
2388.                 break;
2389.             }
2390.         }
2391.         streak_color = c_obj_colors[objects[obj->otyp].oc_color];
2392.         break; /* gem or ring */
2393. 
2394.     default:
2395.         switch (objects[obj->otyp].oc_material) {
2396.         case CLOTH:
2397.             pline("%s a little more polished now.", Tobjnam(tstone, "look"));
2398.             return;
2399.         case LIQUID:
2400.             if (!obj->known) /* note: not "whetstone" */
2401.                 You("must think this is a wetstone, do you?");
2402.             else
2403.                 pline("%s a little wetter now.", Tobjnam(tstone, "are"));
2404.             return;
2405.         case WAX:
2406.             streak_color = "waxy";
2407.             break; /* okay even if not touchstone */
2408.         case WOOD:
2409.             streak_color = "wooden";
2410.             break; /* okay even if not touchstone */
2411.         case GOLD:
2412.             do_scratch = TRUE; /* scratching and streaks */
2413.             streak_color = "golden";
2414.             break;
2415.         case SILVER:
2416.             do_scratch = TRUE; /* scratching and streaks */
2417.             streak_color = "silvery";
2418.             break;
2419.         default:
2420.             /* Objects passing the is_flimsy() test will not
2421.                scratch a stone.  They will leave streaks on
2422.                non-touchstones and touchstones alike. */
2423.             if (is_flimsy(obj))
2424.                 streak_color = c_obj_colors[objects[obj->otyp].oc_color];
2425.             else
2426.                 do_scratch = (tstone->otyp != TOUCHSTONE);
2427.             break;
2428.         }
2429.         break; /* default oclass */
2430.     }
2431. 
2432.     Sprintf(stonebuf, "stone%s", plur(tstone->quan));
2433.     if (do_scratch)
2434.         You("make %s%sscratch marks on the %s.",
2435.             streak_color ? streak_color : (const char *) "",
2436.             streak_color ? " " : "", stonebuf);
2437.     else if (streak_color)
2438.         You_see("%s streaks on the %s.", streak_color, stonebuf);
2439.     else
2440.         pline(scritch);
2441.     return;
2442. }
2443. 
2444. static struct trapinfo {
2445.     struct obj *tobj;
2446.     xchar tx, ty;
2447.     int time_needed;
2448.     boolean force_bungle;
2449. } trapinfo;
2450. 
2451. void
2452. reset_trapset()
2453. {
2454.     trapinfo.tobj = 0;
2455.     trapinfo.force_bungle = 0;
2456. }
2457. 
2458. /* Place a landmine/bear trap.  Helge Hafting */
2459. STATIC_OVL void
2460. use_trap(otmp)
2461. struct obj *otmp;
2462. {
2463.     int ttyp, tmp;
2464.     const char *what = (char *) 0;
2465.     char buf[BUFSZ];
2466.     int levtyp = levl[u.ux][u.uy].typ;
2467.     const char *occutext = "setting the trap";
2468. 
2469.     if (nohands(youmonst.data))
2470.         what = "without hands";
2471.     else if (Stunned)
2472.         what = "while stunned";
2473.     else if (u.uswallow)
2474.         what =
2475.             is_animal(u.ustuck->data) ? "while swallowed" : "while engulfed";
2476.     else if (Underwater)
2477.         what = "underwater";
2478.     else if (Levitation)
2479.         what = "while levitating";
2480.     else if (is_pool(u.ux, u.uy))
2481.         what = "in water";
2482.     else if (is_lava(u.ux, u.uy))
2483.         what = "in lava";
2484.     else if (On_stairs(u.ux, u.uy))
2485.         what = (u.ux == xdnladder || u.ux == xupladder) ? "on the ladder"
2486.                                                         : "on the stairs";
2487.     else if (IS_FURNITURE(levtyp) || IS_ROCK(levtyp)
2488.              || closed_door(u.ux, u.uy) || t_at(u.ux, u.uy))
2489.         what = "here";
2490.     else if (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz))
2491.         what = (levtyp == AIR)
2492.                    ? "in midair"
2493.                    : (levtyp == CLOUD)
2494.                          ? "in a cloud"
2495.                          : "in this place"; /* Air/Water Plane catch-all */
2496.     if (what) {
2497.         You_cant("set a trap %s!", what);
2498.         reset_trapset();
2499.         return;
2500.     }
2501.     ttyp = (otmp->otyp == LAND_MINE) ? LANDMINE : BEAR_TRAP;
2502.     if (otmp == trapinfo.tobj && u.ux == trapinfo.tx && u.uy == trapinfo.ty) {
2503.         You("resume setting %s%s.", shk_your(buf, otmp),
2504.             defsyms[trap_to_defsym(what_trap(ttyp, rn2))].explanation);
2505.         set_occupation(set_trap, occutext, 0);
2506.         return;
2507.     }
2508.     trapinfo.tobj = otmp;
2509.     trapinfo.tx = u.ux, trapinfo.ty = u.uy;
2510.     tmp = ACURR(A_DEX);
2511.     trapinfo.time_needed =
2512.         (tmp > 17) ? 2 : (tmp > 12) ? 3 : (tmp > 7) ? 4 : 5;
2513.     if (Blind)
2514.         trapinfo.time_needed *= 2;
2515.     tmp = ACURR(A_STR);
2516.     if (ttyp == BEAR_TRAP && tmp < 18)
2517.         trapinfo.time_needed += (tmp > 12) ? 1 : (tmp > 7) ? 2 : 4;
2518.     /*[fumbling and/or confusion and/or cursed object check(s)
2519.        should be incorporated here instead of in set_trap]*/
2520.     if (u.usteed && P_SKILL(P_RIDING) < P_BASIC) {
2521.         boolean chance;
2522. 
2523.         if (Fumbling || otmp->cursed)
2524.             chance = (rnl(10) > 3);
2525.         else
2526.             chance = (rnl(10) > 5);
2527.         You("aren't very skilled at reaching from %s.", mon_nam(u.usteed));
2528.         Sprintf(buf, "Continue your attempt to set %s?",
2529.                 the(defsyms[trap_to_defsym(what_trap(ttyp, rn2))]
2530.                     .explanation));
2531.         if (yn(buf) == 'y') {
2532.             if (chance) {
2533.                 switch (ttyp) {
2534.                 case LANDMINE: /* set it off */
2535.                     trapinfo.time_needed = 0;
2536.                     trapinfo.force_bungle = TRUE;
2537.                     break;
2538.                 case BEAR_TRAP: /* drop it without arming it */
2539.                     reset_trapset();
2540.                     You("drop %s!",
2541.                         the(defsyms[trap_to_defsym(what_trap(ttyp, rn2))]
2542.                                 .explanation));
2543.                     dropx(otmp);
2544.                     return;
2545.                 }
2546.             }
2547.         } else {
2548.             reset_trapset();
2549.             return;
2550.         }
2551.     }
2552.     You("begin setting %s%s.", shk_your(buf, otmp),
2553.         defsyms[trap_to_defsym(what_trap(ttyp, rn2))].explanation);
2554.     set_occupation(set_trap, occutext, 0);
2555.     return;
2556. }
2557. 
2558. STATIC_PTR
2559. int
2560. set_trap()
2561. {
2562.     struct obj *otmp = trapinfo.tobj;
2563.     struct trap *ttmp;
2564.     int ttyp;
2565. 
2566.     if (!otmp || !carried(otmp) || u.ux != trapinfo.tx
2567.         || u.uy != trapinfo.ty) {
2568.         /* ?? */
2569.         reset_trapset();
2570.         return 0;
2571.     }
2572. 
2573.     if (--trapinfo.time_needed > 0)
2574.         return 1; /* still busy */
2575. 
2576.     ttyp = (otmp->otyp == LAND_MINE) ? LANDMINE : BEAR_TRAP;
2577.     ttmp = maketrap(u.ux, u.uy, ttyp);
2578.     if (ttmp) {
2579.         ttmp->madeby_u = 1;
2580.         feeltrap(ttmp);
2581.         if (*in_rooms(u.ux, u.uy, SHOPBASE)) {
2582.             add_damage(u.ux, u.uy, 0L); /* schedule removal */
2583.         }
2584.         if (!trapinfo.force_bungle)
2585.             You("finish arming %s.",
2586.                 the(defsyms[trap_to_defsym(what_trap(ttyp, rn2))].explanation));
2587.         if (((otmp->cursed || Fumbling) && (rnl(10) > 5))
2588.             || trapinfo.force_bungle)
2589.             dotrap(ttmp,
2590.                    (unsigned) (trapinfo.force_bungle ? FORCEBUNGLE : 0));
2591.     } else {
2592.         /* this shouldn't happen */
2593.         Your("trap setting attempt fails.");
2594.     }
2595.     useup(otmp);
2596.     reset_trapset();
2597.     return 0;
2598. }
2599. 
2600. STATIC_OVL int
2601. use_whip(obj)
2602. struct obj *obj;
2603. {
2604.     char buf[BUFSZ];
2605.     struct monst *mtmp;
2606.     struct obj *otmp;
2607.     int rx, ry, proficient, res = 0;
2608.     const char *msg_slipsfree = "The bullwhip slips free.";
2609.     const char *msg_snap = "Snap!";
2610. 
2611.     if (obj != uwep) {
2612.         if (!wield_tool(obj, "lash"))
2613.             return 0;
2614.         else
2615.             res = 1;
2616.     }
2617.     if (!getdir((char *) 0))
2618.         return res;
2619. 
2620.     if (u.uswallow) {
2621.         mtmp = u.ustuck;
2622.         rx = mtmp->mx;
2623.         ry = mtmp->my;
2624.     } else {
2625.         if (Stunned || (Confusion && !rn2(5)))
2626.             confdir();
2627.         rx = u.ux + u.dx;
2628.         ry = u.uy + u.dy;
2629.         if (!isok(rx, ry)) {
2630.             You("miss.");
2631.             return res;
2632.         }
2633.         mtmp = m_at(rx, ry);
2634.     }
2635. 
2636.     /* fake some proficiency checks */
2637.     proficient = 0;
2638.     if (Role_if(PM_ARCHEOLOGIST))
2639.         ++proficient;
2640.     if (ACURR(A_DEX) < 6)
2641.         proficient--;
2642.     else if (ACURR(A_DEX) >= 14)
2643.         proficient += (ACURR(A_DEX) - 14);
2644.     if (Fumbling)
2645.         --proficient;
2646.     if (proficient > 3)
2647.         proficient = 3;
2648.     if (proficient < 0)
2649.         proficient = 0;
2650. 
2651.     if (u.uswallow && attack(u.ustuck)) {
2652.         There("is not enough room to flick your bullwhip.");
2653. 
2654.     } else if (Underwater) {
2655.         There("is too much resistance to flick your bullwhip.");
2656. 
2657.     } else if (u.dz < 0) {
2658.         You("flick a bug off of the %s.", ceiling(u.ux, u.uy));
2659. 
2660.     } else if ((!u.dx && !u.dy) || (u.dz > 0)) {
2661.         int dam;
2662. 
2663.         /* Sometimes you hit your steed by mistake */
2664.         if (u.usteed && !rn2(proficient + 2)) {
2665.             You("whip %s!", mon_nam(u.usteed));
2666.             kick_steed();
2667.             return 1;
2668.         }
2669.         if (Levitation || u.usteed) {
2670.             /* Have a shot at snaring something on the floor */
2671.             otmp = level.objects[u.ux][u.uy];
2672.             if (otmp && otmp->otyp == CORPSE && otmp->corpsenm == PM_HORSE) {
2673.                 pline("Why beat a dead horse?");
2674.                 return 1;
2675.             }
2676.             if (otmp && proficient) {
2677.                 You("wrap your bullwhip around %s on the %s.",
2678.                     an(singular(otmp, xname)), surface(u.ux, u.uy));
2679.                 if (rnl(6) || pickup_object(otmp, 1L, TRUE) < 1)
2680.                     pline1(msg_slipsfree);
2681.                 return 1;
2682.             }
2683.         }
2684.         dam = rnd(2) + dbon() + obj->spe;
2685.         if (dam <= 0)
2686.             dam = 1;
2687.         You("hit your %s with your bullwhip.", body_part(FOOT));
2688.         Sprintf(buf, "killed %sself with %s bullwhip", uhim(), uhis());
2689.         losehp(Maybe_Half_Phys(dam), buf, NO_KILLER_PREFIX);
2690.         return 1;
2691. 
2692.     } else if ((Fumbling || Glib) && !rn2(5)) {
2693.         pline_The("bullwhip slips out of your %s.", body_part(HAND));
2694.         dropx(obj);
2695. 
2696.     } else if (u.utrap && u.utraptype == TT_PIT) {
2697.         /*
2698.          * Assumptions:
2699.          *
2700.          * if you're in a pit
2701.          *    - you are attempting to get out of the pit
2702.          * or, if you are applying it towards a small monster
2703.          *    - then it is assumed that you are trying to hit it
2704.          * else if the monster is wielding a weapon
2705.          *    - you are attempting to disarm a monster
2706.          * else
2707.          *    - you are attempting to hit the monster.
2708.          *
2709.          * if you're confused (and thus off the mark)
2710.          *    - you only end up hitting.
2711.          *
2712.          */
2713.         const char *wrapped_what = (char *) 0;
2714. 
2715.         if (mtmp) {
2716.             if (bigmonst(mtmp->data)) {
2717.                 wrapped_what = strcpy(buf, mon_nam(mtmp));
2718.             } else if (proficient) {
2719.                 if (attack(mtmp))
2720.                     return 1;
2721.                 else
2722.                     pline1(msg_snap);
2723.             }
2724.         }
2725.         if (!wrapped_what) {
2726.             if (IS_FURNITURE(levl[rx][ry].typ))
2727.                 wrapped_what = something;
2728.             else if (sobj_at(BOULDER, rx, ry))
2729.                 wrapped_what = "a boulder";
2730.         }
2731.         if (wrapped_what) {
2732.             coord cc;
2733. 
2734.             cc.x = rx;
2735.             cc.y = ry;
2736.             You("wrap your bullwhip around %s.", wrapped_what);
2737.             if (proficient && rn2(proficient + 2)) {
2738.                 if (!mtmp || enexto(&cc, rx, ry, youmonst.data)) {
2739.                     You("yank yourself out of the pit!");
2740.                     teleds(cc.x, cc.y, TRUE);
2741.                     reset_utrap(TRUE);
2742.                     vision_full_recalc = 1;
2743.                 }
2744.             } else {
2745.                 pline1(msg_slipsfree);
2746.             }
2747.             if (mtmp)
2748.                 wakeup(mtmp, TRUE);
2749.         } else
2750.             pline1(msg_snap);
2751. 
2752.     } else if (mtmp) {
2753.         if (!canspotmon(mtmp) && !glyph_is_invisible(levl[rx][ry].glyph)) {
2754.             pline("A monster is there that you couldn't see.");
2755.             map_invisible(rx, ry);
2756.         }
2757.         otmp = MON_WEP(mtmp); /* can be null */
2758.         if (otmp) {
2759.             char onambuf[BUFSZ];
2760.             const char *mon_hand;
2761.             boolean gotit = proficient && (!Fumbling || !rn2(10));
2762. 
2763.             Strcpy(onambuf, cxname(otmp));
2764.             if (gotit) {
2765.                 mon_hand = mbodypart(mtmp, HAND);
2766.                 if (bimanual(otmp))
2767.                     mon_hand = makeplural(mon_hand);
2768.             } else
2769.                 mon_hand = 0; /* lint suppression */
2770. 
2771.             You("wrap your bullwhip around %s.", yname(otmp));
2772.             if (gotit && mwelded(otmp)) {
2773.                 pline("%s welded to %s %s%c",
2774.                       (otmp->quan == 1L) ? "It is" : "They are", mhis(mtmp),
2775.                       mon_hand, !otmp->bknown ? '!' : '.');
2776.                 otmp->bknown = 1;
2777.                 gotit = FALSE; /* can't pull it free */
2778.             }
2779.             if (gotit) {
2780.                 obj_extract_self(otmp);
2781.                 possibly_unwield(mtmp, FALSE);
2782.                 setmnotwielded(mtmp, otmp);
2783. 
2784.                 switch (rn2(proficient + 1)) {
2785.                 case 2:
2786.                     /* to floor near you */
2787.                     You("yank %s to the %s!", yname(otmp),
2788.                         surface(u.ux, u.uy));
2789.                     place_object(otmp, u.ux, u.uy);
2790.                     stackobj(otmp);
2791.                     break;
2792.                 case 3:
2793. #if 0
2794.                     /* right to you */
2795.                     if (!rn2(25)) {
2796.                         /* proficient with whip, but maybe not
2797.                            so proficient at catching weapons */
2798.                         int hitu, hitvalu;
2799. 
2800.                         hitvalu = 8 + otmp->spe;
2801.                         hitu = thitu(hitvalu, dmgval(otmp, &youmonst),
2802.                                      &otmp, (char *)0);
2803.                         if (hitu) {
2804.                             pline_The("%s hits you as you try to snatch it!",
2805.                                       the(onambuf));
2806.                         }
2807.                         place_object(otmp, u.ux, u.uy);
2808.                         stackobj(otmp);
2809.                         break;
2810.                     }
2811. #endif /* 0 */
2812.                     /* right into your inventory */
2813.                     You("snatch %s!", yname(otmp));
2814.                     if (otmp->otyp == CORPSE
2815.                         && touch_petrifies(&mons[otmp->corpsenm]) && !uarmg
2816.                         && !Stone_resistance
2817.                         && !(poly_when_stoned(youmonst.data)
2818.                              && polymon(PM_STONE_GOLEM))) {
2819.                         char kbuf[BUFSZ];
2820. 
2821.                         Sprintf(kbuf, "%s corpse",
2822.                                 an(mons[otmp->corpsenm].mname));
2823.                         pline("Snatching %s is a fatal mistake.", kbuf);
2824.                         instapetrify(kbuf);
2825.                     }
2826.                     (void) hold_another_object(otmp, "You drop %s!",
2827.                                                doname(otmp), (const char *) 0);
2828.                     break;
2829.                 default:
2830.                     /* to floor beneath mon */
2831.                     You("yank %s from %s %s!", the(onambuf),
2832.                         s_suffix(mon_nam(mtmp)), mon_hand);
2833.                     obj_no_longer_held(otmp);
2834.                     place_object(otmp, mtmp->mx, mtmp->my);
2835.                     stackobj(otmp);
2836.                     break;
2837.                 }
2838.             } else {
2839.                 pline1(msg_slipsfree);
2840.             }
2841.             wakeup(mtmp, TRUE);
2842.         } else {
2843.             if (M_AP_TYPE(mtmp) && !Protection_from_shape_changers
2844.                 && !sensemon(mtmp))
2845.                 stumble_onto_mimic(mtmp);
2846.             else
2847.                 You("flick your bullwhip towards %s.", mon_nam(mtmp));
2848.             if (proficient) {
2849.                 if (attack(mtmp))
2850.                     return 1;
2851.                 else
2852.                     pline1(msg_snap);
2853.             }
2854.         }
2855. 
2856.     } else if (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) {
2857.         /* it must be air -- water checked above */
2858.         You("snap your whip through thin air.");
2859. 
2860.     } else {
2861.         pline1(msg_snap);
2862.     }
2863.     return 1;
2864. }
2865. 
2866. static const char
2867.     not_enough_room[] = "There's not enough room here to use that.",
2868.     where_to_hit[] = "Where do you want to hit?",
2869.     cant_see_spot[] = "won't hit anything if you can't see that spot.",
2870.     cant_reach[] = "can't reach that spot from here.";
2871. 
2872. /* find pos of monster in range, if only one monster */
2873. boolean
2874. find_poleable_mon(pos, min_range, max_range)
2875. coord *pos;
2876. int min_range, max_range;
2877. {
2878.     struct monst *mtmp;
2879.     coord mpos;
2880.     boolean impaired;
2881.     int x, y, lo_x, hi_x, lo_y, hi_y, rt, glyph;
2882. 
2883.     if (Blind)
2884.         return FALSE; /* must be able to see target location */
2885.     impaired = (Confusion || Stunned || Hallucination);
2886.     mpos.x = mpos.y = 0; /* no candidate location yet */
2887.     rt = isqrt(max_range);
2888.     lo_x = max(u.ux - rt, 1), hi_x = min(u.ux + rt, COLNO - 1);
2889.     lo_y = max(u.uy - rt, 0), hi_y = min(u.uy + rt, ROWNO - 1);
2890.     for (x = lo_x; x <= hi_x; ++x) {
2891.         for (y = lo_y; y <= hi_y; ++y) {
2892.             if (distu(x, y) < min_range || distu(x, y) > max_range
2893.                 || !isok(x, y) || !cansee(x, y))
2894.                 continue;
2895.             glyph = glyph_at(x, y);
2896.             if (!impaired
2897.                 && glyph_is_monster(glyph)
2898.                 && (mtmp = m_at(x, y)) != 0
2899.                 && (mtmp->mtame || (mtmp->mpeaceful && flags.confirm)))
2900.                 continue;
2901.             if (glyph_is_monster(glyph)
2902.                 || glyph_is_warning(glyph)
2903.                 || glyph_is_invisible(glyph)
2904.                 || (glyph_is_statue(glyph) && impaired)) {
2905.                 if (mpos.x)
2906.                     return FALSE; /* more than one candidate location */
2907.                 mpos.x = x, mpos.y = y;
2908.             }
2909.         }
2910.     }
2911.     if (!mpos.x)
2912.         return FALSE; /* no candidate location */
2913.     *pos = mpos;
2914.     return TRUE;
2915. }
2916. 
2917. static int polearm_range_min = -1;
2918. static int polearm_range_max = -1;
2919. 
2920. STATIC_OVL boolean
2921. get_valid_polearm_position(x, y)
2922. int x, y;
2923. {
2924.     return (isok(x, y) && ACCESSIBLE(levl[x][y].typ)
2925.             && distu(x, y) >= polearm_range_min
2926.             && distu(x, y) <= polearm_range_max);
2927. }
2928. 
2929. void
2930. display_polearm_positions(state)
2931. int state;
2932. {
2933.     if (state == 0) {
2934.         tmp_at(DISP_BEAM, cmap_to_glyph(S_goodpos));
2935.     } else if (state == 1) {
2936.         int x, y, dx, dy;
2937. 
2938.         for (dx = -4; dx <= 4; dx++)
2939.             for (dy = -4; dy <= 4; dy++) {
2940.                 x = dx + (int) u.ux;
2941.                 y = dy + (int) u.uy;
2942.                 if (get_valid_polearm_position(x, y)) {
2943.                     tmp_at(x, y);
2944.                 }
2945.             }
2946.     } else {
2947.         tmp_at(DISP_END, 0);
2948.     }
2949. }
2950. 
2951. /* Distance attacks by pole-weapons */
2952. STATIC_OVL int
2953. use_pole(obj)
2954. struct obj *obj;
2955. {
2956.     int res = 0, typ, max_range, min_range, glyph;
2957.     coord cc;
2958.     struct monst *mtmp;
2959.     struct monst *hitm = context.polearm.hitmon;
2960. 
2961.     /* Are you allowed to use the pole? */
2962.     if (u.uswallow) {
2963.         pline(not_enough_room);
2964.         return 0;
2965.     }
2966.     if (obj != uwep) {
2967.         if (!wield_tool(obj, "swing"))
2968.             return 0;
2969.         else
2970.             res = 1;
2971.     }
2972.     /* assert(obj == uwep); */
2973. 
2974.     /*
2975.      * Calculate allowable range (pole's reach is always 2 steps):
2976.      *  unskilled and basic: orthogonal direction, 4..4;
2977.      *  skilled: as basic, plus knight's jump position, 4..5;
2978.      *  expert: as skilled, plus diagonal, 4..8.
2979.      *      ...9...
2980.      *      .85458.
2981.      *      .52125.
2982.      *      9410149
2983.      *      .52125.
2984.      *      .85458.
2985.      *      ...9...
2986.      *  (Note: no roles in nethack can become expert or better
2987.      *  for polearm skill; Yeoman in slash'em can become expert.)
2988.      */
2989.     min_range = 4;
2990.     typ = uwep_skill_type();
2991.     if (typ == P_NONE || P_SKILL(typ) <= P_BASIC)
2992.         max_range = 4;
2993.     else if (P_SKILL(typ) == P_SKILLED)
2994.         max_range = 5;
2995.     else
2996.         max_range = 8; /* (P_SKILL(typ) >= P_EXPERT) */
2997. 
2998.     polearm_range_min = min_range;
2999.     polearm_range_max = max_range;
3000. 
3001.     /* Prompt for a location */
3002.     pline(where_to_hit);
3003.     cc.x = u.ux;
3004.     cc.y = u.uy;
3005.     if (!find_poleable_mon(&cc, min_range, max_range) && hitm
3006.         && !DEADMONSTER(hitm) && cansee(hitm->mx, hitm->my)
3007.         && distu(hitm->mx, hitm->my) <= max_range
3008.         && distu(hitm->mx, hitm->my) >= min_range) {
3009.         cc.x = hitm->mx;
3010.         cc.y = hitm->my;
3011.     }
3012.     getpos_sethilite(display_polearm_positions, get_valid_polearm_position);
3013.     if (getpos(&cc, TRUE, "the spot to hit") < 0)
3014.         return res; /* ESC; uses turn iff polearm became wielded */
3015. 
3016.     glyph = glyph_at(cc.x, cc.y);
3017.     if (distu(cc.x, cc.y) > max_range) {
3018.         pline("Too far!");
3019.         return res;
3020.     } else if (distu(cc.x, cc.y) < min_range) {
3021.         pline("Too close!");
3022.         return res;
3023.     } else if (!cansee(cc.x, cc.y) && !glyph_is_monster(glyph)
3024.                && !glyph_is_invisible(glyph) && !glyph_is_statue(glyph)) {
3025.         You(cant_see_spot);
3026.         return res;
3027.     } else if (!couldsee(cc.x, cc.y)) { /* Eyes of the Overworld */
3028.         You(cant_reach);
3029.         return res;
3030.     }
3031. 
3032.     context.polearm.hitmon = (struct monst *) 0;
3033.     /* Attack the monster there */
3034.     bhitpos = cc;
3035.     if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != (struct monst *) 0) {
3036.         if (attack_checks(mtmp, uwep))
3037.             return res;
3038.         if (overexertion())
3039.             return 1; /* burn nutrition; maybe pass out */
3040.         context.polearm.hitmon = mtmp;
3041.         check_caitiff(mtmp);
3042.         notonhead = (bhitpos.x != mtmp->mx || bhitpos.y != mtmp->my);
3043.         (void) thitmonst(mtmp, uwep);
3044.     } else if (glyph_is_statue(glyph) /* might be hallucinatory */
3045.                && sobj_at(STATUE, bhitpos.x, bhitpos.y)) {
3046.         struct trap *t = t_at(bhitpos.x, bhitpos.y);
3047. 
3048.         if (t && t->ttyp == STATUE_TRAP
3049.             && activate_statue_trap(t, t->tx, t->ty, FALSE)) {
3050.             ; /* feedback has been give by animate_statue() */
3051.         } else {
3052.             /* Since statues look like monsters now, we say something
3053.                different from "you miss" or "there's nobody there".
3054.                Note:  we only do this when a statue is displayed here,
3055.                because the player is probably attempting to attack it;
3056.                other statues obscured by anything are just ignored. */
3057.             pline("Thump!  Your blow bounces harmlessly off the statue.");
3058.             wake_nearto(bhitpos.x, bhitpos.y, 25);
3059.         }
3060.     } else {
3061.         /* no monster here and no statue seen or remembered here */
3062.         (void) unmap_invisible(bhitpos.x, bhitpos.y);
3063.         You("miss; there is no one there to hit.");
3064.     }
3065.     u_wipe_engr(2); /* same as for melee or throwing */
3066.     return 1;
3067. }
3068. 
3069. STATIC_OVL int
3070. use_cream_pie(obj)
3071. struct obj *obj;
3072. {
3073.     boolean wasblind = Blind;
3074.     boolean wascreamed = u.ucreamed;
3075.     boolean several = FALSE;
3076. 
3077.     if (obj->quan > 1L) {
3078.         several = TRUE;
3079.         obj = splitobj(obj, 1L);
3080.     }
3081.     if (Hallucination)
3082.         You("give yourself a facial.");
3083.     else
3084.         pline("You immerse your %s in %s%s.", body_part(FACE),
3085.               several ? "one of " : "",
3086.               several ? makeplural(the(xname(obj))) : the(xname(obj)));
3087.     if (can_blnd((struct monst *) 0, &youmonst, AT_WEAP, obj)) {
3088.         int blindinc = rnd(25);
3089.         u.ucreamed += blindinc;
3090.         make_blinded(Blinded + (long) blindinc, FALSE);
3091.         if (!Blind || (Blind && wasblind))
3092.             pline("There's %ssticky goop all over your %s.",
3093.                   wascreamed ? "more " : "", body_part(FACE));
3094.         else /* Blind  && !wasblind */
3095.             You_cant("see through all the sticky goop on your %s.",
3096.                      body_part(FACE));
3097.     }
3098. 
3099.     setnotworn(obj);
3100.     /* useup() is appropriate, but we want costly_alteration()'s message */
3101.     costly_alteration(obj, COST_SPLAT);
3102.     obj_extract_self(obj);
3103.     delobj(obj);
3104.     return 0;
3105. }
3106. 
3107. STATIC_OVL int
3108. use_grapple(obj)
3109. struct obj *obj;
3110. {
3111.     int res = 0, typ, max_range = 4, tohit;
3112.     boolean save_confirm;
3113.     coord cc;
3114.     struct monst *mtmp;
3115.     struct obj *otmp;
3116. 
3117.     /* Are you allowed to use the hook? */
3118.     if (u.uswallow) {
3119.         pline(not_enough_room);
3120.         return 0;
3121.     }
3122.     if (obj != uwep) {
3123.         if (!wield_tool(obj, "cast"))
3124.             return 0;
3125.         else
3126.             res = 1;
3127.     }
3128.     /* assert(obj == uwep); */
3129. 
3130.     /* Prompt for a location */
3131.     pline(where_to_hit);
3132.     cc.x = u.ux;
3133.     cc.y = u.uy;
3134.     if (getpos(&cc, TRUE, "the spot to hit") < 0)
3135.         return res; /* ESC; uses turn iff grapnel became wielded */
3136. 
3137.     /* Calculate range; unlike use_pole(), there's no minimum for range */
3138.     typ = uwep_skill_type();
3139.     if (typ == P_NONE || P_SKILL(typ) <= P_BASIC)
3140.         max_range = 4;
3141.     else if (P_SKILL(typ) == P_SKILLED)
3142.         max_range = 5;
3143.     else
3144.         max_range = 8;
3145.     if (distu(cc.x, cc.y) > max_range) {
3146.         pline("Too far!");
3147.         return res;
3148.     } else if (!cansee(cc.x, cc.y)) {
3149.         You(cant_see_spot);
3150.         return res;
3151.     } else if (!couldsee(cc.x, cc.y)) { /* Eyes of the Overworld */
3152.         You(cant_reach);
3153.         return res;
3154.     }
3155. 
3156.     /* What do you want to hit? */
3157.     tohit = rn2(5);
3158.     if (typ != P_NONE && P_SKILL(typ) >= P_SKILLED) {
3159.         winid tmpwin = create_nhwindow(NHW_MENU);
3160.         anything any;
3161.         char buf[BUFSZ];
3162.         menu_item *selected;
3163. 
3164.         any = zeroany; /* set all bits to zero */
3165.         any.a_int = 1; /* use index+1 (cant use 0) as identifier */
3166.         start_menu(tmpwin);
3167.         any.a_int++;
3168.         Sprintf(buf, "an object on the %s", surface(cc.x, cc.y));
3169.         add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf,
3170.                  MENU_UNSELECTED);
3171.         any.a_int++;
3172.         add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, "a monster",
3173.                  MENU_UNSELECTED);
3174.         any.a_int++;
3175.         Sprintf(buf, "the %s", surface(cc.x, cc.y));
3176.         add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf,
3177.                  MENU_UNSELECTED);
3178.         end_menu(tmpwin, "Aim for what?");
3179.         tohit = rn2(4);
3180.         if (select_menu(tmpwin, PICK_ONE, &selected) > 0
3181.             && rn2(P_SKILL(typ) > P_SKILLED ? 20 : 2))
3182.             tohit = selected[0].item.a_int - 1;
3183.         free((genericptr_t) selected);
3184.         destroy_nhwindow(tmpwin);
3185.     }
3186. 
3187.     /* possibly scuff engraving at your feet;
3188.        any engraving at the target location is unaffected */
3189.     if (tohit == 2 || !rn2(2))
3190.         u_wipe_engr(rnd(2));
3191. 
3192.     /* What did you hit? */
3193.     switch (tohit) {
3194.     case 0: /* Trap */
3195.         /* FIXME -- untrap needs to deal with non-adjacent traps */
3196.         break;
3197.     case 1: /* Object */
3198.         if ((otmp = level.objects[cc.x][cc.y]) != 0) {
3199.             You("snag an object from the %s!", surface(cc.x, cc.y));
3200.             (void) pickup_object(otmp, 1L, FALSE);
3201.             /* If pickup fails, leave it alone */
3202.             newsym(cc.x, cc.y);
3203.             return 1;
3204.         }
3205.         break;
3206.     case 2: /* Monster */
3207.         bhitpos = cc;
3208.         if ((mtmp = m_at(cc.x, cc.y)) == (struct monst *) 0)
3209.             break;
3210.         notonhead = (bhitpos.x != mtmp->mx || bhitpos.y != mtmp->my);
3211.         save_confirm = flags.confirm;
3212.         if (verysmall(mtmp->data) && !rn2(4)
3213.             && enexto(&cc, u.ux, u.uy, (struct permonst *) 0)) {
3214.             flags.confirm = FALSE;
3215.             (void) attack_checks(mtmp, uwep);
3216.             flags.confirm = save_confirm;
3217.             check_caitiff(mtmp); /* despite fact there's no damage */
3218.             You("pull in %s!", mon_nam(mtmp));
3219.             mtmp->mundetected = 0;
3220.             rloc_to(mtmp, cc.x, cc.y);
3221.             return 1;
3222.         } else if ((!bigmonst(mtmp->data) && !strongmonst(mtmp->data))
3223.                    || rn2(4)) {
3224.             flags.confirm = FALSE;
3225.             (void) attack_checks(mtmp, uwep);
3226.             flags.confirm = save_confirm;
3227.             check_caitiff(mtmp);
3228.             (void) thitmonst(mtmp, uwep);
3229.             return 1;
3230.         }
3231.     /*FALLTHRU*/
3232.     case 3: /* Surface */
3233.         if (IS_AIR(levl[cc.x][cc.y].typ) || is_pool(cc.x, cc.y))
3234.             pline_The("hook slices through the %s.", surface(cc.x, cc.y));
3235.         else {
3236.             You("are yanked toward the %s!", surface(cc.x, cc.y));
3237.             hurtle(sgn(cc.x - u.ux), sgn(cc.y - u.uy), 1, FALSE);
3238.             spoteffects(TRUE);
3239.         }
3240.         return 1;
3241.     default: /* Yourself (oops!) */
3242.         if (P_SKILL(typ) <= P_BASIC) {
3243.             You("hook yourself!");
3244.             losehp(Maybe_Half_Phys(rn1(10, 10)), "a grappling hook",
3245.                    KILLED_BY);
3246.             return 1;
3247.         }
3248.         break;
3249.     }
3250.     pline1(nothing_happens);
3251.     return 1;
3252. }
3253. 
3254. #define BY_OBJECT ((struct monst *) 0)
3255. 
3256. /* return 1 if the wand is broken, hence some time elapsed */
3257. STATIC_OVL int
3258. do_break_wand(obj)
3259. struct obj *obj;
3260. {
3261.     static const char nothing_else_happens[] = "But nothing else happens...";
3262.     register int i, x, y;
3263.     register struct monst *mon;
3264.     int dmg, damage;
3265.     boolean affects_objects;
3266.     boolean shop_damage = FALSE;
3267.     boolean fillmsg = FALSE;
3268.     int expltype = EXPL_MAGICAL;
3269.     char confirm[QBUFSZ], buf[BUFSZ];
3270.     boolean is_fragile = (!strcmp(OBJ_DESCR(objects[obj->otyp]), "balsa"));
3271. 
3272.     if (!paranoid_query(ParanoidBreakwand,
3273.                        safe_qbuf(confirm,
3274.                                  "Are you really sure you want to break ",
3275.                                  "?", obj, yname, ysimple_name, "the wand")))
3276.         return 0;
3277. 
3278.     if (nohands(youmonst.data)) {
3279.         You_cant("break %s without hands!", yname(obj));
3280.         return 0;
3281.     } else if (ACURR(A_STR) < (is_fragile ? 5 : 10)) {
3282.         You("don't have the strength to break %s!", yname(obj));
3283.         return 0;
3284.     }
3285.     pline("Raising %s high above your %s, you %s it in two!", yname(obj),
3286.           body_part(HEAD), is_fragile ? "snap" : "break");
3287. 
3288.     /* [ALI] Do this first so that wand is removed from bill. Otherwise,
3289.      * the freeinv() below also hides it from setpaid() which causes problems.
3290.      */
3291.     if (obj->unpaid) {
3292.         check_unpaid(obj); /* Extra charge for use */
3293.         costly_alteration(obj, COST_DSTROY);
3294.     }
3295. 
3296.     current_wand = obj; /* destroy_item might reset this */
3297.     freeinv(obj);       /* hide it from destroy_item instead... */
3298.     setnotworn(obj);    /* so we need to do this ourselves */
3299. 
3300.     if (!zappable(obj)) {
3301.         pline(nothing_else_happens);
3302.         goto discard_broken_wand;
3303.     }
3304.     /* successful call to zappable() consumes a charge; put it back */
3305.     obj->spe++;
3306.     /* might have "wrested" a final charge, taking it from 0 to -1;
3307.        if so, we just brought it back up to 0, which wouldn't do much
3308.        below so give it 1..3 charges now, usually making it stronger
3309.        than an ordinary last charge (the wand is already gone from
3310.        inventory, so perm_invent can't accidentally reveal this) */
3311.     if (!obj->spe)
3312.         obj->spe = rnd(3);
3313. 
3314.     obj->ox = u.ux;
3315.     obj->oy = u.uy;
3316.     dmg = obj->spe * 4;
3317.     affects_objects = FALSE;
3318. 
3319.     switch (obj->otyp) {
3320.     case WAN_WISHING:
3321.     case WAN_NOTHING:
3322.     case WAN_LOCKING:
3323.     case WAN_PROBING:
3324.     case WAN_ENLIGHTENMENT:
3325.     case WAN_OPENING:
3326.     case WAN_SECRET_DOOR_DETECTION:
3327.         pline(nothing_else_happens);
3328.         goto discard_broken_wand;
3329.     case WAN_DEATH:
3330.     case WAN_LIGHTNING:
3331.         dmg *= 4;
3332.         goto wanexpl;
3333.     case WAN_FIRE:
3334.         expltype = EXPL_FIERY;
3335.         /*FALLTHRU*/
3336.     case WAN_COLD:
3337.         if (expltype == EXPL_MAGICAL)
3338.             expltype = EXPL_FROSTY;
3339.         dmg *= 2;
3340.         /*FALLTHRU*/
3341.     case WAN_MAGIC_MISSILE:
3342.     wanexpl:
3343.         explode(u.ux, u.uy, -(obj->otyp), dmg, WAND_CLASS, expltype);
3344.         makeknown(obj->otyp); /* explode describes the effect */
3345.         goto discard_broken_wand;
3346.     case WAN_STRIKING:
3347.         /* we want this before the explosion instead of at the very end */
3348.         pline("A wall of force smashes down around you!");
3349.         dmg = d(1 + obj->spe, 6); /* normally 2d12 */
3350.         /*FALLTHRU*/
3351.     case WAN_CANCELLATION:
3352.     case WAN_POLYMORPH:
3353.     case WAN_TELEPORTATION:
3354.     case WAN_UNDEAD_TURNING:
3355.         affects_objects = TRUE;
3356.         break;
3357.     default:
3358.         break;
3359.     }
3360. 
3361.     /* magical explosion and its visual effect occur before specific effects
3362.      */
3363.     /* [TODO?  This really ought to prevent the explosion from being
3364.        fatal so that we never leave a bones file where none of the
3365.        surrounding targets (or underlying objects) got affected yet.] */
3366.     explode(obj->ox, obj->oy, -(obj->otyp), rnd(dmg), WAND_CLASS,
3367.             EXPL_MAGICAL);
3368. 
3369.     /* prepare for potential feedback from polymorph... */
3370.     zapsetup();
3371. 
3372.     /* this makes it hit us last, so that we can see the action first */
3373.     for (i = 0; i <= 8; i++) {
3374.         bhitpos.x = x = obj->ox + xdir[i];
3375.         bhitpos.y = y = obj->oy + ydir[i];
3376.         if (!isok(x, y))
3377.             continue;
3378. 
3379.         if (obj->otyp == WAN_DIGGING) {
3380.             schar typ;
3381. 
3382.             if (dig_check(BY_OBJECT, FALSE, x, y)) {
3383.                 if (IS_WALL(levl[x][y].typ) || IS_DOOR(levl[x][y].typ)) {
3384.                     /* normally, pits and holes don't anger guards, but they
3385.                      * do if it's a wall or door that's being dug */
3386.                     watch_dig((struct monst *) 0, x, y, TRUE);
3387.                     if (*in_rooms(x, y, SHOPBASE))
3388.                         shop_damage = TRUE;
3389.                 }
3390.                 /*
3391.                  * Let liquid flow into the newly created pits.
3392.                  * Adjust corresponding code in music.c for
3393.                  * drum of earthquake if you alter this sequence.
3394.                  */
3395.                 typ = fillholetyp(x, y, FALSE);
3396.                 if (typ != ROOM) {
3397.                     levl[x][y].typ = typ, levl[x][y].flags = 0;
3398.                     liquid_flow(x, y, typ, t_at(x, y),
3399.                                 fillmsg
3400.                                   ? (char *) 0
3401.                                   : "Some holes are quickly filled with %s!");
3402.                     fillmsg = TRUE;
3403.                 } else
3404.                     digactualhole(x, y, BY_OBJECT, (rn2(obj->spe) < 3
3405.                                                     || (!Can_dig_down(&u.uz)
3406.                                                         && !levl[x][y].candig))
3407.                                                       ? PIT
3408.                                                       : HOLE);
3409.             }
3410.             continue;
3411.         } else if (obj->otyp == WAN_CREATE_MONSTER) {
3412.             /* u.ux,u.uy creates it near you--x,y might create it in rock */
3413.             (void) makemon((struct permonst *) 0, u.ux, u.uy, NO_MM_FLAGS);
3414.             continue;
3415.         } else if (x != u.ux || y != u.uy) {
3416.             /*
3417.              * Wand breakage is targetting a square adjacent to the hero,
3418.              * which might contain a monster or a pile of objects or both.
3419.              * Handle objects last; avoids having undead turning raise an
3420.              * undead's corpse and then attack resulting undead monster.
3421.              * obj->bypass in bhitm() prevents the polymorphing of items
3422.              * dropped due to monster's polymorph and prevents undead
3423.              * turning that kills an undead from raising resulting corpse.
3424.              */
3425.             if ((mon = m_at(x, y)) != 0) {
3426.                 (void) bhitm(mon, obj);
3427.                 /* if (context.botl) bot(); */
3428.             }
3429.             if (affects_objects && level.objects[x][y]) {
3430.                 (void) bhitpile(obj, bhito, x, y, 0);
3431.                 if (context.botl)
3432.                     bot(); /* potion effects */
3433.             }
3434.         } else {
3435.             /*
3436.              * Wand breakage is targetting the hero.  Using xdir[]+ydir[]
3437.              * deltas for location selection causes this case to happen
3438.              * after all the surrounding squares have been handled.
3439.              * Process objects first, in case damage is fatal and leaves
3440.              * bones, or teleportation sends one or more of the objects to
3441.              * same destination as hero (lookhere/autopickup); also avoids
3442.              * the polymorphing of gear dropped due to hero's transformation.
3443.              * (Unlike with monsters being hit by zaps, we can't rely on use
3444.              * of obj->bypass in the zap code to accomplish that last case
3445.              * since it's also used by retouch_equipment() for polyself.)
3446.              */
3447.             if (affects_objects && level.objects[x][y]) {
3448.                 (void) bhitpile(obj, bhito, x, y, 0);
3449.                 if (context.botl)
3450.                     bot(); /* potion effects */
3451.             }
3452.             damage = zapyourself(obj, FALSE);
3453.             if (damage) {
3454.                 Sprintf(buf, "killed %sself by breaking a wand", uhim());
3455.                 losehp(Maybe_Half_Phys(damage), buf, NO_KILLER_PREFIX);
3456.             }
3457.             if (context.botl)
3458.                 bot(); /* blindness */
3459.         }
3460.     }
3461. 
3462.     /* potentially give post zap/break feedback */
3463.     zapwrapup();
3464. 
3465.     /* Note: if player fell thru, this call is a no-op.
3466.        Damage is handled in digactualhole in that case */
3467.     if (shop_damage)
3468.         pay_for_damage("dig into", FALSE);
3469. 
3470.     if (obj->otyp == WAN_LIGHT)
3471.         litroom(TRUE, obj); /* only needs to be done once */
3472. 
3473. discard_broken_wand:
3474.     obj = current_wand; /* [see dozap() and destroy_item()] */
3475.     current_wand = 0;
3476.     if (obj)
3477.         delobj(obj);
3478.     nomul(0);
3479.     return 1;
3480. }
3481. 
3482. STATIC_OVL void
3483. add_class(cl, class)
3484. char *cl;
3485. char class;
3486. {
3487.     char tmp[2];
3488. 
3489.     tmp[0] = class;
3490.     tmp[1] = '\0';
3491.     Strcat(cl, tmp);
3492. }
3493. 
3494. static const char tools[] = { TOOL_CLASS, WEAPON_CLASS, WAND_CLASS, 0 };
3495. 
3496. /* augment tools[] if various items are carried */
3497. STATIC_OVL void
3498. setapplyclasses(class_list)
3499. char class_list[];
3500. {
3501.     register struct obj *otmp;
3502.     int otyp;
3503.     boolean knowoil, knowtouchstone, addpotions, addstones, addfood;
3504. 
3505.     knowoil = objects[POT_OIL].oc_name_known;
3506.     knowtouchstone = objects[TOUCHSTONE].oc_name_known;
3507.     addpotions = addstones = addfood = FALSE;
3508.     for (otmp = invent; otmp; otmp = otmp->nobj) {
3509.         otyp = otmp->otyp;
3510.         if (otyp == POT_OIL
3511.             || (otmp->oclass == POTION_CLASS
3512.                 && (!otmp->dknown
3513.                     || (!knowoil && !objects[otyp].oc_name_known))))
3514.             addpotions = TRUE;
3515.         if (otyp == TOUCHSTONE
3516.             || (is_graystone(otmp)
3517.                 && (!otmp->dknown
3518.                     || (!knowtouchstone && !objects[otyp].oc_name_known))))
3519.             addstones = TRUE;
3520.         if (otyp == CREAM_PIE || otyp == EUCALYPTUS_LEAF)
3521.             addfood = TRUE;
3522.     }
3523. 
3524.     class_list[0] = '\0';
3525.     if (addpotions || addstones)
3526.         add_class(class_list, ALL_CLASSES);
3527.     Strcat(class_list, tools);
3528.     if (addpotions)
3529.         add_class(class_list, POTION_CLASS);
3530.     if (addstones)
3531.         add_class(class_list, GEM_CLASS);
3532.     if (addfood)
3533.         add_class(class_list, FOOD_CLASS);
3534. }
3535. 
3536. /* the 'a' command */
3537. int
3538. doapply()
3539. {
3540.     struct obj *obj;
3541.     register int res = 1;
3542.     char class_list[MAXOCLASSES + 2];
3543. 
3544.     if (check_capacity((char *) 0))
3545.         return 0;
3546. 
3547.     setapplyclasses(class_list); /* tools[] */
3548.     obj = getobj(class_list, "use or apply");
3549.     if (!obj)
3550.         return 0;
3551. 
3552.     if (!retouch_object(&obj, FALSE))
3553.         return 1; /* evading your grasp costs a turn; just be
3554.                      grateful that you don't drop it as well */
3555. 
3556.     if (obj->oclass == WAND_CLASS)
3557.         return do_break_wand(obj);
3558. 
3559.     switch (obj->otyp) {
3560.     case BLINDFOLD:
3561.     case LENSES:
3562.         if (obj == ublindf) {
3563.             if (!cursed(obj))
3564.                 Blindf_off(obj);
3565.         } else if (!ublindf) {
3566.             Blindf_on(obj);
3567.         } else {
3568.             You("are already %s.", ublindf->otyp == TOWEL
3569.                                        ? "covered by a towel"
3570.                                        : ublindf->otyp == BLINDFOLD
3571.                                              ? "wearing a blindfold"
3572.                                              : "wearing lenses");
3573.         }
3574.         break;
3575.     case CREAM_PIE:
3576.         res = use_cream_pie(obj);
3577.         break;
3578.     case BULLWHIP:
3579.         res = use_whip(obj);
3580.         break;
3581.     case GRAPPLING_HOOK:
3582.         res = use_grapple(obj);
3583.         break;
3584.     case LARGE_BOX:
3585.     case CHEST:
3586.     case ICE_BOX:
3587.     case SACK:
3588.     case BAG_OF_HOLDING:
3589.     case OILSKIN_SACK:
3590.         res = use_container(&obj, 1, FALSE);
3591.         break;
3592.     case BAG_OF_TRICKS:
3593.         (void) bagotricks(obj, FALSE, (int *) 0);
3594.         break;
3595.     case CAN_OF_GREASE:
3596.         use_grease(obj);
3597.         break;
3598.     case LOCK_PICK:
3599.     case CREDIT_CARD:
3600.     case SKELETON_KEY:
3601.         res = (pick_lock(obj) != 0);
3602.         break;
3603.     case PICK_AXE:
3604.     case DWARVISH_MATTOCK:
3605.         res = use_pick_axe(obj);
3606.         break;
3607.     case TINNING_KIT:
3608.         use_tinning_kit(obj);
3609.         break;
3610.     case LEASH:
3611.         res = use_leash(obj);
3612.         break;
3613.     case SADDLE:
3614.         res = use_saddle(obj);
3615.         break;
3616.     case MAGIC_WHISTLE:
3617.         use_magic_whistle(obj);
3618.         break;
3619.     case TIN_WHISTLE:
3620.         use_whistle(obj);
3621.         break;
3622.     case EUCALYPTUS_LEAF:
3623.         /* MRKR: Every Australian knows that a gum leaf makes an excellent
3624.          * whistle, especially if your pet is a tame kangaroo named Skippy.
3625.          */
3626.         if (obj->blessed) {
3627.             use_magic_whistle(obj);
3628.             /* sometimes the blessing will be worn off */
3629.             if (!rn2(49)) {
3630.                 if (!Blind) {
3631.                     pline("%s %s.", Yobjnam2(obj, "glow"), hcolor("brown"));
3632.                     obj->bknown = 1;
3633.                 }
3634.                 unbless(obj);
3635.             }
3636.         } else {
3637.             use_whistle(obj);
3638.         }
3639.         break;
3640.     case STETHOSCOPE:
3641.         res = use_stethoscope(obj);
3642.         break;
3643.     case MIRROR:
3644.         res = use_mirror(obj);
3645.         break;
3646.     case BELL:
3647.     case BELL_OF_OPENING:
3648.         use_bell(&obj);
3649.         break;
3650.     case CANDELABRUM_OF_INVOCATION:
3651.         use_candelabrum(obj);
3652.         break;
3653.     case WAX_CANDLE:
3654.     case TALLOW_CANDLE:
3655.         use_candle(&obj);
3656.         break;
3657.     case OIL_LAMP:
3658.     case MAGIC_LAMP:
3659.     case BRASS_LANTERN:
3660.         use_lamp(obj);
3661.         break;
3662.     case POT_OIL:
3663.         light_cocktail(&obj);
3664.         break;
3665.     case EXPENSIVE_CAMERA:
3666.         res = use_camera(obj);
3667.         break;
3668.     case TOWEL:
3669.         res = use_towel(obj);
3670.         break;
3671.     case CRYSTAL_BALL:
3672.         use_crystal_ball(&obj);
3673.         break;
3674.     case MAGIC_MARKER:
3675.         res = dowrite(obj);
3676.         break;
3677.     case TIN_OPENER:
3678.         res = use_tin_opener(obj);
3679.         break;
3680.     case FIGURINE:
3681.         use_figurine(&obj);
3682.         break;
3683.     case UNICORN_HORN:
3684.         use_unicorn_horn(obj);
3685.         break;
3686.     case WOODEN_FLUTE:
3687.     case MAGIC_FLUTE:
3688.     case TOOLED_HORN:
3689.     case FROST_HORN:
3690.     case FIRE_HORN:
3691.     case WOODEN_HARP:
3692.     case MAGIC_HARP:
3693.     case BUGLE:
3694.     case LEATHER_DRUM:
3695.     case DRUM_OF_EARTHQUAKE:
3696.         res = do_play_instrument(obj);
3697.         break;
3698.     case HORN_OF_PLENTY: /* not a musical instrument */
3699.         (void) hornoplenty(obj, FALSE);
3700.         break;
3701.     case LAND_MINE:
3702.     case BEARTRAP:
3703.         use_trap(obj);
3704.         break;
3705.     case FLINT:
3706.     case LUCKSTONE:
3707.     case LOADSTONE:
3708.     case TOUCHSTONE:
3709.         use_stone(obj);
3710.         break;
3711.     default:
3712.         /* Pole-weapons can strike at a distance */
3713.         if (is_pole(obj)) {
3714.             res = use_pole(obj);
3715.             break;
3716.         } else if (is_pick(obj) || is_axe(obj)) {
3717.             res = use_pick_axe(obj);
3718.             break;
3719.         }
3720.         pline("Sorry, I don't know how to use that.");
3721.         nomul(0);
3722.         return 0;
3723.     }
3724.     if (res && obj && obj->oartifact)
3725.         arti_speak(obj);
3726.     nomul(0);
3727.     return res;
3728. }
3729. 
3730. /* Keep track of unfixable troubles for purposes of messages saying you feel
3731.  * great.
3732.  */
3733. int
3734. unfixable_trouble_count(is_horn)
3735. boolean is_horn;
3736. {
3737.     int unfixable_trbl = 0;
3738. 
3739.     if (Stoned)
3740.         unfixable_trbl++;
3741.     if (Strangled)
3742.         unfixable_trbl++;
3743.     if (Wounded_legs && !u.usteed)
3744.         unfixable_trbl++;
3745.     if (Slimed)
3746.         unfixable_trbl++;
3747.     /* lycanthropy is undesirable, but it doesn't actually make you feel bad */
3748. 
3749.     if (!is_horn || (Confusion & ~TIMEOUT))
3750.         unfixable_trbl++;
3751.     if (!is_horn || (Sick & ~TIMEOUT))
3752.         unfixable_trbl++;
3753.     if (!is_horn || (HHallucination & ~TIMEOUT))
3754.         unfixable_trbl++;
3755.     if (!is_horn || (Vomiting & ~TIMEOUT))
3756.         unfixable_trbl++;
3757.     if (!is_horn || (HStun & ~TIMEOUT))
3758.         unfixable_trbl++;
3759.     if (!is_horn || (HDeaf & ~TIMEOUT))
3760.         unfixable_trbl++;
3761. 
3762.     return unfixable_trbl;
3763. }
3764. 
3765. /*apply.c*/