Skip to content

Commit

Permalink
Explosives - Optimize creating explosive place actions (#6413)
Browse files Browse the repository at this point in the history
* Optimize explosive actions

* Optimize hasExplosives function

* Readability parentheses

* bump

* testing...

* last try

* for science

* fix for sqf_validator
  • Loading branch information
mharis001 authored and PabstMirror committed Sep 22, 2018
1 parent ab52ff8 commit 8648cca
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 59 deletions.
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 @@
#include "script_component.hpp"
/*
* 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
*/

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,29 +1,24 @@
#include "script_component.hpp"
/*
* 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
*/

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

0 comments on commit 8648cca

Please sign in to comment.