Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disposable - Use native hashmaps #1663

Merged
merged 6 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions addons/disposable/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,21 @@ if (configProperties [configFile >> "CBA_DisposableLaunchers"] isEqualTo []) exi
_unit call FUNC(changeDisposableLauncherClass);
}] call CBA_fnc_addClassEventHandler;

GVAR(NormalLaunchers) = [] call CBA_fnc_createNamespace;
GVAR(LoadedLaunchers) = [] call CBA_fnc_createNamespace;
GVAR(UsedLaunchers) = [] call CBA_fnc_createNamespace;
GVAR(NormalLaunchers) = createHashMap;
GVAR(LoadedLaunchers) = createHashMap;
GVAR(UsedLaunchers) = createHashMap;
GVAR(magazines) = [];
GVAR(BackpackLaunchers) = createHashMap;
GVAR(MagazineLaunchers) = [] call CBA_fnc_createNamespace;
GVAR(MagazineLaunchers) = createHashMap;

private _cfgWeapons = configFile >> "CfgWeapons";
private _cfgMagazines = configFile >> "CfgMagazines";

{
private _launcher = configName _x;
private _magazine = configName (_cfgMagazines >> (getArray (_cfgWeapons >> _launcher >> "magazines") select 0));
// Get case-sensitive config names
private _configLauncher = _cfgWeapons >> configName _x;
private _launcher = configName _configLauncher;
private _magazine = configName (_cfgMagazines >> (getArray (_configLauncher >> "magazines") select 0));
johnb432 marked this conversation as resolved.
Show resolved Hide resolved

if (_magazine == "") then {
ERROR_1("Launcher %1 has an undefined magazine.",_launcher);
Expand All @@ -59,27 +61,26 @@ private _cfgMagazines = configFile >> "CfgMagazines";
continue;
};

private _fitsInBackpacks = TYPE_BACKPACK in getArray (configFile >> "CfgWeapons" >> _loadedLauncher >> "WeaponSlotsInfo" >> "allowedSlots");
private _configLoadedLauncher = _cfgWeapons >> _loadedLauncher;
_loadedLauncher = configName _configLoadedLauncher;
private _fitsInBackpacks = TYPE_BACKPACK in getArray (_configLoadedLauncher >> "WeaponSlotsInfo" >> "allowedSlots");

GVAR(LoadedLaunchers) setVariable [_launcher, _loadedLauncher];
GVAR(UsedLaunchers) setVariable [_launcher, _usedLauncher];

if (isNil {GVAR(NormalLaunchers) getVariable _loadedLauncher}) then {
GVAR(NormalLaunchers) setVariable [_loadedLauncher, [_launcher, _magazine]];
};
GVAR(LoadedLaunchers) set [_launcher, _loadedLauncher];
GVAR(UsedLaunchers) set [_launcher, _usedLauncher];
GVAR(NormalLaunchers) set [_loadedLauncher, [_launcher, _magazine], true]; // insert-only

if (GVAR(magazines) pushBackUnique _magazine != -1) then {
GVAR(MagazineLaunchers) setVariable [_magazine, _loadedLauncher];
GVAR(MagazineLaunchers) set [_magazine, _loadedLauncher];
};

if (_fitsInBackpacks) then {
GVAR(BackpackLaunchers) set [_loadedLauncher, true];
};

// check if mass entries add up
private _massLauncher = getNumber (_cfgWeapons >> _launcher >> "WeaponSlotsInfo" >> "mass");
private _massLauncher = getNumber (_configLauncher >> "WeaponSlotsInfo" >> "mass");
private _massMagazine = getNumber (_cfgMagazines >> _magazine >> "mass");
private _massLoadedLauncher = getNumber (_cfgWeapons >> _loadedLauncher >> "WeaponSlotsInfo" >> "mass");
private _massLoadedLauncher = getNumber (_configLoadedLauncher >> "WeaponSlotsInfo" >> "mass");
private _massUsedLauncher = getNumber (_cfgWeapons >> _usedLauncher >> "WeaponSlotsInfo" >> "mass");

if (_massLauncher != _massUsedLauncher) then {
Expand Down
2 changes: 1 addition & 1 deletion addons/disposable/fnc_changeDisposableLauncherClass.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Author:
params ["_unit"];
if (!local _unit) exitWith {};

private _launcher = GVAR(NormalLaunchers) getVariable secondaryWeapon _unit;
private _launcher = GVAR(NormalLaunchers) get secondaryWeapon _unit;

if (!isNil "_launcher") then {
_launcher params ["_launcher", "_magazine"];
Expand Down
2 changes: 1 addition & 1 deletion addons/disposable/fnc_firedDisposable.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if (!GVAR(replaceDisposableLauncher)) exitWith {};

params ["_unit", "_launcher", "_muzzle", "", "", "", "_projectile"];

private _usedLauncher = GVAR(UsedLaunchers) getVariable _launcher;
private _usedLauncher = GVAR(UsedLaunchers) get _launcher;
if (isNil "_usedLauncher") exitWith {};

[{
Expand Down
2 changes: 1 addition & 1 deletion addons/disposable/fnc_initDisplayInventory.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ private _fnc_update = {
params ["_display"];
private _control = _display displayCtrl IDC_FG_SW_MAGAZINE;

_control ctrlEnable (!GVAR(replaceDisposableLauncher) || {isNil {GVAR(LoadedLaunchers) getVariable secondaryWeapon call CBA_fnc_currentUnit}});
_control ctrlEnable (!GVAR(replaceDisposableLauncher) || {!((secondaryWeapon call CBA_fnc_currentUnit) in GVAR(LoadedLaunchers))});
};

_display displayAddEventHandler ["MouseMoving", _fnc_update];
Expand Down
2 changes: 1 addition & 1 deletion addons/disposable/fnc_replaceMagazineCargo.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private _isBackpack = getNumber (configOf _box >> "isBackpack") == 1;
_x params ["_magazine", "_ammo"];

if (_magazine in GVAR(magazines)) then {
private _loadedLauncher = GVAR(MagazineLaunchers) getVariable _magazine;
private _loadedLauncher = GVAR(MagazineLaunchers) get _magazine;

// As addWeaponCargoGlobal ignores allowedSlots, check here if launcher is allowed to be placed in a backpack
if (!_isBackpack || {_loadedLauncher in GVAR(BackpackLaunchers)}) then {
Expand Down