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

Explosives - Optimize creating explosive place actions #6413

Merged
merged 8 commits into from
Sep 22, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 2 additions & 4 deletions addons/explosives/CfgVehicles.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class CBA_Extended_EventHandlers;

class CfgVehicles {
Expand All @@ -15,12 +14,11 @@ class CfgVehicles {
insertChildren = QUOTE([_player] call FUNC(addTransmitterActions););
class ACE_Place {
displayName = CSTRING(Place);
condition = QUOTE((vehicle _player == _player) and {[_player] call FUNC(hasExplosives)});
statement = "";
insertChildren = QUOTE([_player] call FUNC(addExplosiveActions););
condition = "true";
exceptions[] = {"isNotSwimming"};
showDisabled = 1;
icon = QPATHTOF(UI\Place_Explosive_ca.paa);
insertChildren = QUOTE(_player call FUNC(addExplosiveActions));
};
class ACE_Cellphone {
displayName = CSTRING(cellphone_displayName);
Expand Down
69 changes: 25 additions & 44 deletions addons/explosives/functions/fnc_addExplosiveActions.sqf
Original file line number Diff line number Diff line change
@@ -1,61 +1,42 @@
/*
* Author: Garth 'L-H' de Wet and CAA-Picard
* Adds sub actions for all explosive magazines (from insertChildren)
* Author: Garth 'L-H' de Wet, CAA-Picard, mharis001
* Returns children actions for explosive magazines in the player's inventory.
*
* Arguments:
* 0: Unit <OBJECT>
* 0: Player <OBJECT>
*
* Return Value:
* Actions <ARRAY>
*
* Example:
* [bob] call ace_explosives_fnc_addExplosiveActions
* [_player] call ace_explosives_fnc_addExplosiveActions
*
* Public: No
*/
#include "script_component.hpp"

params ["_unit"];
TRACE_1("params",_unit);
[_this, {
params ["_player"];
TRACE_1("Creating explosive actions",_player);

private _mags = magazines _unit;
private _list = [];
private _itemCount = [];
{
private _item = ConfigFile >> "CfgMagazines" >> _x;
if (getNumber(_item >> QGVAR(Placeable)) == 1) then {
private _index = _list find _item;
if (_index != -1) then {
_itemCount set [_index, (_itemCount select _index) + 1];
} else {
_list pushBack _item;
_itemCount pushBack 1;
};
};
} forEach _mags;

private _children = [];
private _cfgMagazines = configFile >> "CfgMagazines";
private _magazines = magazines _player;
private _totalCount = count _magazines;

{
private _name = getText (_x >> "displayNameShort");
if (_name isEqualTo "") then {
_name = getText (_x >> "displayName");
};
private _actions = [];
{
private _config = _cfgMagazines >> _x;
if (getNumber (_config >> QGVAR(Placeable)) == 1) then {
private _name = getText (_config >> "displayNameShort");
private _picture = getText (_config >> "picture");
if (_name isEqualTo "") then {
_name = getText (_config >> "displayName");
};

_children pushBack
[
[
format ["Explosive_%1", _forEachIndex],
format [_name + " (%1)", _itemCount select _forEachIndex],
getText(_x >> "picture"),
{[{_this call FUNC(setupExplosive)}, _this] call CBA_fnc_execNextFrame},
{true},
{},
(configName _x)
] call EFUNC(interact_menu,createAction),
[],
_unit
];
} forEach _list;
private _action = [_x, format ["%1 (%2)", _name, _totalCount - count (_magazines - [_x])], _picture, {[{_this call FUNC(setupExplosive)}, _this] call CBA_fnc_execNextFrame}, {true}, {}, _x] call EFUNC(interact_menu,createAction);
_actions pushBack [_action, [], _player];
};
} forEach (_magazines arrayIntersect _magazines);

_children
_actions
}, ACE_player, QGVAR(explosiveActions), 3600, "cba_events_loadoutEvent"] call EFUNC(common,cachedCall);
17 changes: 6 additions & 11 deletions addons/explosives/functions/fnc_hasExplosives.sqf
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/*
* Author: Garth 'L-H' de Wet
* Whether the passed unit has any explosives on them.
* Author: Garth 'L-H' de Wet, mharis001
* Checks if given unit has any placeable explosives on them.
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* The unit has explosives <BOOL>
* Has explosives <BOOL>
*
* Example:
* hasExplosives = [player] call ACE_Explosives_fnc_hasExplosives;
* [player] call ace_explosives_fnc_hasExplosives
*
* Public: Yes
*/
Expand All @@ -18,12 +18,7 @@
params ["_unit"];
TRACE_1("params",_unit);

private _result = false;
private _cfgMagazines = configFile >> "CfgMagazines";
private _magazines = magazines _unit;
{
if (getNumber (ConfigFile >> "CfgMagazines" >> _x >> QGVAR(Placeable)) == 1) exitWith {
_result = true;
};
} count _magazines;

_result
((_magazines arrayIntersect _magazines) findIf {getNumber (_cfgMagazines >> _x >> QGVAR(Placeable)) == 1}) > -1