Use macro for radius, minor code cleanup & optimisation

This commit is contained in:
johnb432 2024-07-27 20:52:18 +02:00
parent 76628c1fc2
commit 3c3790e06d
8 changed files with 15 additions and 19 deletions

View File

@ -7,7 +7,7 @@
* 0: CSW <OBJECT>
* 1: Gunner <OBJECT>
* 2: Skip reload time <BOOL> (default: false)
* 3: Clear forced magazine after reloading (default: true)
* 3: Clear forced magazine after reloading (default: false)
*
* Return Value:
* None

View File

@ -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 {

View File

@ -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

View File

@ -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;
{

View File

@ -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];
};

View File

@ -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

View File

@ -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;
};

View File

@ -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]