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
Medical rewrite bug fixes #6523
Conversation
…death Fixes medical variables not being reset on respawn Fixes JiP causing reset of all medical variables for all units Fixes updateHeartRate overshooting the target heartrate which made CPR impossible
@@ -19,6 +19,7 @@ class Extended_PostInit_EventHandlers { | |||
class Extended_Init_EventHandlers { | |||
class CAManBase { | |||
class ADDON { | |||
onRespawn = true; |
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.
This only accepts number 1, no strings. Booleans don't exist in config.
https://github.com/CBATeam/CBA_A3/blob/master/addons/xeh/fnc_compileEventHandlers.sqf#L155
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.
Sorry about that. Took it from the XEH wiki and didn't notice the define statement 4 lines above it... Should be fixed now.
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.
Just looked in the config viewer as I was wondering why this mistake didn't cause unwanted behavior and noticed that it already got converted from true to 1. I'll leave the change in for clarity.
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.
Not all binarizers do this. Mikero converts it despite no define, which causes a lot of other problems.
if (_bloodVolume < BLOOD_VOLUME_CLASS_2_HEMORRHAGE) then { | ||
_targetHR = _heartRate * (_targetBP / (45 max _meanBP)); | ||
}; | ||
if (_painLevel > 0.2) then { | ||
_targetHR = _targetHR max (80 + 50 * _painLevel); | ||
}; | ||
_targetHR = _targetHR + _hrTargetAdjustment; | ||
_targetHR = (_targetHR + _hrTargetAdjustment) max 0; |
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.
Isn't _targetHR
always greater than 0? There is no need for max 0
in my opinion
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.
The hrTargetAdjustment can be a rather large negative value depending on current medication I believe. I don't know if it could ever go below 0 because of that but I'd think its worth ensuring it won't. Will remove it if that's really wanted but it seems like taking a bit of a gamble just to save 6 characters.
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.
This is good, we're just moving the max 0
up from line 73 where it was previously 👍
|
||
_hrChange = round(_targetHR - _heartRate) / 2; | ||
} else { | ||
_hrChange = -round(_heartRate / 10); | ||
}; | ||
_heartRate = (_heartRate + _deltaT * _hrChange) max 0; | ||
if (_hrChange < 0) then { |
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.
You can put the whole new If statement directly under the _hrChange calculation and spare it since it is redundant:
_hrChange = round(_targetHR - _heartRate) / 2;
_heartRate = (_heartRate + _deltaT * _hrChange) min _targetHR;
} else ...
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.
I'm sorry, I don't think I understand what you are suggesting. The heart rate is currently doing a min or max with _targetHR depending on if we are increasing or decreasing our heart rate. Wouldn't the change you are suggesting here cause any gradual change lowering the HR to happen immediately instead?
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.
After going through the code more closely these lines look good to me 👍
This doesn't fix the issue of incorrectly large deltaT
first tick after cardiac arrest, but you're right that we don't want the heart rate to pass the target anyway so it should stay because it does fix that issue (theoretically deltaT
could reach 10 at any time).
For the exiting cardiac arrest deltaT
issue, I think we should still be running handleUnitVitals
while in cardiac arrest because it appears to handle other things not related to heart rate too, if we don't then we should refresh the stored lastTimeUpdated
value on the unit when exiting cardiac arrest to avoid similar issues to the one revealed here.
@@ -46,6 +46,7 @@ private _heartRate = GET_HEART_RATE(_unit); | |||
|
|||
if !IN_CRDC_ARRST(_unit) then { |
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.
Isn't this preventing the unit from entering when in cardiac arrest?
On the first tick of handle vitals once CPR was successfully completed the function would be entered with a HR of 40 and the target HR would be 80. This would make the function
40 + ((80 - 40) / 2 )*10 = 240, which would be a HR high enough to push the unit back into cardiac arrest.
Regarding the XEH for the respawn issue:
https://github.com/acemod/ACE3/pull/6518/files#diff-081751a9b9de93a0af75655dce42c674R22
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.
That is only resetting the statemachine though and not resetting the variables such as openWounds right? My worry is that if the new unit does not override the variables from the old unit on respawn it will have a reference to the actual arrays meaning they will receive any updates to the old arrays (and therefor receive wounds when shooting the old corpse).
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.
The check indeed prevents the unit when entering when in cardiac arrest, but that doesn't matter too much as the updateUnitVitals and therefore updateHeartRate is not being called when in cardiac arrest. Problem is that the first time when the unit leaves cardiac arrest state, updateUnitVitals will run updateHeartRate with a _deltaT of 10 as updateUnitVitals hasn't been run in a while. Even if that would be fixed by running updateUnitVitals when in cardiac arrest, I don't believe that it is intentional to ever report a new HR after adjustment beyond the targetHR.
@@ -19,6 +19,7 @@ class Extended_PostInit_EventHandlers { | |||
class Extended_Init_EventHandlers { | |||
class CAManBase { | |||
class ADDON { | |||
onRespawn = 1; |
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.
👍 I overlooked that this wasn't a respawn XEH in my comment on #6518
All looks good except I need to look more closely at the last point (there's definitely an unhandled scenario in the code there though) 👍 |
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.
One suggestion to avoid mixing goals between components. Maybe the engine component may be a better fit, but I don't think it belongs in the statemachine logic.
@@ -19,4 +19,7 @@ params ["_unit"]; | |||
// Send a local event before death | |||
[QEGVAR(medical,death), [_unit]] call CBA_fnc_localEvent; | |||
|
|||
_unit setVariable [VAR_HEART_RATE, 0, true]; |
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.
This should be done in the medical vitals component through an eventhandler I think.
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.
Well spotted, I would agree that an EH is better here
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.
Would we also want to change leftStateCardiacArrest then?
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.
We probably also want to do it for that function, yes. That may require introducing some new events though. Does not have to be done in this PR, imo. But we should create an issue for it if we do not. I will leave that to your discretion @redbery.
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.
I don't think I'll have the time to do that today as it is somewhat involved which would mean it would need to wait until next weekend. Think it is better to create a new issue for it if you don't mind.
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.
Good fixes and has revealed an issue in the vitals loop when exiting cardiac arrest (time delta is incorrectly at max of 10 because loop doesn't run while in cardiac arrest). We can fix this in a different PR.
I agree with @thojkooi's requested changes, but I think we should merge this and change that in a new PR (since it's also relevant to a file not changed here).
if (_bloodVolume < BLOOD_VOLUME_CLASS_2_HEMORRHAGE) then { | ||
_targetHR = _heartRate * (_targetBP / (45 max _meanBP)); | ||
}; | ||
if (_painLevel > 0.2) then { | ||
_targetHR = _targetHR max (80 + 50 * _painLevel); | ||
}; | ||
_targetHR = _targetHR + _hrTargetAdjustment; | ||
_targetHR = (_targetHR + _hrTargetAdjustment) max 0; |
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.
This is good, we're just moving the max 0
up from line 73 where it was previously 👍
|
||
_hrChange = round(_targetHR - _heartRate) / 2; | ||
} else { | ||
_hrChange = -round(_heartRate / 10); | ||
}; | ||
_heartRate = (_heartRate + _deltaT * _hrChange) max 0; | ||
if (_hrChange < 0) then { |
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.
After going through the code more closely these lines look good to me 👍
This doesn't fix the issue of incorrectly large deltaT
first tick after cardiac arrest, but you're right that we don't want the heart rate to pass the target anyway so it should stay because it does fix that issue (theoretically deltaT
could reach 10 at any time).
For the exiting cardiac arrest deltaT
issue, I think we should still be running handleUnitVitals
while in cardiac arrest because it appears to handle other things not related to heart rate too, if we don't then we should refresh the stored lastTimeUpdated
value on the unit when exiting cardiac arrest to avoid similar issues to the one revealed here.
@SilentSpike yes, sounds good. |
* Fix medical menu not reopening regardless of setting * Ensure no heartrate or bloodpressure on death * Fix status variables not being reset on respawn * Fix JIP resetting status variables for all units * Fix heart rate adjustment overflow and
When merged this pull request will:
40 + ((80 - 40) / 2 )*10 = 240, which would be a HR high enough to push the unit back into cardiac arrest.
Note: I realize the respawn issue has been noted as fixed in #6518, but I can't find the respawn XEH noted in that PR. If I missed or misunderstood this I will of course happily take out my proposed fix. Also my apologies for the seemingly random mix of fixes. These were all the problems we ran into when running a test operation with the rewrite branch today.