From b3e7431e6766d8f9ff5b2239e2f9b1166ce94fff Mon Sep 17 00:00:00 2001 From: Glowbal Date: Sat, 21 Feb 2015 21:09:57 +0100 Subject: [PATCH] Added new treatment framework --- addons/medical/ACE_Medical_Treatments.hpp | 21 +++++ addons/medical/XEH_preInit.sqf | 5 +- addons/medical/config.cpp | 3 +- addons/medical/functions/fnc_canTreat.sqf | 48 +++++++++++ addons/medical/functions/fnc_treatment.sqf | 83 +++++++++++++++---- .../functions/fnc_treatmentCallback.sqf | 32 ------- .../fnc_treatmentCallback_advanced.sqf | 27 ------ .../functions/fnc_treatmentCallback_basic.sqf | 27 ------ 8 files changed, 141 insertions(+), 105 deletions(-) create mode 100644 addons/medical/ACE_Medical_Treatments.hpp create mode 100644 addons/medical/functions/fnc_canTreat.sqf delete mode 100644 addons/medical/functions/fnc_treatmentCallback.sqf delete mode 100644 addons/medical/functions/fnc_treatmentCallback_advanced.sqf delete mode 100644 addons/medical/functions/fnc_treatmentCallback_basic.sqf diff --git a/addons/medical/ACE_Medical_Treatments.hpp b/addons/medical/ACE_Medical_Treatments.hpp new file mode 100644 index 0000000000..41c540ea79 --- /dev/null +++ b/addons/medical/ACE_Medical_Treatments.hpp @@ -0,0 +1,21 @@ + +class ACE_Medical_Treatments { + class ACE_Bandaging { + // Which locations can this treatment action be used? Available: Field, MedicalFacility, MedicalVehicle, All. + treatmentLocations[] = {"Field", "MedicalFacility", "MedicalVehicle"}; + // What is the level of medical skill required for this treatment action? 0 = all soldiers, 1 = medic, 2 = doctor + requiredMedic = 0; + // Available under which medical level settings? 0 = basic, 1 = advanced. + availableLevels[] = {0, 1}; + // The time it takes for a treatment action to complete. Time is in seconds. + treatmentTime = 5; + // Item required for the action. Leave empty for no item required. + items[] = {"ace_sampleItem"}; + // Callbacks + callbackSuccess = "hint ""Success"";"; + callbackFailure = "hint ""Failure "";"; + onProgress = ""; + animationPatient = ""; + animationCaller = ""; + }; +}; diff --git a/addons/medical/XEH_preInit.sqf b/addons/medical/XEH_preInit.sqf index 5692b9a663..e49239511a 100644 --- a/addons/medical/XEH_preInit.sqf +++ b/addons/medical/XEH_preInit.sqf @@ -26,9 +26,8 @@ PREP(addUnconsciousCondition); PREP(setDead); PREP(playInjuredSound); PREP(treatment); -PREP(treatmentCallback); -PREP(treatmentCallback_basic); -PREP(treatmentCallback_advanced); +PREP(canTreat); + GVAR(injuredUnitCollection) = []; diff --git a/addons/medical/config.cpp b/addons/medical/config.cpp index 6b4220b900..51044b37d8 100644 --- a/addons/medical/config.cpp +++ b/addons/medical/config.cpp @@ -6,7 +6,7 @@ class CfgPatches { weapons[] = {}; requiredVersion = REQUIRED_VERSION; requiredAddons[] = {ace_common, ace_interaction}; - author[] = {""}; + author[] = {"Glowbal", "KoffienFlummi"}; authorUrl = ""; VERSION_CONFIG; }; @@ -14,3 +14,4 @@ class CfgPatches { #include "CfgEventHandlers.hpp" #include "CfgVehicles.hpp" +#include "ACE_Medical_Treatments.hpp" diff --git a/addons/medical/functions/fnc_canTreat.sqf b/addons/medical/functions/fnc_canTreat.sqf new file mode 100644 index 0000000000..efbba0e9a1 --- /dev/null +++ b/addons/medical/functions/fnc_canTreat.sqf @@ -0,0 +1,48 @@ +/* + * Author: Glowbal + * Check if the treatment action can be performed. + * + * Arguments: + * 0: The caller + * 1: The target + * 2: Selection name + * 3: ACE_Medical_Treatments Classname + * + * ReturnValue: + * Can Treat + * + * Public: Yes + */ + +#include "script_component.hpp" + +private ["_caller", "_target", "_selectionName", "_className", "_config", "_availableLevels", "_medicRequired", "_items", "_locations", "_return"]; +_caller = _this select 0; +_target = _this select 1; +_selectionName = _this select 2; +_className = _this select 3; + +_config = (ConfigFile >> "ACE_Medical_Treatments" >> _className); +if !(isClass _config) exitwith {false}; + +_availableLevels = getArray (_config >> "availableLevels"); +if !(GVAR(level) in _availableLevels) exitwith {false}; + +_medicRequired = getNumber (_config >> "requiredMedic"); +if !([_caller, _medicRequired] call FUNC(isMedic) || [_target, _medicRequired] call FUNC(isMedic)) exitwith {false}; + +_items = getArray (_config >> "items"); +if (count _items > 0 && {!([_caller, _target, _items] call FUNC(hasItems))}) exitwith {false}; + +_locations = getArray (_config >> "treatmentLocations"); + +if ("All" in _locations) exitwith {true}; + +_return = false; +{ + if (_x == "field") exitwith {_return = true;}; + if (_x == "MedicalFacility" && {[_caller, _target] call FUNC(inMedicalFacility)}) exitwith {_return = true;}; + if (_x == "MedicalVehicle" && {[_caller, _target] call FUNC(inMedicalVehicle)}) exitwith {_return = true;}; +}foreach _locations; + +_return; diff --git a/addons/medical/functions/fnc_treatment.sqf b/addons/medical/functions/fnc_treatment.sqf index 772e73d455..e51ad8341f 100644 --- a/addons/medical/functions/fnc_treatment.sqf +++ b/addons/medical/functions/fnc_treatment.sqf @@ -1,34 +1,87 @@ /* - * Author: KoffeinFlummi + * Author: Glowbal, KoffeinFlummi * Starts the treatment process * * Arguments: * 0: The medic * 1: The patient - * 2: The treatment type/item - * 3+: Additional paramters + * 2: SelectionName + * 3: Treatment classname * * Return Value: - * nil + * Succesful treatment started * * Public: Yes */ #include "script_component.hpp" -_medic = _this select 0; -_patient = _this select 1; -_type = _this select 2; +private ["_caller", "_target", "_selectionName", "_className", "_config", "_availableLevels", "_medicRequired", "_items", "_locations", "_return", "_callbackSuccess", "_callbackFailure", "_onProgress", "_treatmentTime", "_callerAnim", "_patietAnim"]; +_caller = _this select 0; +_target = _this select 1; +_selectionName = _this select 2; +_className = _this select 3; -_params = + _this; -_params deleteAt 0; -_params deleteAt 0; -_params deleteAt 0; +_config = (ConfigFile >> "ACE_Medical_Treatments" >> _className); +if !(isClass _config) exitwith {false}; -// @todo: animation +_availableLevels = getArray (_config >> "availableLevels"); +if !(GVAR(level) in _availableLevels) exitwith {false}; -// @todo: remove item +_medicRequired = getNumber (_config >> "requiredMedic"); +if !([_caller, _medicRequired] call FUNC(isMedic) || [_target, _medicRequired] call FUNC(isMedic)) exitwith {false}; -// @todo: progress bar +_items = getArray (_config >> "items"); +if (count _items > 0 && {!([_caller, _target, _items] call FUNC(hasItems))}) exitwith {false}; -_this call FUNC(treatmentCallback); +_locations = getArray (_config >> "treatmentLocations"); + +if ("All" in _locations) exitwith {true}; + +_return = false; +{ + if (_x == "field") exitwith {_return = true;}; + if (_x == "MedicalFacility" && {[_caller, _target] call FUNC(inMedicalFacility)}) exitwith {_return = true;}; + if (_x == "MedicalVehicle" && {[_caller, _target] call FUNC(inMedicalVehicle)}) exitwith {_return = true;}; +}foreach _locations; + +if !(_return) exitwith {false}; + +// Parse the config for the success callback +_callbackSuccess = getText (_config >> "callbackSuccess"); +if (isNil _callbackSuccess) then { + _callbackSuccess = compile _callbackSuccess; +} else { + _callbackSuccess = missionNamespace getvariable _callbackSuccess; +}; + +// Parse the config for the failure callback +_callbackFailure = getText (_config >> "callbackFailure"); +if (isNil _callbackFailure) then { + _callbackFailure = compile _callbackFailure; +} else { + _callbackFailure = missionNamespace getvariable _callbackFailure; +}; + +// Parse the config for the onProgress callback +_onProgress = getText (_config >> "onProgress"); +if (isNil _onProgress) then { + _onProgress = compile _onProgress; +} else { + _onProgress = missionNamespace getvariable _onProgress; +}; + +_treatmentTime = getNumber (_config >> "treatmentTime"); +[_treatmentTime, [_caller, _target, _selectionName, _className, _items], _callbackSuccess, _callbackFailure, (localize ""), _onProgress] call EFUNC(common,progressBar); + +_callerAnim = getText (_config >> "animationCaller"); +_patietAnim = getText (_confg >> "animationPatient"); + +if (_caller != _target && {vehicle _target == _target} && {_patietAnim != ""}) then { + [_target, _patietAnim] call EFUNC(common,doMove); +}; +if (vehicle _caller == _caller && {_callerAnim != ""}) then { + [_caller, _callerAnim] call EFUNC(common,doMove); +}; + +true; diff --git a/addons/medical/functions/fnc_treatmentCallback.sqf b/addons/medical/functions/fnc_treatmentCallback.sqf deleted file mode 100644 index f7f7b40f3e..0000000000 --- a/addons/medical/functions/fnc_treatmentCallback.sqf +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Author: KoffeinFlummi - * Callback for a successfull treatment. - * - * Arguments: - * 0: The medic - * 1: The patient - * 2: Treatment type/item - * 3+: Additional parameters - * - * Return Value: - * nil - * - * Public: Yes - */ - -#include "script_component.hpp" - -_medic = _this select 0; -_patient = _this select 1; -_type = _this select 2; - -_params = + _this; -_params deleteAt 0; -_params deleteAt 0; -_params deleteAt 0; - -if (GVAR(level) == 0) then { - _this call FUNC(treatmentCallback_basic); -} else { - _this call FUNC(treatmentCallback_advanced); -}; diff --git a/addons/medical/functions/fnc_treatmentCallback_advanced.sqf b/addons/medical/functions/fnc_treatmentCallback_advanced.sqf deleted file mode 100644 index 700048203b..0000000000 --- a/addons/medical/functions/fnc_treatmentCallback_advanced.sqf +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Author: KoffeinFlummi - * Callback for an advanced successfull treatment. - * - * Arguments: - * 0: The medic - * 1: The patient - * 2: Treatment type/item - * 3+: Additional parameters - * - * Return Value: - * nil - * - * Public: Yes - */ - -#include "script_component.hpp" - -_medic = _this select 0; -_patient = _this select 1; -_type = _this select 2; - -_params = + _this; -_params deleteAt 0; -_params deleteAt 0; -_params deleteAt 0; - diff --git a/addons/medical/functions/fnc_treatmentCallback_basic.sqf b/addons/medical/functions/fnc_treatmentCallback_basic.sqf deleted file mode 100644 index 410f1d3df8..0000000000 --- a/addons/medical/functions/fnc_treatmentCallback_basic.sqf +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Author: KoffeinFlummi - * Callback for a basic successfull treatment. - * - * Arguments: - * 0: The medic - * 1: The patient - * 2: Treatment type/item - * 3+: Additional parameters - * - * Return Value: - * nil - * - * Public: Yes - */ - -#include "script_component.hpp" - -_medic = _this select 0; -_patient = _this select 1; -_type = _this select 2; - -_params = + _this; -_params deleteAt 0; -_params deleteAt 0; -_params deleteAt 0; -