2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2015-03-28 10:08:17 +00:00
|
|
|
/*
|
2015-07-03 21:14:23 +00:00
|
|
|
* Author: Glowbal
|
|
|
|
* Check if the repair action can be performed.
|
2015-03-28 10:08:17 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2015-08-16 18:14:54 +00:00
|
|
|
* 0: Unit that does the repairing <OBJECT>
|
|
|
|
* 1: Vehicle to repair <OBJECT>
|
2015-09-26 04:36:35 +00:00
|
|
|
* 2: Selected hitpoint or hitpointIndex <STRING>or<NUMBER>
|
2015-08-16 18:14:54 +00:00
|
|
|
* 3: Repair Action Classname <STRING>
|
2015-07-03 21:14:23 +00:00
|
|
|
*
|
2015-08-16 18:14:54 +00:00
|
|
|
* Return Value:
|
|
|
|
* Can Repair <BOOL>
|
|
|
|
*
|
|
|
|
* Example:
|
2015-09-26 04:36:35 +00:00
|
|
|
* [player, car, "HitHull", "MiscRepair"] call ace_repair_fnc_canRepair
|
2015-03-28 10:08:17 +00:00
|
|
|
*
|
2015-07-03 21:14:23 +00:00
|
|
|
* Public: Yes
|
2015-03-28 10:08:17 +00:00
|
|
|
*/
|
|
|
|
|
2015-08-09 06:54:44 +00:00
|
|
|
params ["_caller", "_target", "_hitPoint", "_className"];
|
|
|
|
TRACE_4("params",_caller,_target,_hitPoint,_className);
|
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _config = (ConfigFile >> "ACE_Repair" >> "Actions" >> _className);
|
2015-11-10 02:11:48 +00:00
|
|
|
if !(isClass _config) exitWith {false}; // or go for a default?
|
2016-04-13 01:04:12 +00:00
|
|
|
|
|
|
|
// if(isEngineOn _target) exitWith {false}; // Ignore here so action shows, then exit and show warning when selected #3348
|
2015-07-03 21:14:23 +00:00
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _engineerRequired = if (isNumber (_config >> "requiredEngineer")) then {
|
2015-07-03 21:14:23 +00:00
|
|
|
getNumber (_config >> "requiredEngineer");
|
|
|
|
} else {
|
|
|
|
// Check for required class
|
2015-11-10 02:11:48 +00:00
|
|
|
if (isText (_config >> "requiredEngineer")) exitWith {
|
2015-08-16 14:45:46 +00:00
|
|
|
missionNamespace getVariable [(getText (_config >> "requiredEngineer")), 0];
|
2015-07-03 21:14:23 +00:00
|
|
|
};
|
|
|
|
0;
|
|
|
|
};
|
2015-11-10 02:11:48 +00:00
|
|
|
if !([_caller, _engineerRequired] call FUNC(isEngineer)) exitWith {false};
|
2015-07-03 21:14:23 +00:00
|
|
|
|
2021-11-11 11:41:25 +00:00
|
|
|
private _items = _config call FUNC(getRepairItems);
|
2015-11-10 02:11:48 +00:00
|
|
|
if (count _items > 0 && {!([_caller, _items] call FUNC(hasItems))}) exitWith {false};
|
2015-07-03 21:14:23 +00:00
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _return = true;
|
2015-07-03 21:14:23 +00:00
|
|
|
if (getText (_config >> "condition") != "") then {
|
2017-10-10 14:39:59 +00:00
|
|
|
private _condition = getText (_config >> "condition");
|
2020-02-12 21:07:19 +00:00
|
|
|
if (isNil _condition) then {
|
2015-07-03 21:14:23 +00:00
|
|
|
_condition = compile _condition;
|
|
|
|
} else {
|
2015-08-16 14:45:46 +00:00
|
|
|
_condition = missionNamespace getVariable _condition;
|
2015-07-03 21:14:23 +00:00
|
|
|
};
|
2015-11-28 03:23:27 +00:00
|
|
|
if (_condition isEqualType false) then {
|
2015-07-03 21:14:23 +00:00
|
|
|
_return = _condition;
|
|
|
|
} else {
|
|
|
|
_return = [_caller, _target, _hitPoint, _className] call _condition;
|
|
|
|
};
|
|
|
|
};
|
2015-08-09 13:53:52 +00:00
|
|
|
|
2015-11-10 02:11:48 +00:00
|
|
|
if (!_return) exitWith {false};
|
2015-07-03 21:14:23 +00:00
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
// private _vehicleStateCondition = if (isText(_config >> "vehicleStateCondition")) then {
|
2015-09-26 04:36:35 +00:00
|
|
|
// missionNamespace getVariable [getText(_config >> "vehicleStateCondition"), 0]
|
|
|
|
// } else {
|
|
|
|
// getNumber(_config >> "vehicleStateCondition")
|
|
|
|
// };
|
2015-11-10 02:11:48 +00:00
|
|
|
// if (_vehicleStateCondition == 1 && {!([_target] call FUNC(isInStableCondition))}) exitWith {false};
|
2015-07-03 21:14:23 +00:00
|
|
|
|
2015-11-10 02:11:48 +00:00
|
|
|
private _repairLocations = getArray (_config >> "repairLocations");
|
2015-09-26 04:36:35 +00:00
|
|
|
if (!("All" in _repairLocations)) then {
|
2015-11-10 02:11:48 +00:00
|
|
|
private _repairFacility = {([_caller] call FUNC(isInRepairFacility)) || ([_target] call FUNC(isInRepairFacility))};
|
|
|
|
private _repairVeh = {([_caller] call FUNC(isNearRepairVehicle)) || ([_target] call FUNC(isNearRepairVehicle))};
|
2015-09-26 04:36:35 +00:00
|
|
|
{
|
2015-11-10 02:11:48 +00:00
|
|
|
if (_x == "field") exitWith {_return = true;};
|
|
|
|
if (_x == "RepairFacility" && _repairFacility) exitWith {_return = true;};
|
|
|
|
if (_x == "RepairVehicle" && _repairVeh) exitWith {_return = true;};
|
2020-02-12 21:07:19 +00:00
|
|
|
if (!isNil _x) exitWith {
|
2015-11-10 02:11:48 +00:00
|
|
|
private _val = missionNamespace getVariable _x;
|
2015-11-28 03:23:27 +00:00
|
|
|
if (_val isEqualType 0) then {
|
2015-09-26 04:36:35 +00:00
|
|
|
_return = switch (_val) do {
|
|
|
|
case 0: {true}; //useAnywhere
|
|
|
|
case 1: {call _repairVeh}; //repairVehicleOnly
|
|
|
|
case 2: {call _repairFacility}; //repairFacilityOnly
|
|
|
|
case 3: {(call _repairFacility) || {call _repairVeh}}; //vehicleAndFacility
|
|
|
|
default {false}; //Disabled
|
|
|
|
};
|
2015-07-03 21:14:23 +00:00
|
|
|
};
|
|
|
|
};
|
2015-09-26 04:36:35 +00:00
|
|
|
} forEach _repairLocations;
|
|
|
|
};
|
2015-11-10 02:11:48 +00:00
|
|
|
if (!_return) exitWith {false};
|
2015-09-26 04:36:35 +00:00
|
|
|
|
|
|
|
//Check that there are required objects nearby
|
2015-11-10 02:11:48 +00:00
|
|
|
private _requiredObjects = getArray (_config >> "claimObjects");
|
2021-02-27 17:05:05 +00:00
|
|
|
if (_requiredObjects isNotEqualTo []) then {
|
2015-11-10 02:11:48 +00:00
|
|
|
private _objectsAvailable = [_caller, 5, _requiredObjects] call FUNC(getClaimObjects);
|
2015-09-26 04:36:35 +00:00
|
|
|
if (_objectsAvailable isEqualTo []) then {
|
|
|
|
TRACE_2("Missing Required Objects",_requiredObjects,_objectsAvailable);
|
|
|
|
_return = false
|
2015-07-03 21:14:23 +00:00
|
|
|
};
|
2015-09-26 04:36:35 +00:00
|
|
|
};
|
2015-04-22 19:01:22 +00:00
|
|
|
|
2015-09-26 04:36:35 +00:00
|
|
|
_return && {alive _target};
|