From 36d244a8684cfc021751aa406b1f15da67c583cc Mon Sep 17 00:00:00 2001 From: commy2 Date: Thu, 29 Sep 2016 16:00:19 +0200 Subject: [PATCH] 'modernize' primary treatment functions, fix animation issues, add anim speed scaling --- addons/medical_engine/CfgMoves.hpp | 11 + addons/medical_engine/config.cpp | 1 + .../ACE_Medical_Treatment_Actions.hpp | 38 +-- addons/medical_treatment/XEH_preInit.sqf | 24 ++ .../functions/fnc_canTreat.sqf | 118 ++++---- .../functions/fnc_litterCreate.sqf | 2 +- .../functions/fnc_treatment.sqf | 253 ++++++------------ .../functions/fnc_treatment_failure.sqf | 54 ++-- .../functions/fnc_treatment_success.sqf | 48 ++-- addons/medical_treatment/script_component.hpp | 2 + 10 files changed, 249 insertions(+), 302 deletions(-) create mode 100644 addons/medical_engine/CfgMoves.hpp diff --git a/addons/medical_engine/CfgMoves.hpp b/addons/medical_engine/CfgMoves.hpp new file mode 100644 index 0000000000..7c9f891c71 --- /dev/null +++ b/addons/medical_engine/CfgMoves.hpp @@ -0,0 +1,11 @@ + +class CfgMovesBasic; +class CfgMovesMaleSdr: CfgMovesBasic { + class States { + // fixes hand being stuck at rifle which is on the back + class AmovPknlMstpSrasWrflDnon_AinvPknlMstpSlayWrflDnon; + class AinvPknlMstpSlayWnonDnon_medicOther: AmovPknlMstpSrasWrflDnon_AinvPknlMstpSlayWrflDnon { + weaponIK = 0; + }; + }; +}; diff --git a/addons/medical_engine/config.cpp b/addons/medical_engine/config.cpp index ce65d837e9..ff8c4aa996 100644 --- a/addons/medical_engine/config.cpp +++ b/addons/medical_engine/config.cpp @@ -17,6 +17,7 @@ class CfgPatches { #include "CfgEventHandlers.hpp" #include "CfgActions.hpp" +#include "CfgMoves.hpp" #include "CfgVehicles.hpp" #include "CfgWeapons.hpp" #include "CfgInGameUI.hpp" diff --git a/addons/medical_treatment/ACE_Medical_Treatment_Actions.hpp b/addons/medical_treatment/ACE_Medical_Treatment_Actions.hpp index a8e73da609..76f078d764 100644 --- a/addons/medical_treatment/ACE_Medical_Treatment_Actions.hpp +++ b/addons/medical_treatment/ACE_Medical_Treatment_Actions.hpp @@ -1,5 +1,5 @@ -class ACE_Medical_Treatment_Actions { +class GVAR(Actions) { class Basic { class Bandage { displayName = ECSTRING(medical,Bandage); @@ -22,7 +22,7 @@ class ACE_Medical_Treatment_Actions { animationPatient = ""; animationPatientUnconscious = "AinjPpneMstpSnonWrflDnon_rolltoback"; animationPatientUnconsciousExcludeOn[] = {"ainjppnemstpsnonwrfldnon"}; - animationCaller = "AinvPknlMstpSlayWrflDnon_medicOther"; + animationCaller = "AinvPknlMstpSlayW[wpn]Dnon_medicOther"; animationCallerProne = "AinvPpneMstpSlayW[wpn]Dnon_medicOther"; animationCallerSelf = "AinvPknlMstpSlayW[wpn]Dnon_medic"; animationCallerSelfProne = "AinvPpneMstpSlayW[wpn]Dnon_medic"; @@ -37,7 +37,7 @@ class ACE_Medical_Treatment_Actions { allowedSelections[] = {"hand_l", "hand_r", "leg_l", "leg_r"}; allowSelfTreatment = 1; category = "medication"; - treatmentTime = 2; + treatmentTime = 8; items[] = {"ACE_morphine"}; callbackSuccess = QUOTE(DFUNC(treatmentBasic_morphine)); animationCaller = "AinvPknlMstpSnonWnonDnon_medic1"; @@ -50,7 +50,7 @@ class ACE_Medical_Treatment_Actions { allowSelfTreatment = 1; category = "medication"; requiredMedic = QEGVAR(medical,medicSetting_basicEpi); - treatmentTime = 3; + treatmentTime = 8; items[] = {"ACE_epinephrine"}; callbackSuccess = QUOTE(DFUNC(treatmentBasic_epipen)); animationCaller = "AinvPknlMstpSnonWnonDnon_medic1"; @@ -64,7 +64,7 @@ class ACE_Medical_Treatment_Actions { allowSelfTreatment = 0; category = "advanced"; requiredMedic = 1; - treatmentTime = 20; + treatmentTime = 12; items[] = {"ACE_bloodIV"}; // callbackSuccess = QUOTE(DFUNC(treatmentBasic_bloodbag)); callbackSuccess = QUOTE(DFUNC(treatmentIV)); @@ -85,9 +85,9 @@ class ACE_Medical_Treatment_Actions { category = "advanced"; treatmentLocations[] = {"All"}; requiredMedic = 0; - treatmentTime = 4; + treatmentTime = 20; items[] = {"ACE_bodyBag"}; - condition = "!alive (_this select 1);"; + condition = "!alive _target"; callbackSuccess = QUOTE(DFUNC(actionPlaceInBodyBag)); callbackFailure = ""; callbackProgress = ""; @@ -123,13 +123,13 @@ class ACE_Medical_Treatment_Actions { requiredMedic = 0; treatmentTime = 15; items[] = {}; - condition = QUOTE(!([(_this select 1)] call ace_common_fnc_isAwake) && EGVAR(medical,enableRevive)>0); + condition = QUOTE(!(_target call EFUNC(common,isAwake)) && EGVAR(medical,enableRevive) > 0); callbackSuccess = QUOTE(DFUNC(treatmentAdvanced_CPR)); callbackFailure = ""; - callbackProgress = "!([((_this select 0) select 1)] call ace_common_fnc_isAwake)"; + callbackProgress = QUOTE((_this select 0 select 1) call EFUNC(common,isAwake)); animationPatient = ""; animationPatientUnconscious = "AinjPpneMstpSnonWrflDnon_rolltoback"; - animationCaller = "AinvPknlMstpSlayWnonDnon_medic"; + animationCaller = "AinvPknlMstpSlayW[wpn]Dnon_medic"; animationCallerProne = "AinvPpneMstpSlayW[wpn]Dnon_medic"; animationCallerSelf = ""; animationCallerSelfProne = ""; @@ -201,7 +201,7 @@ class ACE_Medical_Treatment_Actions { items[] = {"ACE_tourniquet"}; treatmentTime = 4; callbackSuccess = QUOTE(DFUNC(treatmentTourniquet)); - condition = QUOTE(!([ARR_2(_this select 1, _this select 2)] call EFUNC(medical,hasTourniquetAppliedTo))); + condition = QUOTE(!([ARR_2(_target,_selectionName)] call EFUNC(medical,hasTourniquetAppliedTo))); litter[] = {}; }; class Morphine: fieldDressing { @@ -291,7 +291,7 @@ class ACE_Medical_Treatment_Actions { allowSelfTreatment = 0; requiredMedic = QEGVAR(medical,medicSetting_SurgicalKit); patientStateCondition = QEGVAR(medical,useCondition_SurgicalKit); - treatmentTime = "(count ((_this select 1) getVariable ['ACE_Medical_bandagedWounds', []]) * 5)"; + treatmentTime = QUOTE(count (_target getVariable [ARR_2('EGVAR(medical,bandagedWounds)',[])]) * 5); callbackSuccess = ""; callbackProgress = QUOTE(DFUNC(treatmentAdvanced_surgicalKit_onProgress)); itemConsumed = QEGVAR(medical,consumeItem_SurgicalKit); @@ -307,12 +307,12 @@ class ACE_Medical_Treatment_Actions { allowSelfTreatment = 0; requiredMedic = QEGVAR(medical,medicSetting_PAK); patientStateCondition = QEGVAR(medical,useCondition_PAK); - treatmentTime = QUOTE((_this select 1) call FUNC(treatmentAdvanced_fullHealTreatmentTime)); + treatmentTime = QUOTE(_target call FUNC(treatmentAdvanced_fullHealTreatmentTime)); callbackSuccess = QUOTE(DFUNC(treatmentAdvanced_fullHeal)); itemConsumed = QEGVAR(medical,consumeItem_PAK); animationPatient = ""; animationPatientUnconscious = "AinjPpneMstpSnonWrflDnon_rolltoback"; - animationCaller = "AinvPknlMstpSlayWnonDnon_medicOther"; + animationCaller = "AinvPknlMstpSlayW[wpn]Dnon_medicOther"; animationCallerProne = "AinvPpneMstpSlayW[wpn]Dnon_medicOther"; animationCallerSelf = ""; animationCallerSelfProne = ""; @@ -356,7 +356,7 @@ class ACE_Medical_Treatment_Actions { items[] = {}; treatmentTime = 2.5; callbackSuccess = QUOTE(DFUNC(actionRemoveTourniquet)); - condition = QUOTE([ARR_2(_this select 1, _this select 2)] call EFUNC(medical,hasTourniquetAppliedTo)); + condition = QUOTE([ARR_2(_target,_selectionName)] call EFUNC(medical,hasTourniquetAppliedTo)); displayNameProgress = ECSTRING(medical,RemovingTourniquet); litter[] = {}; }; @@ -370,13 +370,13 @@ class ACE_Medical_Treatment_Actions { requiredMedic = 0; treatmentTime = 15; items[] = {}; - condition = "!([(_this select 1)] call ace_common_fnc_isAwake)"; + condition = QUOTE(!(_target call EFUNC(common,isAwake))); callbackSuccess = QUOTE(DFUNC(treatmentAdvanced_CPR)); callbackFailure = ""; - callbackProgress = "!([((_this select 0) select 1)] call ace_common_fnc_isAwake)"; + callbackProgress = QUOTE((_this select 0 select 1) call EFUNC(common,isAwake)); animationPatient = ""; animationPatientUnconscious = "AinjPpneMstpSnonWrflDnon_rolltoback"; - animationCaller = "AinvPknlMstpSlayWnonDnon_medic"; + animationCaller = "AinvPknlMstpSlayW[wpn]Dnon_medic"; animationCallerProne = "AinvPpneMstpSlayW[wpn]Dnon_medic"; animationCallerSelf = ""; animationCallerSelfProne = ""; @@ -392,7 +392,7 @@ class ACE_Medical_Treatment_Actions { requiredMedic = 0; treatmentTime = 15; items[] = {"ACE_bodyBag"}; - condition = "!alive (_this select 1);"; + condition = "!alive _target"; callbackSuccess = QUOTE(DFUNC(actionPlaceInBodyBag)); callbackFailure = ""; callbackProgress = ""; diff --git a/addons/medical_treatment/XEH_preInit.sqf b/addons/medical_treatment/XEH_preInit.sqf index a7feade1c3..6d203ba790 100644 --- a/addons/medical_treatment/XEH_preInit.sqf +++ b/addons/medical_treatment/XEH_preInit.sqf @@ -4,4 +4,28 @@ ADDON = false; #include "XEH_PREP.hpp" +// config to determine animation acceleration coefficient +// adjusting these is trail and error +// if the animation is cut of ingame, increase these values +// if the unit idles too much, decrease them +GVAR(animDurations) = [] call CBA_fnc_createNamespace; + +{ + GVAR(animDurations) setVariable _x; +} forEach [ + ["AinvPknlMstpSlayWnonDnon_medic", 9], + ["AinvPknlMstpSlayWnonDnon_medicOther", 8.5], + ["AinvPpneMstpSlayWnonDnon_medic", 7.5], + ["AinvPpneMstpSlayWnonDnon_medicOther", 8.5], + ["AinvPknlMstpSlayWrflDnon_medic", 7], + ["AinvPknlMstpSlayWrflDnon_medicOther", 7], + ["AinvPpneMstpSlayWrflDnon_medic", 9.5], + ["AinvPpneMstpSlayWrflDnon_medicOther", 9], + ["AinvPknlMstpSlayWlnrDnon_medic", 14], + ["AinvPknlMstpSlayWpstDnon_medic", 10], + ["AinvPknlMstpSlayWpstDnon_medicOther", 10], + ["AinvPpneMstpSlayWpstDnon_medic", 10], + ["AinvPpneMstpSlayWpstDnon_medicOther", 8.5] +]; + ADDON = true; diff --git a/addons/medical_treatment/functions/fnc_canTreat.sqf b/addons/medical_treatment/functions/fnc_canTreat.sqf index 4625a554c0..e4dabecf0a 100644 --- a/addons/medical_treatment/functions/fnc_canTreat.sqf +++ b/addons/medical_treatment/functions/fnc_canTreat.sqf @@ -16,85 +16,103 @@ * * Public: Yes */ - +#define DEBUG_MODE_FULL #include "script_component.hpp" params ["_caller", "_target", "_selectionName", "_className"]; -if !(_target isKindOf "CAManBase") exitWith { false }; +if !(_target isKindOf "CAManBase") exitWith {false}; -private _config = (configFile >> "ACE_Medical_Treatment_Actions" >> (["Basic", "Advanced"] select (EGVAR(medical,level)>=2)) >> _className); +private _config = configFile >> QGVAR(Actions) >> CUR_LEVEL >> _className; if !(isClass _config) exitwith {false}; -// Allow self treatment check -if (_caller == _target && {getNumber (_config >> "allowSelfTreatment") == 0}) exitwith {false}; +// allow self treatment check +private _isSelf = _caller isEqualTo _target; -private _medicRequired = if (isNumber (_config >> "requiredMedic")) then { - getNumber (_config >> "requiredMedic"); +if (_isSelf && {getNumber (_config >> "allowSelfTreatment") == 0}) exitwith {false}; + +private _medicRequired = 0; + +if (isNumber (_config >> "requiredMedic")) then { + _medicRequired = getNumber (_config >> "requiredMedic"); } else { - // Check for required class - if (isText (_config >> "requiredMedic")) exitwith { - missionNamespace getVariable [getText (_config >> "requiredMedic"), 0]; + if (isText (_config >> "requiredMedic")) then { + _medicRequired = missionNamespace getVariable [getText (_config >> "requiredMedic"), 0]; }; - 0; }; -if !([_caller, _medicRequired] call EFUNC(medical,isMedic)) exitwith { false }; - -private _items = getArray (_config >> "items"); -if (count _items > 0 && {!([_caller, _target, _items] call FUNC(hasItems))}) exitwith { false }; +if !([_caller, _medicRequired] call EFUNC(medical,isMedic)) exitWith {false}; +// check selection private _allowedSelections = getArray (_config >> "allowedSelections"); -if !("All" in _allowedSelections || {(_selectionName in _allowedSelections)}) exitwith { false }; -private _return = true; -if (getText (_config >> "condition") != "") then { - private _condition = getText (_config >> "condition"); - if (isnil _condition) then { +if !("All" in _allowedSelections || {(_selectionName in _allowedSelections)}) exitWith {false}; + +// check item +private _items = getArray (_config >> "items"); + +if (count _items > 0 && {!([_caller, _target, _items] call FUNC(hasItems))}) exitWith {false}; + +private _condition = true; + +if (isText (_config >> "condition")) then { + _condition = getText (_config >> "condition"); + + if (_condition isEqualTo "") exitWith { + _condition = true; + }; + + if (isNil _condition) then { _condition = compile _condition; } else { _condition = missionNamespace getVariable _condition; }; - if (_condition isEqualType false) then { - _return = _condition; - } else { - _return = [_caller, _target, _selectionName, _className] call _condition; + + if !(_condition isEqualType false) then { + _condition = call _condition; }; }; -if (!_return) exitwith { - false; -}; -private _patientStateCondition = if (isText(_config >> "patientStateCondition")) then { - missionNamespace getVariable [getText(_config >> "patientStateCondition"), 0] +if !(_condition) exitWith {false}; + +private _patientStateCondition = 0; + +if (isNumber (_config >> "patientStateCondition")) then { + _patientStateCondition = getNumber (_config >> "patientStateCondition"); } else { - getNumber(_config >> "patientStateCondition") + if (isText (_config >> "patientStateCondition")) then { + _patientStateCondition = missionNamespace getVariable [getText (_config >> "patientStateCondition"), 0]; + }; }; -if (_patientStateCondition == 1 && {!([_target] call EFUNC(medical,isInStableCondition))}) exitwith {false}; +if (_patientStateCondition == 1 && {!([_target] call EFUNC(medical,isInStableCondition))}) exitWith {false}; + +// check allowed locations private _locations = getArray (_config >> "treatmentLocations"); -if ("All" in _locations) exitwith { true }; -private _medFacility = {([_caller] call EFUNC(medical,isInMedicalFacility)) || ([_target] call EFUNC(medical,isInMedicalFacility))}; -private _medVeh = {([_caller] call EFUNC(medical,isInMedicalVehicle)) || ([_target] call EFUNC(medical,isInMedicalVehicle))}; +if ("All" in _locations) then { + _locations = true; +} else { + private _medFacility = {([_caller] call EFUNC(medical,isInMedicalFacility)) || ([_target] call EFUNC(medical,isInMedicalFacility))}; + private _medVeh = {([_caller] call EFUNC(medical,isInMedicalVehicle)) || ([_target] call EFUNC(medical,isInMedicalVehicle))}; -{ - if (_x == "field") exitwith {_return = true;}; - if (_x == "MedicalFacility" && _medFacility) exitwith {_return = true;}; - if (_x == "MedicalVehicle" && _medVeh) exitwith {_return = true;}; - if !(isnil _x) exitwith { - private _val = missionNamespace getVariable _x; - if (_val isEqualType 0) then { - _return = switch (_val) do { - case 0: {true}; //AdvancedMedicalSettings_anywhere - case 1: {call _medVeh}; //AdvancedMedicalSettings_vehicle - case 2: {call _medFacility}; //AdvancedMedicalSettings_facility - case 3: {(call _medFacility) || {call _medVeh}}; //AdvancedMedicalSettings_vehicleAndFacility - default {false}; //Disabled + { + if (_x == "field") exitWith { _locations = true; }; + if (_x == "MedicalFacility" && _medFacility) exitWith { _locations = true; }; + if (_x == "MedicalVehicle" && _medVeh) exitWith { _locations = true; }; + if !(isNil _x) exitWith { + _locations = missionNamespace getVariable _x; + + if !(_locations isEqualType false) then { + if (_locations isEqualTo 0) exitWith { _locations = true; }; //AdvancedMedicalSettings_anywhere + if (_locations isEqualTo 1) exitWith { _locations = call _medVeh; }; //AdvancedMedicalSettings_vehicle + if (_locations isEqualTo 2) exitWith { _locations = call _medFacility; }; //AdvancedMedicalSettings_facility + if (_locations isEqualTo 3) exitWith { _locations = call _medFacility || {call _medVeh}; }; //AdvancedMedicalSettings_vehicleAndFacility + _locations = false; //Disabled }; }; - }; -} foreach _locations; + } forEach _locations; +}; -_return; +_locations diff --git a/addons/medical_treatment/functions/fnc_litterCreate.sqf b/addons/medical_treatment/functions/fnc_litterCreate.sqf index 3104f4b2a4..120f9f85b2 100644 --- a/addons/medical_treatment/functions/fnc_litterCreate.sqf +++ b/addons/medical_treatment/functions/fnc_litterCreate.sqf @@ -32,7 +32,7 @@ if !(EGVAR(medical,allowLitterCreation)) exitWith {}; // Don't create litter if medic or patient are inside a vehicle if (vehicle _caller != _caller || {vehicle _target != _target}) exitWith {}; -private _config = configFile >> "ACE_Medical_Treatment_Actions" >> ["Basic", "Advanced"] select (EGVAR(medical,level) >= 2) >> _className; +private _config = configFile >> "ACE_Medical_Treatment_Actions" >> CUR_LEVEL >> _className; if !(isClass _config) exitWith {TRACE_1("No action config",_className);}; if !(isArray (_config >> "litter")) exitWith {TRACE_1("No litter config",_className);}; diff --git a/addons/medical_treatment/functions/fnc_treatment.sqf b/addons/medical_treatment/functions/fnc_treatment.sqf index 754b1e1f0f..c0b8db1092 100644 --- a/addons/medical_treatment/functions/fnc_treatment.sqf +++ b/addons/medical_treatment/functions/fnc_treatment.sqf @@ -18,131 +18,56 @@ params ["_caller", "_target", "_selectionName", "_className"]; -// If the cursorMenu is open, the loading bar will fail. If we execute the function one frame later, it will work fine -if (uiNamespace getVariable [QEGVAR(interact_menu,cursorMenuOpened),false]) exitwith { +// if the cursorMenu is open, the loading bar will fail. If we execute the function one frame later, it will work fine +if (uiNamespace getVariable [QEGVAR(interact_menu,cursorMenuOpened), false]) exitWith { [DFUNC(treatment), _this] call CBA_fnc_execNextFrame; }; -if !(_target isKindOf "CAManBase") exitWith {false}; +if !([_caller, _target, _selectionName, _className] call FUNC(canTreat)) exitWith {false}; -private _config = (configFile >> "ACE_Medical_Treatment_Actions" >> "Basic" >> _className); -if (EGVAR(medical,level) >= 2) then { - _config = (configFile >> "ACE_Medical_Treatment_Actions" >> "Advanced" >> _className); -}; +private _config = configFile >> QGVAR(Actions) >> CUR_LEVEL >> _className; -if !(isClass _config) exitwith {false}; +private _consumeItems = 0; -// Allow self treatment check -if (_caller == _target && {getNumber (_config >> "allowSelfTreatment") == 0}) exitwith {false}; - -private _medicRequired = if (isNumber (_config >> "requiredMedic")) then { - getNumber (_config >> "requiredMedic"); +if (isNumber (_config >> "itemConsumed")) then { + _consumeItems = getNumber (_config >> "itemConsumed"); } else { - // Check for required class - if (isText (_config >> "requiredMedic")) exitwith { - missionNamespace getVariable [(getText (_config >> "requiredMedic")), 0]; - }; - 0; -}; - -if !([_caller, _medicRequired] call EFUNC(medical,isMedic)) exitwith {false}; - -private _allowedSelections = getArray (_config >> "allowedSelections"); -if !("All" in _allowedSelections || {(_selectionName in _allowedSelections)}) exitwith {false}; - -// Check item -private _items = getArray (_config >> "items"); -if (count _items > 0 && {!([_caller, _target, _items] call FUNC(hasItems))}) exitwith {false}; - -private _return = true; -if (isText (_config >> "Condition")) then { - private _condition = getText(_config >> "condition"); - if (_condition != "") then { - if (isnil _condition) then { - _condition = compile _condition; - } else { - _condition = missionNamespace getVariable _condition; - }; - if (_condition isEqualType false) then { - _return = _condition; - } else { - _return = [_caller, _target, _selectionName, _className] call _condition; - }; + if (isText (_config >> "itemConsumed")) then { + _consumeItems = missionNamespace getVariable [getText (_config >> "itemConsumed"), 0]; }; }; -if (!_return) exitwith {false}; - -private _patientStateCondition = if (isText(_config >> "patientStateCondition")) then { - missionNamespace getVariable [getText(_config >> "patientStateCondition"), 0] -} else { - getNumber(_config >> "patientStateCondition") -}; -if (_patientStateCondition == 1 && {!([_target] call EFUNC(medical,isInStableCondition))}) exitwith {false}; - -// Check allowed locations -private _locations = getArray (_config >> "treatmentLocations"); - -if ("All" in _locations) then { - _return = true; -} else { - private _medFacility = {([_caller] call EFUNC(medical,isInMedicalFacility)) || ([_target] call EFUNC(medical,isInMedicalFacility))}; - private _medVeh = {([_caller] call EFUNC(medical,isInMedicalVehicle)) || ([_target] call EFUNC(medical,isInMedicalVehicle))}; - - { - if (_x == "field") exitwith {_return = true;}; - if (_x == "MedicalFacility" && _medFacility) exitwith {_return = true;}; - if (_x == "MedicalVehicle" && _medVeh) exitwith {_return = true;}; - if !(isnil _x) exitwith { - private _val = missionNamespace getVariable _x; - if (_val isEqualType 0) then { - _return = switch (_val) do { - case 0: {true}; //AdvancedMedicalSettings_anywhere - case 1: {call _medVeh}; //AdvancedMedicalSettings_vehicle - case 2: {call _medFacility}; //AdvancedMedicalSettings_facility - case 3: {(call _medFacility) || {call _medVeh}}; //AdvancedMedicalSettings_vehicleAndFacility - default {false}; //Disabled - }; - }; - }; - } foreach _locations; -}; - -if !(_return) exitwith {false}; private _usersOfItems = []; -private _consumeItems = if (isNumber (_config >> "itemConsumed")) then { - getNumber (_config >> "itemConsumed"); -} else { - // Check for required class - if (isText (_config >> "itemConsumed")) exitwith { - missionNamespace getVariable [(getText (_config >> "itemConsumed")), 0]; - }; - 0; -}; + if (_consumeItems > 0) then { _usersOfItems = ([_caller, _target, _items] call FUNC(useItems)) select 1; }; -// Parse the config for the progress callback +// parse the config for the progress callback private _callbackProgress = getText (_config >> "callbackProgress"); -if (_callbackProgress == "") then { + +if (_callbackProgress isEqualTo "") then { _callbackProgress = "true"; }; + if (isNil _callbackProgress) then { _callbackProgress = compile _callbackProgress; } else { _callbackProgress = missionNamespace getVariable _callbackProgress; }; -// Patient Animation +// play patient animation private _patientAnim = getText (_config >> "animationPatient"); + if (_target getVariable ["ACE_isUnconscious", false] && EGVAR(medical,allowUnconsciousAnimationOnTreatment)) then { if !(animationState _target in (getArray (_config >> "animationPatientUnconsciousExcludeOn"))) then { _patientAnim = getText (_config >> "animationPatientUnconscious"); }; }; -if (_caller != _target && {vehicle _target == _target} && {_patientAnim != ""}) then { +private _isSelf = _caller isEqualTo _target; + +if (!_isSelf && {vehicle _target == _target} && {_patientAnim != ""}) then { if (_target getVariable ["ACE_isUnconscious", false]) then { [_target, _patientAnim, 2, true] call EFUNC(common,doAnimation); } else { @@ -150,71 +75,65 @@ if (_caller != _target && {vehicle _target == _target} && {_patientAnim != ""}) }; }; -// Player Animation -private _callerAnim = [getText (_config >> "animationCaller"), getText (_config >> "animationCallerProne")] select (stance _caller == "PRONE"); -if (_caller == _target) then { - _callerAnim = [getText (_config >> "animationCallerSelf"), getText (_config >> "animationCallerSelfProne")] select (stance _caller == "PRONE"); -}; +// play animation +private "_callerAnim"; -_caller setVariable [QGVAR(selectedWeaponOnTreatment), (weaponState _caller)]; - -// Cannot use secondairy weapon for animation -if (currentWeapon _caller == secondaryWeapon _caller) then { - _caller selectWeapon (primaryWeapon _caller); -}; - -private _wpn = switch (true) do { - case ((currentWeapon _caller) == ""): {"non"}; - case ((currentWeapon _caller) == (primaryWeapon _caller)): {"rfl"}; - case ((currentWeapon _caller) == (handgunWeapon _caller)): {"pst"}; - default {"non"}; -}; -private _callerAnim = [_callerAnim, "[wpn]", _wpn] call CBA_fnc_replace; -if (vehicle _caller == _caller && {_callerAnim != ""}) then { - if (primaryWeapon _caller == "") then { - _caller addWeapon "ACE_FakePrimaryWeapon"; - }; - if (currentWeapon _caller == "") then { - _caller selectWeapon (primaryWeapon _caller); // unit always has a primary weapon here - }; - - if (isWeaponDeployed _caller) then { - TRACE_1("Weapon Deployed, breaking out first",(stance _caller)); - [_caller, "", 0] call EFUNC(common,doAnimation); - }; - - if ((stance _caller) == "STAND") then { - switch (_wpn) do {//If standing, end in a crouched animation based on their current weapon - case ("rfl"): {_caller setVariable [QGVAR(treatmentPrevAnimCaller), "AmovPknlMstpSrasWrflDnon"];}; - case ("pst"): {_caller setVariable [QGVAR(treatmentPrevAnimCaller), "AmovPknlMstpSrasWpstDnon"];}; - case ("non"): {_caller setVariable [QGVAR(treatmentPrevAnimCaller), "AmovPknlMstpSnonWnonDnon"];}; - }; - } else { - _caller setVariable [QGVAR(treatmentPrevAnimCaller), animationState _caller]; - }; - [_caller, _callerAnim] call EFUNC(common,doAnimation); -}; - -//Get treatment time -private _treatmentTime = if (isNumber (_config >> "treatmentTime")) then { - getNumber (_config >> "treatmentTime"); +if (_isSelf) then { + _callerAnim = getText (_config >> ["animationCallerSelf", "animationCallerSelfProne"] select (stance _caller == "PRONE")); } else { - if (isText (_config >> "treatmentTime")) exitwith { - private _treatmentTimeConfig = getText(_config >> "treatmentTime"); - if (isnil _treatmentTimeConfig) then { - _treatmentTimeConfig = compile _treatmentTimeConfig; - } else { - _treatmentTimeConfig = missionNamespace getVariable _treatmentTimeConfig; - }; - if (_treatmentTimeConfig isEqualType 0) exitwith { - _treatmentTimeConfig; - }; - [_caller, _target, _selectionName, _className] call _treatmentTimeConfig; - }; - 0; + _callerAnim = getText (_config >> ["animationCaller", "animationCallerProne"] select (stance _caller == "PRONE")); }; -// Start treatment +_caller setVariable [QGVAR(selectedWeaponOnTreatment), weaponState _caller]; + +private _wpn = ["non", "rfl", "lnr", "pst"] param [["", primaryWeapon _caller, secondaryWeapon _caller, handgunWeapon _caller] find currentWeapon _caller, "non"]; + +_callerAnim = [_callerAnim, "[wpn]", _wpn] call CBA_fnc_replace; + +if (vehicle _caller == _caller && {_callerAnim != ""}) then { + private _endInAnim = "AmovP[pos]MstpS[stn]W[wpn]Dnon"; + + private _pos = ["knl", "pne"] select (stance _caller == "PRONE"); + private _stn = "non"; + + if (_wpn != "non") then { + _stn = ["ras", "low"] select (weaponLowered _caller); + }; + + _endInAnim = [_endInAnim, "[pos]", _pos] call CBA_fnc_replace; + _endInAnim = [_endInAnim, "[stn]", _stn] call CBA_fnc_replace; + _endInAnim = [_endInAnim, "[wpn]", _wpn] call CBA_fnc_replace; + TRACE_1("",_endInAnim); + + [_caller, _callerAnim] call EFUNC(common,doAnimation); + [_caller, _endInAnim] call EFUNC(common,doAnimation); + _caller setVariable [QGVAR(endInAnim), _endInAnim]; +}; + +// get treatment time +private _treatmentTime = 0; + +// reads number from config. supports variables and code expressions +if (isNumber (_config >> "treatmentTime")) then { + _treatmentTime = getNumber (_config >> "treatmentTime"); +} else { + if (isText (_config >> "treatmentTime")) then { + _treatmentTime = getText (_config >> "treatmentTime"); + + if (isNil _treatmentTime) then { + _treatmentTime = compile _treatmentTime; + } else { + _treatmentTime = missionNamespace getVariable _treatmentTime; + }; + + if !(_treatmentTime isEqualType 0) then { + _treatmentTime = call _treatmentTime; + }; + }; +}; +TRACE_1("",_treatmentTime); + +// start treatment [ _treatmentTime, [_caller, _target, _selectionName, _className, _items, _usersOfItems], @@ -225,22 +144,26 @@ private _treatmentTime = if (isNumber (_config >> "treatmentTime")) then { ["isnotinside"] ] call EFUNC(common,progressBar); -// Display Icon +// speed up animation depending on treatment time +private _animDuration = GVAR(animDurations) getVariable _callerAnim; + +if (!isNil "_animDuration") then { + _caller setAnimSpeedCoef (_animDuration / _treatmentTime); + TRACE_2("",_animDuration,_treatmentTime); +}; + +// display icon private _iconDisplayed = getText (_config >> "actionIconPath"); + if (_iconDisplayed != "") then { - [QGVAR(treatmentActionIcon), true, _iconDisplayed, [1,1,1,1], getNumber(_config >> "actionIconDisplayTime")] call EFUNC(common,displayIcon); + [QGVAR(treatmentActionIcon), true, _iconDisplayed, [1,1,1,1], getNumber (_config >> "actionIconDisplayTime")] call EFUNC(common,displayIcon); }; // handle display of text/hints -private _displayText = ""; -if (_target != _caller) then { - _displayText = getText(_config >> "displayTextOther"); -} else { - _displayText = getText(_config >> "displayTextSelf"); -}; +private _displayText = getText (_config >> ["displayTextOther", "displayTextSelf"] select _isSelf); if (_displayText != "") then { - [QEGVAR(common,displayTextStructured), [[_displayText, [_caller] call EFUNC(common,getName), [_target] call EFUNC(common,getName)], 1.5, _caller], [_caller]] call CBA_fnc_targetEvent; + [QEGVAR(common,displayTextStructured), [[_displayText, _caller call EFUNC(common,getName), _target call EFUNC(common,getName)], 1.5, _caller], _caller] call CBA_fnc_targetEvent; }; -true; +true diff --git a/addons/medical_treatment/functions/fnc_treatment_failure.sqf b/addons/medical_treatment/functions/fnc_treatment_failure.sqf index d3e9644dfb..8810640f5b 100644 --- a/addons/medical_treatment/functions/fnc_treatment_failure.sqf +++ b/addons/medical_treatment/functions/fnc_treatment_failure.sqf @@ -20,54 +20,38 @@ params ["_args"]; _args params ["_caller", "_target", "_selectionName", "_className", "_items", "_usersOfItems"]; -if (primaryWeapon _caller == "ACE_FakePrimaryWeapon") then { - _caller removeWeapon "ACE_FakePrimaryWeapon"; -}; -if (vehicle _caller == _caller) then { - private _lastAnim = _caller getVariable [QGVAR(treatmentPrevAnimCaller), ""]; - //Don't play another medic animation (when player is rapidily treating) - TRACE_2("Reseting to old animation", animationState player, _lastAnim); - switch (toLower _lastAnim) do { - case "ainvpknlmstpslaywrfldnon_medic": {_lastAnim = "AmovPknlMstpSrasWrflDnon"}; - case "ainvppnemstpslaywrfldnon_medic": {_lastAnim = "AmovPpneMstpSrasWrflDnon"}; - case "ainvpknlmstpslaywnondnon_medic": {_lastAnim = "AmovPknlMstpSnonWnonDnon"}; - case "ainvppnemstpslaywpstdnon_medic": {_lastAnim = "AinvPpneMstpSlayWpstDnon"}; - case "ainvpknlmstpslaywpstdnon_medic": {_lastAnim = "AmovPknlMstpSrasWpstDnon"}; - }; +// switch to end anim immediately +private _endInAnim = _caller getVariable QGVAR(endInAnim); - [_caller, _lastAnim, 2] call EFUNC(common,doAnimation); -}; -_caller setVariable [QGVAR(treatmentPrevAnimCaller), nil]; - -private _weaponSelect = (_caller getVariable [QGVAR(selectedWeaponOnTreatment), []]); -if ((_weaponSelect params [["_previousWeapon", ""]]) && {(_previousWeapon != "") && {_previousWeapon in (weapons _caller)}}) then { - for "_index" from 0 to 99 do { - _caller action ["SwitchWeapon", _caller, _caller, _index]; - //Just check weapon, muzzle and mode (ignore ammo in case they were reloading) - if (((weaponState _caller) select [0,3]) isEqualTo (_weaponSelect select [0,3])) exitWith {TRACE_1("Restoring", (weaponState _caller));}; - if ((weaponState _caller) isEqualTo ["","","","",0]) exitWith {ERROR("weaponState not found");}; +if (!isNil "_endInAnim") then { + if (animationState _caller != _endInAnim) then { + [_caller, _endInAnim, 2] call EFUNC(common,doAnimation); }; -} else { - _caller action ["SwitchWeapon", _caller, _caller, 99]; + _caller setVariable [QGVAR(endInAnim), nil]; + TRACE_1("abort",_endInAnim); }; +// reset sped up animations +_caller setAnimSpeedCoef 1; + { _x params ["_unit", "_item"]; _unit addItem _item; } forEach _usersOfItems; // Record specific callback -private _config = (configFile >> "ACE_Medical_Treatment_Actions" >> "Basic" >> _className); -if (EGVAR(medical,level) >= 2) then { - _config = (configFile >> "ACE_Medical_Treatment_Actions" >> "Advanced" >> _className); -}; +private _config = configFile >> QGVAR(Actions) >> CUR_LEVEL >> _className; private _callback = getText (_config >> "callbackFailure"); -_callback = if (isNil _callback) then { - compile _callback + +if (isNil _callback) then { + _callback = compile _callback; } else { - missionNamespace getVariable _callback + _callback = missionNamespace getVariable _callback; +}; + +if !(_callback isEqualType {}) then { + _callback = {TRACE_1("callback was NOT code",_callback)}; }; -if (!(_callback isEqualType {})) then {_callback = {TRACE_1("callback was NOT code",_callback)};}; _args call _callback; diff --git a/addons/medical_treatment/functions/fnc_treatment_success.sqf b/addons/medical_treatment/functions/fnc_treatment_success.sqf index 454ae1baa2..cbbeb4b5b7 100644 --- a/addons/medical_treatment/functions/fnc_treatment_success.sqf +++ b/addons/medical_treatment/functions/fnc_treatment_success.sqf @@ -20,50 +20,34 @@ params ["_args"]; _args params ["_caller", "_target", "_selectionName", "_className", "_items", "_usersOfItems"]; -if (primaryWeapon _caller == "ACE_FakePrimaryWeapon") then { - _caller removeWeapon "ACE_FakePrimaryWeapon"; -}; -if (vehicle _caller == _caller) then { - private _lastAnim = _caller getVariable [QGVAR(treatmentPrevAnimCaller), ""]; - //Don't play another medic animation (when player is rapidily treating) - TRACE_2("Reseting to old animation", animationState player, _lastAnim); - switch (toLower _lastAnim) do { - case "ainvpknlmstpslaywrfldnon_medic": {_lastAnim = "AmovPknlMstpSrasWrflDnon"}; - case "ainvppnemstpslaywrfldnon_medic": {_lastAnim = "AmovPpneMstpSrasWrflDnon"}; - case "ainvpknlmstpslaywnondnon_medic": {_lastAnim = "AmovPknlMstpSnonWnonDnon"}; - case "ainvppnemstpslaywpstdnon_medic": {_lastAnim = "AinvPpneMstpSlayWpstDnon"}; - case "ainvpknlmstpslaywpstdnon_medic": {_lastAnim = "AmovPknlMstpSrasWpstDnon"}; - }; +// switch to end anim immediately +private _endInAnim = _caller getVariable QGVAR(endInAnim); - [_caller, _lastAnim, 2] call EFUNC(common,doAnimation); -}; -_caller setVariable [QGVAR(treatmentPrevAnimCaller), nil]; - -private _weaponSelect = (_caller getVariable [QGVAR(selectedWeaponOnTreatment), []]); -if ((_weaponSelect params [["_previousWeapon", ""]]) && {(_previousWeapon != "") && {_previousWeapon in (weapons _caller)}}) then { - for "_index" from 0 to 99 do { - _caller action ["SwitchWeapon", _caller, _caller, _index]; - //Just check weapon, muzzle and mode (ignore ammo in case they were reloading) - if (((weaponState _caller) select [0,3]) isEqualTo (_weaponSelect select [0,3])) exitWith {TRACE_1("Restoring", (weaponState _caller));}; - if ((weaponState _caller) isEqualTo ["","","","",0]) exitWith {ERROR("weaponState not found");}; +if (!isNil "_endInAnim") then { + if (animationState _caller != _endInAnim) then { + [_caller, _endInAnim, 2] call EFUNC(common,doAnimation); }; -} else { - _caller action ["SwitchWeapon", _caller, _caller, 99]; + _caller setVariable [QGVAR(endInAnim), nil]; + TRACE_1("abort",_endInAnim); }; +// reset sped up animations +_caller setAnimSpeedCoef 1; + // Record specific callback -private _config = (configFile >> "ACE_Medical_Treatment_Actions" >> "Basic" >> _className); -if (EGVAR(medical,level) >= 2) then { - _config = (configFile >> "ACE_Medical_Treatment_Actions" >> "Advanced" >> _className); -}; +private _config = configFile >> QGVAR(Actions) >> CUR_LEVEL >> _className; private _callback = getText (_config >> "callbackSuccess"); + if (isNil _callback) then { _callback = compile _callback; } else { _callback = missionNamespace getVariable _callback; }; -if (!(_callback isEqualType {})) then {_callback = {TRACE_1("callback was NOT code",_callback)};}; + +if !(_callback isEqualType {}) then { + _callback = {TRACE_1("callback was NOT code",_callback)}; +}; //Get current blood loose on limb (for "bloody" litter) private _bloodLossOnSelection = 0; diff --git a/addons/medical_treatment/script_component.hpp b/addons/medical_treatment/script_component.hpp index 2144b12a9f..cfc16518f8 100644 --- a/addons/medical_treatment/script_component.hpp +++ b/addons/medical_treatment/script_component.hpp @@ -16,3 +16,5 @@ #endif #include "\z\ace\addons\main\script_macros.hpp" + +#define CUR_LEVEL (["Basic", "Advanced"] select (EGVAR(medical,level) >= 2))