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

Function avoid_trap_andor_region

src/hack.c:2514–2582  ·  view source on GitHub ↗

if paranoid_confirm:Trap is enabled, check whether the next step forward needs player confirmation due to visible region or discovered trap; result: True => stop moving, False => proceed */

Source from the content-addressed store, hash-verified

2512 needs player confirmation due to visible region or discovered trap;
2513 result: True => stop moving, False => proceed */
2514staticfn boolean
2515avoid_trap_andor_region(coordxy x, coordxy y)
2516{
2517 char qbuf[QBUFSZ];
2518 NhRegion *newreg, *oldreg;
2519 struct trap *trap = NULL;
2520
2521 /* treat entering a visible gas cloud region like entering a trap;
2522 there could be a known trap as well as a region at the target spot;
2523 if so, ask about entring the region first; even though this could
2524 lead to two consecutive confirmation prompts, the situation seems
2525 to be too uncommon to warrant a separate case with combined
2526 trap+region confirmation */
2527 if (ParanoidTrap && !Blind && !Stunned && !Confusion && !Hallucination
2528 /* skip if player used 'm' prefix or is moving recklessly */
2529 && (!svc.context.nopick || svc.context.run)
2530 /* check for region(s) */
2531 && (newreg = visible_region_at(x, y)) != 0
2532 && ((oldreg = visible_region_at(u.ux, u.uy)) == 0
2533 /* if moving from one region into another, only ask for
2534 confirmation if the one potentially being entered inflicts
2535 damage (poison gas) and the one being exited doesn't (vapor) */
2536 || (reg_damg(newreg) > 0 && reg_damg(oldreg) == 0))
2537 /* check whether attempted move will be viable */
2538 && test_move(u.ux, u.uy, u.dx, u.dy, TEST_MOVE)
2539 /* we don't override confirmation for poison resistance since the
2540 region also hinders hero's vision even if/when no damage is done */
2541 ) {
2542 Snprintf(qbuf, sizeof qbuf, "%s into that %s cloud?",
2543 u_locomotion("step"),
2544 (reg_damg(newreg) > 0) ? "poison gas" : "vapor");
2545 if (!paranoid_query(ParanoidConfirm, upstart(qbuf))) {
2546 nomul(0);
2547 svc.context.move = 0;
2548 return TRUE;
2549 }
2550 }
2551
2552 /* maybe ask player for confirmation before walking into known trap */
2553 if (ParanoidTrap && !Stunned && !Confusion
2554 /* skip if player used 'm' prefix or is moving recklessly */
2555 && (!svc.context.nopick || svc.context.run)
2556 /* check for discovered trap */
2557 && (trap = t_at(x, y)) != 0 && trap->tseen
2558 /* check whether attempted move will be viable */
2559 && test_move(u.ux, u.uy, u.dx, u.dy, TEST_MOVE)
2560 /* override confirmation if the trap is harmless to the hero */
2561 && (immune_to_trap(&gy.youmonst, trap->ttyp) != TRAP_CLEARLY_IMMUNE
2562 /* Hallucination: all traps still show as ^, but the
2563 hero can't tell what they are, so treat as dangerous */
2564 || Hallucination)) {
2565 int traptype = (Hallucination ? rnd(TRAPNUM - 1) : (int) trap->ttyp);
2566 boolean into = into_vs_onto(traptype);
2567
2568 Snprintf(qbuf, sizeof qbuf, "Really %s %s that %s?",
2569 u_locomotion("step"), into ? "into" : "onto",
2570 defsyms[trap_to_defsym(traptype)].explanation);
2571 /* handled like paranoid_confirm:pray; when paranoid_confirm:trap

Callers 1

domove_coreFunction · 0.85

Calls 11

visible_region_atFunction · 0.85
reg_damgFunction · 0.85
test_moveFunction · 0.85
u_locomotionFunction · 0.85
paranoid_queryFunction · 0.85
upstartFunction · 0.85
nomulFunction · 0.85
t_atFunction · 0.85
immune_to_trapFunction · 0.85
rndFunction · 0.85
into_vs_ontoFunction · 0.85

Tested by

no test coverage detected