From 1689829f93f4a87cecbda48e108c6078a2c7f791 Mon Sep 17 00:00:00 2001 From: KoffeinFlummi Date: Sat, 28 Feb 2015 22:10:20 +0100 Subject: [PATCH] Get treatment callback structure working --- addons/medical/ACE_Medical_Treatments.hpp | 2 +- addons/medical/functions/fnc_treatment.sqf | 27 ++++++++------- .../functions/fnc_treatmentBasic_bandage.sqf | 6 ++-- .../functions/fnc_treatmentBasic_bloodbag.sqf | 20 ++++++----- .../functions/fnc_treatmentBasic_epipen.sqf | 19 ++++++----- .../functions/fnc_treatmentBasic_morphine.sqf | 33 +++++++++++++++++++ .../functions/fnc_treatment_failure.sqf | 23 +++++++++---- .../functions/fnc_treatment_success.sqf | 23 +++++++++---- 8 files changed, 105 insertions(+), 48 deletions(-) diff --git a/addons/medical/ACE_Medical_Treatments.hpp b/addons/medical/ACE_Medical_Treatments.hpp index c8bdc1961d..eafabbe783 100644 --- a/addons/medical/ACE_Medical_Treatments.hpp +++ b/addons/medical/ACE_Medical_Treatments.hpp @@ -15,7 +15,7 @@ class ACE_Medical_Actions { itemConsumed = 1; callbackSuccess = QUOTE(DFUNC(treatmentBasic_bandage)); - callbackFailure = QUOTE(DFUNC(treatmentBasic_abort)); + callbackFailure = ""; callbackProgress = ""; animationPatient = ""; diff --git a/addons/medical/functions/fnc_treatment.sqf b/addons/medical/functions/fnc_treatment.sqf index 939cda68b4..44bb0749d5 100644 --- a/addons/medical/functions/fnc_treatment.sqf +++ b/addons/medical/functions/fnc_treatment.sqf @@ -54,23 +54,15 @@ if !(_return) exitwith {false}; // Parse the config for the progress callback _callbackProgress = getText (_config >> "callbackProgress"); +if (_callbackProgress == "") then { + _callbackProgress = "true"; +}; if (isNil _callbackProgress) then { _callbackProgress = compile _callbackProgress; } else { _callbackProgress = missionNamespace getvariable _callbackProgress; }; -// Start treatment -_treatmentTime = getNumber (_config >> "treatmentTime"); -[ - _treatmentTime, - [_caller, _target, _selectionName, _className, _items], - DFUNC(treatment_success), - DFUNC(treatment_failure), - getText (_config >> "displayNameProgress"), - _callbackProgress -] call EFUNC(common,progressBar); - // Patient Animation _patientAnim = getText (_confg >> "animationPatient"); if (_caller != _target && {vehicle _target == _target} && {_patientAnim != ""}) then { @@ -89,10 +81,21 @@ if (vehicle _caller == _caller && {_callerAnim != ""}) then { _caller addWeapon "ACE_FakePrimaryWeapon"; }; _caller selectWeapon (primaryWeapon _caller); - _caller setvariable [QGVAR(treatmentPrevAnimCaller), animationState _target]; + _caller setvariable [QGVAR(treatmentPrevAnimCaller), animationState _caller]; [_caller, _callerAnim] call EFUNC(common,doAnimation); }; +// Start treatment +_treatmentTime = getNumber (_config >> "treatmentTime"); +[ + _treatmentTime, + [_caller, _target, _selectionName, _className, _items], + DFUNC(treatment_success), + DFUNC(treatment_failure), + getText (_config >> "displayNameProgress"), + _callbackProgress +] call EFUNC(common,progressBar); + // Display Icon _iconDisplayed = getText (_config >> "actionIconPath"); if (_iconDisplayed != "") then { diff --git a/addons/medical/functions/fnc_treatmentBasic_bandage.sqf b/addons/medical/functions/fnc_treatmentBasic_bandage.sqf index 82402dd2fa..39b910d6e4 100644 --- a/addons/medical/functions/fnc_treatmentBasic_bandage.sqf +++ b/addons/medical/functions/fnc_treatmentBasic_bandage.sqf @@ -17,7 +17,7 @@ #include "script_component.hpp" #define BANDAGEHEAL 0.8 -private ["_caller", "_target","_selection","_className","_config","_callback"]; +private ["_caller", "_target","_selection","_className","_target","_hitSelections","_hitPoints","_point"]; _caller = _this select 0; _target = _this select 1; _selection = _this select 2; @@ -30,8 +30,8 @@ if (_selection == "all") then { _hitPoints = ["HitHead", "HitBody", "HitLeftArm", "HitRightArm", "HitLeftLeg", "HitRightLeg"]; _point = _hitPoints select (_hitSelections find _selection); - systemChat _point; - _damage = ((_target getHitPointDamage _point) - BANDAGEHEAL) max 0; [_target, _point, _damage] call FUNC(setHitPointDamage); + + // @todo: leg/arm damage - in setHitPointDamage? }; diff --git a/addons/medical/functions/fnc_treatmentBasic_bloodbag.sqf b/addons/medical/functions/fnc_treatmentBasic_bloodbag.sqf index 0505028b8e..57563ad8fc 100644 --- a/addons/medical/functions/fnc_treatmentBasic_bloodbag.sqf +++ b/addons/medical/functions/fnc_treatmentBasic_bloodbag.sqf @@ -1,13 +1,12 @@ /* * Author: KoffeinFlummi - * Epipen treatment. + * Callback when the bloodbag treatment is complete * * Arguments: - * 0: Medic - * 1: Patient + * 0: The medic + * 1: The patient * 2: Selection Name - * 3: Treatment Classname - * 4: Items required > + * 3: Treatment classname * * Return Value: * nil @@ -16,9 +15,12 @@ */ #include "script_component.hpp" +#define BLOODBAGHEAL 70 -_medic = _this select 0; -_patient = _this select 1; -_items = _this select 4; +private ["_caller", "_target","_className","_blood"]; +_caller = _this select 0; +_target = _this select 1; +_className = _this select 3; -[_patient, false] call FUNC(setUnconscious); +_blood = ((_target getVariable [QGVAR(bloodVolume), 100]) + BLOODBAGHEAL) min 100; +_target setVariable [QGVAR(bloodVolume), _blood, true]; diff --git a/addons/medical/functions/fnc_treatmentBasic_epipen.sqf b/addons/medical/functions/fnc_treatmentBasic_epipen.sqf index 0505028b8e..e616327673 100644 --- a/addons/medical/functions/fnc_treatmentBasic_epipen.sqf +++ b/addons/medical/functions/fnc_treatmentBasic_epipen.sqf @@ -1,13 +1,12 @@ /* * Author: KoffeinFlummi - * Epipen treatment. + * Callback when the epipen treatment is complete * * Arguments: - * 0: Medic - * 1: Patient + * 0: The medic + * 1: The patient * 2: Selection Name - * 3: Treatment Classname - * 4: Items required > + * 3: Treatment classname * * Return Value: * nil @@ -16,9 +15,11 @@ */ #include "script_component.hpp" +#define BLOODBAGHEAL 70 -_medic = _this select 0; -_patient = _this select 1; -_items = _this select 4; +private ["_caller", "_target","_className"]; +_caller = _this select 0; +_target = _this select 1; +_className = _this select 3; -[_patient, false] call FUNC(setUnconscious); +[_target, false] call FUNC(setUnconscious); diff --git a/addons/medical/functions/fnc_treatmentBasic_morphine.sqf b/addons/medical/functions/fnc_treatmentBasic_morphine.sqf index e69de29bb2..30c87b6f05 100644 --- a/addons/medical/functions/fnc_treatmentBasic_morphine.sqf +++ b/addons/medical/functions/fnc_treatmentBasic_morphine.sqf @@ -0,0 +1,33 @@ +/* + * Author: KoffeinFlummi + * Callback when the morphine treatment is complete + * + * Arguments: + * 0: The medic + * 1: The patient + * 2: Selection Name + * 3: Treatment classname + * + * Return Value: + * nil + * + * Public: No + */ + +#include "script_component.hpp" +#define MORPHINEHEAL 0.4 + +private ["_caller", "_target","_className","_blood","_morphine","_pain"]; +_caller = _this select 0; +_target = _this select 1; +_className = _this select 3; + +// reduce pain, pain sensitivity +_morphine = (_target getVariable [QGVAR(morphine), 0] + MORPHINEHEAL) min 1; +_target setVariable [QGVAR(morphine), _morphine, true]; +_pain = ((_target getVariable [QGVAR(pain), 0]) - MORPHINEHEAL) max 0; +_target setVariable [QGVAR(pain), _pain, true]; + +// @todo overdose + +// @todo pain, painkiller reduction diff --git a/addons/medical/functions/fnc_treatment_failure.sqf b/addons/medical/functions/fnc_treatment_failure.sqf index e451257487..6174956934 100644 --- a/addons/medical/functions/fnc_treatment_failure.sqf +++ b/addons/medical/functions/fnc_treatment_failure.sqf @@ -7,6 +7,7 @@ * 1: The patient * 2: SelectionName * 3: Treatment classname + * 4: Items available > * * Return Value: * nil @@ -17,17 +18,20 @@ #include "script_component.hpp" private ["_caller", "_target","_selectionName","_className","_config","_callback"]; -_caller = _this select 0; -_target = _this select 1; -_selectionName = _this select 2; -_className = _this select 3; + +_args = _this select 0; +_caller = _args select 0; +_target = _args select 1; +_selectionName = _args select 2; +_className = _args select 3; if (primaryWeapon _caller == "ACE_FakePrimaryWeapon") then { _caller removeWeapon "ACE_FakePrimaryWeapon"; - [_caller, _caller getvariable [QGVAR(treatmentPrevAnimCaller), ""]] call EFUNC(common,doAnimation); - _caller setvariable [QGVAR(treatmentPrevAnimCaller), nil]; }; +[_caller, _caller getvariable [QGVAR(treatmentPrevAnimCaller), ""], 1] call EFUNC(common,doAnimation); +_caller setvariable [QGVAR(treatmentPrevAnimCaller), nil]; +// @todo remove item? // Record specific callback _config = (configFile >> "ACE_Medical_Actions" >> "Basic" >> _className); @@ -36,5 +40,10 @@ if (GVAR(level) >= 1) then { }; _callback = getText (_config >> "callbackFailure"); +if (isNil _callback) then { + _callback = compile _callback; +} else { + _callback = missionNamespace getvariable _callback; +}; -_this call compile _callback +_args call _callback diff --git a/addons/medical/functions/fnc_treatment_success.sqf b/addons/medical/functions/fnc_treatment_success.sqf index 1a5ad677f9..878aaa01b7 100644 --- a/addons/medical/functions/fnc_treatment_success.sqf +++ b/addons/medical/functions/fnc_treatment_success.sqf @@ -7,6 +7,7 @@ * 1: The patient * 2: SelectionName * 3: Treatment classname + * 4: Items available > * * Return Value: * nil @@ -17,17 +18,20 @@ #include "script_component.hpp" private ["_caller", "_target","_selectionName","_className","_config","_callback"]; -_caller = _this select 0; -_target = _this select 1; -_selectionName = _this select 2; -_className = _this select 3; + +_args = _this select 0; +_caller = _args select 0; +_target = _args select 1; +_selectionName = _args select 2; +_className = _args select 3; if (primaryWeapon _caller == "ACE_FakePrimaryWeapon") then { _caller removeWeapon "ACE_FakePrimaryWeapon"; - [_caller, _caller getvariable [QGVAR(treatmentPrevAnimCaller), ""]] call EFUNC(common,doAnimation); - _caller setvariable [QGVAR(treatmentPrevAnimCaller), nil]; }; +[_caller, _caller getvariable [QGVAR(treatmentPrevAnimCaller), ""], 1] call EFUNC(common,doAnimation); +_caller setvariable [QGVAR(treatmentPrevAnimCaller), nil]; +// @todo remove item // Record specific callback _config = (configFile >> "ACE_Medical_Actions" >> "Basic" >> _className); @@ -36,5 +40,10 @@ if (GVAR(level) >= 1) then { }; _callback = getText (_config >> "callbackSuccess"); +if (isNil _callback) then { + _callback = compile _callback; +} else { + _callback = missionNamespace getvariable _callback; +}; -_this call compile _callback +_args call _callback