Skip to content

Commit

Permalink
implement addWeaponWithAttachmentsCargoGlobal command (#1188)
Browse files Browse the repository at this point in the history
* implement addWeaponWithAttachmentsCargoGlobal command

* use AWWACG in removeXCargo functions

* fix test
  • Loading branch information
commy2 authored Jul 26, 2019
1 parent 4833ee3 commit 3227dbb
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 131 deletions.
46 changes: 9 additions & 37 deletions addons/common/fnc_removeBackpackCargo.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -94,45 +94,17 @@ private _fnc_addContents = {
// weaponsItems magazineGL does not exist if not loaded (not even as empty array)
if (count _x < 7) then {
_bipod = _magazineGL;
_magazineGL = "";
_magazineGL = [];
};

// Some weapons don't have non-preset parents
private _weaponNonPreset = [_weapon] call CBA_fnc_getNonPresetClass;
if (_weaponNonPreset == "") then {
_weaponNonPreset = _weapon;
};

_container addWeaponCargoGlobal [_weaponNonPreset, 1];

// If weapon does not have a non-preset parent, only add attachments that were custom added
// Removed attachments cannot be handled (engine limitation) and will be readded due to having to readd preset weapon
private _presetAttachments = [];
if (_weaponNonPreset == _weapon) then {
_presetAttachments = _weapon call CBA_fnc_weaponComponents;
};
if !(toLower _muzzle in _presetAttachments) then {
_container addItemCargoGlobal [_muzzle, 1];
};
if !(toLower _pointer in _presetAttachments) then {
_container addItemCargoGlobal [_pointer, 1];
};
if !(toLower _optic in _presetAttachments) then {
_container addItemCargoGlobal [_optic, 1];
};
if !(toLower _bipod in _presetAttachments) then {
_container addItemCargoGlobal [_bipod, 1];
};

_magazine params [["_magazineClass", ""], ["_magazineAmmoCount", 0]];
if (_magazineClass != "") then {
_container addMagazineAmmoCargo [_magazineClass, 1, _magazineAmmoCount];
};

_magazineGL params [["_magazineGLClass", ""], ["_magazineGLAmmoCount", 0]];
if (_magazineGLClass != "") then {
_container addMagazineAmmoCargo [_magazineGLClass, 1, _magazineGLAmmoCount];
};
_container addWeaponWithAttachmentsCargoGlobal [
[
_weapon,
_muzzle, _pointer, _optic,
_magazine, _magazineGL,
_bipod
], 1
];
} forEach _weaponsItemsCargo;
};

Expand Down
46 changes: 9 additions & 37 deletions addons/common/fnc_removeItemCargo.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -111,45 +111,17 @@ private _fnc_addContents = {
// weaponsItems magazineGL does not exist if not loaded (not even as empty array)
if (count _x < 7) then {
_bipod = _magazineGL;
_magazineGL = "";
_magazineGL = [];
};

// Some weapons don't have non-preset parents
private _weaponNonPreset = [_weapon] call CBA_fnc_getNonPresetClass;
if (_weaponNonPreset == "") then {
_weaponNonPreset = _weapon;
};

_container addWeaponCargoGlobal [_weaponNonPreset, 1];

// If weapon does not have a non-preset parent, only add attachments that were custom added
// Removed attachments cannot be handled (engine limitation) and will be readded due to having to readd preset weapon
private _presetAttachments = [];
if (_weaponNonPreset == _weapon) then {
_presetAttachments = _weapon call CBA_fnc_weaponComponents;
};
if !(toLower _muzzle in _presetAttachments) then {
_container addItemCargoGlobal [_muzzle, 1];
};
if !(toLower _pointer in _presetAttachments) then {
_container addItemCargoGlobal [_pointer, 1];
};
if !(toLower _optic in _presetAttachments) then {
_container addItemCargoGlobal [_optic, 1];
};
if !(toLower _bipod in _presetAttachments) then {
_container addItemCargoGlobal [_bipod, 1];
};

_magazine params [["_magazineClass", ""], ["_magazineAmmoCount", 0]];
if (_magazineClass != "") then {
_container addMagazineAmmoCargo [_magazineClass, 1, _magazineAmmoCount];
};

_magazineGL params [["_magazineGLClass", ""], ["_magazineGLAmmoCount", 0]];
if (_magazineGLClass != "") then {
_container addMagazineAmmoCargo [_magazineGLClass, 1, _magazineGLAmmoCount];
};
_container addWeaponWithAttachmentsCargoGlobal [
[
_weapon,
_muzzle, _pointer, _optic,
_magazine, _magazineGL,
_bipod
], 1
];
} forEach _weaponsItemsCargo;
};

Expand Down
40 changes: 9 additions & 31 deletions addons/common/fnc_removeWeaponCargo.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ clearWeaponCargoGlobal _container;
// weaponsItems magazineGL does not exist if not loaded (not even as empty array)
if (count _x < 7) then {
_bipod = _magazineGL;
_magazineGL = "";
_magazineGL = [];
};

