Skip to content

Commit

Permalink
Merge pull request #1663 from johnb432/disposable-use-native-hashmaps
Browse files Browse the repository at this point in the history
Disposable - Use native hashmaps
  • Loading branch information
PabstMirror authored Aug 10, 2024
2 parents 31eefbe + 792616e commit bdcb661
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
27 changes: 13 additions & 14 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(allowedSlotsLaunchers) = 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 = (compatibleMagazines _launcher) select 0;

if (_magazine == "") then {
ERROR_1("Launcher %1 has an undefined magazine.",_launcher);
Expand All @@ -62,21 +64,18 @@ private _cfgMagazines = configFile >> "CfgMagazines";
private _configLoadedLauncher = _cfgWeapons >> _loadedLauncher;
_loadedLauncher = configName _configLoadedLauncher;

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

GVAR(allowedSlotsLaunchers) set [_loadedLauncher, getArray (_configLoadedLauncher >> "WeaponSlotsInfo" >> "allowedSlots")];

// 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 (_configLoadedLauncher >> "WeaponSlotsInfo" >> "mass");
private _massUsedLauncher = getNumber (_cfgWeapons >> _usedLauncher >> "WeaponSlotsInfo" >> "mass");
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 @@ -59,7 +59,7 @@ _containerType = if (getNumber (configOf _container >> "isBackpack") == 1) then
{
_container addMagazineCargoGlobal [_x, -1];

private _loadedLauncher = GVAR(MagazineLaunchers) getVariable _x;
private _loadedLauncher = GVAR(MagazineLaunchers) get _x;

// Slot restrictions only apply if uniform, vest or backpack
// If slot restrictions apply, remove magazine but don't add weapon
Expand Down

0 comments on commit bdcb661

Please sign in to comment.