ACE3/addons/csw/functions/fnc_ai_reload.sqf

52 lines
1.6 KiB
Plaintext
Raw Normal View History

#include "script_component.hpp"
/*
* Author: PabstMirror, LinkIsGrim
* Handles AI reloading
*
* Arguments:
2023-07-13 10:20:21 +00:00
* 0: CSW <OBJECT>
* 1: Gunner <OBJECT>
* 2: Weapon <STRING>
*
* Return Value:
* None
*
* Public: No
*/
2023-07-13 10:20:21 +00:00
params ["_vehicle", "_gunner", "_weapon"];
TRACE_3("AI reload",_vehicle,_gunner,_weapon);
2023-07-13 10:20:21 +00:00
private _loadableMagazines = [_vehicle, _gunner, true] call FUNC(reload_getLoadableMagazines);
if (_loadableMagazines isEqualTo []) exitWith {TRACE_1("could not find reloadable mag",_vehicle)};
2023-07-13 07:42:30 +00:00
private _bestAmmo = 0;
private _magazineInfo = [];
{
2023-07-13 07:42:30 +00:00
_x params ["", "", "", "", "", "_ammo"];
if (_ammo > _bestAmmo) then {
_bestAmmo = _ammo;
_magazineInfo = _x;
};
2023-07-13 07:42:30 +00:00
} forEach _loadableMagazines;
_magazineInfo params ["_carryMag", "_turretPath", "_loadInfo", "_magSource", "", "_ammo"];
// Remove the mag from the source
2023-07-13 07:42:30 +00:00
[_magSource, _carryMag, _ammo] call EFUNC(common,removeSpecificMagazine);
2023-07-01 15:39:42 +00:00
// see fnc_reload_loadMagazine #L54
// AI never returns ammo and removes the magazine before reloading, so we can skip distance and weaponHolder checks
2023-07-13 10:20:21 +00:00
private _eventParams = [_vehicle, _turretPath, objNull, _carryMag, _ammo, _gunner];
2023-07-01 15:39:42 +00:00
2023-07-13 10:20:21 +00:00
private _timeToLoad = GET_NUMBER(configOf _vehicle >> QUOTE(ADDON) >> "ammoLoadTime", 1);
TRACE_1("Reloading in progress",_timeToLoad);
[{
2023-07-13 10:20:21 +00:00
params ["_vehicle", "", "", "", "", "_gunner"];
if !(alive _vehicle && {alive _gunner}) exitWith {TRACE_2("invalid state",alive _vehicle,alive _gunner);};
// Reload the static weapon
2023-07-13 07:42:30 +00:00
TRACE_1("calling addTurretMag event: AI reload",_this);
[QGVAR(addTurretMag), _this] call CBA_fnc_globalEvent;
2023-07-01 15:39:42 +00:00
}, _eventParams, _timeToLoad] call CBA_fnc_waitAndExecute;