// Some weapons don't have non-preset parents
Expand Down Expand Up @@ -103,36 +103,14 @@ clearWeaponCargoGlobal _container;
};
};
} else {
_container addWeaponCargoGlobal [_weaponNonPreset, 1];

// If weapon does not have a non-preset parent, only add attachments that were custom added
// Removed attachments cannot be handled (engine limitation) and will be readded due to having to readd preset weapon
private _presetAttachments = [];
if (_weaponNonPreset == _weapon) then {
_presetAttachments = _weapon call CBA_fnc_weaponComponents;
};
if !(toLower _muzzle in _presetAttachments) then {
_container addItemCargoGlobal [_muzzle, 1];
};
if !(toLower _pointer in _presetAttachments) then {
_container addItemCargoGlobal [_pointer, 1];
};
if !(toLower _optic in _presetAttachments) then {
_container addItemCargoGlobal [_optic, 1];
};
if !(toLower _bipod in _presetAttachments) then {
_container addItemCargoGlobal [_bipod, 1];
};

_magazine params [["_magazineClass", ""], ["_magazineAmmoCount", 0]];
if (_magazineClass != "") then {
_container addMagazineAmmoCargo [_magazineClass, 1, _magazineAmmoCount];
};

_magazineGL params [["_magazineGLClass", ""], ["_magazineGLAmmoCount", 0]];
if (_magazineGLClass != "") then {
_container addMagazineAmmoCargo [_magazineGLClass, 1, _magazineGLAmmoCount];
};
_container addWeaponWithAttachmentsCargoGlobal [
[
_weaponNonPreset,
_muzzle, _pointer, _optic,
_magazine, _magazineGL,
_bipod
], 1
];
};
} forEach _weaponsItemsCargo;

Expand Down
2 changes: 1 addition & 1 deletion addons/common/test_inventory.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ _container addBackpackCargoGlobal ["B_AssaultPack_mcamo", 1];
((everyBackpack _container) select 0) addWeaponCargoGlobal ["arifle_MX_ACO_pointer_F", 1];
_result = [_container, "B_AssaultPack_mcamo", 1, true] call CBA_fnc_removeBackpackCargo;
TEST_TRUE(_result,_funcName);
TEST_TRUE(count (backpackCargo _container) == 0 && count (weaponCargo _container) == 1 && count (itemCargo _container) == 2,_funcName);
TEST_TRUE(count (backpackCargo _container) == 0 && count (weaponCargo _container) == 1 && count (itemCargo _container) == 0,_funcName);
clearBackpackCargoGlobal _container;
clearWeaponCargoGlobal _container;
clearItemCargoGlobal _container;
Expand Down
35 changes: 10 additions & 25 deletions addons/disposable/fnc_firedDisposable.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -79,42 +79,27 @@ if (isNil "_usedLauncher") exitWith {};
}) exitWith {
if (GVAR(dropUsedLauncher) isEqualTo 1 && {_unit == call CBA_fnc_currentUnit}) exitWith {true};

private _launcherItems = secondaryWeaponItems _unit;
private _launcherMagazines = WEAPON_MAGAZINES(_unit,secondaryWeapon _unit);
secondaryWeaponItems _unit params ["_silencer", "_pointer", "_optic", "_bipod"];
WEAPON_MAGAZINES(_unit,secondaryWeapon _unit) params [["_magazineAmmo1", []], ["_magazineAmmo2", []]];

_unit removeWeapon _usedLauncher;

private _dir = getDir _unit - 180;

private _container = createVehicle ["WeaponHolderSimulated", [0,0,0], [], 0, "CAN_COLLIDE"];
_container addWeaponCargoGlobal [_usedLauncher, 1];
_container addWeaponWithAttachmentsCargoGlobal [
[
_usedLauncher,
_silencer, _pointer, _optic,
_magazineAmmo1, _magazineAmmo2,
_bipod
], 1
];

_container setDir (_dir + 90);
_container setPosASL AGLToASL (_unit modelToWorld (_unit selectionPosition "rightshoulder" vectorAdd [0, 0.2, 0.1]));
_container setVelocity (velocity _unit vectorAdd ([sin _dir, cos _dir, 0] vectorMultiply 1.5));

/*
_container addWeaponWithAttachmentsCargoGlobal [
_usedLauncher,
_silencer, _pointer, _optic, _bipod, [
_magazine1, _ammo1,
_magazine2, _ammo2
],
1];
*/

{
_container addItemCargoGlobal [_x, 1];
} forEach _launcherItems;

{
_x params ["_magazine", "_ammo"];

if (_ammo > 0) then {
_container addMagazineAmmoCargo [_x, 1, _ammo];
};
} forEach _launcherMagazines;

true // quit
};

Expand Down

0 comments on commit 3227dbb

Please sign in to comment.