Prevent monsters from leaping to their death in water #38150
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
SUMMARY: Bugfixes "Prevent monsters from leaping to their death in water"
Purpose of change
Fixes #38038 by preventing monsters that could drown from leaping into drownable terrain.
Describe the solution
I refactored the die_if_drowning method to separate out a method (is_aquatic_danger) that defines terrain that would drown a drownable monster. In the leaping code, I consider a square unleapable if it would drown the leaper, and prevent leaping.
This refactor removed some redundant code checking for TFLAG_DEEP_WATER before doing the die_if_drowning checks and encapsulated it in hopefully a better way.
Describe alternatives you've considered
Should leaping animals always know that they would drown? I decided yes, because they won't willingly walk to their death, but the alternative of allowing some version of the existing behaviour was considered. It didn't seem appropriate, unless there is some case where monsters do this that I'm not aware of.
Testing
I couldn't figure out how to make cougars reliably hostile while on the shoreline! My testing was with evolved mutants, who also have the Leap attack and are hostile.
I tested before and after, and before, an entire group of evolved mutants leaped to their death when I was on a motorboat just off the shore.
Afterwards, I verified that they did not leap directly into the water. I tested that they would leap if their target was on my boat, which they did occasionally:
(Note the dead monsters in deep water are almost exclusively from the "before" save.)
Additional context
When I did have a boarded mutant on my boat, the mutant behaviour was a bit strange but I am quite certain it was not related to this change -- I just think that boarded walkers on boats don't navigate as expected. The mutant was shaking the boat but wasn't charging me. It looks like there is a navigation issue with walkers on boats over deep water? I think there's a separate issue here if someone wants to improve the behaviour of walkers on boarded boats.