Source:NetHack 5.0.0/src/lock.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to lock.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/lock.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 5.0	lock.c	$NHDT-Date: 1741793439 2025/03/12 07:30:39 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.145 $ */
2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3. /*-Copyright (c) Robert Patrick Rankin, 2011. */
4. /* NetHack may be freely redistributed.  See license for details. */
5. 
6. #include "hack.h"
7. 
8. /* occupation callbacks */
9. staticfn int picklock(void);
10. staticfn int forcelock(void);
11. 
12. staticfn const char *lock_action(void);
13. staticfn boolean obstructed(coordxy, coordxy, boolean);
14. staticfn void chest_shatter_msg(struct obj *);
15. 
16. boolean
17. picking_lock(coordxy *x, coordxy *y)
18. {
19.     if (go.occupation == picklock) {
20.         *x = u.ux + u.dx;
21.         *y = u.uy + u.dy;
22.         return TRUE;
23.     } else {
24.         *x = *y = 0;
25.         return FALSE;
26.     }
27. }
28. 
29. boolean
30. picking_at(coordxy x, coordxy y)
31. {
32.     return (boolean) (go.occupation == picklock
33.                       && gx.xlock.door == &levl[x][y]);
34. }
35. 
36. /* produce an occupation string appropriate for the current activity */
37. staticfn const char *
38. lock_action(void)
39. {
40.     /* "unlocking"+2 == "locking" */
41.     static const char *const actions[] = {
42.         "unlocking the door",   /* [0] */
43.         "unlocking the chest",  /* [1] */
44.         "unlocking the box",    /* [2] */
45.         "picking the lock"      /* [3] */
46.     };
47. 
48.     /* if the target is currently unlocked, we're trying to lock it now */
49.     if (gx.xlock.door && !(gx.xlock.door->doormask & D_LOCKED))
50.         return actions[0] + 2; /* "locking the door" */
51.     else if (gx.xlock.box && !gx.xlock.box->olocked)
52.         return gx.xlock.box->otyp == CHEST ? actions[1] + 2 : actions[2] + 2;
53.     /* otherwise we're trying to unlock it */
54.     else if (gx.xlock.picktyp == LOCK_PICK)
55.         return actions[3]; /* "picking the lock" */
56.     else if (gx.xlock.picktyp == CREDIT_CARD)
57.         return actions[3]; /* same as lock_pick */
58.     else if (gx.xlock.door)
59.         return actions[0]; /* "unlocking the door" */
60.     else if (gx.xlock.box)
61.         return gx.xlock.box->otyp == CHEST ? actions[1] : actions[2];
62.     else
63.         return actions[3];
64. }
65. 
66. /* try to open/close a lock */
67. staticfn int
68. picklock(void)
69. {
70.     if (gx.xlock.box) {
71.         if (gx.xlock.box->where != OBJ_FLOOR
72.             || gx.xlock.box->ox != u.ux || gx.xlock.box->oy != u.uy) {
73.             return ((gx.xlock.usedtime = 0)); /* you or it moved */
74.         }
75.     } else { /* door */
76.         if (gx.xlock.door != &(levl[u.ux + u.dx][u.uy + u.dy])) {
77.             return ((gx.xlock.usedtime = 0)); /* you moved */
78.         }
79.         switch (gx.xlock.door->doormask) {
80.         case D_NODOOR:
81.             pline("This doorway has no door.");
82.             return ((gx.xlock.usedtime = 0));
83.         case D_ISOPEN:
84.             You("cannot lock an open door.");
85.             return ((gx.xlock.usedtime = 0));
86.         case D_BROKEN:
87.             pline("This door is broken.");
88.             return ((gx.xlock.usedtime = 0));
89.         }
90.     }
91. 
92.     if (gx.xlock.usedtime++ >= 50 || nohands(gy.youmonst.data)) {
93.         You("give up your attempt at %s.", lock_action());
94.         exercise(A_DEX, TRUE); /* even if you don't succeed */
95.         return ((gx.xlock.usedtime = 0));
96.     }
97. 
98.     if (rn2(100) >= gx.xlock.chance)
99.         return 1; /* still busy */
100. 
101.     /* using the Master Key of Thievery finds traps if its bless/curse
102.        state is adequate (non-cursed for rogues, blessed for others;
103.        checked when setting up 'xlock') */
104.     if ((!gx.xlock.door ? (int) gx.xlock.box->otrapped
105.                        : (gx.xlock.door->doormask & D_TRAPPED) != 0)
106.         && gx.xlock.magic_key) {
107.         gx.xlock.chance += 20; /* less effort needed next time */
108.         if (!gx.xlock.door) {
109.             if (!gx.xlock.box->tknown)
110.                 You("find a trap!");
111.             gx.xlock.box->tknown = 1;
112.         }
113.         if (y_n("Do you want to try to disarm it?") == 'y') {
114.             const char *what;
115.             boolean alreadyunlocked;
116. 
117.             /* disarming while using magic key always succeeds */
118.             if (gx.xlock.door) {
119.                 gx.xlock.door->doormask &= ~D_TRAPPED;
120.                 what = "door";
121.                 alreadyunlocked = !(gx.xlock.door->doormask & D_LOCKED);
122.             } else {
123.                 gx.xlock.box->otrapped = 0;
124.                 gx.xlock.box->tknown = 0;
125.                 what = (gx.xlock.box->otyp == CHEST) ? "chest" : "box";
126.                 alreadyunlocked = !gx.xlock.box->olocked;
127.             }
128.             You("succeed in disarming the trap.  The %s is still %slocked.",
129.                 what, alreadyunlocked ? "un" : "");
130.             exercise(A_WIS, TRUE);
131.         } else {
132.             You("stop %s.", lock_action());
133.             exercise(A_WIS, FALSE);
134.         }
135.         return ((gx.xlock.usedtime = 0));
136.     }
137. 
138.     You("succeed in %s.", lock_action());
139.     if (gx.xlock.door) {
140.         if (gx.xlock.door->doormask & D_TRAPPED) {
141.             b_trapped("door", FINGER);
142.             gx.xlock.door->doormask = D_NODOOR;
143.             unblock_point(u.ux + u.dx, u.uy + u.dy);
144.             if (*in_rooms(u.ux + u.dx, u.uy + u.dy, SHOPBASE))
145.                 add_damage(u.ux + u.dx, u.uy + u.dy, SHOP_DOOR_COST);
146.             newsym(u.ux + u.dx, u.uy + u.dy);
147.         } else if (gx.xlock.door->doormask & D_LOCKED)
148.             gx.xlock.door->doormask = D_CLOSED;
149.         else
150.             gx.xlock.door->doormask = D_LOCKED;
151.     } else {
152.         gx.xlock.box->olocked = !gx.xlock.box->olocked;
153.         gx.xlock.box->lknown = 1;
154.         if (gx.xlock.box->otrapped)
155.             (void) chest_trap(gx.xlock.box, FINGER, FALSE);
156.     }
157.     exercise(A_DEX, TRUE);
158.     return ((gx.xlock.usedtime = 0));
159. }
160. 
161. void
162. breakchestlock(struct obj *box, boolean destroyit)
163. {
164.     if (!destroyit) { /* bill for the box but not for its contents */
165.         struct obj *hide_contents = box->cobj;
166. 
167.         box->cobj = 0;
168.         costly_alteration(box, COST_BRKLCK);
169.         box->cobj = hide_contents;
170.         box->olocked = 0;
171.         box->obroken = 1;
172.         box->lknown = 1;
173.     } else { /* #force has destroyed this box (at <u.ux,u.uy>) */
174.         struct obj *otmp;
175.         struct monst *shkp = (*u.ushops && costly_spot(u.ux, u.uy))
176.                                  ? shop_keeper(*u.ushops)
177.                                  : 0;
178.         boolean costly = (boolean) (shkp != 0),
179.                 peaceful_shk = costly && (boolean) shkp->mpeaceful;
180.         long loss = 0L;
181. 
182.         pline("In fact, you've totally destroyed %s.", the(xname(box)));
183.         /* Put the contents on ground at the hero's feet. */
184.         while ((otmp = box->cobj) != 0) {
185.             obj_extract_self(otmp);
186.             if (!rn2(3) || otmp->oclass == POTION_CLASS) {
187.                 chest_shatter_msg(otmp);
188.                 if (costly)
189.                     loss += stolen_value(otmp, u.ux, u.uy, peaceful_shk,
190.                                          TRUE);
191.                 if (otmp->quan == 1L) {
192.                     obfree(otmp, (struct obj *) 0);
193.                     continue;
194.                 }
195.                 /* this works because we're sure to have at least 1 left;
196.                    otherwise it would fail since otmp is not in inventory */
197.                 useup(otmp);
198.             }
199.             if (box->otyp == ICE_BOX && otmp->otyp == CORPSE) {
200.                 otmp->age = svm.moves - otmp->age; /* actual age */
201.                 start_corpse_timeout(otmp);
202.             }
203.             place_object(otmp, u.ux, u.uy);
204.             stackobj(otmp);
205.         }
206.         if (costly)
207.             loss += stolen_value(box, u.ux, u.uy, peaceful_shk, TRUE);
208.         if (loss)
209.             You("owe %ld %s for objects destroyed.", loss, currency(loss));
210.         delobj(box);
211.     }
212. }
213. 
214. /* try to force a locked chest */
215. staticfn int
216. forcelock(void)
217. {
218.     if ((gx.xlock.box->ox != u.ux) || (gx.xlock.box->oy != u.uy))
219.         return ((gx.xlock.usedtime = 0)); /* you or it moved */
220. 
221.     if (gx.xlock.usedtime++ >= 50 || !uwep || nohands(gy.youmonst.data)) {
222.         You("give up your attempt to force the lock.");
223.         if (gx.xlock.usedtime >= 50) /* you made the effort */
224.             exercise((gx.xlock.picktyp) ? A_DEX : A_STR, TRUE);
225.         return ((gx.xlock.usedtime = 0));
226.     }
227. 
228.     if (gx.xlock.picktyp) { /* blade */
229.         if (rn2(1000 - (int) uwep->spe) > (992 - greatest_erosion(uwep) * 10)
230.             && !uwep->cursed && !obj_resists(uwep, 0, 99)) {
231.             /* for a +0 weapon, probability that it survives an unsuccessful
232.              * attempt to force the lock is (.992)^50 = .67
233.              */
234.             pline("%sour %s broke!", (uwep->quan > 1L) ? "One of y" : "Y",
235.                   xname(uwep));
236.             useup(uwep);
237.             You("give up your attempt to force the lock.");
238.             exercise(A_DEX, TRUE);
239.             return ((gx.xlock.usedtime = 0));
240.         }
241.     } else             /* blunt */
242.         wake_nearby(FALSE); /* due to hammering on the container */
243. 
244.     if (rn2(100) >= gx.xlock.chance)
245.         return 1; /* still busy */
246. 
247.     You("succeed in forcing the lock.");
248.     exercise(gx.xlock.picktyp ? A_DEX : A_STR, TRUE);
249.     /* breakchestlock() might destroy xlock.box; if so, xlock context will
250.        be cleared (delobj -> obfree -> maybe_reset_pick); but it might not,
251.        so explicitly clear that manually */
252.     breakchestlock(gx.xlock.box, (boolean) (!gx.xlock.picktyp && !rn2(3)));
253.     reset_pick(); /* lock-picking context is no longer valid */
254. 
255.     return 0;
256. }
257. 
258. void
259. reset_pick(void)
260. {
261.     gx.xlock.usedtime = gx.xlock.chance = gx.xlock.picktyp = 0;
262.     gx.xlock.magic_key = FALSE;
263.     gx.xlock.door = (struct rm *) 0;
264.     gx.xlock.box = (struct obj *) 0;
265. }
266. 
267. /* level change or object deletion; context may no longer be valid */
268. void
269. maybe_reset_pick(struct obj *container) /* passed from obfree() */
270. {
271.     /*
272.      * If a specific container, only clear context if it is for that
273.      * particular container (which is being deleted).  Other stuff on
274.      * the current dungeon level remains valid.
275.      * However if 'container' is Null, clear context if not carrying
276.      * gx.xlock.box (which might be Null if context is for a door).
277.      * Used for changing levels, where a floor container or a door is
278.      * being left behind and won't be valid on the new level but a
279.      * carried container will still be.  There might not be any context,
280.      * in which case redundantly clearing it is harmless.
281.      */
282.     if (container ? (container == gx.xlock.box)
283.                   : (!gx.xlock.box || !carried(gx.xlock.box)))
284.         reset_pick();
285. }
286. 
287. /* pick a tool for autounlock */
288. struct obj *
289. autokey(boolean opening) /* True: key, pick, or card; False: key or pick */
290. {
291.     struct obj *o, *key, *pick, *card, *akey, *apick, *acard;
292. 
293.     /* mundane item or regular artifact or own role's quest artifact */
294.     key = pick = card = (struct obj *) 0;
295.     /* other role's quest artifact (Rogue's Key or Tourist's Credit Card) */
296.     akey = apick = acard = (struct obj *) 0;
297.     for (o = gi.invent; o; o = o->nobj) {
298.         if (any_quest_artifact(o) && !is_quest_artifact(o)) {
299.             switch (o->otyp) {
300.             case SKELETON_KEY:
301.                 if (!akey)
302.                     akey = o;
303.                 break;
304.             case LOCK_PICK:
305.                 if (!apick)
306.                     apick = o;
307.                 break;
308.             case CREDIT_CARD:
309.                 if (!acard)
310.                     acard = o;
311.                 break;
312.             default:
313.                 break;
314.             }
315.         } else {
316.             switch (o->otyp) {
317.             case SKELETON_KEY:
318.                 if (!key || is_magic_key(&gy.youmonst, o))
319.                     key = o;
320.                 break;
321.             case LOCK_PICK:
322.                 if (!pick)
323.                     pick = o;
324.                 break;
325.             case CREDIT_CARD:
326.                 if (!card)
327.                     card = o;
328.                 break;
329.             default:
330.                 break;
331.             }
332.         }
333.     }
334.     if (!opening)
335.         card = acard = 0;
336.     /* only resort to other role's quest artifact if no other choice */
337.     if (!key && !pick && !card)
338.         key = akey;
339.     if (!pick && !card)
340.         pick = apick;
341.     if (!card)
342.         card = acard;
343.     return key ? key : pick ? pick : card ? card : 0;
344. }
345. 
346. DISABLE_WARNING_FORMAT_NONLITERAL
347. 
348. /* for doapply(); if player gives a direction or resumes an interrupted
349.    previous attempt then it usually costs hero a move even if nothing
350.    ultimately happens; when told "can't do that" before being asked for
351.    direction or player cancels with ESC while giving direction, it doesn't */
352. #define PICKLOCK_LEARNED_SOMETHING (-1) /* time passes */
353. #define PICKLOCK_DID_NOTHING 0          /* no time passes */
354. #define PICKLOCK_DID_SOMETHING 1
355. 
356. /* player is applying a key, lock pick, or credit card */
357. int
358. pick_lock(
359.     struct obj *pick,
360.     coordxy rx, coordxy ry, /* coordinates of door/container, for autounlock:
361.                              * doesn't prompt for direction if these are set */
362.     struct obj *container)  /* container, for autounlock */
363. {
364.     struct obj dummypick;
365.     int picktyp, c, ch;
366.     coord cc;
367.     struct rm *door;
368.     struct obj *otmp;
369.     char qbuf[QBUFSZ];
370.     boolean autounlock = (rx != 0 || container != NULL);
371. 
372.     /* 'pick' might be Null [called by do_loot_cont() for AUTOUNLOCK_UNTRAP] */
373.     if (!pick) {
374.         dummypick = cg.zeroobj;
375.         pick = &dummypick; /* pick->otyp will be STRANGE_OBJECT */
376.     }
377.     picktyp = pick->otyp;
378. 
379.     /* check whether we're resuming an interrupted previous attempt */
380.     if (gx.xlock.usedtime && picktyp == gx.xlock.picktyp) {
381.         static char no_longer[] = "Unfortunately, you can no longer %s %s.";
382. 
383.         if (nohands(gy.youmonst.data)) {
384.             const char *what = (picktyp == LOCK_PICK) ? "pick" : "key";
385. 
386.             if (picktyp == CREDIT_CARD)
387.                 what = "card";
388.             pline(no_longer, "hold the", what);
389.             reset_pick();
390.             return PICKLOCK_LEARNED_SOMETHING;
391.         } else if (u.uswallow || (gx.xlock.box && !can_reach_floor(TRUE))) {
392.             pline(no_longer, "reach the", "lock");
393.             reset_pick();
394.             return PICKLOCK_LEARNED_SOMETHING;
395.         } else {
396.             const char *action = lock_action();
397. 
398.             You("resume your attempt at %s.", action);
399.             gx.xlock.magic_key = is_magic_key(&gy.youmonst, pick);
400.             set_occupation(picklock, action, 0);
401.             return PICKLOCK_DID_SOMETHING;
402.         }
403.     }
404. 
405.     if (nohands(gy.youmonst.data)) {
406.         You_cant("hold %s -- you have no hands!", doname(pick));
407.         return PICKLOCK_DID_NOTHING;
408.     } else if (u.uswallow) {
409.         You_cant("%sunlock %s.", (picktyp == CREDIT_CARD) ? "" : "lock or ",
410.                  mon_nam(u.ustuck));
411.         return PICKLOCK_DID_NOTHING;
412.     }
413. 
414.     if (pick != &dummypick && picktyp != SKELETON_KEY
415.         && picktyp != LOCK_PICK && picktyp != CREDIT_CARD) {
416.         impossible("picking lock with object %d?", picktyp);
417.         return PICKLOCK_DID_NOTHING;
418.     }
419.     ch = 0; /* lint suppression */
420. 
421.     if (rx != 0) { /* autounlock; caller has provided coordinates */
422.         cc.x = rx;
423.         cc.y = ry;
424.     } else if (!get_adjacent_loc((char *) 0, "Invalid location!",
425.                                  u.ux, u.uy, &cc)) {
426.         return PICKLOCK_DID_NOTHING;
427.     }
428. 
429.     if (u_at(cc.x, cc.y)) { /* pick lock on a container */
430.         const char *verb;
431.         char qsfx[QBUFSZ];
432.         boolean it;
433.         int count;
434. 
435.         if (u.dz < 0 && !autounlock) { /* beware stale u.dz value */
436.             There("isn't any sort of lock up %s.",
437.                   Levitation ? "here" : "there");
438.             return PICKLOCK_LEARNED_SOMETHING;
439.         } else if (is_lava(u.ux, u.uy)) {
440.             pline("Doing that would probably melt %s.", yname(pick));
441.             return PICKLOCK_LEARNED_SOMETHING;
442.         } else if (is_pool(u.ux, u.uy) && !Underwater) {
443.             pline_The("%s has no lock.", hliquid("water"));
444.             return PICKLOCK_LEARNED_SOMETHING;
445.         }
446. 
447.         count = 0;
448.         c = 'n'; /* in case there are no boxes here */
449.         for (otmp = svl.level.objects[cc.x][cc.y]; otmp;
450.              otmp = otmp->nexthere) {
451.             /* autounlock on boxes: only the one that was just discovered to
452.                be locked; don't include any other boxes which might be here */
453.             if (autounlock && otmp != container)
454.                 continue;
455.             if (Is_box(otmp)) {
456.                 ++count;
457.                 if (!can_reach_floor(TRUE)) {
458.                     You_cant("reach %s from up here.", the(xname(otmp)));
459.                     return PICKLOCK_LEARNED_SOMETHING;
460.                 }
461.                 it = 0;
462.                 if (otmp->obroken)
463.                     verb = "fix";
464.                 else if (!otmp->olocked)
465.                     verb = "lock", it = 1;
466.                 else if (picktyp != LOCK_PICK)
467.                     verb = "unlock", it = 1;
468.                 else
469.                     verb = "pick";
470. 
471.                 if (autounlock && (flags.autounlock & AUTOUNLOCK_UNTRAP) != 0
472.                     && could_untrap(FALSE, TRUE)
473.                     && (c = otmp->tknown ? (otmp->otrapped ? 'y' : 'n')
474.                             : ynq(safe_qbuf(qbuf, "Check ", " for a trap?",
475.                                           otmp, yname, ysimple_name, "this")))
476.                        != 'n') {
477.                     if (c == 'q')
478.                         return PICKLOCK_DID_NOTHING; /* c == 'q' */
479.                     /* c == 'y' */
480.                     untrap(FALSE, 0, 0, otmp);
481.                     return PICKLOCK_DID_SOMETHING; /* even if no trap found */
482.                 } else if (autounlock
483.                           && (flags.autounlock & AUTOUNLOCK_APPLY_KEY) != 0) {
484.                     c = 'q';
485.                     if (pick != &dummypick) {
486.                         Sprintf(qbuf, "Unlock it with %s?", yname(pick));
487.                         c = ynq(qbuf);
488.                     }
489.                     if (c != 'y')
490.                         return PICKLOCK_DID_NOTHING;
491.                 } else {
492.                     /* "There is <a box> here; <verb> <it|its lock>?" */
493.                     Sprintf(qsfx, " here; %s %s?",
494.                             verb, it ? "it" : "its lock");
495.                     (void) safe_qbuf(qbuf, "There is ", qsfx, otmp, doname,
496.                                      ansimpleoname, "a box");
497.                     otmp->lknown = 1;
498. 
499.                     c = ynq(qbuf);
500.                     if (c == 'q')
501.                         return PICKLOCK_DID_NOTHING;
502.                     if (c == 'n')
503.                         continue; /* try next box */
504.                 }
505. 
506.                 if (otmp->obroken) {
507.                     You_cant("fix its broken lock with %s.",
508.                              ansimpleoname(pick));
509.                     return PICKLOCK_LEARNED_SOMETHING;
510.                 } else if (picktyp == CREDIT_CARD && !otmp->olocked) {
511.                     /* credit cards are only good for unlocking */
512.                     You_cant("do that with %s.",
513.                              an(simple_typename(picktyp)));
514.                     return PICKLOCK_LEARNED_SOMETHING;
515.                 } else if (autounlock
516.                            && !touch_artifact(pick, &gy.youmonst)) {
517.                     /* note: for !autounlock, apply already did touch check */
518.                     return PICKLOCK_DID_SOMETHING;
519.                 }
520.                 switch (picktyp) {
521.                 case CREDIT_CARD:
522.                     ch = ACURR(A_DEX) + 20 * Role_if(PM_ROGUE);
523.                     break;
524.                 case LOCK_PICK:
525.                     ch = 4 * ACURR(A_DEX) + 25 * Role_if(PM_ROGUE);
526.                     break;
527.                 case SKELETON_KEY:
528.                     ch = 75 + ACURR(A_DEX);
529.                     break;
530.                 default:
531.                     ch = 0;
532.                 }
533.                 if (otmp->cursed)
534.                     ch /= 2;
535. 
536.                 gx.xlock.box = otmp;
537.                 gx.xlock.door = 0;
538.                 break;
539.             }
540.         }
541.         if (c != 'y') {
542.             if (!count)
543.                 There("doesn't seem to be any sort of lock here.");
544.             return PICKLOCK_LEARNED_SOMETHING; /* decided against all boxes */
545.         }
546. 
547.     /* not the hero's location; pick the lock in an adjacent door */
548.     } else {
549.         struct monst *mtmp;
550. 
551.         if (u.utrap && u.utraptype == TT_PIT) {
552.             You_cant("reach over the edge of the pit.");
553.             /* this used to return PICKLOCK_LEARNED_SOMETHING but the
554.                #open command doesn't use a turn for similar situation */
555.             return PICKLOCK_DID_NOTHING;
556.         }
557. 
558.         door = &levl[cc.x][cc.y];
559.         mtmp = m_at(cc.x, cc.y);
560.         if (mtmp && canseemon(mtmp) && M_AP_TYPE(mtmp) != M_AP_FURNITURE
561.             && M_AP_TYPE(mtmp) != M_AP_OBJECT) {
562.             if (picktyp == CREDIT_CARD
563.                 && (mtmp->isshk || mtmp->data == &mons[PM_ORACLE])) {
564.                 SetVoice(mtmp, 0, 80, 0);
565.                 verbalize("No checks, no credit, no problem.");
566.             } else {
567.                 pline("I don't think %s would appreciate that.",
568.                       mon_nam(mtmp));
569.             }
570.             return PICKLOCK_LEARNED_SOMETHING;
571.         } else if (mtmp && is_door_mappear(mtmp)) {
572.             /* "The door actually was a <mimic>!" */
573.             stumble_onto_mimic(mtmp);
574.             /* mimic might keep the key (50% chance, 10% for PYEC or MKoT) */
575.             maybe_absorb_item(mtmp, pick, 50, 10);
576.             return PICKLOCK_LEARNED_SOMETHING;
577.         }
578.         if (!IS_DOOR(door->typ)) {
579.             int res = PICKLOCK_DID_NOTHING, oldglyph = door->glyph;
580.             schar oldlastseentyp = update_mapseen_for(cc.x, cc.y);
581. 
582.             /* this is probably only relevant when blind */
583.             feel_location(cc.x, cc.y);
584.             if (door->glyph != oldglyph
585.                 || svl.lastseentyp[cc.x][cc.y] != oldlastseentyp)
586.                 res = PICKLOCK_LEARNED_SOMETHING;
587. 
588.             if (is_drawbridge_wall(cc.x, cc.y) >= 0)
589.                 You("%s no lock on the drawbridge.", Blind ? "feel" : "see");
590.             else
591.                 You("%s no door there.", Blind ? "feel" : "see");
592.             return res;
593.         }
594.         switch (door->doormask) {
595.         case D_NODOOR:
596.             pline("This doorway has no door.");
597.             return PICKLOCK_LEARNED_SOMETHING;
598.         case D_ISOPEN:
599.             You("cannot lock an open door.");
600.             return PICKLOCK_LEARNED_SOMETHING;
601.         case D_BROKEN:
602.             pline("This door is broken.");
603.             return PICKLOCK_LEARNED_SOMETHING;
604.         default:
605.             if ((flags.autounlock & AUTOUNLOCK_UNTRAP) != 0
606.                 && could_untrap(FALSE, FALSE)
607.                 && (c = ynq("Check this door for a trap?")) != 'n') {
608.                 if (c == 'q')
609.                     return PICKLOCK_DID_NOTHING;
610.                 /* c == 'y' */
611.                 untrap(FALSE, cc.x, cc.y, (struct obj *) 0);
612.                 return PICKLOCK_DID_SOMETHING; /* even if no trap found */
613.             }
614.             /* credit cards are only good for unlocking */
615.             if (picktyp == CREDIT_CARD && !(door->doormask & D_LOCKED)) {
616.                 You_cant("lock a door with a credit card.");
617.                 return PICKLOCK_LEARNED_SOMETHING;
618.             }
619. 
620.             Sprintf(qbuf, "%s it%s%s?",
621.                     (door->doormask & D_LOCKED) ? "Unlock" : "Lock",
622.                     autounlock ? " with " : "",
623.                     autounlock ? yname(pick) : "");
624.             c = ynq(qbuf);
625.             if (c != 'y')
626.                 return PICKLOCK_DID_NOTHING;
627. 
628.             /* note: for !autounlock, 'apply' already did touch check */
629.             if (autounlock && !touch_artifact(pick, &gy.youmonst))
630.                 return PICKLOCK_DID_SOMETHING;
631. 
632.             switch (picktyp) {
633.             case CREDIT_CARD:
634.                 ch = 2 * ACURR(A_DEX) + 20 * Role_if(PM_ROGUE);
635.                 break;
636.             case LOCK_PICK:
637.                 ch = 3 * ACURR(A_DEX) + 30 * Role_if(PM_ROGUE);
638.                 break;
639.             case SKELETON_KEY:
640.                 ch = 70 + ACURR(A_DEX);
641.                 break;
642.             default:
643.                 ch = 0;
644.             }
645.             gx.xlock.door = door;
646.             gx.xlock.box = 0;
647.         }
648.     }
649.     svc.context.move = 0;
650.     gx.xlock.chance = ch;
651.     gx.xlock.picktyp = picktyp;
652.     gx.xlock.magic_key = is_magic_key(&gy.youmonst, pick);
653.     gx.xlock.usedtime = 0;
654.     set_occupation(picklock, lock_action(), 0);
655.     return PICKLOCK_DID_SOMETHING;
656. }
657. 
658. /* is hero wielding a weapon that can #force? */
659. boolean
660. u_have_forceable_weapon(void)
661. {
662.     if (!uwep /* proper type test */
663.         || ((uwep->oclass == WEAPON_CLASS || is_weptool(uwep))
664.             ? (objects[uwep->otyp].oc_skill < P_DAGGER
665.                || objects[uwep->otyp].oc_skill == P_FLAIL
666.                || objects[uwep->otyp].oc_skill > P_LANCE)
667.             : uwep->oclass != ROCK_CLASS))
668.         return FALSE;
669.     return TRUE;
670. }
671. 
672. RESTORE_WARNING_FORMAT_NONLITERAL
673. 
674. /* the #force command - try to force a chest with your weapon */
675. int
676. doforce(void)
677. {
678.     struct obj *otmp;
679.     int c, picktyp;
680.     char qbuf[QBUFSZ];
681. 
682.     /*
683.      * TODO?
684.      *  allow force with edged weapon to be performed on doors.
685.      */
686. 
687.     if (u.uswallow) {
688.         You_cant("force anything from inside here.");
689.         return ECMD_OK;
690.     }
691.     if (!u_have_forceable_weapon()) {
692.         boolean use_plural = uwep && uwep->quan > 1;
693. 
694.         You_cant("force anything %s weapon%s.",
695.                  !uwep ? "when not wielding a"
696.                  : (uwep->oclass != WEAPON_CLASS && !is_weptool(uwep))
697.                    ? (use_plural ? "without proper" : "without a proper")
698.                    : (use_plural ? "with those" : "with that"),
699.                  use_plural ? "s" : "");
700.         return ECMD_OK;
701.     }
702.     if (!can_reach_floor(TRUE)) {
703.         cant_reach_floor(u.ux, u.uy, FALSE, TRUE, FALSE);
704.         return ECMD_OK;
705.     }
706. 
707.     picktyp = is_blade(uwep) && !is_pick(uwep);
708.     if (gx.xlock.usedtime && gx.xlock.box && picktyp == gx.xlock.picktyp) {
709.         You("resume your attempt to force the lock.");
710.         set_occupation(forcelock, "forcing the lock", 0);
711.         return ECMD_TIME;
712.     }
713. 
714.     /* A lock is made only for the honest man, the thief will break it. */
715.     gx.xlock.box = (struct obj *) 0;
716.     for (otmp = svl.level.objects[u.ux][u.uy]; otmp; otmp = otmp->nexthere)
717.         if (Is_box(otmp)) {
718.             if (otmp->obroken || !otmp->olocked) {
719.                 /* force doname() to omit known "broken" or "unlocked"
720.                    prefix so that the message isn't worded redundantly;
721.                    since we're about to set lknown, there's no need to
722.                    remember and then reset its current value */
723.                 otmp->lknown = 0;
724.                 There("is %s here, but its lock is already %s.",
725.                       doname(otmp), otmp->obroken ? "broken" : "unlocked");
726.                 otmp->lknown = 1;
727.                 continue;
728.             }
729.             (void) safe_qbuf(qbuf, "There is ", " here; force its lock?",
730.                              otmp, doname, ansimpleoname, "a box");
731.             otmp->lknown = 1;
732. 
733.             c = ynq(qbuf);
734.             if (c == 'q')
735.                 return ECMD_OK;
736.             if (c == 'n')
737.                 continue;
738. 
739.             if (picktyp)
740.                 You("force %s into a crack and pry.", yname(uwep));
741.             else
742.                 You("start bashing it with %s.", yname(uwep));
743.             gx.xlock.box = otmp;
744.             gx.xlock.chance = objects[uwep->otyp].oc_wldam * 2;
745.             gx.xlock.picktyp = picktyp;
746.             gx.xlock.magic_key = FALSE;
747.             gx.xlock.usedtime = 0;
748.             break;
749.         }
750. 
751.     if (gx.xlock.box)
752.         set_occupation(forcelock, "forcing the lock", 0);
753.     else
754.         You("decide not to force the issue.");
755.     return ECMD_TIME;
756. }
757. 
758. boolean
759. stumble_on_door_mimic(coordxy x, coordxy y)
760. {
761.     struct monst *mtmp;
762. 
763.     if ((mtmp = m_at(x, y)) && is_door_mappear(mtmp)
764.         && !Protection_from_shape_changers) {
765.         stumble_onto_mimic(mtmp);
766.         return TRUE;
767.     }
768.     return FALSE;
769. }
770. 
771. /* the #open command - try to open a door */
772. int
773. doopen(void)
774. {
775.     return doopen_indir(0, 0);
776. }
777. 
778. /* try to open a door in direction u.dx/u.dy */
779. int
780. doopen_indir(coordxy x, coordxy y)
781. {
782.     coord cc;
783.     struct rm *door;
784.     boolean portcullis;
785.     const char *dirprompt;
786.     int res = ECMD_OK;
787. 
788.     if (nohands(gy.youmonst.data)) {
789.         You_cant("open anything -- you have no hands!");
790.         return ECMD_OK;
791.     }
792. 
793.     dirprompt = NULL; /* have get_adjacent_loc() -> getdir() use default */
794.     if (u.utrap && u.utraptype == TT_PIT && container_at(u.ux, u.uy, FALSE))
795.         dirprompt = "Open where? [.>]";
796. 
797.     if (x > 0 && y >= 0) {
798.         /* nonzero <x,y> is used when hero in amorphous form tries to
799.            flow under a closed door at <x,y>; the test here was using
800.            'y > 0' but that would give incorrect results if doors are
801.            ever allowed to be placed on the top row of the map */
802.         cc.x = x;
803.         cc.y = y;
804.     } else if (!get_adjacent_loc(dirprompt, (char *) 0, u.ux, u.uy, &cc)) {
805.         return ECMD_OK;
806.     }
807. 
808.     /* open at yourself/up/down: switch to loot unless there is a closed
809.        door here (possible with Passes_walls) and direction isn't 'down' */
810.     if (u_at(cc.x, cc.y) && (u.dz > 0 || !closed_door(u.ux, u.uy)))
811.         return doloot();
812. 
813.     /* this used to be done prior to get_adjacent_loc() but doing so was
814.        incorrect once open at hero's spot became an alternate way to loot */
815.     if (u.utrap && u.utraptype == TT_PIT) {
816.         You_cant("reach over the edge of the pit.");
817.         return ECMD_OK;
818.     }
819. 
820.     if (stumble_on_door_mimic(cc.x, cc.y))
821.         return ECMD_TIME;
822. 
823.     /* when choosing a direction is impaired, use a turn
824.        regardless of whether a door is successfully targeted */
825.     if (Confusion || Stunned)
826.         res = ECMD_TIME;
827. 
828.     door = &levl[cc.x][cc.y];
829.     portcullis = (is_drawbridge_wall(cc.x, cc.y) >= 0);
830.     /* this used to be 'if (Blind)' but using a key skips that so we do too */
831.     {
832.         int oldglyph = door->glyph;
833.         schar oldlastseentyp = update_mapseen_for(cc.x, cc.y);
834. 
835.         newsym(cc.x, cc.y);
836.         if (door->glyph != oldglyph
837.             || svl.lastseentyp[cc.x][cc.y] != oldlastseentyp)
838.             res = ECMD_TIME; /* learned something */
839.     }
840. 
841.     if (portcullis || !IS_DOOR(door->typ)) {
842.         /* closed portcullis or spot that opened bridge would span */
843.         if (is_db_wall(cc.x, cc.y) || door->typ == DRAWBRIDGE_UP)
844.             There("is no obvious way to open the drawbridge.");
845.         else if (portcullis || door->typ == DRAWBRIDGE_DOWN)
846.             pline_The("drawbridge is already open.");
847.         else if (container_at(cc.x, cc.y, TRUE))
848.             pline("%s like something lootable over there.",
849.                   Blind ? "Feels" : "Seems");
850.         else
851.             You("%s no door there.", Blind ? "feel" : "see");
852.         return res;
853.     }
854. 
855.     if (!(door->doormask & D_CLOSED)) {
856.         const char *mesg;
857.         boolean locked = FALSE;
858. 
859.         switch (door->doormask) {
860.         case D_BROKEN:
861.             mesg = " is broken";
862.             break;
863.         case D_NODOOR:
864.             mesg = "way has no door";
865.             break;
866.         case D_ISOPEN:
867.             mesg = " is already open";
868.             break;
869.         default:
870.             mesg = " is locked";
871.             locked = TRUE;
872.             break;
873.         }
874.         set_msg_xy(cc.x, cc.y);
875.         pline("This door%s.", mesg);
876.         if (locked && flags.autounlock) {
877.             struct obj *unlocktool;
878. 
879.             u.dz = 0; /* should already be 0 since hero moved toward door */
880.             if ((flags.autounlock & AUTOUNLOCK_APPLY_KEY) != 0
881.                 && (unlocktool = autokey(TRUE)) != 0) {
882.                 res = pick_lock(unlocktool, cc.x, cc.y,
883.                                 (struct obj *) 0) ? ECMD_TIME : ECMD_OK;
884.             } else if ((flags.autounlock & AUTOUNLOCK_KICK) != 0
885.                        && !u.usteed /* kicking is different when mounted */
886.                        && ynq("Kick it?") == 'y') {
887.                 cmdq_add_ec(CQ_CANNED, dokick);
888.                 cmdq_add_dir(CQ_CANNED,
889.                              sgn(cc.x - u.ux), sgn(cc.y - u.uy), 0);
890.                 /* this was 'ECMD_TIME', but time shouldn't elapse until
891.                    the canned kick takes place */
892.                 res = ECMD_OK;
893.             }
894.         }
895.         return res;
896.     }
897. 
898.     if (verysmall(gy.youmonst.data)) {
899.         pline("You're too small to pull the door open.");
900.         return res;
901.     }
902. 
903.     /* door is known to be CLOSED */
904.     if (rnl(20) < (ACURRSTR + ACURR(A_DEX) + ACURR(A_CON)) / 3) {
905.         set_msg_xy(cc.x, cc.y);
906.         pline_The("door opens.");
907.         if (door->doormask & D_TRAPPED) {
908.             b_trapped("door", FINGER);
909.             door->doormask = D_NODOOR;
910.             if (*in_rooms(cc.x, cc.y, SHOPBASE))
911.                 add_damage(cc.x, cc.y, SHOP_DOOR_COST);
912.         } else
913.             door->doormask = D_ISOPEN;
914.         feel_newsym(cc.x, cc.y); /* the hero knows she opened it */
915.         recalc_block_point(cc.x, cc.y); /* vision: new see through there */
916.     } else {
917.         exercise(A_STR, TRUE);
918.         set_msg_xy(cc.x, cc.y);
919.         pline_The("door resists!");
920.     }
921. 
922.     return ECMD_TIME;
923. }
924. 
925. staticfn boolean
926. obstructed(coordxy x, coordxy y, boolean quietly)
927. {
928.     struct monst *mtmp = m_at(x, y);
929. 
930.     if (mtmp && M_AP_TYPE(mtmp) != M_AP_FURNITURE) {
931.         if (M_AP_TYPE(mtmp) == M_AP_OBJECT)
932.             goto objhere;
933.         if (!quietly) {
934.             char *Mn = Some_Monnam(mtmp); /* Monnam, Someone or Something */
935. 
936.             if ((mtmp->mx != x || mtmp->my != y) && canspotmon(mtmp))
937.                 /* s_suffix() returns a modifiable buffer */
938.                 Mn = strcat(s_suffix(Mn), " tail");
939. 
940.             pline("%s blocks the way!", Mn);
941.         }
942.         if (!canspotmon(mtmp))
943.             map_invisible(x, y);
944.         return TRUE;
945.     }
946.     if (OBJ_AT(x, y)) {
947.  objhere:
948.         if (!quietly)
949.             pline("%s's in the way.", Something);
950.         return TRUE;
951.     }
952.     return FALSE;
953. }
954. 
955. /* the #close command - try to close a door */
956. int
957. doclose(void)
958. {
959.     coordxy x, y;
960.     struct rm *door;
961.     boolean portcullis;
962.     int res = ECMD_OK;
963. 
964.     if (nohands(gy.youmonst.data)) {
965.         You_cant("close anything -- you have no hands!");
966.         return ECMD_OK;
967.     }
968. 
969.     if (u.utrap && u.utraptype == TT_PIT) {
970.         You_cant("reach over the edge of the pit.");
971.         return ECMD_OK;
972.     }
973. 
974.     if (!getdir((char *) 0))
975.         return ECMD_CANCEL;
976. 
977.     x = u.ux + u.dx;
978.     y = u.uy + u.dy;
979.     if (u_at(x, y) && !Passes_walls) {
980.         You("are in the way!");
981.         return ECMD_TIME;
982.     }
983. 
984.     if (!isok(x, y))
985.         goto nodoor;
986. 
987.     if (stumble_on_door_mimic(x, y))
988.         return ECMD_TIME;
989. 
990.     /* when choosing a direction is impaired, use a turn
991.        regardless of whether a door is successfully targeted */
992.     if (Confusion || Stunned)
993.         res = ECMD_TIME;
994. 
995.     door = &levl[x][y];
996.     portcullis = (is_drawbridge_wall(x, y) >= 0);
997.     if (Blind) {
998.         int oldglyph = door->glyph;
999.         schar oldlastseentyp = update_mapseen_for(x, y);
1000. 
1001.         feel_location(x, y);
1002.         if (door->glyph != oldglyph
1003.             || svl.lastseentyp[x][y] != oldlastseentyp)
1004.             res = ECMD_TIME; /* learned something */
1005.     }
1006. 
1007.     if (portcullis || !IS_DOOR(door->typ)) {
1008.         /* is_db_wall: closed portcullis */
1009.         if (is_db_wall(x, y) || door->typ == DRAWBRIDGE_UP)
1010.             pline_The("drawbridge is already closed.");
1011.         else if (portcullis || door->typ == DRAWBRIDGE_DOWN)
1012.             There("is no obvious way to close the drawbridge.");
1013.         else {
1014.  nodoor:
1015.             You("%s no door there.", Blind ? "feel" : "see");
1016.         }
1017.         return res;
1018.     }
1019. 
1020.     if (door->doormask == D_NODOOR) {
1021.         pline("This doorway has no door.");
1022.         return res;
1023.     } else if (obstructed(x, y, FALSE)) {
1024.         return res;
1025.     } else if (door->doormask == D_BROKEN) {
1026.         pline("This door is broken.");
1027.         return res;
1028.     } else if (door->doormask & (D_CLOSED | D_LOCKED)) {
1029.         pline("This door is already closed.");
1030.         return res;
1031.     }
1032. 
1033.     if (door->doormask == D_ISOPEN) {
1034.         if (verysmall(gy.youmonst.data) && !u.usteed) {
1035.             pline("You're too small to push the door closed.");
1036.             return res;
1037.         }
1038.         if (u.usteed
1039.             || rn2(25) < (ACURRSTR + ACURR(A_DEX) + ACURR(A_CON)) / 3) {
1040.             pline_The("door closes.");
1041.             door->doormask = D_CLOSED;
1042.             feel_newsym(x, y); /* the hero knows she closed it */
1043.             block_point(x, y); /* vision:  no longer see there */
1044.         } else {
1045.             exercise(A_STR, TRUE);
1046.             pline_The("door resists!");
1047.         }
1048.     }
1049. 
1050.     return ECMD_TIME;
1051. }
1052. 
1053. /* box obj was hit with spell or wand effect otmp;
1054.    returns true if something happened */
1055. boolean
1056. boxlock(struct obj *obj, struct obj *otmp) /* obj *is* a box */
1057. {
1058.     boolean res = 0;
1059. 
1060.     switch (otmp->otyp) {
1061.     case WAN_LOCKING:
1062.     case SPE_WIZARD_LOCK:
1063.         if (!obj->olocked) { /* lock it; fix if broken */
1064.             Soundeffect(se_klunk, 50);
1065.             pline("Klunk!");
1066.             obj->olocked = 1;
1067.             obj->obroken = 0;
1068.             if (Role_if(PM_WIZARD))
1069.                 obj->lknown = 1;
1070.             else
1071.                 obj->lknown = 0;
1072.             res = 1;
1073.         } /* else already closed and locked */
1074.         break;
1075.     case WAN_OPENING:
1076.     case SPE_KNOCK:
1077.         if (obj->olocked) { /* unlock; isn't broken so doesn't need fixing */
1078.             Soundeffect(se_klick, 50);
1079.             pline("Klick!");
1080.             obj->olocked = 0;
1081.             res = 1;
1082.             if (Role_if(PM_WIZARD))
1083.                 obj->lknown = 1;
1084.             else
1085.                 obj->lknown = 0;
1086.         } else /* silently fix if broken */
1087.             obj->obroken = 0;
1088.         break;
1089.     case WAN_POLYMORPH:
1090.     case SPE_POLYMORPH:
1091.         /* maybe start unlocking chest, get interrupted, then zap it;
1092.            we must avoid any attempt to resume unlocking it */
1093.         if (gx.xlock.box == obj)
1094.             reset_pick();
1095.         break;
1096.     }
1097.     return res;
1098. }
1099. 
1100. /* Door/secret door was hit with spell or wand effect otmp;
1101.    returns true if something happened */
1102. boolean
1103. doorlock(struct obj *otmp, coordxy x, coordxy y)
1104. {
1105.     struct rm *door = &levl[x][y];
1106.     boolean res = TRUE;
1107.     int loudness = 0;
1108.     const char *msg = (const char *) 0;
1109.     const char *dustcloud = "A cloud of dust";
1110.     const char *quickly_dissipates = "quickly dissipates";
1111.     boolean mysterywand = (otmp->oclass == WAND_CLASS && !otmp->dknown);
1112. 
1113.     if (door->typ == SDOOR) {
1114.         switch (otmp->otyp) {
1115.         case WAN_OPENING:
1116.         case SPE_KNOCK:
1117.         case WAN_STRIKING:
1118.         case SPE_FORCE_BOLT:
1119.             door->typ = DOOR;
1120.             door->doormask = D_CLOSED | (door->doormask & D_TRAPPED);
1121.             newsym(x, y);
1122.             if (cansee(x, y))
1123.                 pline("A door appears in the wall!");
1124.             if (otmp->otyp == WAN_OPENING || otmp->otyp == SPE_KNOCK)
1125.                 return TRUE;
1126.             break; /* striking: continue door handling below */
1127.         case WAN_LOCKING:
1128.         case SPE_WIZARD_LOCK:
1129.         default:
1130.             return FALSE;
1131.         }
1132.     }
1133. 
1134.     switch (otmp->otyp) {
1135.     case WAN_LOCKING:
1136.     case SPE_WIZARD_LOCK:
1137.         if (Is_rogue_level(&u.uz)) {
1138.             boolean vis = cansee(x, y);
1139. 
1140.             /* Can't have real locking in Rogue, so just hide doorway */
1141.             if (vis) {
1142.                 pline("%s springs up in the older, more primitive doorway.",
1143.                       dustcloud);
1144.             } else {
1145.                 Soundeffect(se_swoosh, 25);
1146.                 You_hear("a swoosh.");
1147.             }
1148.             if (obstructed(x, y, mysterywand)) {
1149.                 if (vis)
1150.                     pline_The("cloud %s.", quickly_dissipates);
1151.                 return FALSE;
1152.             }
1153.             block_point(x, y);
1154.             door->typ = SDOOR, door->doormask = D_NODOOR;
1155.             if (vis)
1156.                 pline_The("doorway vanishes!");
1157.             newsym(x, y);
1158.             return TRUE;
1159.         }
1160.         if (obstructed(x, y, mysterywand))
1161.             return FALSE;
1162.         /* Don't allow doors to close over traps.  This is for pits */
1163.         /* & trap doors, but is it ever OK for anything else? */
1164.         if (t_at(x, y)) {
1165.             /* maketrap() clears doormask, so it should be NODOOR */
1166.             pline("%s springs up in the doorway, but %s.", dustcloud,
1167.                   quickly_dissipates);
1168.             return FALSE;
1169.         }
1170. 
1171.         switch (door->doormask & ~D_TRAPPED) {
1172.         case D_CLOSED:
1173.             msg = "The door locks!";
1174.             break;
1175.         case D_ISOPEN:
1176.             msg = "The door swings shut, and locks!";
1177.             break;
1178.         case D_BROKEN:
1179.             msg = "The broken door reassembles and locks!";
1180.             break;
1181.         case D_NODOOR:
1182.             msg =
1183.                "A cloud of dust springs up and assembles itself into a door!";
1184.             break;
1185.         default:
1186.             res = FALSE;
1187.             break;
1188.         }
1189.         block_point(x, y);
1190.         door->doormask = D_LOCKED | (door->doormask & D_TRAPPED);
1191.         newsym(x, y);
1192.         break;
1193.     case WAN_OPENING:
1194.     case SPE_KNOCK:
1195.         if (door->doormask & D_LOCKED) {
1196.             msg = "The door unlocks!";
1197.             door->doormask = D_CLOSED | (door->doormask & D_TRAPPED);
1198.         } else
1199.             res = FALSE;
1200.         break;
1201.     case WAN_STRIKING:
1202.     case SPE_FORCE_BOLT:
1203.         if (door->doormask & (D_LOCKED | D_CLOSED)) {
1204.             /* sawit: closed door location is more visible than open */
1205.             boolean sawit, seeit;
1206. 
1207.             if (door->doormask & D_TRAPPED) {
1208.                 struct monst *mtmp = m_at(x, y);
1209. 
1210.                 sawit = mtmp ? canseemon(mtmp) : cansee(x, y);
1211.                 door->doormask = D_NODOOR;
1212.                 unblock_point(x, y);
1213.                 newsym(x, y);
1214.                 seeit = mtmp ? canseemon(mtmp) : cansee(x, y);
1215.                 if (mtmp) {
1216.                     (void) mb_trapped(mtmp, sawit || seeit);
1217.                 } else {
1218.                     /* for mtmp, mb_trapped() does is own wake_nearto() */
1219.                     loudness = 40;
1220.                     if (flags.verbose) {
1221.                         Soundeffect(se_kaboom_door_explodes, 75);
1222.                         if ((sawit || seeit) && !Unaware) {
1223.                             pline("KABOOM!!  You see a door explode.");
1224.                         } else if (!Deaf) {
1225.                             Soundeffect(se_explosion, 75);
1226.                             You_hear("a %s explosion.",
1227.                                      (distu(x, y) > 7 * 7) ? "distant"
1228.                                                            : "nearby");
1229.                         }
1230.                     }
1231.                 }
1232.                 break;
1233.             }
1234.             sawit = cansee(x, y);
1235.             door->doormask = D_BROKEN;
1236.             recalc_block_point(x, y);
1237.             seeit = cansee(x, y);
1238.             newsym(x, y);
1239.             if (flags.verbose) {
1240.                 if ((sawit || seeit) && !Unaware) {
1241.                     pline_The("door crashes open!");
1242.                 } else if (!Deaf) {
1243.                     Soundeffect(se_crashing_sound, 100);
1244.                     You_hear("a crashing sound.");
1245.                 }
1246.             }
1247.             /* force vision recalc before printing more messages */
1248.             if (gv.vision_full_recalc)
1249.                 vision_recalc(0);
1250.             loudness = 20;
1251.         } else
1252.             res = FALSE;
1253.         break;
1254.     default:
1255.         impossible("magic (%d) attempted on door.", otmp->otyp);
1256.         break;
1257.     }
1258.     if (msg && cansee(x, y))
1259.         pline1(msg);
1260.     if (loudness > 0) {
1261.         /* door was destroyed */
1262.         wake_nearto(x, y, loudness);
1263.         if (*in_rooms(x, y, SHOPBASE))
1264.             add_damage(x, y, 0L);
1265.     }
1266. 
1267.     if (res && picking_at(x, y)) {
1268.         /* maybe unseen monster zaps door you're unlocking */
1269.         stop_occupation();
1270.         reset_pick();
1271.     }
1272.     return res;
1273. }
1274. 
1275. staticfn void
1276. chest_shatter_msg(struct obj *otmp)
1277. {
1278.     const char *disposition;
1279.     const char *thing;
1280.     long save_HBlinded, save_BBlinded;
1281. 
1282.     if (otmp->oclass == POTION_CLASS) {
1283.         You("%s %s shatter!", Blind ? "hear" : "see", an(bottlename()));
1284.         if (!breathless(gy.youmonst.data) || haseyes(gy.youmonst.data))
1285.             potionbreathe(otmp);
1286.         return;
1287.     }
1288.     /* We have functions for distant and singular names, but not one */
1289.     /* which does _both_... */
1290.     save_HBlinded = HBlinded,  save_BBlinded = BBlinded;
1291.     HBlinded = 1L,  BBlinded = 0L;
1292.     thing = singular(otmp, xname);
1293.     HBlinded = save_HBlinded,  BBlinded = save_BBlinded;
1294.     switch (objects[otmp->otyp].oc_material) {
1295.     case PAPER:
1296.         disposition = "is torn to shreds";
1297.         break;
1298.     case WAX:
1299.         disposition = "is crushed";
1300.         break;
1301.     case VEGGY:
1302.         disposition = "is pulped";
1303.         break;
1304.     case FLESH:
1305.         disposition = "is mashed";
1306.         break;
1307.     case GLASS:
1308.         disposition = "shatters";
1309.         break;
1310.     case WOOD:
1311.         disposition = "splinters to fragments";
1312.         break;
1313.     default:
1314.         disposition = "is destroyed";
1315.         break;
1316.     }
1317.     pline("%s %s!", An(thing), disposition);
1318. }
1319. 
1320. /*lock.c*/