-
Notifications
You must be signed in to change notification settings - Fork 739
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Explosives - Optimize creating explosive place actions (#6413)
* Optimize explosive actions * Optimize hasExplosives function * Readability parentheses * bump * testing... * last try * for science * fix for sqf_validator
- Loading branch information
1 parent
ab52ff8
commit 8648cca
Showing
3 changed files
with
33 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |