ACE3/addons/medical_treatment/functions/fnc_treatment.sqf
mharis001 44050df98b Medical Treatment - Modernize and Cleanup (#6933)
* Modernize and cleanup medical_treatment

* One line for each old public function

* Fix litterCleanupDelay name

* Improve adjustment calcs / wound blood loss / medications

fix func descriptions

Calc wound blood loss on events

reorder includes so scritpmacroMed has global effect

trivial optimization for getCardiacOutput

Fix var

Fix wounds not reopening (nil _category)

Fix surgical kit inherting canBandage conditional

debug hitpoints

Update ACE_Medical_Treatment_Actions.hpp

Use woundBleeding for IS_BLEEDING macro

rework medication vars

comments

Reset var in init / fullHeal

Update addons/medical_treatment/functions/fnc_onMedicationUsage.sqf

Co-Authored-By: PabstMirror <pabstmirror@gmail.com>

* Change wound data array

Drop unique id and merge classId and category

* Splinting and treatment and gui

* Add arm fractures and aim effects

* localizations and event

* fix

* fix merge for renamed files

* Fixes and code review changes

* Move medical logs clearing to treatment

* More cleanup work

* cleanup

* Apply suggestions from code review

Co-Authored-By: PabstMirror <pabstmirror@gmail.com>

* formating, rename bone images

* Fix args for setDead call in actionPlaceInBodyBag

* Apply suggestions from code review

Co-Authored-By: PabstMirror <pabstmirror@gmail.com>

* disable calls to extension

* Update fnc_onMedicationUsage.sqf

* Medical - Skip unneeded setVars on initUnit (#6949)

*  Medical - Transfer state machine state on locality (#6950)

* Medical - Transfer state machine state on locality

* Fix feedback isUnconscious var

* Exclude AI

* Make UAV excludes consistant, formating

* Update fnc_treatmentFullHealLocal.sqf

* reset fractures on respawn

* Fix merge

* Add PAK time coefficient setting

* Fix medication

* Add ace_medical_replacementItems config array

* checkItems performance improvement

* Treatment - cap max animation speed (#6995)

* Treatment - cap max animation speed

and add lock to prevent AF from reseting anim

* Update fnc_getBandageTime.sqf

* Use local version of setAnimSpeedCoef

* Revert "Use local version of setAnimSpeedCoef"

This reverts commit 36c22a9047.

* Move replacementItems compiling to preInit

* Improve replacementItems compiling

* Cleanup splint functions, use macros for fractures

* Rename splintCondition to canSplint

* Add cprCreatesPulse setting

* Cleanup remaining functions

* Capitalize stringtable entry names

* getStitchTime function and fix treatment locations

* Update addons/medical_treatment/functions/fnc_getHealTime.sqf

Co-Authored-By: SilentSpike <silentspike100+Github@gmail.com>
2019-06-03 10:31:46 -05:00

147 lines
5.0 KiB
Plaintext

#include "script_component.hpp"
/*
* Author: Glowbal, KoffeinFlummi, mharis001
* Starts the treatment process.
*
* Arguments:
* 0: Medic <OBJECT>
* 1: Patient <OBJECT>
* 2: Body Part <STRING>
* 3: Treatment <STRING>
*
* Return Value:
* Treatment Started <BOOL>
*
* Example:
* [player, cursorObject, "Head", "BasicBandage"] call ace_medical_treatment_fnc_treatment
*
* Public: No
*/
params ["_medic", "_patient", "_bodyPart", "_classname"];
// Delay by a frame if cursor menu is open to prevent progress bar failing
if (uiNamespace getVariable [QEGVAR(interact_menu,cursorMenuOpened), false]) exitWith {
[FUNC(treatment), _this] call CBA_fnc_execNextFrame;
};
if !(_this call FUNC(canTreat)) exitWith {false};
private _config = configFile >> QGVAR(actions) >> _classname;
// Get treatment time from config, exit if treatment time is zero
private _treatmentTime = if (isText (_config >> "treatmentTime")) then {
GET_FUNCTION(_treatmentTime,_config >> "treatmentTime");
if (_treatmentTime isEqualType {}) then {
_treatmentTime = call _treatmentTime;
};
_treatmentTime
} else {
getNumber (_config >> "treatmentTime");
};
if (_treatmentTime == 0) exitWith {false};
// Consume one of the treatment items if needed
// Store item user so that used item can be returned on failure
private _userAndItem = if (GET_NUMBER_ENTRY(_config >> "consumeItem") == 1) then {
[_medic, _patient, getArray (_config >> "items")] call FUNC(useItem);
} else {
[objNull, ""]; // Treatment does not require items to be consumed
};
_userAndItem params ["_itemUser", "_usedItem"];
// Get treatment animation for the medic
private _medicAnim = if (_medic isEqualTo _patient) then {
getText (_config >> ["animationMedicSelf", "animationMedicSelfProne"] select (stance _medic == "PRONE"));
} else {
getText (_config >> ["animationMedic", "animationMedicProne"] select (stance _medic == "PRONE"));
};
_medic setVariable [QGVAR(selectedWeaponOnTreatment), weaponState _medic];
// Adjust animation based on the current weapon of the medic
private _wpn = ["non", "rfl", "lnr", "pst"] param [["", primaryWeapon _medic, secondaryWeapon _medic, handgunWeapon _medic] find currentWeapon _medic, "non"];
_medicAnim = [_medicAnim, "[wpn]", _wpn] call CBA_fnc_replace;
// This animation is missing, use alternative
if (_medicAnim == "AinvPknlMstpSlayWlnrDnon_medic") then {
_medicAnim = "AinvPknlMstpSlayWlnrDnon_medicOther";
};
// Determine the animation length
private _animDuration = GVAR(animDurations) getVariable _medicAnim;
// These animations have transitions that take a bit longer...
if (weaponLowered _medic) then {
_animDuration = _animDuration + 0.5;
// Fix problems with lowered weapon transitions by raising the weapon first
if (currentWeapon _medic != "" && {_medicAnim != ""}) then {
_medic action ["WeaponInHand", _medic];
};
};
if (binocular _medic != "" && {binocular _medic == currentWeapon _medic}) then {
_animDuration = _animDuration + 1;
};
// Play treatment animation for medic and determine the ending animation
if (vehicle _medic == _medic && {_medicAnim != ""}) then {
private _endInAnim = "AmovP[pos]MstpS[stn]W[wpn]Dnon";
private _pos = ["knl", "pne"] select (stance _medic == "PRONE");
private _stn = "non";
if (_wpn != "non") then {
_stn = ["ras", "low"] select (weaponLowered _medic);
};
_endInAnim = [_endInAnim, "[pos]", _pos] call CBA_fnc_replace;
_endInAnim = [_endInAnim, "[stn]", _stn] call CBA_fnc_replace;
_endInAnim = [_endInAnim, "[wpn]", _wpn] call CBA_fnc_replace;
[_medic, _medicAnim] call EFUNC(common,doAnimation);
[_medic, _endInAnim] call EFUNC(common,doAnimation);
_medic setVariable [QGVAR(endInAnim), _endInAnim];
// Speed up animation based on treatment time (but cap max to prevent odd animiations/cam shake)
private _animRatio = (_animDuration / _treatmentTime) min 3;
TRACE_3("setAnimSpeedCoef",_animRatio,_animDuration,_treatmentTime);
[QEGVAR(common,setAnimSpeedCoef), [_medic, _animRatio]] call CBA_fnc_globalEvent;
if (!isNil QEGVAR(advanced_fatigue,setAnimExclusions)) then {
EGVAR(advanced_fatigue,setAnimExclusions) pushBack QUOTE(ADDON);
};
};
// Play a random treatment sound globally if defined
if (isArray (_config >> "sounds")) then {
selectRandom getArray (_config >> "sounds") params ["_file", ["_volume", 1], ["_pitch", 1], ["_distance", 10]];
playSound3D [_file, objNull, false, getPosASL _medic, _volume, _pitch, _distance];
};
GET_FUNCTION(_callbackStart,_config >> "callbackStart");
GET_FUNCTION(_callbackProgress,_config >> "callbackProgress");
if (_callbackProgress isEqualTo {}) then {
_callbackProgress = {true};
};
[_medic, _patient, _bodyPart, _classname, _itemUser, _usedItem] call _callbackStart;
[
_treatmentTime,
[_medic, _patient, _bodyPart, _classname, _itemUser, _usedItem],
FUNC(treatmentSuccess),
FUNC(treatmentFailure),
getText (_config >> "displayNameProgress"),
_callbackProgress,
["isNotInside"]
] call EFUNC(common,progressBar);
true