2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2015-03-18 19:17:53 +00:00
|
|
|
/*
|
2023-08-28 18:14:45 +00:00
|
|
|
* Author: commy2, johnb43, drofseh
|
2023-08-28 17:27:01 +00:00
|
|
|
* Start reloading a launcher, reload started by the unit who has the missile.
|
2015-03-18 19:17:53 +00:00
|
|
|
*
|
2016-06-18 09:50:41 +00:00
|
|
|
* Arguments:
|
2023-08-28 17:27:01 +00:00
|
|
|
* 0: Unit executing the reload <OBJECT>
|
|
|
|
* 1: Unit equipped with the launcher <OBJECT>
|
|
|
|
* 2: Launcher name <STRING>
|
|
|
|
* 3: Missile name <STRING>
|
2015-03-18 19:17:53 +00:00
|
|
|
*
|
2016-06-18 09:50:41 +00:00
|
|
|
* Return Value:
|
2017-06-08 13:31:51 +00:00
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
2023-08-28 17:27:01 +00:00
|
|
|
* [player, cursorTarget, "launch_RPG32_F", "RPG32_F"] call ace_reloadlaunchers_fnc_load
|
2016-04-28 03:58:47 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
2015-03-18 19:17:53 +00:00
|
|
|
*/
|
|
|
|
|
2016-04-28 03:58:47 +00:00
|
|
|
params ["_unit", "_target", "_weapon", "_magazine"];
|
|
|
|
TRACE_4("params",_unit,_target,_weapon,_magazine);
|
2015-03-18 19:17:53 +00:00
|
|
|
|
2023-08-28 17:27:01 +00:00
|
|
|
private _config = configFile >> "CfgWeapons" >> _weapon >> QGVAR(buddyReloadTime);
|
|
|
|
|
|
|
|
private _reloadTime = if (isNumber _config) then {
|
|
|
|
getNumber _config
|
2016-05-04 04:13:43 +00:00
|
|
|
} else {
|
2023-08-28 18:14:45 +00:00
|
|
|
getNumber (configFile >> "CfgWeapons" >> _weapon >> "magazineReloadTime") min 2.5
|
2016-05-04 04:13:43 +00:00
|
|
|
};
|
2015-03-18 19:17:53 +00:00
|
|
|
|
2023-08-28 17:27:01 +00:00
|
|
|
// Play animation
|
2015-03-22 13:05:31 +00:00
|
|
|
[_unit] call EFUNC(common,goKneeling);
|
2015-03-18 19:17:53 +00:00
|
|
|
|
2023-08-28 18:14:45 +00:00
|
|
|
// Notify unit that is being reloaded that reload has been started
|
|
|
|
[QGVAR(reloadStarted), [_unit, _target], _target] call CBA_fnc_targetEvent;
|
|
|
|
|
2023-08-28 17:27:01 +00:00
|
|
|
// Show progress bar
|
2017-10-10 14:39:59 +00:00
|
|
|
private _onSuccess = {
|
2023-08-28 17:27:01 +00:00
|
|
|
(_this select 0) params ["_unit", "_target", "_weapon", "_magazine"];
|
|
|
|
|
2023-08-28 18:14:45 +00:00
|
|
|
// Check if the unit has any of the same magazines and calculate max ammo
|
|
|
|
private _maxAmmo = 0;
|
|
|
|
|
|
|
|
{
|
|
|
|
_maxAmmo = _maxAmmo max (_x select 1);
|
|
|
|
} forEach (magazinesAmmo _unit select {(_x select 0) == _magazine});
|
|
|
|
|
|
|
|
// Check if the launcher can still be loaded; If possible, then try to remove magazine
|
|
|
|
if !(_maxAmmo > 0 && {[_unit, _target, _weapon, _magazine] call FUNC(canLoad)} && {[_unit, _magazine, _maxAmmo] call EFUNC(common,removeSpecificMagazine)}) exitWith {
|
|
|
|
// Notify unit that was being reloaded that reload has been stopped
|
|
|
|
[QGVAR(reloadAborted), [_unit, _target], _target] call CBA_fnc_targetEvent;
|
|
|
|
|
|
|
|
// Notify reloading unit about failure
|
|
|
|
if (GVAR(displayStatusText)) then {
|
|
|
|
[LSTRING(LauncherNotLoaded)] call EFUNC(common,displayTextStructured);
|
|
|
|
};
|
|
|
|
};
|
2015-03-22 13:05:31 +00:00
|
|
|
|
2023-08-28 17:27:01 +00:00
|
|
|
// Reload target's launcher
|
2023-08-28 18:14:45 +00:00
|
|
|
[QGVAR(reloadLauncher), [_unit, _target, _weapon, _magazine, _maxAmmo], _target] call CBA_fnc_targetEvent;
|
2023-08-28 17:27:01 +00:00
|
|
|
|
2023-08-28 18:14:45 +00:00
|
|
|
// Notify reloading unit about success
|
|
|
|
if (GVAR(displayStatusText)) then {
|
|
|
|
[LSTRING(LauncherLoaded)] call EFUNC(common,displayTextStructured);
|
|
|
|
};
|
2015-03-22 13:05:31 +00:00
|
|
|
};
|
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _onFailure = {
|
2023-08-28 18:14:45 +00:00
|
|
|
(_this select 0) params ["_unit", "_target"];
|
|
|
|
|
|
|
|
// Notify unit that was being reloaded that reload has been stopped
|
|
|
|
[QGVAR(reloadAborted), [_unit, _target], _target] call CBA_fnc_targetEvent;
|
|
|
|
|
|
|
|
// Notify reloading unit about failure
|
|
|
|
if (GVAR(displayStatusText)) then {
|
|
|
|
[LSTRING(LauncherNotLoaded)] call EFUNC(common,displayTextStructured);
|
|
|
|
};
|
2015-03-22 13:05:31 +00:00
|
|
|
};
|
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _condition = {
|
2023-08-28 17:27:01 +00:00
|
|
|
(_this select 0) params ["_unit", "_target"];
|
|
|
|
|
|
|
|
(_this select 0) call FUNC(canLoad) && {_unit distance _target < 4}
|
2015-03-22 13:05:31 +00:00
|
|
|
};
|
|
|
|
|
2023-08-28 17:27:01 +00:00
|
|
|
[_reloadTime, [_unit, _target, _weapon, _magazine], _onSuccess, _onFailure, LLSTRING(LoadingLauncher), _condition, ["isNotInside", "isNotSwimming"]] call EFUNC(common,progressBar);
|