Invalidate seen cache properly in many-z-level mode #30940
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 "Prevents occasional inappropriate vision across z-levels."
Purpose of change
Fixes #29175
When walking on a roof, a shocker on a lower floor could sometimes fire it's shockstorm attack at the player.
This would only occur if both z-levels and 3D vision options were enabled.
The reason shockstorm came up is that it's a ranged attack that does not double-check for a path to the target, treating vision as sufficient.
It turns out the cause of this issue is that the "seen" cache calculated for the player was not fully cleared after map shift, meaning the tile occupied by the shocker could remain labeled "seen" after a shift, which transitively meant that the shocker was also considered able to see the player in order to fire.
A consistent reproduction case for the issue is to find a relatively small building whose center point is no more than 11 tiles from any edge, spawn a shocker on the lower floor, move the player to the upper floor, and then cross the midline of the building, which triggers the map shift and resultant cache error. The shocker will very consistently be in a position to fire on the player since they track the player by sound.
Describe the solution
Couldn't be simpler, when clearing the seen cache before regenerating it, clear every level of the cache instead of just the current one.
Describe alternatives you've considered
A more sophisticated caching system may be possible in the future, but we don't have the infrastructure for it right now.