mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
CSW - Fix belt linking (#10148)
* fix unloading to units with full inventory * fix belt linking issues * Enhance workaround * Use unit instead if magSource is null --------- Co-authored-by: Salluci <salluci.lovi@gmail.com>
This commit is contained in:
parent
ba22c407e3
commit
b7cd72e936
@ -10,7 +10,7 @@
|
|||||||
* 2: Source of magazine <OBJECT>
|
* 2: Source of magazine <OBJECT>
|
||||||
* 3: Vehicle Magazine <STRING>
|
* 3: Vehicle Magazine <STRING>
|
||||||
* 4: Ammo in magazine <NUMBER>
|
* 4: Ammo in magazine <NUMBER>
|
||||||
* 5: Unit or object to return ammo to <OBJECT>
|
* 5: Unit or object to return ammo to <OBJECT> (default: Source of magazine)
|
||||||
*
|
*
|
||||||
* Return Value:
|
* Return Value:
|
||||||
* None
|
* None
|
||||||
@ -21,7 +21,8 @@
|
|||||||
* Public: No
|
* Public: No
|
||||||
*/
|
*/
|
||||||
|
|
||||||
params ["_vehicle", "_turret", "_magSource", "_carryMag", "_ammoReceived", ["_returnTo", _magSource]];
|
params ["_vehicle", "_turret", "_magSource", "_carryMag", "_ammoReceived"];
|
||||||
|
private _returnTo = param [5, _magSource];
|
||||||
TRACE_6("reload_handleAddTurretMag",_vehicle,_turret,_magSource,_carryMag,_ammoReceived,_returnTo);
|
TRACE_6("reload_handleAddTurretMag",_vehicle,_turret,_magSource,_carryMag,_ammoReceived,_returnTo);
|
||||||
|
|
||||||
TRACE_2("",local _vehicle,_vehicle turretLocal _turret);
|
TRACE_2("",local _vehicle,_vehicle turretLocal _turret);
|
||||||
|
@ -18,13 +18,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
params ["_unloadTo", "_carryMag", "_ammo"];
|
params ["_unloadTo", "_carryMag", "_ammo"];
|
||||||
TRACE_3("reload_handleReturnAmmo",_unloadTo,_carryMag,_ammo);
|
TRACE_4("reload_handleReturnAmmo",_unloadTo,typeOf _unloadTo,_carryMag,_ammo);
|
||||||
|
|
||||||
private _carryMaxAmmo = getNumber (configFile >> "CfgMagazines" >> _carryMag >> "count");
|
private _carryMaxAmmo = getNumber (configFile >> "CfgMagazines" >> _carryMag >> "count");
|
||||||
private _fullMagazines = floor (_ammo / _carryMaxAmmo);
|
private _fullMagazines = floor (_ammo / _carryMaxAmmo);
|
||||||
private _bulletsRemaining = _ammo % _carryMaxAmmo;
|
private _bulletsRemaining = _ammo % _carryMaxAmmo;
|
||||||
|
|
||||||
if (_unloadTo isKindOf "CaManBase") then {
|
private _unloadToUnit = _unloadTo isKindOf "CAManBase";
|
||||||
|
|
||||||
|
if (_unloadToUnit) then {
|
||||||
while {(_fullMagazines > 0) && {[_unloadTo, _carryMag] call CBA_fnc_canAddItem}} do {
|
while {(_fullMagazines > 0) && {[_unloadTo, _carryMag] call CBA_fnc_canAddItem}} do {
|
||||||
_unloadTo addMagazine [_carryMag, _carryMaxAmmo];
|
_unloadTo addMagazine [_carryMag, _carryMaxAmmo];
|
||||||
_fullMagazines = _fullMagazines - 1;
|
_fullMagazines = _fullMagazines - 1;
|
||||||
@ -37,19 +39,21 @@ if (_unloadTo isKindOf "CaManBase") then {
|
|||||||
|
|
||||||
if ((_fullMagazines == 0) && {_bulletsRemaining == 0}) exitWith {};
|
if ((_fullMagazines == 0) && {_bulletsRemaining == 0}) exitWith {};
|
||||||
|
|
||||||
// Try to use existing container
|
// Try to use object inventory or existing container
|
||||||
private _container = _unloadTo getVariable [QGVAR(container), objNull];
|
private _container = [_unloadTo, objNull] select _unloadToUnit;
|
||||||
if ((_container distance _unloadTo) > 10) then { _container = objNull; };
|
if ((maxLoad _container) isEqualTo 0) then {
|
||||||
if (isNull _container) then {
|
_container = _unloadTo getVariable [QGVAR(container), objNull];
|
||||||
|
if ((_container distance _unloadTo) > 10) then { _container = objNull; };
|
||||||
|
if (isNull _container) then {
|
||||||
_container = (nearestObjects [_unloadTo, [["GroundWeaponHolder"], [QGVAR(ammo_holder)]] select GVAR(handleExtraMagazinesType), 10]) param [0, objNull];
|
_container = (nearestObjects [_unloadTo, [["GroundWeaponHolder"], [QGVAR(ammo_holder)]] select GVAR(handleExtraMagazinesType), 10]) param [0, objNull];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
if (isNull _container) then {
|
if (isNull _container) then {
|
||||||
// Create ammo storage container
|
// Create ammo storage container
|
||||||
private _weaponRelPos = _unloadTo getRelPos RELATIVE_DIRECTION(270);
|
private _weaponRelPos = _unloadTo getRelPos RELATIVE_DIRECTION(270);
|
||||||
_weaponRelPos set [2, ((getPosATL _unloadTo) select 2) + 0.05];
|
_weaponRelPos set [2, ((getPosATL _unloadTo) select 2) + 0.05];
|
||||||
_container = createVehicle [["GroundWeaponHolder", QGVAR(ammo_holder)] select GVAR(handleExtraMagazinesType), [0, 0, 0], [], 0, "NONE"];
|
_container = createVehicle [["GroundWeaponHolder", QGVAR(ammo_holder)] select GVAR(handleExtraMagazinesType), [0, 0, 0], [], 0, "CAN_COLLIDE"];
|
||||||
_unloadTo setVariable [QGVAR(container), _container, true];
|
_unloadTo setVariable [QGVAR(container), _container, true];
|
||||||
_container setDir random [0, 180, 360];
|
_container setDir random [0, 180, 360];
|
||||||
_container setPosATL _weaponRelPos;
|
_container setPosATL _weaponRelPos;
|
||||||
@ -59,7 +63,7 @@ if (isNull _container) then {
|
|||||||
TRACE_2("Creating NEW Container",_container,_weaponRelPos);
|
TRACE_2("Creating NEW Container",_container,_weaponRelPos);
|
||||||
};
|
};
|
||||||
|
|
||||||
TRACE_3("adding to container",_container,_fullMagazines,_bulletsRemaining);
|
TRACE_4("adding to container",_container,typeOf _container,_fullMagazines,_bulletsRemaining);
|
||||||
|
|
||||||
if (_fullMagazines > 0) then {
|
if (_fullMagazines > 0) then {
|
||||||
_container addMagazineAmmoCargo [_carryMag, _fullMagazines, _carryMaxAmmo];
|
_container addMagazineAmmoCargo [_carryMag, _fullMagazines, _carryMaxAmmo];
|
||||||
|
@ -52,8 +52,19 @@ private _onFinish = {
|
|||||||
[_magSource, _carryMag, _bestAmmoToSend] call EFUNC(common,removeSpecificMagazine);
|
[_magSource, _carryMag, _bestAmmoToSend] call EFUNC(common,removeSpecificMagazine);
|
||||||
if (_bestAmmoToSend == 0) exitWith {};
|
if (_bestAmmoToSend == 0) exitWith {};
|
||||||
|
|
||||||
TRACE_6("calling addTurretMag event",_vehicle,_turret,_magSource,_carryMag,_bestAmmoToSend,_unit);
|
// Workaround for removeSpecificMagazine and WeaponHolders being deleted when empty, give back to the unit if the weapon holder was deleted
|
||||||
[QGVAR(addTurretMag), [_vehicle, _turret, _magSource, _carryMag, _bestAmmoToSend, _unit]] call CBA_fnc_globalEvent;
|
// TODO: Pass type and position of deleted object to create a new one
|
||||||
|
// TODO: Use '_magSource getEntityInfo 14' in 2.18 and the isSetForDeletion flag to execute in same frame
|
||||||
|
[{
|
||||||
|
params ["_magSource", "_unit", "_args"];
|
||||||
|
|
||||||
|
if (isNull _magSource) then {
|
||||||
|
_args pushBack _unit;
|
||||||
|
};
|
||||||
|
|
||||||
|
TRACE_1("calling addTurretMag event",_args);
|
||||||
|
[QGVAR(addTurretMag), _args] call CBA_fnc_globalEvent;
|
||||||
|
}, [_magSource, _unit, [_vehicle, _turret, _magSource, _carryMag, _bestAmmoToSend]]] call CBA_fnc_execNextFrame;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user