mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
add forcedMag and ai_unloadMagazines
This commit is contained in:
parent
cafe1f40e8
commit
7647123683
@ -5,6 +5,7 @@ PREP(aceRearmGetCarryMagazines);
|
|||||||
PREP(ai_handleFired);
|
PREP(ai_handleFired);
|
||||||
PREP(ai_handleGetIn);
|
PREP(ai_handleGetIn);
|
||||||
PREP(ai_reload);
|
PREP(ai_reload);
|
||||||
|
PREP(ai_unloadMagazines);
|
||||||
|
|
||||||
PREP(assemble_canDeployTripod);
|
PREP(assemble_canDeployTripod);
|
||||||
PREP(assemble_canDeployWeapon);
|
PREP(assemble_canDeployWeapon);
|
||||||
|
@ -6,38 +6,50 @@
|
|||||||
* Arguments:
|
* Arguments:
|
||||||
* 0: CSW <OBJECT>
|
* 0: CSW <OBJECT>
|
||||||
* 1: Gunner <OBJECT>
|
* 1: Gunner <OBJECT>
|
||||||
* 2: Weapon <STRING>
|
* 2: Skip reload time <BOOL> (default: false)
|
||||||
*
|
*
|
||||||
* Return Value:
|
* Return Value:
|
||||||
* None
|
* None
|
||||||
*
|
*
|
||||||
* Public: No
|
* Public: No
|
||||||
*/
|
*/
|
||||||
params ["_vehicle", "_gunner", "_weapon"];
|
params ["_vehicle", "_gunner", ["_instantReload", false]];
|
||||||
TRACE_3("AI reload",_vehicle,_gunner,_weapon);
|
TRACE_3("AI reload",_vehicle,_gunner,_instantReload);
|
||||||
|
|
||||||
private _loadableMagazines = [_vehicle, _gunner, true] call FUNC(reload_getLoadableMagazines);
|
private _loadableMagazines = [_vehicle, _gunner, true] call FUNC(reload_getLoadableMagazines);
|
||||||
if (_loadableMagazines isEqualTo []) exitWith {TRACE_1("could not find reloadable mag",_vehicle)};
|
if (_loadableMagazines isEqualTo []) exitWith {TRACE_1("could not find reloadable mag",_vehicle)};
|
||||||
|
|
||||||
|
// API, to be used by artillerytables
|
||||||
|
private _forcedMag = _vehicle getVariable [QGVAR(forcedMag), ""];
|
||||||
|
|
||||||
|
// If this is called while CSW has ammo, unload mags in gunner's turret
|
||||||
|
if (someAmmo _vehicle) then {[_vehicle, _gunner, [_gunner] call EFUNC(common,getTurretIndex)] call FUNC(ai_unloadMagazine)};
|
||||||
|
|
||||||
private _bestAmmo = 0;
|
private _bestAmmo = 0;
|
||||||
private _magazineInfo = [];
|
private _magazineInfo = [];
|
||||||
{
|
{
|
||||||
_x params ["", "", "", "", "", "_ammo"];
|
_x params ["_xMag", "", "", "", "", "_ammo"];
|
||||||
|
if (_forcedMag isNotEqualTo "" && {_xMag != _forcedMag}) then {continue};
|
||||||
if (_ammo > _bestAmmo) then {
|
if (_ammo > _bestAmmo) then {
|
||||||
_bestAmmo = _ammo;
|
_bestAmmo = _ammo;
|
||||||
_magazineInfo = _x;
|
_magazineInfo = _x;
|
||||||
};
|
};
|
||||||
} forEach _loadableMagazines;
|
} forEach _loadableMagazines;
|
||||||
|
|
||||||
|
if (_magazineInfo isEqualTo []) exitWith {};
|
||||||
_magazineInfo params ["_carryMag", "_turretPath", "_loadInfo", "_magSource", "", "_ammo"];
|
_magazineInfo params ["_carryMag", "_turretPath", "_loadInfo", "_magSource", "", "_ammo"];
|
||||||
|
|
||||||
// Remove the mag from the source
|
// Remove the mag from the source
|
||||||
[_magSource, _carryMag, _ammo] call EFUNC(common,removeSpecificMagazine);
|
[_magSource, _carryMag, _ammo] call EFUNC(common,removeSpecificMagazine);
|
||||||
|
|
||||||
// see fnc_reload_loadMagazine #L54
|
|
||||||
// AI never returns ammo and removes the magazine before reloading, so we can skip distance and weaponHolder checks
|
// AI never returns ammo and removes the magazine before reloading, so we can skip distance and weaponHolder checks
|
||||||
private _eventParams = [_vehicle, _turretPath, objNull, _carryMag, _ammo, _gunner];
|
private _eventParams = [_vehicle, _turretPath, objNull, _carryMag, _ammo, _gunner];
|
||||||
|
|
||||||
|
if (_instantReload) exitWith {
|
||||||
|
TRACE_1("calling addTurretMag event: instant AI reload",_this);
|
||||||
|
[QGVAR(addTurretMag), _eventParams] call CBA_fnc_globalEvent;
|
||||||
|
};
|
||||||
|
|
||||||
private _timeToLoad = GET_NUMBER(configOf _vehicle >> QUOTE(ADDON) >> "ammoLoadTime", 1);
|
private _timeToLoad = GET_NUMBER(configOf _vehicle >> QUOTE(ADDON) >> "ammoLoadTime", 1);
|
||||||
|
|
||||||
TRACE_1("Reloading in progress",_timeToLoad);
|
TRACE_1("Reloading in progress",_timeToLoad);
|
||||||
|
43
addons/csw/functions/fnc_ai_unloadMagazines.sqf
Normal file
43
addons/csw/functions/fnc_ai_unloadMagazines.sqf
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#include "script_component.hpp"
|
||||||
|
/*
|
||||||
|
* Author: LinkIsGrim
|
||||||
|
* Switch loaded magazine on an AI CSW
|
||||||
|
*
|
||||||
|
* Arguments:
|
||||||
|
* 0: CSW <OBJECT>
|
||||||
|
* 1: Gunner <OBJECT>
|
||||||
|
* 2: Turret Path <ARRAY>
|
||||||
|
*
|
||||||
|
* Return Value:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Public: No
|
||||||
|
*/
|
||||||
|
params ["_vehicle", "_gunner", "_turretPath"];
|
||||||
|
|
||||||
|
private _magsToRemove = [];
|
||||||
|
private _containerMagazineClassnames = [];
|
||||||
|
private _containerMagazineCount = [];
|
||||||
|
|
||||||
|
{
|
||||||
|
_x params ["_xMag", "_xTurret", "_xAmmo"];
|
||||||
|
if (_xTurret isNotEqualTo _turretPath) then {continue};
|
||||||
|
private _carryMag = _xMag call FUNC(getCarryMagazine);
|
||||||
|
if (_carryMag != "") then {
|
||||||
|
_magsToRemove pushBackUnique [_xMag, _xTurret];
|
||||||
|
private _index = _containerMagazineClassnames find _carryMag;
|
||||||
|
if (_index < 0) then {
|
||||||
|
_index = _containerMagazineClassnames pushBack _carryMag;
|
||||||
|
_containerMagazineCount pushBack 0;
|
||||||
|
};
|
||||||
|
_containerMagazineCount set [_index, (_containerMagazineCount select _index) + _xAmmo];
|
||||||
|
};
|
||||||
|
} forEach (_vehicle magazinesAllTurrets _vehicle);
|
||||||
|
|
||||||
|
{
|
||||||
|
_vehicle removeMagazinesTurret _x;
|
||||||
|
} forEach _magsToRemove;
|
||||||
|
|
||||||
|
{
|
||||||
|
[_vehicle, _x, _containerMagazineCount select _forEachIndex] call FUNC(reload_handleReturnAmmo);
|
||||||
|
} forEach _containerMagazineClassnames;
|
Loading…
Reference in New Issue
Block a user