2018-09-17 19:19:29 +00:00
#include "script_component.hpp"
2016-03-05 19:25:35 +00:00
/*
* Author: BaerMitUmlaut
* Auomatically deploy a helicopter filled with AI units.
*
* Arguments:
* 0: The helicopter <OBJECT>
* 1: Deploy special roles (gunners, copilot) (default: false) <BOOL>
* 2: Create deployment group (default: true) <BOOL>
*
* Return Value:
* None
*
* Example:
* [_vehicle] call ace_fastroping_fnc_deployAI
*
* Public: Yes
*/
params [["_vehicle", objNull, [objNull]], ["_deploySpecial", false, [true]], ["_createDeploymentGroup", true, [true]]];
if (isNull _vehicle || {!(_vehicle isKindOf "Helicopter")}) exitWith {
if (hasInterface) then {
2016-03-05 20:22:45 +00:00
// Note: BIS_fnc_guiMessage causes a CTD with call, so spawn is used instead.
2016-03-05 19:25:35 +00:00
["deployAI was called with an invalid or non-existant vehicle.", QFUNC(deployAI)] spawn BIS_fnc_guiMessage;
};
2016-10-02 10:55:31 +00:00
ERROR('FUNC(deployAI): deployAI was called with an invalid or non-existant vehicle.');
2016-03-05 19:25:35 +00:00
};
2021-02-18 18:58:08 +00:00
private _config = configOf _vehicle;
2017-09-19 20:38:49 +00:00
private _configEnabled = getNumber (_config >> QGVAR(enabled));
2016-03-05 19:25:35 +00:00
if (_configEnabled == 0) exitWith {
if (hasInterface) then {
[format ["You cannot fast rope from a ""%1"" helicopter.", getText (_config >> "DisplayName")], QFUNC(deployAI)] spawn BIS_fnc_guiMessage;
};
2016-10-02 10:55:31 +00:00
ERROR_1('FUNC(deployAI): You cannot fast rope from a "%1" helicopter.',getText (_config >> "DisplayName"));
2016-03-05 19:25:35 +00:00
};
if (_configEnabled == 2 && {isNull (_vehicle getVariable [QGVAR(FRIES), objNull])}) exitWith {
if (hasInterface) then {
[format ["""%1"" requires a FRIES for fastroping, but has not been equipped with one.", getText (_config >> "DisplayName")], QFUNC(deployAI)] spawn BIS_fnc_guiMessage;
};
2016-10-02 10:55:31 +00:00
ERROR_1('FUNC(deployAI): "%1" requires a FRIES for fastroping but has not been equipped with one.',getText (_config >> "DisplayName"));
2016-03-05 19:25:35 +00:00
};
2017-09-19 20:38:49 +00:00
private _unitsToDeploy = crew _vehicle;
2016-03-05 19:25:35 +00:00
if (_deploySpecial) then {
_unitsToDeploy deleteAt (_unitsToDeploy find driver _vehicle);
} else {
_unitsToDeploy = _unitsToDeploy select {(assignedVehicleRole _x) select 0 == "cargo"};
};
if (_unitsToDeploy isEqualTo []) exitWith {
2016-10-02 10:55:31 +00:00
WARNING_1('FUNC(deployAI): Found no units to deploy in "%1".',getText (_config >> "DisplayName"));
2016-03-05 19:25:35 +00:00
};
if (_createDeploymentGroup) then {
2017-09-19 20:38:49 +00:00
private _deployGroup = createGroup side (_unitsToDeploy select 0);
2016-03-05 19:25:35 +00:00
_unitsToDeploy joinSilent _deployGroup;
};
2017-09-19 20:38:49 +00:00
private _deployTime = 0;
2020-02-20 05:28:57 +00:00
2016-03-05 19:25:35 +00:00
if (getText (_config >> QGVAR(onPrepare)) != "") then {
_deployTime = [_vehicle] call (missionNamespace getVariable (getText (_config >> QGVAR(onPrepare))));
};
2020-02-20 05:28:57 +00:00
[FUNC(deployRopes), _vehicle, _deployTime] call CBA_fnc_waitAndExecute;
2016-03-05 19:25:35 +00:00
driver _vehicle disableAI "MOVE";
DFUNC(deployAIRecursive) = {
params ["_vehicle", "_unitsToDeploy"];
private _unit = _unitsToDeploy deleteAt 0;
unassignVehicle _unit;
[_unit, _vehicle] call FUNC(fastRope);
2021-02-27 17:05:05 +00:00
if (_unitsToDeploy isNotEqualTo []) then {
2016-03-05 19:25:35 +00:00
[{
[{
params ["_vehicle"];
private _deployedRopes = _vehicle getVariable [QGVAR(deployedRopes), []];
({!(_x select 5)} count (_deployedRopes)) > 0
2016-05-22 13:27:24 +00:00
}, FUNC(deployAIRecursive), _this] call CBA_fnc_waitUntilAndExecute;
}, [_vehicle, _unitsToDeploy], 1] call CBA_fnc_waitAndExecute;
2016-03-05 19:25:35 +00:00
} else {
[{
private _deployedRopes = _this getVariable [QGVAR(deployedRopes), []];
({_x select 5} count (_deployedRopes)) == 0
}, {
[_this] call FUNC(cutRopes);
driver _this enableAI "MOVE";
2016-05-22 13:27:24 +00:00
}, _vehicle] call CBA_fnc_waitUntilAndExecute;
2016-03-05 19:25:35 +00:00
};
};
2016-05-22 13:27:24 +00:00
[FUNC(deployAIRecursive), [_vehicle, _unitsToDeploy], _deployTime + 4] call CBA_fnc_waitAndExecute;