diff --git a/addons/vitals/functions/fnc_handleOxygenFunction.sqf b/addons/vitals/functions/fnc_handleOxygenFunction.sqf index 272efc273..d71072689 100644 --- a/addons/vitals/functions/fnc_handleOxygenFunction.sqf +++ b/addons/vitals/functions/fnc_handleOxygenFunction.sqf @@ -1,7 +1,7 @@ #include "..\script_component.hpp" /* * Author: Mazinski - * Updates the respiratory variables + * Updates the respiratory variables * * Arguments: * 0: The Unit @@ -13,7 +13,7 @@ * 6: Opioid Depression * 7: ACE Fatigue * 8: Time since last update - * 9: Sync value? + * 9: Sync value? * * ReturnValue: * Current O2 Saturation @@ -88,7 +88,7 @@ private _paco2 = 40; if (EGVAR(breathing,paco2Active)) then { // The greater the imbalance between CO2 explusion and O2 intake, the higher PaCO2 gets - _paco2 = if ((_demandVentilation / _actualVentilation) == 1) then { _previousCyclePaco2 + (PACO2_MAX_CHANGE min (-PACO2_MAX_CHANGE max ((DEFAULT_PACO2 + ((_anerobicPressure max 1) - 1) * 150) - _previousCyclePaco2))) } else { [ _previousCyclePaco2 - (PACO2_MAX_CHANGE * _deltaT), _previousCyclePaco2 + (PACO2_MAX_CHANGE * _deltaT)] select ((_demandVentilation / _actualVentilation) > 1) }; + _paco2 = if ((_demandVentilation / _actualVentilation) == 1) then { _previousCyclePaco2 + (PACO2_MAX_CHANGE min (-PACO2_MAX_CHANGE max ((DEFAULT_PACO2 + ((_anerobicPressure max 1) - 1) * 150) - _previousCyclePaco2))) } else { [ _previousCyclePaco2 - (PACO2_MAX_CHANGE * _deltaT), _previousCyclePaco2 + (PACO2_MAX_CHANGE * _deltaT)] select ((_demandVentilation / _actualVentilation) > 1) }; }; private _etco2 = 37; @@ -102,7 +102,7 @@ if (IN_CRDC_ARRST(_unit)) then { _etco2 = 0; }; } else { - // Generated ETCO2 quadratic. Ensures ETCO2 moves with Respiratory Rate and is constantly below PaCO2 + // Generated ETCO2 quadratic. Ensures ETCO2 moves with Respiratory Rate and is constantly below PaCO2 _etco2 = (((-0.0416667 * (_respiratoryRate^2)) + (3.09167 * (_respiratoryRate))) * (_respiratoryDepth / 10 )) max 5; }; @@ -113,7 +113,7 @@ if (EGVAR(pharma,kidneyAction)) then { // Extenal pH impacts from saline is included _externalPh = _unit getVariable [QEGVAR(pharma,externalPh), 0]; - // Adjust dissociation constant based on temperature + // Adjust dissociation constant based on temperature private _phConstant = ((-0.00006653 * (_temperature ^ 2)) - (0.03268 * _temperature) + 7.4); // pH is from the Henderson-Hasselbalch equation @@ -122,8 +122,8 @@ if (EGVAR(pharma,kidneyAction)) then { // Fractional Oxygen when breathing normal air is 0.21, 1 when breathing 100% Oxygen, and 0 when no air is being brought into the lungs private _fio2 = switch (true) do { - case ((_unit getVariable [QEGVAR(airway,occluded), false]) || (_unit getVariable [QEGVAR(airway,obstruction), false])): { - [0, DEFAULT_FIO2] select ((_unit getVariable [QEGVAR(airway,recovery), false]) || (_unit getVariable [QEGVAR(airway,overstretch), false])) + case ((_unit getVariable [QEGVAR(airway,occluded), false]) || (_unit getVariable [QEGVAR(airway,obstruction), false])): { + [0, DEFAULT_FIO2] select ((_unit getVariable [QEGVAR(airway,recovery), false]) || (_unit getVariable [QEGVAR(airway,overstretch), false])) }; case ((_respiratoryRate == 0) && (EGVAR(breathing,SpO2_perfusion)) && !_cprAssistSpO2): { 0 }; case ((_unit getVariable [QEGVAR(chemical,airPoisoning), false]) || (_unit getVariable [QEGVAR(breathing,tensionpneumothorax), false]) || (_unit getVariable [QEGVAR(breathing,hemopneumothorax), false])): { 0 }; @@ -142,8 +142,10 @@ private _pao2 = (DEFAULT_PAO2 - ((DEFAULT_ECB / ((GET_BODY_FLUID(_unit) select 0 _pao2 = (((linearConversion[-50, 50, (_pALVo2 - _pao2), -20, 20, false]) + _pao2) min _pALVo2) max 0; private _arrestPerfusion = [1, (1 * EGVAR(breathing,SpO2_PerfusionMultiplier))] select ((IN_CRDC_ARRST(_unit)) && (EGVAR(breathing,SpO2_perfusion))); +// Scale positive PaO2 shift rate when BVM with supplemental O2 is in use +private _bvmPositiveMultiplier = [1, EGVAR(breathing,BVMOxygen_Multiplier)] select ((_unit getVariable [QEGVAR(breathing,BVMInUse), false]) && {_unit getVariable [QEGVAR(breathing,oxygenTankConnected), false]}); // PaO2 moves in controlled steps to prevent hard movements when Ventilation Demand spikes -_pao2 = if (_previousCyclePao2 != _pao2) then { ([ (_previousCyclePao2 - ((PAO2_MAX_CHANGE * EGVAR(breathing,SpO2_MultiplyNegative) * _arrestPerfusion) * _deltaT)) , (_previousCyclePao2 + ((PAO2_MAX_CHANGE * EGVAR(breathing,SpO2_MultiplyPositive)) * _deltaT))] select ((_previousCyclePao2 - _pao2) < 0)) } else { _pao2 }; +_pao2 = if (_previousCyclePao2 != _pao2) then { ([ (_previousCyclePao2 - ((PAO2_MAX_CHANGE * EGVAR(breathing,SpO2_MultiplyNegative) * _arrestPerfusion) * _deltaT)) , (_previousCyclePao2 + ((PAO2_MAX_CHANGE * EGVAR(breathing,SpO2_MultiplyPositive) * _bvmPositiveMultiplier) * _deltaT))] select ((_previousCyclePao2 - _pao2) < 0)) } else { _pao2 }; // Oxy-Hemo Dissociation Curve, driven by PaO2 with shaping done by pH. private _o2Sat = (((_pao2 max 1)^2.7 / ((25 - (((_pH / DEFAULT_PH) - 1) * 150))^2.7 + _pao2^2.7))) min 0.999;