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

Traps cleanup #1009

wants to merge 4 commits into from

Conversation

ufshaikh
Copy link
Contributor

These are few commits cleaning up some minor things I noticed while digging around in traps.cc.

The last commit doesn't seem like an especially elegant way to do this to me---I'm open to suggestions.

Testbits isn't necessary here; it's sufficient to use & to see whether
the branch has the dangerous_end flag. This is at least as easy to read
and removes an unnecessary equality test. Note that this is what
do_trap_effects already does in its version of this logic.
The function do_trap_effects duplicates logic from
is_valid_shaft_effect_level. The latter function is apparently never
called. I suspect the intention was for do_trap_effects to call
is_valid_shaft_effect_level and the author forgot to make the change. In
any case, this commit removes the logic from do_trap_effects and inserts
a call to is_valid_shaft_effect_level.
This makes the comment a little less likely to go out of date if someone
starts moving things around in the future.
The current flow is to decide whether the player is trapped when
revealing a tile (player_view_update_at calls roll_trap_effects); if so,
you.trapped is set to true. The next time the world reacts,
do_trap_effects is called and then you.trapped is cleared back to false.
Currently do_trap_effects rolls for which trap effect will happen and
then checks to see if it is allowed to happen in that place; if not,
nothing happens. This has the result that, all else equal, the player is
less likely to suffer any trap effect on floors where one of the effect
types is ruled out, e.g., the player is less likely to get trapped on
Snake:3 than Snake:2.

This commit changes do_trap_effects to first find the valid trap effects
for the location and then choose among them. So, all else equal, the
player will be just as likely to get trapped on a floor where shafts
cannot be placed---the other trap effect types will pick up the slack.
(In general all else is not equal, since trap effect rate depends on
depth; see trap_rate_for_place. But probably this means that code
affecting rate of triggering trap effect should be there, and not rolled
in with code choosing the effect in do_trap_effects.)
crawl-ref/source/traps.cc Show resolved Hide resolved
@ebering ebering added the refactor Involving a refactor of some part of crawlcode label Mar 15, 2019
@ebering ebering closed this in 1152973 Mar 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Involving a refactor of some part of crawlcode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants