MCPcopy Index your code
hub / github.com/NetHack/NetHack / picklock

Function picklock

src/lock.c:67–159  ·  view source on GitHub ↗

try to open/close a lock */

Source from the content-addressed store, hash-verified

65
66/* try to open/close a lock */
67staticfn int
68picklock(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;

Callers

nothing calls this directly

Calls 11

YouFunction · 0.85
lock_actionFunction · 0.85
exerciseFunction · 0.85
rn2Function · 0.85
b_trappedFunction · 0.85
unblock_pointFunction · 0.85
in_roomsFunction · 0.85
add_damageFunction · 0.85
newsymFunction · 0.85
chest_trapFunction · 0.85
plineFunction · 0.70

Tested by

no test coverage detected