2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2019-06-08 04:47:39 +00:00
|
|
|
/*
|
2024-02-07 23:36:13 +00:00
|
|
|
* Author: tcvm
|
2024-07-27 17:42:31 +00:00
|
|
|
* Deploys the current CSW.
|
2019-06-08 04:47:39 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2024-06-22 17:03:32 +00:00
|
|
|
* 0: Target <OBJECT>
|
2024-07-27 17:42:31 +00:00
|
|
|
* 1: Player <OBJECT>
|
2024-06-22 17:03:32 +00:00
|
|
|
* 2: Args <ANY>
|
|
|
|
* 3: Action Data <ARRAY>
|
2019-06-08 04:47:39 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
2024-06-22 17:03:32 +00:00
|
|
|
* [cursorObject, player] call ace_csw_fnc_assemble_deployWeapon
|
2019-06-08 04:47:39 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
|
|
|
[{
|
2024-06-22 17:03:32 +00:00
|
|
|
params ["_tripod", "_player"];
|
|
|
|
|
|
|
|
// Save magazines and attachments (handle loaded launchers which can become csw like CUP Metis)
|
|
|
|
private _carryWeaponInfo = (getUnitLoadout _player) select 1;
|
|
|
|
private _carryWeaponClassname = _carryWeaponInfo deleteAt 0;
|
|
|
|
|
|
|
|
// Remove empty entries
|
|
|
|
_carryWeaponInfo = _carryWeaponInfo select {_x isNotEqualTo "" && {_x isNotEqualTo []}};
|
|
|
|
|
2019-06-08 04:47:39 +00:00
|
|
|
TRACE_3("assemble_deployWeapon_carryWeaponClassname",_tripod,_player,_carryWeaponClassname);
|
|
|
|
|
|
|
|
private _tripodClassname = typeOf _tripod;
|
2024-04-02 15:22:45 +00:00
|
|
|
private _weaponConfig = configfile >> "CfgWeapons" >> _carryWeaponClassname >> QUOTE(ADDON);
|
|
|
|
private _assembledClassname = getText (_weaponConfig >> "assembleTo" >> _tripodClassname);
|
|
|
|
|
2019-06-08 04:47:39 +00:00
|
|
|
if (!isClass (configFile >> "CfgVehicles" >> _assembledClassname)) exitWith {ERROR_1("bad static classname [%1]",_assembledClassname);};
|
|
|
|
|
2024-06-22 17:03:32 +00:00
|
|
|
_player removeWeaponGlobal _carryWeaponClassname;
|
|
|
|
|
2024-04-02 15:22:45 +00:00
|
|
|
private _deployTime = getNumber (_weaponConfig >> "deployTime");
|
|
|
|
|
2019-06-08 04:47:39 +00:00
|
|
|
TRACE_4("",_carryWeaponClassname,_tripodClassname,_assembledClassname,_deployTime);
|
|
|
|
|
|
|
|
private _onFinish = {
|
|
|
|
params ["_args"];
|
2024-06-22 17:03:32 +00:00
|
|
|
_args params ["_tripod", "_player", "_assembledClassname", "", "_carryWeaponInfo"];
|
2019-06-08 04:47:39 +00:00
|
|
|
TRACE_3("deployWeapon finish",_tripod,_player,_assembledClassname);
|
|
|
|
|
2024-06-22 17:03:32 +00:00
|
|
|
private _secondaryWeaponMagazines = _tripod getVariable [QGVAR(secondaryWeaponMagazines), []];
|
|
|
|
|
2019-06-08 04:47:39 +00:00
|
|
|
private _tripodPos = getPosATL _tripod;
|
|
|
|
private _tripodDir = getDir _tripod;
|
|
|
|
deleteVehicle _tripod;
|
|
|
|
|
|
|
|
_tripodPos set [2, (_tripodPos select 2) + 0.1];
|
|
|
|
// Delay a frame so tripod has a chance to be deleted
|
|
|
|
[{
|
2024-06-22 17:03:32 +00:00
|
|
|
params ["_assembledClassname", "_tripodDir", "_tripodPos", "_player", "_carryWeaponInfo", "_secondaryWeaponMagazines"];
|
2019-06-08 04:47:39 +00:00
|
|
|
private _csw = createVehicle [_assembledClassname, [0, 0, 0], [], 0, "NONE"];
|
2019-07-05 22:57:22 +00:00
|
|
|
// Assembly mode: [0=disabled, 1=enabled, 2=enabled&unload, 3=default]
|
|
|
|
_csw setVariable [QGVAR(assemblyMode), 2, true]; // Explicitly set advanced assembly mode + unload, and broadcast
|
2024-06-22 17:03:32 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
// Magazines
|
|
|
|
if (_x isEqualType []) then {
|
|
|
|
_secondaryWeaponMagazines pushBack _x;
|
|
|
|
} else {
|
|
|
|
// Items
|
|
|
|
[_player, _x, true] call CBA_fnc_addItem;
|
|
|
|
};
|
|
|
|
} forEach _carryWeaponInfo;
|
|
|
|
|
|
|
|
// Only add magazines once the weapon is fully ready
|
|
|
|
if (_secondaryWeaponMagazines isNotEqualTo []) then {
|
|
|
|
_csw setVariable [QGVAR(secondaryWeaponMagazines), _secondaryWeaponMagazines, true];
|
|
|
|
};
|
|
|
|
|
2019-06-08 04:47:39 +00:00
|
|
|
if (!GVAR(defaultAssemblyMode)) then {
|
2023-11-23 00:16:42 +00:00
|
|
|
[_csw, "disableWeaponAssembly", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set);
|
2019-06-08 04:47:39 +00:00
|
|
|
};
|
|
|
|
_csw setDir _tripodDir;
|
|
|
|
_csw setPosATL _tripodPos;
|
2019-07-05 22:57:22 +00:00
|
|
|
if ((_tripodPos select 2) < 0.5) then {
|
|
|
|
_csw setVectorUp (surfaceNormal _tripodPos);
|
|
|
|
};
|
2020-04-14 14:34:34 +00:00
|
|
|
[QGVAR(deployWeaponSucceeded), [_csw]] call CBA_fnc_localEvent;
|
2019-07-05 22:57:22 +00:00
|
|
|
TRACE_2("csw placed",_csw,_assembledClassname);
|
2024-06-22 17:03:32 +00:00
|
|
|
}, [_assembledClassname, _tripodDir, _tripodPos, _player, _carryWeaponInfo, _secondaryWeaponMagazines]] call CBA_fnc_execNextFrame;
|
2019-06-08 04:47:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private _onFailure = {
|
|
|
|
params ["_args"];
|
2024-06-22 17:03:32 +00:00
|
|
|
_args params ["", "_player", "", "_carryWeaponClassname", "_carryWeaponInfo"];
|
2019-06-08 04:47:39 +00:00
|
|
|
TRACE_2("deployWeapon failure",_player,_carryWeaponClassname);
|
|
|
|
|
2024-06-22 17:03:32 +00:00
|
|
|
// Add weapon back
|
|
|
|
[_player, _carryWeaponClassname] call CBA_fnc_addWeaponWithoutItems;
|
|
|
|
|
|
|
|
// Add all attachments back
|
|
|
|
{
|
|
|
|
_player addWeaponItem [_carryWeaponClassname, _x, true];
|
|
|
|
} forEach _carryWeaponInfo;
|
2019-06-08 04:47:39 +00:00
|
|
|
};
|
|
|
|
|
2024-06-22 17:39:36 +00:00
|
|
|
private _condition = {
|
2019-06-08 04:47:39 +00:00
|
|
|
params ["_args"];
|
|
|
|
_args params ["_tripod"];
|
2024-04-02 15:15:06 +00:00
|
|
|
|
|
|
|
alive _tripod
|
2019-06-08 04:47:39 +00:00
|
|
|
};
|
|
|
|
|
2024-06-22 17:39:36 +00:00
|
|
|
[TIME_PROGRESSBAR(_deployTime), [_tripod, _player, _assembledClassname, _carryWeaponClassname, _carryWeaponInfo], _onFinish, _onFailure, LLSTRING(AssembleCSW_progressBar), _condition] call EFUNC(common,progressBar);
|
2019-06-08 04:47:39 +00:00
|
|
|
}, _this] call CBA_fnc_execNextFrame;
|