diff --git a/addons/csw/functions/fnc_ai_reload.sqf b/addons/csw/functions/fnc_ai_reload.sqf index 88a21644c2..3090b8d3f9 100644 --- a/addons/csw/functions/fnc_ai_reload.sqf +++ b/addons/csw/functions/fnc_ai_reload.sqf @@ -7,7 +7,7 @@ * 0: CSW * 1: Gunner * 2: Skip reload time (default: false) - * 3: Clear forced magazine after reloading (default: true) + * 3: Clear forced magazine after reloading (default: false) * * Return Value: * None diff --git a/addons/csw/functions/fnc_getNearbySources.sqf b/addons/csw/functions/fnc_getNearbySources.sqf index fc322b44ed..f7b48c9b11 100644 --- a/addons/csw/functions/fnc_getNearbySources.sqf +++ b/addons/csw/functions/fnc_getNearbySources.sqf @@ -20,9 +20,9 @@ [_this, { params ["_unit", ["_skipVehicles", false], ["_includeCrew", false]]; - private _nearSupplies = (_unit nearSupplies 5) select { + private _nearSupplies = (_unit nearSupplies DISTANCE_SEARCH_RADIUS) select { isNull (group _x) || - {!([_x] call EFUNC(common,isPlayer)) && {[side group _unit, side group _x] call BIS_fnc_sideIsFriendly}} + {!(_x call EFUNC(common,isPlayer)) && {[side group _unit, side group _x] call BIS_fnc_sideIsFriendly}} }; if (_includeCrew) then { diff --git a/addons/csw/functions/fnc_reload_canLoadMagazine.sqf b/addons/csw/functions/fnc_reload_canLoadMagazine.sqf index 72aac1ea84..7759d66357 100644 --- a/addons/csw/functions/fnc_reload_canLoadMagazine.sqf +++ b/addons/csw/functions/fnc_reload_canLoadMagazine.sqf @@ -34,7 +34,7 @@ if !(isNull _magSource) then { if !(_carryMag in (magazineCargo _magSource)) exitWith {TRACE_3("no carry mag",_magSource,_carryMag,magazineCargo _magSource); _return breakOut "main"}; // Verify holder has not moved away from vehicle, with workaround for containers within containers - if ((_vehicle distance _magSource) > 5 && {(_vehicle distance (objectParent _magSource)) > 5}) exitWith {TRACE_1("too far",""); _return breakOut "main"}; + if ((_vehicle distance _magSource) > DISTANCE_SEARCH_RADIUS && {(_vehicle distance (objectParent _magSource)) > DISTANCE_SEARCH_RADIUS}) exitWith {TRACE_1("too far",""); _return breakOut "main"}; }; // solve config lookups diff --git a/addons/csw/functions/fnc_reload_canUnloadMagazine.sqf b/addons/csw/functions/fnc_reload_canUnloadMagazine.sqf index d7899e655a..d26feb5fd2 100644 --- a/addons/csw/functions/fnc_reload_canUnloadMagazine.sqf +++ b/addons/csw/functions/fnc_reload_canUnloadMagazine.sqf @@ -21,8 +21,8 @@ params ["_vehicle", "_turretPath", "_unit", "_carryMag", "_vehMag"]; -// handle disassembled or deleted -if ((!alive _vehicle) || {(_vehicle distance _unit) > 5}) exitWith {false}; +// Handle disassembled or deleted +if (!alive _vehicle || {(_vehicle distance _unit) > DISTANCE_SEARCH_RADIUS}) exitWith {false}; private _return = false; { diff --git a/addons/csw/functions/fnc_reload_handleReturnAmmo.sqf b/addons/csw/functions/fnc_reload_handleReturnAmmo.sqf index 5ec5fd4ce3..d893450c55 100644 --- a/addons/csw/functions/fnc_reload_handleReturnAmmo.sqf +++ b/addons/csw/functions/fnc_reload_handleReturnAmmo.sqf @@ -25,7 +25,7 @@ private _fullMagazines = floor (_ammo / _carryMaxAmmo); private _bulletsRemaining = _ammo % _carryMaxAmmo; // Get nearby units to clear cache -private _nearUnits = _unloadTo nearEntities ["CAManBase", 5]; +private _nearUnits = _unloadTo nearEntities ["CAManBase", DISTANCE_SEARCH_RADIUS]; private _unloadToUnit = _unloadTo isKindOf "CAManBase"; if (_unloadToUnit) then { @@ -47,7 +47,7 @@ if ((_fullMagazines == 0) && {_bulletsRemaining == 0}) exitWith { private _container = [_unloadTo, objNull] select _unloadToUnit; if ((maxLoad _container) isEqualTo 0) then { _container = _unloadTo getVariable [QGVAR(container), objNull]; - if ((_container distance _unloadTo) > 5) then { _container = objNull; }; + if ((_container distance _unloadTo) > DISTANCE_SEARCH_RADIUS) then { _container = objNull; }; if (isNull _container) then { _container = (nearestObjects [_unloadTo, [["GroundWeaponHolder"], [QGVAR(ammo_holder)]] select GVAR(handleExtraMagazinesType), 5]) param [0, objNull]; }; diff --git a/addons/csw/functions/fnc_reload_loadMagazine.sqf b/addons/csw/functions/fnc_reload_loadMagazine.sqf index 6c8e21268b..d6ebce2a4a 100644 --- a/addons/csw/functions/fnc_reload_loadMagazine.sqf +++ b/addons/csw/functions/fnc_reload_loadMagazine.sqf @@ -36,7 +36,7 @@ private _onFinish = { [_magSource, _carryMag, _ammo] call EFUNC(common,removeSpecificMagazine); - private _nearUnits = _vehicle nearEntities ["CAManBase", 5]; + private _nearUnits = _vehicle nearEntities ["CAManBase", DISTANCE_SEARCH_RADIUS]; [QGVAR(clearNearbySourcesCache), [], _nearUnits] call CBA_fnc_targetEvent; // Workaround for removeSpecificMagazine and WeaponHolders being deleted when empty, give back to the unit if the weapon holder was deleted diff --git a/addons/csw/functions/fnc_unloadMagazines.sqf b/addons/csw/functions/fnc_unloadMagazines.sqf index fd073e3664..133b0734be 100644 --- a/addons/csw/functions/fnc_unloadMagazines.sqf +++ b/addons/csw/functions/fnc_unloadMagazines.sqf @@ -19,10 +19,10 @@ params [["_vehicle", objNull, [objNull]], ["_turretPath", [0], [[0], true]], ["_returnMags", true, [true]]]; -if (isNull _vehicle) exitWith {}; +if (!alive _vehicle) exitWith {}; private _magsToRemove = []; -private _containerMagazineClassnames = []; +private _carryMagazines = createHashMap; private _containerMagazineCount = []; { @@ -31,12 +31,7 @@ private _containerMagazineCount = []; 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]; + _carryMagazines set [_carryMag, (_carryMagazines getOrDefault [_carryMag, 0]) + _xAmmo]; }; } forEach (magazinesAllTurrets _vehicle); @@ -46,6 +41,6 @@ private _containerMagazineCount = []; if (_returnMags) then { { - [_vehicle, _x, _containerMagazineCount select _forEachIndex] call FUNC(reload_handleReturnAmmo); - } forEach _containerMagazineClassnames; + [_vehicle, _x, _y] call FUNC(reload_handleReturnAmmo); + } forEach _carryMagazines; }; diff --git a/addons/csw/script_component.hpp b/addons/csw/script_component.hpp index 42b292c17e..79c0811339 100644 --- a/addons/csw/script_component.hpp +++ b/addons/csw/script_component.hpp @@ -19,6 +19,7 @@ #define GET_NUMBER(config,default) (if (isNumber (config)) then {getNumber (config)} else {default}) +#define DISTANCE_SEARCH_RADIUS 5 #define DISTANCE_FROM_GUN 1.5 #define RELATIVE_DIRECTION(direction) [DISTANCE_FROM_GUN, direction]