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

Function untrap_prob

src/trap.c:5288–5337  ·  view source on GitHub ↗

Probability of disabling a trap. Helge Hafting; Returns 0 for success, non-0 for failure. */

Source from the content-addressed store, hash-verified

5286/* Probability of disabling a trap. Helge Hafting;
5287 Returns 0 for success, non-0 for failure. */
5288staticfn int
5289untrap_prob(
5290 struct trap *ttmp) /* must not be Null */
5291{
5292 int chance = 3;
5293
5294 /* non-spiders are less adept at dealing with webs */
5295 if (ttmp->ttyp == WEB) {
5296 /* this assumes that all fiery artifacts are blades; no need to
5297 make it more complicated unless/until that changes */
5298 struct obj *wep = (uwep && is_blade(uwep)) ? uwep
5299 : (uswapwep && u.twoweap && is_blade(uswapwep))
5300 ? uswapwep : NULL;
5301
5302 /* FIXME? Forcefight of adjacent web works with bare-handed and
5303 martial arts but #untrap of same resorts to !webmaker() chance */
5304 if (wep && !m_at(ttmp->tx, ttmp->ty)) {
5305 /* primary or secondary weapon is a blade (which includes
5306 daggers but not axes or bladed polearms) */
5307 if (u_wield_art(ART_STING) || attacks(AD_FIRE, wep))
5308 chance = 1;
5309 /* else chance stays 3 */
5310 } else if (!webmaker(gy.youmonst.data)) {
5311 chance = 7; /* 5.0: used to be 30 */
5312 }
5313 }
5314 if (Confusion || Hallucination)
5315 chance++;
5316 if (Blind)
5317 chance++;
5318 if (Stunned)
5319 chance += 2;
5320 if (Fumbling)
5321 chance *= 2;
5322 /* Your own traps are better known than others. */
5323 if (ttmp->madeby_u)
5324 chance--;
5325 if (Role_if(PM_RANGER) && ttmp->ttyp == BEAR_TRAP && chance <= 3)
5326 return 0; /* always succeeds */
5327 if (Role_if(PM_ROGUE)) {
5328 if (rn2(2 * MAXULEV) < u.ulevel)
5329 chance--;
5330 if (u.uhave.questart && chance > 1)
5331 chance--;
5332 } else if (Role_if(PM_RANGER) && chance > 1)
5333 chance--;
5334 if (chance < 1)
5335 chance = 1;
5336 return rn2(chance);
5337}
5338
5339/* Replace trap with object(s). Helge Hafting */
5340void

Callers 2

try_disarmFunction · 0.85
help_monster_outFunction · 0.85

Calls 2

attacksFunction · 0.85
rn2Function · 0.85

Tested by

no test coverage detected