fix case sensitivy, move container creation

This commit is contained in:
Salluci 2023-07-13 13:45:52 +03:00
parent ed44c0d445
commit aa8fff3041
5 changed files with 25 additions and 28 deletions

View File

@ -18,10 +18,12 @@
*/
params [["_csw", objNull, [objNull]]];
if !(typeOf _csw in GVAR(initializedStaticTypes)) exitWith {createHashMap};
if !((typeOf _csw) in GVAR(initializedStaticTypes)) exitWith {createHashMap};
// fast exit for csw with single weapon, most common scenario
if (count allTurrets _csw isEqualTo 1 && {count weapons _csw isEqualTo 1}) exitWith {
systemChat "has single weapon";
systemChat str (weapons _csw);
GVAR(compatibleMagsCache) get ((weapons _csw) select 0) // return
};

View File

@ -13,7 +13,7 @@
* Magazine ammo <NUMBER>
*
* Example:
* [player, cursorObject] call ace_csw_fnc_getSourceCompatibleMagazines
* [backpackContainer player, cursorObject] call ace_csw_fnc_getSourceCompatibleMagazines
*
* Public: Yes
*/

View File

@ -37,11 +37,14 @@ if ((missionNamespace getVariable [_proxyWeapon, objNull]) isEqualType {}) then
};
if (!_needed) exitWith { TRACE_2("not needed",_needed,_proxyWeapon); };
// Config case for hashmap key
_proxyWeapon = configName (configFile >> "CfgWeapons" >> _proxyWeapon);
// Cache compatible magazines
if !(_proxyWeapon in GVAR(compatibleVehicleMagsCache)) then {
if !(_proxyWeapon in GVAR(compatibleMagsCache)) then {
private _compatibleMagazines = compatibleMagazines _proxyWeapon;
GVAR(compatibleVehicleMagsCache) set [_proxyWeapon, _compatibleMagazines];
GVAR(compatibleCarryMagsCache) set [_proxyWeapon, (_compatibleMagazines apply {_x call FUNC(getCarryMagazine)}) createHashMapFromArray []];
GVAR(compatibleMagsCache) set [_proxyWeapon, (_compatibleMagazines apply {_x call FUNC(getCarryMagazine)}) createHashMapFromArray []];
};
TRACE_2("swapping to proxy weapon",_currentWeapon,_proxyWeapon);

View File

@ -56,8 +56,22 @@ if ((maxLoad _container) isEqualTo 0) then {
if (isNull _container) then {
// Create ammo storage container
private _containerType = getText (configOf _vehicle >> QUOTE(ADDON) >> "container");
// Use setting if container already created or not defined
if (_containerType isEqualTo "" || {!isNull (_vehicle getVariable [QGVAR(container), objNull])}) then {
_containerType = ["GroundWeaponHolder", QGVAR(ammo_holder)] select GVAR(handleExtraMagazinesType);
};
_container = createVehicle [_containerType, [0, 0, 0], [], 0, "CAN_COLLIDE"];
if ((loadAbs _container) isNotEqualTo 0) then {
clearItemCargoGlobal _container;
clearWeaponCargoGlobal _container;
clearBackpackCargoGlobal _container;
clearMagazineCargoGlobal _container;
};
private _weaponRelPos = (_unloadTo getRelPos RELATIVE_DIRECTION(270)) vectorAdd [0, 0, 0.05];
_container = createVehicle [["GroundWeaponHolder", QGVAR(ammo_holder)] select GVAR(handleExtraMagazinesType), [0, 0, 0], [], 0, "CAN_COLLIDE"];
_unloadTo setVariable [QGVAR(container), _container, true];
_container setDir random [0, 180, 360];
_container setPosATL _weaponRelPos;

View File

@ -81,29 +81,7 @@ if (_vehicle getVariable [QGVAR(secondaryWeaponMagazine), ""] isNotEqualTo "") t
if (_storeExtraMagazines) then {
TRACE_1("saving extra mags to container",_containerMagazineCount);
// Create container from config if available, use setting if not
private _containerType = getText (configOf _vehicle >> QUOTE(ADDON) >> "container");
if (_containerType isNotEqualTo "") then {
private _relPos = (_vehicle getRelPos RELATIVE_DIRECTION(270)) vectorAdd [0, 0, 0.05];
_container = createVehicle [_containerType, [0, 0, 0], [], 0, "CAN_COLLIDE"];
_vehicle setVariable [QGVAR(container), _container, true];
_container setDir random [0, 180, 360];
_container setPosATL _relPos;
if ((_relPos select 2) < 0.5) then {
_container setVectorUp (surfaceNormal _relPos);
};
// empty container inventory
// TODO: make a function in common?
clearItemCargoGlobal _container;
clearWeaponCargoGlobal _container;
clearMagazineCargoGlobal _container;
clearBackpackCargoGlobal _container;
} else {
_container = _vehicle;
};
{
[_container, _x, _containerMagazineCount select _forEachIndex] call FUNC(reload_handleReturnAmmo);
[_vehicle, _x, _containerMagazineCount select _forEachIndex] call FUNC(reload_handleReturnAmmo);
} forEach _containerMagazineClassnames;
};