-
Notifications
You must be signed in to change notification settings - Fork 738
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 Vitals - Extract update logic to separate functions #10566
base: master
Are you sure you want to change the base?
Changes from 12 commits
4a63b97
dee674b
d248f18
a2cae4e
84b8b76
2a16a5d
302a83c
8cea489
77db3f6
c3119fe
ad79d95
a4c0ffd
4e57482
f66ae18
832571b
fdb1d42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
PREP(consumeIVs); | ||
PREP(consumeMedications); | ||
PREP(handleUnitVitals); | ||
PREP(scanConfig); | ||
PREP(updateBloodPressure); | ||
PREP(updateBloodVolume); | ||
PREP(updateHeartRate); | ||
PREP(updateOxygen); | ||
PREP(updatePain); | ||
PREP(updatePainSuppress); | ||
PREP(updatePeripheralResistance); | ||
PREP(updateState); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "..\script_component.hpp" | ||
/* | ||
* Author: Glowbal, LinkIsGrim | ||
* Calculates fluid intake and consumes unit's IVs. | ||
* | ||
* Arguments: | ||
* 0: The Unit <OBJECT> | ||
* 1: Time since last update <NUMBER> | ||
* 2: Global Sync Values (IVs) <BOOL> | ||
* | ||
* Return Value: | ||
* Blood volume change (liters per second) <NUMBER> | ||
* | ||
* Example: | ||
* [player, 1, true] call ace_medical_vitals_fnc_consumeIVs | ||
* | ||
* Public: No | ||
*/ | ||
|
||
params ["_unit", "_deltaT", "_syncValues"]; | ||
|
||
private _ivBags = _unit getVariable [QEGVAR(medical,ivBags), []]; | ||
|
||
if (_ivBags isEqualTo []) exitWith {0}; | ||
|
||
private _tourniquets = GET_TOURNIQUETS(_unit); | ||
private _bloodVolumeChange = 0; | ||
private _consumedIVs = []; | ||
|
||
{ | ||
_x params ["_bagVolumeRemaining", "_type", "_bodyPartIndex", "_treatment", "_rateCoef", "_item"]; | ||
|
||
if (_tourniquets select _bodyPartIndex > 0) then { | ||
continue | ||
}; | ||
|
||
private _bagChange = (_deltaT * EGVAR(medical,ivFlowRate) * IV_CHANGE_PER_SECOND * _rateCoef) min _bagVolumeRemaining; // absolute value of the change in miliLiters | ||
_bagVolumeRemaining = _bagVolumeRemaining - _bagChange; | ||
_consumedIVs pushBack [_type, _treatment, _bagChange]; | ||
|
||
if (_type in ["Blood", "Plasma", "Saline"]) then { | ||
_bloodVolumeChange = _bloodVolumeChange + (_bagChange / 1000); | ||
}; | ||
|
||
if (_bagVolumeRemaining >= 0.01) then { | ||
_x set [0, _bagVolumeRemaining]; | ||
} else { | ||
_ivBags deleteAt _forEachIndex; | ||
}; | ||
} forEachReversed _ivBags; | ||
|
||
(GVAR(deferredEvents) getOrDefault [_unit, [], true]) pushBack ([QEGVAR(medical,consumedIVs), [_unit, _consumedIVs]]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Key can't be an object, you need to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally not a huge fan of having a global hashmap for this kind of thing:
Why not use an object variable instead? Handles 1) and no longer requires There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hashmap is slightly faster (might not be with hashvalue), that was the only incentive. If we don't have to worry about keeping 3rd-party code out of the counter, I'd rather just raise the events outright. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Do that then, makes more sense.
LinkIsGrim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (_ivBags isEqualTo []) then { | ||
_unit setVariable [QEGVAR(medical,ivBags), nil, true]; | ||
} else { | ||
_unit setVariable [QEGVAR(medical,ivBags), _ivBags, _syncValues]; | ||
}; | ||
|
||
_bloodVolumeChange // return |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include "..\script_component.hpp" | ||
/* | ||
* Author: Glowbal, LinkIsGrim | ||
* Consumes unit's medications and update relevant vitals | ||
* | ||
* Arguments: | ||
* 0: The Unit <OBJECT> | ||
* 1: Time since last update <NUMBER> | ||
* 2: Global Sync Values (medications) <BOOL> | ||
* | ||
* Return Value: | ||
* Values should be synced <BOOL> | ||
* | ||
* Example: | ||
* [player, 1, true] call ace_medical_vitals_fnc_consumeMedications | ||
* | ||
* Public: No | ||
*/ | ||
|
||
params ["_unit", "_deltaT", "_syncValues"]; | ||
|
||
private _medications = _unit getVariable [VAR_MEDICATIONS, []]; | ||
|
||
if (_medications isEqualTo []) exitWith { | ||
[0, 0, 0, false] | ||
}; | ||
|
||
private _hrTargetAdjustment = 0; | ||
private _painSupressAdjustment = 0; | ||
private _peripheralResistanceAdjustment = 0; | ||
private _consumedMedications = []; | ||
|
||
{ | ||
_x params ["_medication", "_timeAdded", "_timeTillMaxEffect", "_maxTimeInSystem", "_hrAdjust", "_painAdjust", "_flowAdjust"]; | ||
|
||
private _timeInSystem = CBA_missionTime - _timeAdded; | ||
if (_timeInSystem >= _maxTimeInSystem) then { | ||
_syncValues = true; | ||
_medications deleteAt _forEachIndex; | ||
} else { | ||
private _effectRatio = (((_timeInSystem / _timeTillMaxEffect) ^ 2) min 1) * (_maxTimeInSystem - _timeInSystem) / _maxTimeInSystem; | ||
|
||
_consumedMedications pushBack [_medication, _effectRatio]; | ||
|
||
if (_hrAdjust != 0) then { _hrTargetAdjustment = _hrTargetAdjustment + _hrAdjust * _effectRatio; }; | ||
if (_painAdjust != 0) then { _painSupressAdjustment = _painSupressAdjustment + _painAdjust * _effectRatio; }; | ||
if (_flowAdjust != 0) then { _peripheralResistanceAdjustment = _peripheralResistanceAdjustment + _flowAdjust * _effectRatio; }; | ||
}; | ||
} forEachReversed _medications; | ||
|
||
(GVAR(deferredEvents) getOrDefault [_unit, [], true]) pushBack ([QEGVAR(medical,consumeMedications), [_unit, _consumedMedications]]); | ||
LinkIsGrim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (_syncValues) then { | ||
_unit setVariable [VAR_MEDICATIONS, _medications, true] | ||
}; | ||
|
||
[_unit, _hrTargetAdjustment, _deltaT, _syncValues] call FUNC(updateHeartRate); | ||
[_unit, _painSupressAdjustment, _deltaT, _syncValues] call FUNC(updatePainSuppress); | ||
[_unit, _peripheralResistanceAdjustment, _deltaT, _syncValues] call FUNC(updatePeripheralResistance); | ||
|
||
_syncValues // return |
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.
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 just gonna fix that properly instead.