Merge pull request #2626 from acemod/340weaponselectcleanup

Code Cleanup WeaponSelect
This commit is contained in:
commy2 2015-09-28 18:10:16 +02:00
commit 6289a0cadb
18 changed files with 160 additions and 569 deletions

View File

@ -375,8 +375,8 @@ if (!isNil QGVAR(PreInit_playerChanged_PFHID)) then {
// @todo still needed?
[QGVAR(StateArrested), false, true, QUOTE(ADDON)] call FUNC(defineVariable);
["displayTextStructured", FUNC(displayTextStructured)] call FUNC(addEventhandler);
["displayTextPicture", FUNC(displayTextPicture)] call FUNC(addEventhandler);
["displayTextStructured", {_this call FUNC(displayTextStructured)}] call FUNC(addEventhandler);
["displayTextPicture", {_this call FUNC(displayTextPicture)}] call FUNC(addEventhandler);
["medical_onUnconscious", {
params ["_unit", "_isUnconscious"];

View File

@ -1,3 +1,4 @@
class ACE_Settings {
class GVAR(DisplayText) {
typeName = "BOOL";

View File

@ -13,8 +13,8 @@ class Extended_PostInit_EventHandlers {
class Extended_FiredBIS_EventHandlers {
class CAManBase {
class GVAR(ThrowGrenade) {
clientFiredBIS = QUOTE(if (_this select 0 == ACE_player) then {_this call FUNC(throwGrenade)};);
class GVAR(throwGrenade) {
clientFiredBIS = QUOTE(if (_this select 0 == ACE_player) then {_this call FUNC(throwGrenade)});
};
};
};

View File

@ -3,9 +3,8 @@
if (!hasInterface) exitWith {};
// Add keybinds
["ACE3 Weapons", QGVAR(SelectPistolNew), localize LSTRING(SelectPistol),
{
// add keybinds
["ACE3 Weapons", QGVAR(SelectPistolNew), localize LSTRING(SelectPistol), {
// Conditions: canInteract
if !([ACE_player, ACE_player, ["isNotInside", "isNotEscorting"]] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
@ -16,10 +15,9 @@ if (!hasInterface) exitWith {};
false
},
{false},
[0, [false, false, false]], false] call cba_fnc_addKeybind; //Unbound (was 1 Key)
[0, [false, false, false]], false] call CBA_fnc_addKeybind; //Unbound (was 1 Key)
["ACE3 Weapons", QGVAR(SelectRifleNew), localize LSTRING(SelectRifle),
{
["ACE3 Weapons", QGVAR(SelectRifleNew), localize LSTRING(SelectRifle), {
// Conditions: canInteract
if !([ACE_player, ACE_player, ["isNotInside", "isNotEscorting"]] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
@ -30,10 +28,9 @@ if (!hasInterface) exitWith {};
false
},
{false},
[0, [false, false, false]], false] call cba_fnc_addKeybind; //Unbound (was 2 Key)
[0, [false, false, false]], false] call CBA_fnc_addKeybind; //Unbound (was 2 Key)
["ACE3 Weapons", QGVAR(SelectRifleMuzzleNew), localize LSTRING(SelectRifleMuzzle),
{
["ACE3 Weapons", QGVAR(SelectRifleMuzzleNew), localize LSTRING(SelectRifleMuzzle), {
// Conditions: canInteract
if !([ACE_player, ACE_player, ["isNotInside", "isNotEscorting"]] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
@ -44,10 +41,9 @@ if (!hasInterface) exitWith {};
false
},
{false},
[0, [false, false, false]], false] call cba_fnc_addKeybind; //Unbound (was 3 Key)
[0, [false, false, false]], false] call CBA_fnc_addKeybind; //Unbound (was 3 Key)
["ACE3 Weapons", QGVAR(SelectLauncherNew), localize LSTRING(SelectLauncher),
{
["ACE3 Weapons", QGVAR(SelectLauncherNew), localize LSTRING(SelectLauncher), {
// Conditions: canInteract
if !([ACE_player, ACE_player, ["isNotInside", "isNotEscorting"]] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
@ -58,10 +54,9 @@ if (!hasInterface) exitWith {};
false
},
{false},
[0, [false, false, false]], false] call cba_fnc_addKeybind; //Unbound (was 4 Key)
[0, [false, false, false]], false] call CBA_fnc_addKeybind; //Unbound (was 4 Key)
["ACE3 Weapons", QGVAR(SelectBinocularNew), localize LSTRING(SelectBinocular),
{
["ACE3 Weapons", QGVAR(SelectBinocularNew), localize LSTRING(SelectBinocular), {
// Conditions: canInteract
if !([ACE_player, ACE_player, ["isNotInside", "isNotEscorting"]] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
@ -72,38 +67,35 @@ if (!hasInterface) exitWith {};
false
},
{false},
[0, [false, false, false]], false] call cba_fnc_addKeybind; //Unbound (was 5 Key)
[0, [false, false, false]], false] call CBA_fnc_addKeybind; //Unbound (was 5 Key)
["ACE3 Weapons", QGVAR(SelectGrenadeFrag), localize LSTRING(SelectGrenadeFrag),
{
["ACE3 Weapons", QGVAR(SelectGrenadeFrag), localize LSTRING(SelectGrenadeFrag), {
// Conditions: canInteract
if !([ACE_player, ACE_player, ["isNotInside", "isNotEscorting"]] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
if !([ACE_player] call EFUNC(common,canUseWeapon)) exitWith {false};
// Statement
[ACE_player] call FUNC(selectGrenadeFrag);
[ACE_player, 1] call FUNC(selectNextGrenade);
true
},
{false},
[7, [false, false, false]], false] call cba_fnc_addKeybind; //6 Key
[7, [false, false, false]], false] call CBA_fnc_addKeybind; //6 Key
["ACE3 Weapons", QGVAR(SelectGrenadeOther), localize LSTRING(SelectGrenadeOther),
{
["ACE3 Weapons", QGVAR(SelectGrenadeOther), localize LSTRING(SelectGrenadeOther), {
// Conditions: canInteract
if !([ACE_player, ACE_player, ["isNotInside", "isNotEscorting"]] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
if !([ACE_player] call EFUNC(common,canUseWeapon)) exitWith {false};
// Statement
[ACE_player] call FUNC(selectGrenadeOther);
[ACE_player, 2] call FUNC(selectNextGrenade);
true
},
{false},
[8, [false, false, false]], false] call cba_fnc_addKeybind; //7 Key
[8, [false, false, false]], false] call CBA_fnc_addKeybind; //7 Key
["ACE3 Weapons", QGVAR(HolsterWeapon), localize LSTRING(HolsterWeapon),
{
["ACE3 Weapons", QGVAR(HolsterWeapon), localize LSTRING(HolsterWeapon), {
// Conditions: canInteract
if !([ACE_player, ACE_player, ["isNotInside", "isNotEscorting"]] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
@ -125,10 +117,9 @@ if (!hasInterface) exitWith {};
true
},
{false},
[11, [false, false, false]], false] call cba_fnc_addKeybind; //0 Key
[11, [false, false, false]], false] call CBA_fnc_addKeybind; //0 Key
["ACE3 Vehicles", QGVAR(EngineOn), localize LSTRING(EngineOn),
{
["ACE3 Vehicles", QGVAR(EngineOn), localize LSTRING(EngineOn), {
// Conditions: canInteract
if !([ACE_player, vehicle ACE_player, []] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
@ -139,10 +130,9 @@ if (!hasInterface) exitWith {};
true
},
{false},
[3, [false, false, false]], false] call cba_fnc_addKeybind; //2 Key
[3, [false, false, false]], false] call CBA_fnc_addKeybind; //2 Key
["ACE3 Vehicles", QGVAR(EngineOff), localize LSTRING(EngineOff),
{
["ACE3 Vehicles", QGVAR(EngineOff), localize LSTRING(EngineOff), {
// Conditions: canInteract
if !([ACE_player, vehicle ACE_player, []] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
@ -153,10 +143,9 @@ if (!hasInterface) exitWith {};
true
},
{false},
[2, [false, false, false]], false] call cba_fnc_addKeybind; //1 Key
[2, [false, false, false]], false] call CBA_fnc_addKeybind; //1 Key
["ACE3 Vehicles", QGVAR(SelectMainGunNew), localize LSTRING(SelectMainGun),
{
["ACE3 Vehicles", QGVAR(SelectMainGunNew), localize LSTRING(SelectMainGun), {
// Conditions: canInteract
if !([ACE_player, vehicle ACE_player, []] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
@ -167,10 +156,9 @@ if (!hasInterface) exitWith {};
true
},
{false},
[0, [false, false, false]], false] call cba_fnc_addKeybind; //Unbound (was 3 Key)
[0, [false, false, false]], false] call CBA_fnc_addKeybind; //Unbound (was 3 Key)
["ACE3 Vehicles", QGVAR(SelectMachineGunNew), localize LSTRING(SelectMachineGun),
{
["ACE3 Vehicles", QGVAR(SelectMachineGunNew), localize LSTRING(SelectMachineGun), {
// Conditions: canInteract
if !([ACE_player, vehicle ACE_player, []] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
@ -181,10 +169,9 @@ if (!hasInterface) exitWith {};
true
},
{false},
[0, [false, false, false]], false] call cba_fnc_addKeybind; //Unbound (was 4 Key)
[0, [false, false, false]], false] call CBA_fnc_addKeybind; //Unbound (was 4 Key)
["ACE3 Vehicles", QGVAR(SelectMissilesNew), localize LSTRING(SelectMissiles),
{
["ACE3 Vehicles", QGVAR(SelectMissilesNew), localize LSTRING(SelectMissiles), {
// Conditions: canInteract
if !([ACE_player, vehicle ACE_player, []] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
@ -195,10 +182,9 @@ if (!hasInterface) exitWith {};
true
},
{false},
[0, [false, false, false]], false] call cba_fnc_addKeybind; //Unbound (was 5 Key)
[0, [false, false, false]], false] call CBA_fnc_addKeybind; //Unbound (was 5 Key)
["ACE3 Vehicles", QGVAR(FireSmokeLauncher), localize LSTRING(FireSmokeLauncher),
{
["ACE3 Vehicles", QGVAR(FireSmokeLauncher), localize LSTRING(FireSmokeLauncher), {
// Conditions: canInteract
if !([ACE_player, vehicle ACE_player, []] call EFUNC(common,canInteractWith)) exitWith {false};
// Conditions: specific
@ -209,4 +195,4 @@ if (!hasInterface) exitWith {};
true
},
{false},
[10, [false, false, false]], false] call cba_fnc_addKeybind; //9 Key
[10, [false, false, false]], false] call CBA_fnc_addKeybind; //9 Key

View File

@ -2,67 +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");
{
_magazines = getArray (configFile >> "CfgWeapons" >> "Throw" >> _x >> "magazines");
_magazine = _magazines select 0;
GVAR(GrenadesAll) append _magazines;
_ammo = getText (configfile >> "CfgMagazines" >> _magazine >> "ammo");
_explosive = getNumber (configfile >> "CfgAmmo" >> _ammo >> "explosive");
{
_ammo = getText (configfile >> "CfgMagazines" >> _x >> "ammo");
_explosive = getNumber (configfile >> "CfgAmmo" >> _ammo >> "explosive");
if (_explosive == 0) then {
GVAR(NonFragMuzzles) pushBack _x;
GVAR(NonFragMagazines) pushBack _magazines;
} else {
GVAR(FragMuzzles) pushBack _x;
GVAR(FragMagazines) pushBack _magazines;
};
GVAR(AllMuzzles) pushBack _x;
GVAR(AllMagazines) pushBack _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(GrenadesFrag), GVAR(GrenadesNonFrag)] select (_explosive == 0)) pushBack _x;
false
} count _magazines;
false
} count getArray (configfile >> "CfgWeapons" >> "Throw" >> "muzzles");
ADDON = true;

View File

@ -1,55 +0,0 @@
/*
* Author: esteldunedain
* Count how many grenade magazines the unit has on the uniform and vest.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Muzzle Class <STRING>
*
* Return Value:
* 0: Number of magazines <NUMBER>
* 1: First magazine name <STRING>
*
* 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]

View File

@ -1,10 +1,10 @@
/*
* Author: esteldunedain
* Author: esteldunedain, commy2
* Display a grenade type and quantity.
*
* Arguments:
* 0: magazine class <STRING>
* 1: number of magazines <NUMBER>
* 0: grenade magazine class <STRING>
* 1: number of grenades <NUMBER>
*
* Return Value:
* None
@ -18,14 +18,14 @@
if !(GVAR(DisplayText)) exitwith {};
params ["_magazine", "_numberofGrenades"];
private ["_color", "_name", "_text", "_picture"];
params ["_magazine", "_numberofMagazines"];
_color = [[1, 0, 0], [1, 1, 1]] select (_numberofMagazines > 0);
_color = [[1, 0, 0], [1, 1, 1]] select (_numberofGrenades > 0);
_name = getText (configFile >> "CfgMagazines" >> _magazine >> "displayNameShort");
_text = [format["%1 x%2", _name, _numberofMagazines], _color] call EFUNC(common,stringToColoredText);
_text = [format ["%1 x%2", _name, _numberofGrenades], _color] call EFUNC(common,stringToColoredText);
_picture = getText (configFile >> "CfgMagazines" >> _magazine >> "picture");
[_text, _picture] call EFUNC(common,displayTextPicture);
["displayTextPicture", [_text, _picture]] call EFUNC(common,localEvent);

View File

@ -1,47 +0,0 @@
/*
* Author: commy2
* Find the next Grenade Magazine.
*
* Arguments:
* 0: Grenade Type ("All", "Frag", "NonFrag") <STRING>
*
* Return Value:
* Magazine classname <STRING>
*
* 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

View File

@ -1,47 +0,0 @@
/*
* Author: commy2
* Find the next Grenade Muzzle.
*
* Arguments:
* 0: Grenade Type ("All", "Frag", "NonFrag") <STRING>
*
* Return Value:
* Class name of next throw muzzle <STRING>
*
* 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

View File

@ -15,10 +15,10 @@
*/
#include "script_component.hpp"
private ["_turret", "_weapons"];
params ["_vehicle"];
private ["_turret", "_weapons"];
_turret = [_vehicle] call EFUNC(common,getTurretCommander);
_weapons = _vehicle weaponsTurret _turret;
@ -29,11 +29,10 @@ if (
) then {
//This doesn't work reliably for vehilces with additional weapons for the commander. Select smoke launcher instead.
private "_index";
// avoid infinite loop
if !("SmokeLauncher" in _weapons) exitWith {};
private "_index";
_index = 0;
while {
_vehicle currentWeaponTurret _turret != "SmokeLauncher"
@ -46,8 +45,9 @@ if (
// fire away!
private "_logic";
_logic = createGroup sideLogic createUnit ["Logic", [0,0,0], [], 0, "NONE"];
_logic action ["useWeapon", _vehicle, commander _vehicle, 0];
deleteVehicle _logic;
};

View File

@ -1,18 +0,0 @@
/*
* Author: commy2
* Returns the selected Grenade Muzzle.
*
* Arguments:
* None
*
* Return Value:
* Class name of selected throw muzzle <STRING>
*
* Example:
* [] call ace_weaponselect_fnc_getSelectedGrenade
*
* Public: No
*/
#include "script_component.hpp"
[GVAR(CurrentGrenadeMuzzleOther), GVAR(CurrentGrenadeMuzzleFrag)] select GVAR(CurrentGrenadeMuzzleIsFrag)

View File

@ -1,6 +1,6 @@
/*
* Author: commy2
* Play the change firemode sound for specified weapon at units position.
* Play weapon firemode change sound.
*
* Arguments:
* 0: Unit <OBJECT>
@ -16,32 +16,24 @@
*/
#include "script_component.hpp"
private ["_sound"];
params ["_unit", "_weapon"];
private ["_sound", "_position"];
_sound = getArray (configFile >> "CfgWeapons" >> _weapon >> "changeFiremodeSound");
if (count _sound == 0) exitWith {};
if (_sound isEqualTo []) exitWith {};
// add file extension
if call {
{
if (toLower (_sound select 0) find _x == count toArray (_sound select 0) - count toArray _x - 1) exitWith {false};
true
} forEach [".wav", ".ogg", ".wss"];
} then {
_sound set [0, (_sound select 0) + ".wss"];
// get position where to play the sound (position of the weapon)
_position = AGLToASL (_unit modelToWorldVisual (_unit selectionPosition "RightHand"));
_sound params ["_filename", ["_volume", 1], ["_soundPitch", 1], ["_distance", 0]];
if (_filename == "") exitWith {};
// add file extension .wss as default
if !(toLower (_filename select [count _filename - 4]) in [".wav", ".ogg", ".wss"]) then {
_filename = format ["%1.wss", _filename];
};
// add default volume, pitch and distance
if (count _sound < 2) then {_sound pushBack 1};
if (count _sound < 3) then {_sound pushBack 1};
if (count _sound < 4) then {_sound pushBack 0};
private "_position";
_position = _unit modelToWorldVisual (_unit selectionPosition "RightHand");
_position set [2, (_position select 2) + ((getPosASLW _unit select 2) - (getPosATL _unit select 2) max 0)];
playSound3D [_sound select 0, objNull, false, _position, _sound select 1, _sound select 2, _sound select 3];
playSound3D [_filename, objNull, false, _position, _volume, _soundPitch, _distance];

View File

@ -11,7 +11,7 @@
* Example:
* [player] call ace_weaponselect_fnc_putWeaponAway
*
* Public: NO
* Public: Yes
*/
#include "script_component.hpp"

View File

@ -1,54 +0,0 @@
/*
* Author: esteldunedain, commy2
* Cycle through all grenades.
*
* Arguments:
* 0: Unit <OBJECT>
*
* 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;
};

View File

@ -1,48 +0,0 @@
/*
* Author: esteldunedain, commy2
* Cycle through frags.
*
* Arguments:
* 0: Unit <OBJECT>
*
* 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;

View File

@ -1,48 +0,0 @@
/*
* Author: esteldunedain, commy2
* Cycle through non explosive grenades.
*
* Arguments:
* 0: Unit <OBJECT>
*
* 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;

View File

@ -0,0 +1,78 @@
/*
* Author: commy2
* Select the next grenade.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Grenade type [0: all, 1: frags, 2: non-frags] (default: 0) <NUMBER>
*
* Return Value:
* Selecting successful? <BOOL>
*
* Example:
* [player] call ace_weaponselect_fnc_selectNextGrenade
*
* Public: Yes
*/
#include "script_component.hpp"
params ["_unit", ["_type", 0]];
private ["_currentGrenade", "_magazines", "_grenades", "_nextGrenadeIndex", "_nextGrenade", "_uniformGrenades", "_vestGrenades", "_backpackGrenades"];
// get currently selected grenade
_currentGrenade = currentThrowable _unit;
// get correct array format if no grenade is selected
if (_currentGrenade isEqualTo []) then {
_currentGrenade = ["", ""];
};
_currentGrenade = _currentGrenade select 0;
// get available magazines for that unit
_magazines = magazines _unit;
_grenades = [];
{
if (_x in _magazines) then {
_grenades pushBack _x;
};
false
} count ([GVAR(GrenadesAll), GVAR(GrenadesFrag), GVAR(GrenadesNonFrag)] select _type);
// abort if no grenades are available
if (_grenades isEqualTo []) exitWith {false};
// get next grenade muzzle
_nextGrenadeIndex = (_grenades find _currentGrenade) + 1;
// roll over if the last grenade was selected
if (_nextGrenadeIndex >= count _grenades) then {
_nextGrenadeIndex = 0;
};
_nextGrenade = _grenades select _nextGrenadeIndex;
// abort if the same grenade would be selected
if (_currentGrenade == _nextGrenade) exitWith {false};
// current best method to select a grenade: remove all grenades except the one you want to select, then add them back
_uniformGrenades = [uniformItems _unit, {_x in GVAR(GrenadesAll) && {_x != _nextGrenade}}] call EFUNC(common,filter);
_vestGrenades = [vestItems _unit, {_x in GVAR(GrenadesAll) && {_x != _nextGrenade}}] call EFUNC(common,filter);
_backpackGrenades = [backpackItems _unit, {_x in GVAR(GrenadesAll) && {_x != _nextGrenade}}] call EFUNC(common,filter);
// remove all grenades except those we are switching to --> this breaks the selector
{_unit removeItemFromUniform _x; false} count _uniformGrenades;
{_unit removeItemFromVest _x; false} count _vestGrenades;
{_unit removeItemFromBackpack _x; false} count _backpackGrenades;
// readd grenades
{_unit addItemToUniform _x; false} count _uniformGrenades;
{_unit addItemToVest _x; false} count _vestGrenades;
{_unit addItemToBackpack _x; false} count _backpackGrenades;
[_nextGrenade, {_x == _nextGrenade} count _magazines] call FUNC(displayGrenadeTypeAndNumber);
true

View File

@ -1,118 +0,0 @@
/*
* Author: esteldunedain
* Select the next grenade muzzle to throw.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Muzzlename <STRING>
*
* 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;