Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traps cleanup #1009

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
82 changes: 51 additions & 31 deletions crawl-ref/source/traps.cc
Expand Up @@ -1320,7 +1320,7 @@ bool is_valid_shaft_effect_level()
// Don't shaft the player when we can't, and also when it would be into a
// dangerous end.
return is_valid_shaft_level()
&& !(testbits(branch.branch_flags, brflag::dangerous_end)
ebering marked this conversation as resolved.
Show resolved Hide resolved
&& !(branch.branch_flags & brflag::dangerous_end
&& brdepth[place.branch] - place.depth == 1);
}

Expand Down Expand Up @@ -1368,46 +1368,66 @@ void roll_trap_effects()
}

/***
* Separate from the previous function so the trap triggers when crawl is in an
* Separate from roll_trap_effects so the trap triggers when crawl is in an
* appropriate state
*/
void do_trap_effects()
{
const level_id place = level_id::current();
const Branch &branch = branches[place.branch];

// Try to shaft, teleport, or alarm the player.
int roll = random2(3);
switch (roll)

// We figure out which possibilites are allowed before picking which happens
// so that the overall chance of being trapped doesn't depend on which
// possibilities are allowed.

// Don't shaft the player when shafts aren't allowed in the location or when
// it would be into a dangerous end.
bool shaft_allowed = is_valid_shaft_effect_level();
// No alarms on the first 3 floors
bool alarm_allowed = env.absdepth0 > 3;
// Teleport effects are allowed everywhere, no need to check

trap_type trap_effect = TRAP_UNASSIGNED;

if (alarm_allowed)
{
case 0:
// Don't shaft the player when we can't, and also when it would be into a
// dangerous end.
if (is_valid_shaft_level()
&& !(branch.branch_flags & brflag::dangerous_end
&& brdepth[place.branch] - place.depth == 1))
{
dprf("Attempting to shaft player.");
you.do_shaft();
}
if (shaft_allowed)
trap_effect = random_choose(TRAP_ALARM, TRAP_SHAFT, TRAP_TELEPORT);
else
trap_effect = random_choose(TRAP_ALARM, TRAP_TELEPORT);
}
else
{
if (shaft_allowed)
trap_effect = random_choose(TRAP_SHAFT, TRAP_TELEPORT);
else
trap_effect = TRAP_TELEPORT;
}
ufshaikh marked this conversation as resolved.
Show resolved Hide resolved

switch (trap_effect)
{
case TRAP_SHAFT:
dprf("Attempting to shaft player.");
you.do_shaft();
break;
case 1:
// No alarms on the first 3 floors
if (env.absdepth0 > 3)
{
// Alarm effect alarms are always noisy, even if the player is
// silenced, to avoid "travel only while silenced" behavior.
// XXX: improve messaging to make it clear theres a wail outside of the
// player's silence
mprf("You set off the alarm!");
fake_noisy(40, you.pos());
you.sentinel_mark(true);
}

case TRAP_ALARM:
// Alarm effect alarms are always noisy, even if the player is
// silenced, to avoid "travel only while silenced" behavior.
// XXX: improve messaging to make it clear theres a wail outside of the
// player's silence
mprf("You set off the alarm!");
fake_noisy(40, you.pos());
you.sentinel_mark(true);
break;
case 2:
// Teleportitis

case TRAP_TELEPORT:
you_teleport_now(false, true, "You stumble into a teleport trap!");
break;

// Other cases shouldn't be possible, but having a default here quiets
// compiler warnings
default:
break;
}
}

Expand Down