ACE3/addons/medical/functions/fnc_treatment.sqf

119 lines
4.3 KiB
Plaintext
Raw Normal View History

2015-02-20 21:04:01 +00:00
/*
2015-02-21 20:09:57 +00:00
* Author: Glowbal, KoffeinFlummi
2015-02-20 21:04:01 +00:00
* Starts the treatment process
*
* Arguments:
* 0: The medic <OBJECT>
* 1: The patient <OBJECT>
2015-02-21 20:09:57 +00:00
* 2: SelectionName <STRING>
* 3: Treatment classname <STRING>
2015-02-20 21:04:01 +00:00
*
* Return Value:
2015-02-21 20:09:57 +00:00
* Succesful treatment started <BOOL>
2015-02-20 21:04:01 +00:00
*
* Public: Yes
*/
#include "script_component.hpp"
private ["_caller", "_target", "_selectionName", "_className", "_config", "_availableLevels", "_medicRequired", "_items", "_locations", "_return", "_callbackSuccess", "_callbackFailure", "_callbackProgress", "_treatmentTime", "_callerAnim", "_patientAnim", "_iconDisplayed"];
2015-02-21 20:09:57 +00:00
_caller = _this select 0;
_target = _this select 1;
_selectionName = _this select 2;
_className = _this select 3;
2015-02-20 21:04:01 +00:00
2015-02-28 19:46:36 +00:00
if !(_target isKindOf "CAManBase") exitWith {false};
_config = (configFile >> "ACE_Medical_Actions" >> "Basic" >> _className);
2015-03-06 21:54:44 +00:00
if (GVAR(level) >= 2) then {
2015-02-28 19:46:36 +00:00
_config = (configFile >> "ACE_Medical_Actions" >> "Advanced" >> _className);
};
2015-02-21 20:09:57 +00:00
if !(isClass _config) exitwith {false};
2015-02-20 21:04:01 +00:00
2015-02-28 19:46:36 +00:00
// Check for required class
2015-02-21 20:09:57 +00:00
_medicRequired = getNumber (_config >> "requiredMedic");
if !([_caller, _medicRequired] call FUNC(isMedic) || [_target, _medicRequired] call FUNC(isMedic)) exitwith {false};
2015-02-20 21:04:01 +00:00
2015-02-28 19:46:36 +00:00
// Check item
2015-02-21 20:09:57 +00:00
_items = getArray (_config >> "items");
if (count _items > 0 && {!([_caller, _target, _items] call FUNC(hasItems))}) exitwith {false};
2015-02-20 21:04:01 +00:00
2015-02-28 19:46:36 +00:00
// Check allowed locations
2015-02-21 20:09:57 +00:00
_locations = getArray (_config >> "treatmentLocations");
_return = false;
if ("All" in _locations) then {
2015-02-28 14:23:12 +00:00
_return = true;
} else {
2015-02-28 14:23:12 +00:00
{
if (_x == "field") exitwith {_return = true;};
if (_x == "MedicalFacility" && {([_caller] call FUNC(isInMedicalFacility)) || ([_target] call FUNC(isInMedicalFacility))}) exitwith {_return = true;};
if (_x == "MedicalVehicle" && {([vehicle _caller] call FUNC(isMedicalVehicle)) || ([vehicle _target] call FUNC(isMedicalVehicle))}) exitwith {_return = true;};
}foreach _locations;
};
2015-02-21 20:09:57 +00:00
if !(_return) exitwith {false};
2015-02-24 21:09:31 +00:00
// Parse the config for the progress callback
_callbackProgress = getText (_config >> "callbackProgress");
if (_callbackProgress == "") then {
_callbackProgress = "true";
};
if (isNil _callbackProgress) then {
2015-02-28 14:23:12 +00:00
_callbackProgress = compile _callbackProgress;
2015-02-21 20:09:57 +00:00
} else {
2015-02-28 14:23:12 +00:00
_callbackProgress = missionNamespace getvariable _callbackProgress;
2015-02-21 20:09:57 +00:00
};
2015-02-28 19:46:36 +00:00
// Patient Animation
_patientAnim = getText (_confg >> "animationPatient");
if (_caller != _target && {vehicle _target == _target} && {_patientAnim != ""}) then {
[_target, _patientAnim] call EFUNC(common,doAnimation);
};
2015-02-21 20:09:57 +00:00
2015-02-28 19:46:36 +00:00
// Player Animation
_callerAnim = [getText (_config >> "animationCaller"), getText (_config >> "animationCallerProne")] select (stance _caller == "PRONE");
if (_caller == _target) then {
2015-02-28 14:23:12 +00:00
_callerAnim = [getText (_config >> "animationCallerSelf"), getText (_config >> "animationCallerSelfProne")] select (stance _caller == "PRONE");
};
_wpn = ["non", "rfl", "pst"] select (["", primaryWeapon _caller, handgunWeapon _caller] find (currentWeapon _caller));
_callerAnim = [_callerAnim, "[wpn]", _wpn] call CBA_fnc_replace;
2015-02-21 20:09:57 +00:00
if (vehicle _caller == _caller && {_callerAnim != ""}) then {
2015-02-28 14:23:12 +00:00
if (primaryWeapon _caller == "") then {
_caller addWeapon "ACE_FakePrimaryWeapon";
};
_caller selectWeapon (primaryWeapon _caller);
_caller setvariable [QGVAR(treatmentPrevAnimCaller), animationState _caller];
2015-02-28 14:23:12 +00:00
[_caller, _callerAnim] call EFUNC(common,doAnimation);
2015-02-21 20:09:57 +00:00
};
// 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);
2015-02-28 19:46:36 +00:00
// Display Icon
_iconDisplayed = getText (_config >> "actionIconPath");
if (_iconDisplayed != "") then {
2015-02-28 19:46:36 +00:00
[QGVAR(treatmentActionIcon), true, _iconDisplayed, [1,1,1,1], getNumber(_config >> "actionIconDisplayTime")] call EFUNC(common,displayIcon);
};
// handle display of text/hints
_displayText = "";
if (_target != _caller) then {
_displayText = getText(_config >> "displayTextOther");
} else {
_displayText = getText(_config >> "displayTextSelf");
};
if (_displayText != "") then {
2015-02-28 17:59:37 +00:00
["displayTextStructured", [_caller], [[_displayText, [_caller] call EFUNC(common,getName), [_target] call EFUNC(common,getName)], 1.5, _caller]] call EFUNC(common,targetEvent);
};
2015-02-21 20:09:57 +00:00
true;