ACE3/addons/medical/functions/fnc_canTreat.sqf

98 lines
3.4 KiB
Plaintext
Raw Normal View History

2015-02-21 20:09:57 +00:00
/*
* Author: Glowbal
* Check if the treatment action can be performed.
*
* Arguments:
* 0: The caller <OBJECT>
* 1: The target <OBJECT>
* 2: Selection name <STRING>
* 3: ACE_Medical_Treatments Classname <STRING>
*
* Return Value:
2015-02-21 20:09:57 +00:00
* Can Treat <BOOL>
*
* Example:
* [player, cursorTarget, "Head", "SurgicalKit"] call ace_medical_fnc_canTreat
*
2015-02-21 20:09:57 +00:00
* Public: Yes
*/
#include "script_component.hpp"
2015-08-22 14:25:10 +00:00
params ["_caller", "_target", "_selectionName", "_className"];
2015-02-21 20:09:57 +00:00
2015-08-22 14:25:10 +00:00
if !(_target isKindOf "CAManBase") exitWith { false };
2016-06-13 08:55:19 +00:00
private _config = (ConfigFile >> "ACE_Medical_Actions" >> (["Basic", "Advanced"] select (GVAR(level)>=2)) >> _className);
2015-08-29 13:29:02 +00:00
2015-02-21 20:09:57 +00:00
if !(isClass _config) exitwith {false};
// Allow self treatment check
if (_caller == _target && {getNumber (_config >> "allowSelfTreatment") == 0}) exitwith {false};
2016-06-13 08:55:19 +00:00
private _medicRequired = if (isNumber (_config >> "requiredMedic")) then {
getNumber (_config >> "requiredMedic");
} else {
// Check for required class
if (isText (_config >> "requiredMedic")) exitwith {
missionNamespace getVariable [(getText (_config >> "requiredMedic")), 0]
};
0;
};
2015-08-22 14:25:10 +00:00
if !([_caller, _medicRequired] call FUNC(isMedic)) exitwith { false };
2015-02-21 20:09:57 +00:00
2016-06-13 08:55:19 +00:00
private _items = getArray (_config >> "items");
2015-08-22 14:25:10 +00:00
if (count _items > 0 && {!([_caller, _target, _items] call FUNC(hasItems))}) exitwith { false };
2015-02-21 20:09:57 +00:00
2016-06-13 08:55:19 +00:00
private _allowedSelections = getArray (_config >> "allowedSelections");
2015-08-22 14:25:10 +00:00
if !("All" in _allowedSelections || {(_selectionName in _allowedSelections)}) exitwith { false };
2015-02-21 20:09:57 +00:00
2016-06-13 08:55:19 +00:00
private _return = true;
if (getText (_config >> "condition") != "") then {
2016-06-13 08:55:19 +00:00
private _condition = getText (_config >> "condition");
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;
2015-03-09 21:27:01 +00:00
};
};
2015-08-22 14:25:10 +00:00
if (!_return) exitwith { false };
2015-03-09 20:42:09 +00:00
2016-06-13 08:55:19 +00:00
private _patientStateCondition = if (isText(_config >> "patientStateCondition")) then {
missionNamespace getVariable [getText(_config >> "patientStateCondition"), 0]
} else {
getNumber(_config >> "patientStateCondition")
};
if (_patientStateCondition == 1 && {!([_target] call FUNC(isInStableCondition))}) exitwith {false};
2016-06-13 08:55:19 +00:00
private _locations = getArray (_config >> "treatmentLocations");
2015-08-22 14:25:10 +00:00
if ("All" in _locations) exitwith { true };
2015-03-09 20:42:09 +00:00
2016-06-13 08:55:19 +00:00
private _medFacility = {([_caller] call FUNC(isInMedicalFacility)) || ([_target] call FUNC(isInMedicalFacility))};
private _medVeh = {([_caller] call FUNC(isInMedicalVehicle)) || ([_target] call FUNC(isInMedicalVehicle))};
2015-04-06 12:32:37 +00:00
2015-03-09 20:42:09 +00:00
{
if (_x == "field") exitwith {_return = true;};
2015-04-06 12:32:37 +00:00
if (_x == "MedicalFacility" && _medFacility) exitwith {_return = true;};
if (_x == "MedicalVehicle" && _medVeh) exitwith {_return = true;};
if !(isnil _x) exitwith {
2016-06-13 08:55:19 +00:00
private _val = missionNamespace getVariable _x;
if (_val isEqualType 0) then {
2015-04-06 12:32:37 +00:00
_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
};
};
};
2015-08-22 14:25:10 +00:00
} foreach _locations;
2015-02-21 20:09:57 +00:00
_return;