-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Make monster::heal actually return amount healed #51183
Conversation
It is assumed in multiple places, and stated in monster.h, that the monster::heal function returns the amount healed. Now it actually does. This came about via CleverRaven#17452, which was to prevent heal from returning a negative number; I see no way that it now can, but just in case I have put in a std::max( 0, hp - old_hp ).
Please change
We need to give the monster its full speed if they did a full heal.
|
I'm not sure how this change would break the above. Healed is the amount that was actually healed. If the potential heal amount is more than how much actually got healed, the "extra" goes to increasing speed... rather oddly, I agree.
I agree with both of the above; will do the below, thank you.
|
As suggested by @eltank (not sure how to get github to properly credit them, and would like to know), make the healing/recovering of speed in monster::on_load() proportional to the monster's current hp, so that a fully healed monster also fully heals speed. Admittedly, it is rather weird that healing speed doesn't seem to take place elsewhere, as in while in the reality bubble.
Currently that if condition evaluates to true (kind of by accident) if the monster was close to max hp. After your change (and without the additional modifications) the condition would evaluate to false when the monster is close to max and regen is capped. That would prevent it from healing speed. But the code was broken anyway when monster hp is low (the if condition evaluates to false). The suggested change should fix all that. |
There really shouldn't be any way that it'll return negative now, and it would probably be better to have some chance of realizing this (via the negative return) if it did.
Actually, healed will be less than heal_amount if it's capped, meaning it will heal speed. But I agree that the code is confusing and doesn't make much sense, especially considering that there doesn't seem to be any other healing of speed in the reality bubble! |
Should the proportional healing of speed be rounded up? |
This probably doesn't matter, but make sure there's at least a bit of healing of speed each time. Also fix one typo (`type-> speed`).
Probably doesn't matter since they'll likely do a full heal anyway, but you can change to lround or round up or even roll_remainder if you prefer. This is just the simplest option. |
Just in case, making sure there's always a bit of healing of speed; also fixing a typo that I'm surprised astyle didn't object to - space between |
Probably out of scope for this PR, but regenerating monsters seem to only regenerate speed when they enter the reality bubble (on_load) and not while in the reality bubble (in which case they only regen hp). Not sure what the implications are. AFAIK the only way monsters can lose base speed is during resurrection, which I think can only happen in the bubble anyway. So when would speed regen on load even trigger? The main implication of that is: I don't know how to test that the speed regen change works. |
Float/int conversions strike again! Co-authored-by: eltank <8000047+eltank@users.noreply.github.com>
Scenario: Something manages to revive, but you move and it's no longer in the reality bubble. You come back, it should have regenerated speed as well as hp in the meantime. (Of course, it should also be doing that while in the reality bubble... hmm.)
Sounds good to me!
|
Effect processing (including regen) happens before it gets its moves (at the beginning of the turn) -- |
src/monster.cpp
Outdated
set_speed_base( std::min( old_speed + speed_delta, type->speed ) ); | ||
type->speed ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set_speed_base( std::min( old_speed + speed_delta, type->speed ) ); | |
type->speed ) ); | |
set_speed_base( std::min( old_speed + speed_delta, type->speed ) ); |
Something got messed up here. Let's remove the junk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Github is insisting that there's no change in your suggestion - doing a pull to my local machine to check.
Applying a change suggested by @eltank on Github does not appear to have gone correctly. Fixing.
First round of testing. You can see that before this change, dissolute regen was reported as "visibly regenerating", which should be displayed when healing more than 50 points. But dissolutes only have 1 point of regen. After the change, the report is "healing slowly", which is what is expected for this monster: Note that even after regaining all hp, they can barely move after rez if you keep then in the bubble while they heal up (unchanged by this PR) |
Odd. Did you catch the debug message at the end of on_load()? |
No, that part is working fine. |
Oh, interesting. (I note that npc::on_unload() doesn't even try to set last_updated? Ah. Probably because Character::update_body does it.) |
It looks like that last_update bug is going to take a while to debug. |
Excellent! (What was the bug, BTW? I look forward to a PR to fix it; that will also be very helpful for having morale and anger properly affected by time out of the reality bubble.) |
But... now they heal extremely slowly after reviving so I want to get feedback on whether we need to buff that. |
* Make monster::heal actually return amount healed It is assumed in multiple places, and stated in monster.h, that the monster::heal function returns the amount healed. Now it actually does. This came about via CleverRaven#17452, which was to prevent heal from returning a negative number; I see no way that it now can, but just in case I have put in a std::max( 0, hp - old_hp ). * Make recovering speed in on_load more sensible. As suggested by @eltank (not sure how to get github to properly credit them, and would like to know), make the healing/recovering of speed in monster::on_load() proportional to the monster's current hp, so that a fully healed monster also fully heals speed. Admittedly, it is rather weird that healing speed doesn't seem to take place elsewhere, as in while in the reality bubble. * Follow @eltank's advice re not being paranoid There really shouldn't be any way that it'll return negative now, and it would probably be better to have some chance of realizing this (via the negative return) if it did. * Round up proportional healing of speed; typo fix This probably doesn't matter, but make sure there's at least a bit of healing of speed each time. Also fix one typo (`type-> speed`). * Apply suggestions from code review Float/int conversions strike again! Co-authored-by: eltank <8000047+eltank@users.noreply.github.com> * Fix error (likely from Github). Applying a change suggested by @eltank on Github does not appear to have gone correctly. Fixing. Co-authored-by: actual-nh <actual-nh@users.noreply.github.com> Co-authored-by: eltank <8000047+eltank@users.noreply.github.com>
Summary
Bugfixes "Make monster::heal actually return the amount healed"
Purpose of change
It is assumed in multiple places, and stated in monster.h, that the monster::heal function returns the amount healed. It doesn't, but it should.
Describe the solution
To get the return value, do hp - old_hp, not maxhp - old_hp.
Describe alternatives you've considered
This came about via #17452, which was to prevent heal from returning a negative number; I see no way that it now can, but just in case I have put in a std::max( 0, hp - old_hp ). It may be preferable to not do the max, or to emit an error if the heal amount somehow manages to be negative.
Testing
CI and by @eltank; thanks very much!
Additional context
See dev discord.