CSW - Fix AI reloading from GroundWeaponHolder (#8399)

* fix fnc_ai_handleFired

* remove debug messages

* use banana instead of FakePrimaryWeapon

* switch from dummy item to new weaponholder

* use exitWith instead of break
This commit is contained in:
Salluci 2021-09-25 12:39:03 -03:00 committed by GitHub
parent 82a8350fb4
commit a4f24cbe3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 59 deletions

View File

@ -1,7 +1,7 @@
#include "script_component.hpp" #include "script_component.hpp"
/* /*
* Author: esteldunedain * Author: esteldunedain
* Removes a magazine from the unit that has an specific ammo count * Removes a magazine from the unit or object that has a specific ammo count
* *
* Arguments: * Arguments:
* 0: Unit <OBJECT> * 0: Unit <OBJECT>
@ -9,7 +9,7 @@
* 2: Ammo count <NUMBER> * 2: Ammo count <NUMBER>
* *
* Return Value: * Return Value:
* None * Magazine Removed <BOOL>
* *
* Example: * Example:
* [bob, "magazine", 5] call ace_common_fnc_removeSpecificMagazine * [bob, "magazine", 5] call ace_common_fnc_removeSpecificMagazine
@ -21,62 +21,35 @@ params [["_unit", objNull, [objNull]], ["_magazineType", "", [""]], ["_ammoCount
private _isRemoved = false; private _isRemoved = false;
// Check uniform private _fnc_removeMagazine = {
private _magazines = magazinesAmmoCargo uniformContainer _unit select {_x select 0 == _magazineType}; params ["_container", "_magArray"];
private _index = _magazines find [_magazineType, _ammoCount]; _magArray params ["_magazineType", "_ammoCount"];
if (_index > -1) exitWith { private _allMagazines = magazinesAmmoCargo _container;
{ private _specificMagazineIndex = _allMagazines findIf {_x isEqualTo _magArray};
_unit removeItemFromUniform (_x select 0); _allMagazines deleteAt _specificMagazineIndex;
false
} count _magazines;
{ if (_specificMagazineIndex > -1) exitWith {
if (!_isRemoved && (_x isEqualTo [_magazineType,_ammoCount])) then { clearMagazineCargoGlobal _container;
_isRemoved = true; private _containerType = typeOf _container;
} else { if (_containerType in ["GroundWeaponHolder", "WeaponHolderSimulated"]) then {
(uniformContainer _unit) addMagazineAmmoCargo [_x select 0, 1, _x select 1]; _container = createVehicle [_containerType, getPosATL _container, [], 0, "CAN_COLLIDE"];
}; };
false {
} count _magazines; _container addMagazineAmmoCargo [_x select 0, 1, _x select 1];
} forEach _allMagazines;
true
};
false
}; };
// Check vest private _containerArray = [_unit];
_magazines = magazinesAmmoCargo vestContainer _unit select {_x select 0 == _magazineType}; if (_unit isKindOf "CAManBase") then {
_index = _magazines find [_magazineType, _ammoCount]; _containerArray = [uniformContainer _unit, vestContainer _unit, backpackContainer _unit];
if (_index > -1) exitWith {
{
_unit removeItemFromVest (_x select 0);
false
} count _magazines;
{
if (!_isRemoved && (_x isEqualTo [_magazineType,_ammoCount])) then {
_isRemoved = true;
} else {
(vestContainer _unit) addMagazineAmmoCargo [_x select 0, 1, _x select 1];
};
false
} count _magazines;
}; };
// Check backpack {
_magazines = magazinesAmmoCargo backpackContainer _unit select {_x select 0 == _magazineType}; if ([_x, [_magazineType, _ammoCount]] call _fnc_removeMagazine) exitWith {_isRemoved = true};
_index = _magazines find [_magazineType, _ammoCount]; } forEach _containerArray;
if (_index > -1) exitWith { _isRemoved
{
_unit removeItemFromBackpack (_x select 0);
false
} count _magazines;
{
if (!_isRemoved && (_x isEqualTo [_magazineType,_ammoCount])) then {
_isRemoved = true;
} else {
(backpackContainer _unit) addMagazineAmmoCargo [_x select 0, 1, _x select 1];
};
false
} count _magazines;
};

View File

@ -56,7 +56,7 @@ private _reloadNeededAmmo = -1;
}; };
} forEach _cswMagazines; } forEach _cswMagazines;
} forEach _compatibleMags; } forEach _compatibleMags;
} forEach ([_gunner] + (_staticWeapon nearEntities [["groundWeaponHolder", "ReammoBox_F"], 10])); } forEach ([_gunner] + (_staticWeapon nearSupplies 10));
if (_reloadMag == "") exitWith {TRACE_1("could not find mag",_reloadMag);}; if (_reloadMag == "") exitWith {TRACE_1("could not find mag",_reloadMag);};
// Figure out what we can add from the magazines we have // Figure out what we can add from the magazines we have
@ -74,11 +74,7 @@ TRACE_4("",_reloadSource,_reloadMag,_reloadNeededAmmo,_bestAmmoToSend);
if (_bestAmmoToSend == -1) exitWith {ERROR("No ammo");}; if (_bestAmmoToSend == -1) exitWith {ERROR("No ammo");};
// Remove the mag from the source // Remove the mag from the source
if (_reloadSource isKindOf "CaManBase") then { [_reloadSource, _reloadMag, _bestAmmoToSend] call EFUNC(common,removeSpecificMagazine);
[_reloadSource, _reloadMag, _bestAmmoToSend] call EFUNC(common,removeSpecificMagazine);
} else {
[_reloadSource, _reloadMag, 1, _bestAmmoToSend] call CBA_fnc_removeMagazineCargo;
};
private _timeToLoad = 1; private _timeToLoad = 1;
if (!isNull(configOf _staticWeapon >> QUOTE(ADDON) >> "ammoLoadTime")) then { if (!isNull(configOf _staticWeapon >> QUOTE(ADDON) >> "ammoLoadTime")) then {