|
| 1 | +#include "script_component.hpp" |
| 2 | +/* |
| 3 | + * Author: BackpackOnChestRedux contributors |
| 4 | + * Capture ACRE2 radio states for radios referenced by a loadout cargo array |
| 5 | + * (typically: getUnitLoadout _unit select 5 select 1 for backpack contents). |
| 6 | + * |
| 7 | + * Arguments: |
| 8 | + * 0: Unit <OBJECT> |
| 9 | + * 1: Loadout cargo array <ARRAY> |
| 10 | + * |
| 11 | + * Return Value: |
| 12 | + * Array of radio state arrays <ARRAY> |
| 13 | + * |
| 14 | + * Example: |
| 15 | + * [player, ((getUnitLoadout player) select 5) select 1] call bocr_main_fnc_acreCaptureRadioStatesFromLoadout; |
| 16 | + * |
| 17 | + * Public: No |
| 18 | + */ |
| 19 | + |
| 20 | +params ["_unit", "_cargoLoadout"]; |
| 21 | + |
| 22 | +if (!([_unit] call FUNC(acreIsInitialized))) exitWith {[]}; |
| 23 | +if !(_cargoLoadout isEqualType []) exitWith {[]}; |
| 24 | + |
| 25 | +private _unitRadios = [_unit] call FUNC(acreGetUnitRadioIds); |
| 26 | +if (_unitRadios isEqualTo []) exitWith {[]}; |
| 27 | + |
| 28 | +// Extract classnames referenced by the cargo loadout. |
| 29 | +private _classnames = []; |
| 30 | +{ |
| 31 | + if (_x isEqualType [] && {count _x > 0}) then { |
| 32 | + private _cargoClass = _x select 0; |
| 33 | + if (_cargoClass isEqualType "") then { |
| 34 | + _classnames pushBack _cargoClass; |
| 35 | + }; |
| 36 | + }; |
| 37 | +} forEach _cargoLoadout; |
| 38 | + |
| 39 | +// Radios are represented by their ID classnames; capture only those present in this cargo loadout. |
| 40 | +private _radioIds = []; |
| 41 | +private _unitRadiosLc = _unitRadios apply {toLower _x}; |
| 42 | +{ |
| 43 | + // Loadout/cargo can contain ID classnames with different casing than ACRE returns (e.g. "ACRE_PRC343_ID_3" |
| 44 | + // vs "acre_prc343_id_3"), so match case-insensitively but store the actual carried ID string. |
| 45 | + private _idx = _unitRadiosLc find (toLower _x); |
| 46 | + if (_idx >= 0) then {_radioIds pushBackUnique (_unitRadios select _idx);}; |
| 47 | +} forEach _classnames; |
| 48 | + |
| 49 | +private _states = []; |
| 50 | +{ |
| 51 | + private _state = [_x] call FUNC(acreGetRadioState); |
| 52 | + if (_state isNotEqualTo []) then { |
| 53 | + _states pushBack _state; |
| 54 | + }; |
| 55 | +} forEach _radioIds; |
| 56 | + |
| 57 | +_states |
0 commit comments