ACE3/addons/medical_treatment/functions/fnc_canTreat.sqf

106 lines
3.4 KiB
Plaintext
Raw Normal View History

/*
* Author: Glowbal
* Check if the treatment action can be performed.
*
* Arguments:
* 0: The caller <OBJECT>
* 1: The target <OBJECT>
2016-10-13 07:47:52 +00:00
* 2: Body part <STRING>
* 3: Treatment class name <STRING>
*
* ReturnValue:
* Can Treat <BOOL>
*
* Example:
2016-09-18 20:58:56 +00:00
* [player, cursorTarget, "Head", "SurgicalKit"] call ace_medical_treatment_fnc_canTreat
*
* Public: Yes
*/
#include "script_component.hpp"
2016-10-13 07:47:52 +00:00
params ["_caller", "_target", "_bodyPart", "_className"];
if !(_target isKindOf "CAManBase") exitWith {false};
2016-10-13 07:47:52 +00:00
private _config = configFile >> QGVAR(Actions) >> _className;
if !(isClass _config) exitwith {false};
// allow self treatment check
private _isSelf = _caller isEqualTo _target;
if (_isSelf && {getNumber (_config >> "allowSelfTreatment") == 0}) exitwith {false};
private _medicRequired = 0;
if (isNumber (_config >> "requiredMedic")) then {
_medicRequired = getNumber (_config >> "requiredMedic");
} else {
if (isText (_config >> "requiredMedic")) then {
_medicRequired = missionNamespace getVariable [getText (_config >> "requiredMedic"), 0];
};
};
2016-09-18 20:58:56 +00:00
if !([_caller, _medicRequired] call EFUNC(medical,isMedic)) exitWith {false};
// check selection
private _allowedSelections = getArray (_config >> "allowedSelections") apply {toLower _x};
2016-10-13 07:47:52 +00:00
if !("all" in _allowedSelections || {(_bodyPart 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 {
_condition = call _condition;
};
};
if !(_condition) exitWith {false};
// check allowed locations
private _locations = getArray (_config >> "treatmentLocations") apply {toLower _x};
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 { _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;
};
_locations