MCPcopy Create free account
hub / github.com/NetHack/NetHack / forcelock

Function forcelock

src/lock.c:215–256  ·  view source on GitHub ↗

try to force a locked chest */

Source from the content-addressed store, hash-verified

213
214/* try to force a locked chest */
215staticfn int
216forcelock(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
258void
259reset_pick(void)

Callers

nothing calls this directly

Calls 10

YouFunction · 0.85
exerciseFunction · 0.85
rn2Function · 0.85
obj_resistsFunction · 0.85
xnameFunction · 0.85
useupFunction · 0.85
wake_nearbyFunction · 0.85
breakchestlockFunction · 0.85
reset_pickFunction · 0.85
plineFunction · 0.70

Tested by

no test coverage detected