diff --git a/addons/weaponselect/XEH_postInit.sqf b/addons/weaponselect/XEH_postInit.sqf index 336358381a..491a86f39d 100644 --- a/addons/weaponselect/XEH_postInit.sqf +++ b/addons/weaponselect/XEH_postInit.sqf @@ -76,7 +76,7 @@ if (!hasInterface) exitWith {}; if !([ACE_player] call EFUNC(common,canUseWeapon)) exitWith {false}; // Statement - [ACE_player] call FUNC(selectGrenadeFrag); + [ACE_player, 1] call FUNC(selectNextGrenade); true }, {false}, @@ -89,7 +89,7 @@ if (!hasInterface) exitWith {}; if !([ACE_player] call EFUNC(common,canUseWeapon)) exitWith {false}; // Statement - [ACE_player] call FUNC(selectGrenadeOther); + [ACE_player, 2] call FUNC(selectNextGrenade); true }, {false}, diff --git a/addons/weaponselect/XEH_preInit.sqf b/addons/weaponselect/XEH_preInit.sqf index 4319a507dd..1f324f7fb0 100644 --- a/addons/weaponselect/XEH_preInit.sqf +++ b/addons/weaponselect/XEH_preInit.sqf @@ -2,78 +2,36 @@ ADDON = false; -PREP(countMagazinesForGrenadeMuzzle); PREP(displayGrenadeTypeAndNumber); -PREP(findNextGrenadeMagazine); -PREP(findNextGrenadeMuzzle); PREP(fireSmokeLauncher); -PREP(getSelectedGrenade); PREP(playChangeFiremodeSound); PREP(putWeaponAway); -PREP(selectGrenadeAll); -PREP(selectGrenadeFrag); -PREP(selectGrenadeOther); PREP(selectNextGrenade); PREP(selectWeaponMode); PREP(selectWeaponMuzzle); PREP(selectWeaponVehicle); -PREP(setNextGrenadeMuzzle); PREP(throwGrenade); -// prepare grenades from config -GVAR(CurrentGrenadeMuzzleIsFrag) = true; -GVAR(CurrentGrenadeMuzzleFrag) = ""; -GVAR(CurrentGrenadeMuzzleOther) = ""; +// collect frag and other grenades separately +GVAR(GrenadesAll) = []; +GVAR(GrenadesFrag) = []; +GVAR(GrenadesNonFrag) = []; -// Collect frag and other muzzles separately -with uiNamespace do { - private ["_magazines", "_magazine", "_ammo", "_explosive"]; - if (isNil QGVAR(FragMuzzles)) then { - GVAR(FragMuzzles) = []; - GVAR(NonFragMuzzles) = []; - GVAR(AllMuzzles) = []; +private ["_magazines", "_ammo", "_explosive"]; - GVAR(FragMagazines) = []; - GVAR(NonFragMagazines) = []; - GVAR(AllMagazines) = []; +{ + _magazines = getArray (configFile >> "CfgWeapons" >> "Throw" >> _x >> "magazines"); - GVAR(GrenadesAll) = []; - GVAR(GrenadesFrag) = [];// - GVAR(GrenadesNonFrag) = [];// + GVAR(GrenadesAll) append _magazines; - { - _magazines = getArray (configFile >> "CfgWeapons" >> "Throw" >> _x >> "magazines"); - _magazine = _magazines select 0; + { + _ammo = getText (configfile >> "CfgMagazines" >> _x >> "ammo"); + _explosive = getNumber (configfile >> "CfgAmmo" >> _ammo >> "explosive"); - _ammo = getText (configfile >> "CfgMagazines" >> _magazine >> "ammo"); - _explosive = getNumber (configfile >> "CfgAmmo" >> _ammo >> "explosive"); - - if (_explosive == 0) then { - GVAR(NonFragMuzzles) pushBack _x; - GVAR(NonFragMagazines) pushBack _magazines; - GVAR(GrenadesNonFrag) append _magazines;// - } else { - GVAR(FragMuzzles) pushBack _x; - GVAR(FragMagazines) pushBack _magazines; - GVAR(GrenadesFrag) append _magazines;// - }; - - GVAR(AllMuzzles) pushBack _x; - GVAR(AllMagazines) pushBack _magazines; - GVAR(GrenadesAll) append _magazines;// - - } forEach getArray (configfile >> "CfgWeapons" >> "Throw" >> "muzzles"); - }; -}; - -GVAR(FragMuzzles) = uiNamespace getVariable QGVAR(FragMuzzles); -GVAR(NonFragMuzzles) = uiNamespace getVariable QGVAR(NonFragMuzzles); -GVAR(AllMuzzles) = uiNamespace getVariable QGVAR(AllMuzzles); -GVAR(FragMagazines) = uiNamespace getVariable QGVAR(FragMagazines); -GVAR(NonFragMagazines) = uiNamespace getVariable QGVAR(NonFragMagazines); -GVAR(AllMagazines) = uiNamespace getVariable QGVAR(AllMagazines); -GVAR(GrenadesAll) = uiNamespace getVariable QGVAR(GrenadesAll);// -GVAR(GrenadesFrag) = uiNamespace getVariable QGVAR(GrenadesFrag);// -GVAR(GrenadesNonFrag) = uiNamespace getVariable QGVAR(GrenadesNonFrag);// + ([GVAR(GrenadesFrag), GVAR(GrenadesNonFrag)] select (_explosive == 0)) pushBack _x; + false + } count _magazines; + false +} count getArray (configfile >> "CfgWeapons" >> "Throw" >> "muzzles"); ADDON = true; diff --git a/addons/weaponselect/functions/fnc_countMagazinesForGrenadeMuzzle.sqf b/addons/weaponselect/functions/fnc_countMagazinesForGrenadeMuzzle.sqf deleted file mode 100644 index 572a83edf1..0000000000 --- a/addons/weaponselect/functions/fnc_countMagazinesForGrenadeMuzzle.sqf +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Author: esteldunedain - * Count how many grenade magazines the unit has on the uniform and vest. - * - * Arguments: - * 0: Unit - * 1: Muzzle Class - * - * Return Value: - * 0: Number of magazines - * 1: First magazine name - * - * Example: - * [player, currentMuzzle player] call ace_weaponselect_fnc_countMagazinesForGrenadeMuzzle - * - * Public: No - */ -#include "script_component.hpp" - -private ["_uniformMags", "_vestMags", "_backpackMags", "_numberOfMagazines", "_magazineClasses", "_firstMagazine"]; - -params ["_unit", "_muzzle"]; - -_uniformMags = getMagazineCargo uniformContainer _unit; -_vestMags = getMagazineCargo vestContainer _unit; -_backpackMags = getMagazineCargo backpackContainer _unit; - -_numberOfMagazines = 0; -_magazineClasses = getArray (configFile >> "CfgWeapons" >> "Throw" >> _muzzle >> "magazines"); -_firstMagazine = _magazineClasses select 0; - -{ - private ["_indexInUniform", "_indexInVest", "_indexInBackpack"]; - - _indexInUniform = (_uniformMags select 0) find _x; - if (_indexInUniform > -1) then { - _numberOfMagazines = _numberOfMagazines + ((_uniformMags select 1) select _indexInUniform); - _firstMagazine = _x; - }; - - _indexInVest = (_vestMags select 0) find _x; - if (_indexInVest > -1) then { - _numberOfMagazines = _numberOfMagazines + ((_vestMags select 1) select _indexInVest); - _firstMagazine = _x; - }; - - _indexInBackpack = (_backpackMags select 0) find _x; - if (_indexInBackpack > -1) then { - _numberOfMagazines = _numberOfMagazines + ((_backpackMags select 1) select _indexInBackpack); - _firstMagazine = _x; - }; - -} forEach _magazineClasses; - -[_numberOfMagazines, _firstMagazine] diff --git a/addons/weaponselect/functions/fnc_findNextGrenadeMagazine.sqf b/addons/weaponselect/functions/fnc_findNextGrenadeMagazine.sqf deleted file mode 100644 index 2b2370260a..0000000000 --- a/addons/weaponselect/functions/fnc_findNextGrenadeMagazine.sqf +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Author: commy2 - * Find the next Grenade Magazine. - * - * Arguments: - * 0: Grenade Type ("All", "Frag", "NonFrag") - * - * Return Value: - * Magazine classname - * - * Example: - * ["All"] call ace_weaponselect_fnc_findNextGrenadeMagazine - * - * Public: No - */ -#include "script_component.hpp" - -private ["_allMags", "_allMuzzles", "_magazines", "_start", "_index", "_nextMagazine"]; - -params ["_type"]; - -_allMags = missionNamespace getVariable [format [QGVAR(%1Magazines), _type], []]; -_allMuzzles = missionNamespace getVariable [format [QGVAR(%1Muzzles), _type], []]; - -_magazines = magazines ACE_player; - -_start = [GVAR(CurrentGrenadeMuzzleOther), GVAR(CurrentGrenadeMuzzleFrag)] select GVAR(CurrentGrenadeMuzzleIsFrag); -_index = _allMuzzles find _start; - -scopeName "SearchMain"; - -_nextMagazine = ""; -for "_index" from (_index + 1) to (count _allMuzzles - 1) do { - { - if (_x in (_allMags select _index)) exitWith {_nextMagazine = _x; breakTo "SearchMain"}; - } count _magazines; -}; - -if (_nextMagazine != "") exitWith {_nextMagazine}; - -for "_index" from 0 to _index do { - { - if (_x in (_allMags select _index)) exitWith {_nextMagazine = _x; breakTo "SearchMain"}; - } count _magazines; -}; - -_nextMagazine diff --git a/addons/weaponselect/functions/fnc_findNextGrenadeMuzzle.sqf b/addons/weaponselect/functions/fnc_findNextGrenadeMuzzle.sqf deleted file mode 100644 index 5aa096f44e..0000000000 --- a/addons/weaponselect/functions/fnc_findNextGrenadeMuzzle.sqf +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Author: commy2 - * Find the next Grenade Muzzle. - * - * Arguments: - * 0: Grenade Type ("All", "Frag", "NonFrag") - * - * Return Value: - * Class name of next throw muzzle - * - * Example: - * ["All"] call ace_weaponselect_fnc_findNextGrenadeMuzzle - * - * Public: No - */ -#include "script_component.hpp" - -private ["_allMags", "_allMuzzles", "_magazines", "_start", "_index", "_nextMuzzle"]; - -params ["_type"]; - -_allMags = missionNamespace getVariable [format [QGVAR(%1Magazines), _type], []]; -_allMuzzles = missionNamespace getVariable [format [QGVAR(%1Muzzles), _type], []]; - -_magazines = magazines ACE_player; - -_start = [GVAR(CurrentGrenadeMuzzleOther), GVAR(CurrentGrenadeMuzzleFrag)] select GVAR(CurrentGrenadeMuzzleIsFrag); -_index = _allMuzzles find _start; - -scopeName "SearchMain"; - -_nextMuzzle = ""; -for "_index" from (_index + 1) to (count _allMuzzles - 1) do { - { - if (_x in (_allMags select _index)) exitWith {_nextMuzzle = _allMuzzles select _index; breakTo "SearchMain"}; - } count _magazines; -}; - -if (_nextMuzzle != "") exitWith {_nextMuzzle}; - -for "_index" from 0 to _index do { - { - if (_x in (_allMags select _index)) exitWith {_nextMuzzle = _allMuzzles select _index; breakTo "SearchMain"}; - } count _magazines; -}; - -_nextMuzzle diff --git a/addons/weaponselect/functions/fnc_getSelectedGrenade.sqf b/addons/weaponselect/functions/fnc_getSelectedGrenade.sqf deleted file mode 100644 index aa89a13c98..0000000000 --- a/addons/weaponselect/functions/fnc_getSelectedGrenade.sqf +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Author: commy2 - * Returns the selected Grenade Muzzle. - * - * Arguments: - * None - * - * Return Value: - * Class name of selected throw muzzle - * - * Example: - * [] call ace_weaponselect_fnc_getSelectedGrenade - * - * Public: No - */ -#include "script_component.hpp" - -[GVAR(CurrentGrenadeMuzzleOther), GVAR(CurrentGrenadeMuzzleFrag)] select GVAR(CurrentGrenadeMuzzleIsFrag) diff --git a/addons/weaponselect/functions/fnc_selectGrenadeAll.sqf b/addons/weaponselect/functions/fnc_selectGrenadeAll.sqf deleted file mode 100644 index a68670184a..0000000000 --- a/addons/weaponselect/functions/fnc_selectGrenadeAll.sqf +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Author: esteldunedain, commy2 - * Cycle through all grenades. - * - * Arguments: - * 0: Unit - * - * Return Value: - * None - * - * Example: - * [player] call ace_weaponselect_fnc_selectGrenadeAll - * - * Public: No - */ -#include "script_component.hpp" - -private ["_text", "_nextMuzzle"]; - -params ["_unit"]; - -_nextMuzzle = ["All"] call FUNC(findNextGrenadeMuzzle); - -if (_nextMuzzle != "") then { - - private ["_magazines", "_magazine", "_count", "_return"]; - _magazines = GVAR(AllMagazines) select (GVAR(AllMuzzles) find _nextMuzzle); - reverse _magazines; - - _magazine = ""; - _count = {_return = _x in _magazines; if (_return) then {_magazine = _x}; _return} count magazines _unit; - - // There is a muzzle with magazines --> cycle to it - [_unit, _nextMuzzle] call FUNC(setNextGrenadeMuzzle); - - [_magazine, _count] call FUNC(displayGrenadeTypeAndNumber); - -} else { - // There is a no muzzle with magazines --> select nothing - GVAR(CurrentGrenadeMuzzleFrag) = ""; GVAR(CurrentGrenadeMuzzleOther) = ""; - - if (GVAR(DisplayText)) then { - _text = [localize LSTRING(NoGrenadesLeft), [1,0,0]] call EFUNC(common,stringToColoredText); - [composeText [lineBreak, _text]] call EFUNC(common,displayTextStructured); - }; -}; - -if (_nextMuzzle in GVAR(FragMuzzles)) then { - GVAR(CurrentGrenadeMuzzleFrag) = _nextMuzzle; - GVAR(CurrentGrenadeMuzzleIsFrag) = true; -} else { - GVAR(CurrentGrenadeMuzzleOther) = _nextMuzzle; - GVAR(CurrentGrenadeMuzzleIsFrag) = false; -}; diff --git a/addons/weaponselect/functions/fnc_selectGrenadeFrag.sqf b/addons/weaponselect/functions/fnc_selectGrenadeFrag.sqf deleted file mode 100644 index c221b6cc30..0000000000 --- a/addons/weaponselect/functions/fnc_selectGrenadeFrag.sqf +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Author: esteldunedain, commy2 - * Cycle through frags. - * - * Arguments: - * 0: Unit - * - * Return Value: - * None - * - * Example: - * [player] call ace_weaponselect_fnc_selectGrenadeFrag - * - * Public: No - */ -#include "script_component.hpp" - -private ["_text", "_nextMuzzle"]; - -params ["_unit"]; - -_nextMuzzle = ["Frag"] call FUNC(findNextGrenadeMuzzle); - -if (_nextMuzzle != "") then { - GVAR(CurrentGrenadeMuzzleFrag) = _nextMuzzle; - - private ["_magazines", "_magazine", "_count", "_return"]; - _magazines = GVAR(FragMagazines) select (GVAR(FragMuzzles) find _nextMuzzle); - reverse _magazines; - - _magazine = ""; - _count = {_return = _x in _magazines; if (_return) then {_magazine = _x}; _return} count magazines _unit; - - // There is a muzzle with magazines --> cycle to it - [_unit, _nextMuzzle] call FUNC(setNextGrenadeMuzzle); - - [_magazine, _count] call FUNC(displayGrenadeTypeAndNumber); - -} else { - // There is a no muzzle with magazines --> select nothing - GVAR(CurrentGrenadeMuzzleFrag) = ""; - if (GVAR(DisplayText)) then { - _text = [localize LSTRING(NoFragsLeft), [1,0,0]] call EFUNC(common,stringToColoredText); - [composeText [lineBreak, _text]] call EFUNC(common,displayTextStructured); - }; -}; - -GVAR(CurrentGrenadeMuzzleIsFrag) = true; diff --git a/addons/weaponselect/functions/fnc_selectGrenadeOther.sqf b/addons/weaponselect/functions/fnc_selectGrenadeOther.sqf deleted file mode 100644 index 2f219989eb..0000000000 --- a/addons/weaponselect/functions/fnc_selectGrenadeOther.sqf +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Author: esteldunedain, commy2 - * Cycle through non explosive grenades. - * - * Arguments: - * 0: Unit - * - * Return Value: - * None - * - * Example: - * [player] call ace_weaponselect_fnc_selectGrenadeOther - * - * Public: No - */ -#include "script_component.hpp" - -private ["_nextMuzzle", "_text"]; - -params ["_unit"]; - -_nextMuzzle = ["NonFrag"] call FUNC(findNextGrenadeMuzzle); - -if (_nextMuzzle != "") then { - GVAR(CurrentGrenadeMuzzleOther) = _nextMuzzle; - - private ["_magazines", "_magazine", "_count", "_return"]; - _magazines = GVAR(NonFragMagazines) select (GVAR(NonFragMuzzles) find _nextMuzzle); - reverse _magazines; - - _magazine = ""; - _count = {_return = _x in _magazines; if (_return) then {_magazine = _x}; _return} count magazines _unit; - - // There is a muzzle with magazines --> cycle to it - [_unit, _nextMuzzle] call FUNC(setNextGrenadeMuzzle); - - [_magazine, _count] call FUNC(displayGrenadeTypeAndNumber); - -} else { - // There is a no muzzle with magazines --> select nothing - GVAR(CurrentGrenadeMuzzleOther) = ""; - if (GVAR(DisplayText)) then { - _text = [localize LSTRING(NoMiscGrenadeLeft), [1,0,0]] call EFUNC(common,stringToColoredText); - [composeText [lineBreak, _text]] call EFUNC(common,displayTextStructured); - }; -}; - -GVAR(CurrentGrenadeMuzzleIsFrag) = false; diff --git a/addons/weaponselect/functions/fnc_selectNextGrenade.sqf b/addons/weaponselect/functions/fnc_selectNextGrenade.sqf index 0c0d834a3d..d4a00b5718 100644 --- a/addons/weaponselect/functions/fnc_selectNextGrenade.sqf +++ b/addons/weaponselect/functions/fnc_selectNextGrenade.sqf @@ -73,4 +73,6 @@ _backpackGrenades = [backpackItems _unit, {_x in GVAR(GrenadesAll) && {_x != _ne {_unit addItemToVest _x; false} count _vestGrenades; {_unit addItemToBackpack _x; false} count _backpackGrenades; +[_nextGrenade, {_x == _nextGrenade} count _magazines] call FUNC(displayGrenadeTypeAndNumber); + true diff --git a/addons/weaponselect/functions/fnc_setNextGrenadeMuzzle.sqf b/addons/weaponselect/functions/fnc_setNextGrenadeMuzzle.sqf deleted file mode 100644 index ce7ec55393..0000000000 --- a/addons/weaponselect/functions/fnc_setNextGrenadeMuzzle.sqf +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Author: esteldunedain - * Select the next grenade muzzle to throw. - * - * Arguments: - * 0: Unit - * 1: Muzzlename - * - * Return Value: - * None - * - * Example: - * [player, currentMuzzle player] call ace_weaponselect_fnc_setNextGrenadeMuzzle - * - * Public: No - */ -#include "script_component.hpp" - -private ["_uniformMags", "_vestMags", "_backpackMags", "_i", "_uniformMagsToRemove", "_vestMagsToRemove", "_backpackMagsToRemove", "_firstMagazine", "_throwMuzzleNames"]; - -params ["_unit", "_muzzle"]; - -_uniformMags = getMagazineCargo uniformContainer _unit; -_vestMags = getMagazineCargo vestContainer _unit; -_backpackMags = getMagazineCargo backpackContainer _unit; - -_uniformMagsToRemove = []; -_vestMagsToRemove = []; -_backpackMagsToRemove = []; - -_firstMagazine = ""; -_throwMuzzleNames = getArray (configfile >> "CfgWeapons" >> "Throw" >> "muzzles"); - -// Collect which magazines to remove -{ - private "_muzzleMagazines"; - _muzzleMagazines = getArray (configFile >> "CfgWeapons" >> "Throw" >> _x >> "magazines" ); - - if (_x != _muzzle) then { - - { - private "_index"; - _index = (_uniformMags select 0) find _x; - if (_index > -1) then { - _uniformMagsToRemove = _uniformMagsToRemove + [[_x, (_uniformMags select 1) select _index]]; - }; - - _index = (_vestMags select 0) find _x; - if (_index > -1) then { - _vestMagsToRemove = _vestMagsToRemove + [[_x, (_vestMags select 1) select _index]]; - }; - - _index = (_backpackMags select 0) find _x; - if (_index > -1) then { - _backpackMagsToRemove = _backpackMagsToRemove + [[_x, (_backpackMags select 1) select _index]]; - }; - } forEach _muzzleMagazines; - - } else { - - { - private "_index"; - _index = (_uniformMags select 0) find _x; - if (_index > -1) then { - _firstMagazine = _x; - }; - - _index = (_vestMags select 0) find _x; - if (_index > -1) then { - _firstMagazine = _x; - }; - - _index = (_backpackMags select 0) find _x; - if (_index > -1) then { - _firstMagazine = _x; - }; - } forEach _muzzleMagazines; - - }; -} forEach _throwMuzzleNames; - -// Remove all magazines except those we are switching to --> this breaks the selector -{ - for [{_i = 0}, {_i < (_x select 1)}, {_i = _i + 1}] do { - _unit removeItem (_x select 0); - }; -} forEach _uniformMagsToRemove; - -{ - for [{_i = 0}, {_i < (_x select 1)}, {_i = _i + 1}] do { - _unit removeItem (_x select 0); - }; -} forEach _vestMagsToRemove; - -{ - for [{_i = 0}, {_i < (_x select 1)}, {_i = _i + 1}] do { - _unit removeItem (_x select 0); - }; -} forEach _backpackMagsToRemove; - -// Readd magazines -{ - for [{_i = 0}, {_i < (_x select 1)}, {_i = _i + 1}] do { - _unit addItemToUniform (_x select 0); - }; -} forEach _uniformMagsToRemove; - -{ - for [{_i = 0}, {_i < (_x select 1)}, {_i = _i + 1}] do { - _unit addItemToVest (_x select 0); - }; -} forEach _vestMagsToRemove; - -{ - for [{_i = 0}, {_i < (_x select 1)}, {_i = _i + 1}] do { - _unit addItemToBackpack (_x select 0); - }; -} forEach _backpackMagsToRemove;