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

edit regen in darkness code for readability and correctness #70799

Merged
merged 2 commits into from
Jan 21, 2024

Conversation

db48x
Copy link
Contributor

@db48x db48x commented Jan 9, 2024

Summary

Bugfixes "monsters that regenerate in darkness would only regenerate by a single HP per turn"

Describe the solution

The boolean > 0 check was inside the call to heal(), so it ended up passing either 1 or 0 rather than the calculated amount of healing. The clear intent of the check, however, is to only print the message if the monster actually needed to be healed.

I also gave the calculated amount of healing a name (dHP), so that it is clear to future readers what the calculation is for; see the discussion in #67027 for an example of one of the easy ways to misread the old code.

This patch does not change when or by how much the monster regenerates.

Describe alternatives you've considered

See also #70774.

Testing

I used a debugger to step through the code, observing that the heal method was only passed a 1 or a 0 before the patch, and that afterwards it was passed integers between 0 and 50.

The boolean > 0 check was inside the call to heal(), so it ended up
passing either 1 or 0 rather than the calculated amount of
healing. The clear intent of the check, however, is to only print the
message if the monster actually needed to be healed.

I also gave the calculated amount of healing a name (dHP), so that it
is clear to future readers what the calculation is for; see the
discussion in CleverRaven#67027 for an example of one of the easy ways to misread
the old code.

This patch does not change when or by how much the monster regenerates.
@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` Monsters Monsters both friendly and unfriendly. <Bugfix> This is a fix for a bug (or closes open issue) labels Jan 9, 2024
src/monster.cpp Outdated Show resolved Hide resolved
@github-actions github-actions bot added the json-styled JSON lint passed, label assigned by github actions label Jan 9, 2024
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@db48x
Copy link
Contributor Author

db48x commented Jan 9, 2024

This is a little bug that I noticed during my analysis for #67027, but didn’t bother to mention because it was less interesting than the light levels.

@github-actions github-actions bot added astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions labels Jan 9, 2024
@Maleclypse Maleclypse merged commit 2fa63b9 into CleverRaven:master Jan 21, 2024
25 of 26 checks passed
@Procyonae Procyonae added the 0.H Backport PR to backport to the 0.H stable release canddiate label May 20, 2024
Procyonae pushed a commit to Procyonae/Cataclysm-DDA that referenced this pull request May 24, 2024
…ven#70799)

* edit regen in darkness code for readability and correctness

The boolean > 0 check was inside the call to heal(), so it ended up
passing either 1 or 0 rather than the calculated amount of
healing. The clear intent of the check, however, is to only print the
message if the monster actually needed to be healed.

I also gave the calculated amount of healing a name (dHP), so that it
is clear to future readers what the calculation is for; see the
discussion in CleverRaven#67027 for an example of one of the easy ways to misread
the old code.

This patch does not change when or by how much the monster regenerates.

* fix parenthesis style in monster.cpp

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
kevingranade added a commit that referenced this pull request May 26, 2024
@Procyonae Procyonae added 0.H Backported and removed 0.H Backport PR to backport to the 0.H stable release canddiate labels May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.H Backported astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` json-styled JSON lint passed, label assigned by github actions Monsters Monsters both friendly and unfriendly.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants