Skip to content

Commit a87923d

Browse files
committed
Restore ACRE radio state even when not initialized
1 parent 3ee869e commit a87923d

3 files changed

Lines changed: 32 additions & 18 deletions

File tree

addons/main/functions/fnc_acreRestoreRadioStates.sqf

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,28 @@
1919

2020
params ["_unit", "_preRadios", "_states"];
2121

22-
if (!([_unit] call FUNC(acreIsInitialized))) exitWith {};
23-
if !(_preRadios isEqualType []) exitWith {};
24-
if (!(_states isEqualType []) || {_states isEqualTo []}) exitWith {};
25-
2622
private _debug = GETMVAR(GVAR(debugACRE),false);
2723
if (_debug) then {
28-
diag_log text format ["[BOCR][ACRE] restore start unit=%1 pre=%2 states=%3", _unit, _preRadios, _states];
24+
diag_log text format ["[BOCR][ACRE] restore called unit=%1 local=%2 pre=%3 states=%4", _unit, local _unit, _preRadios, _states];
2925
};
3026

27+
if (!(missionNamespace getVariable [QGVAR(isACRELoaded), false])) exitWith {
28+
if (_debug) then {diag_log text "[BOCR][ACRE] restore exit: ACRE not loaded";};
29+
};
30+
if (isNil "acre_api_fnc_getCurrentRadioList") exitWith {
31+
if (_debug) then {diag_log text "[BOCR][ACRE] restore exit: ACRE API not present";};
32+
};
33+
if (!local _unit) exitWith {
34+
if (_debug) then {diag_log text format ["[BOCR][ACRE] restore exit: unit not local (%1)", _unit];};
35+
};
36+
if !(_preRadios isEqualType []) exitWith {};
37+
if (!(_states isEqualType []) || {_states isEqualTo []}) exitWith {};
38+
3139
// Wait a moment for ACRE to register the new radios (inventory changes are not always immediate).
3240
[
3341
{
3442
params ["_unit", "_preRadios", "_states"];
43+
if (!([_unit] call FUNC(acreIsInitialized))) exitWith {false};
3544
private _postRadios = [_unit] call FUNC(acreGetUnitRadioIds);
3645
private _added = _postRadios - _preRadios;
3746
private _expected = count _states;
@@ -110,11 +119,16 @@ if (_debug) then {
110119
};
111120
},
112121
[_unit, _preRadios, _states],
113-
2,
122+
6,
114123
{
115124
// Timed out - best effort apply using whatever radios exist now.
116125
params ["_unit", "_preRadios", "_states"];
117126
private _debug = GETMVAR(GVAR(debugACRE),false);
127+
if (!([_unit] call FUNC(acreIsInitialized))) exitWith {
128+
if (_debug) then {
129+
diag_log text format ["[BOCR][ACRE] restore timeout: ACRE not initialized unit=%1", _unit];
130+
};
131+
};
118132
private _postRadios = [_unit] call FUNC(acreGetUnitRadioIds);
119133
private _added = _postRadios - _preRadios;
120134
if (_debug) then {

addons/main/functions/fnc_actionOnBack.sqf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ private _shouldSwitchNVGs = currentVisionMode _unit != 0;
2626
//make sure the player has a chestpack and no backpack
2727
if ((_chestpack isEqualTo "") or (backpack _unit isNotEqualTo "")) exitWith {};
2828

29-
private _acreEnabled = [_unit] call FUNC(acreIsInitialized);
29+
private _acreLoaded = (missionNamespace getVariable [QGVAR(isACRELoaded), false]) && {!isNil "acre_api_fnc_getCurrentRadioList"};
3030
private _preRadios = [];
31-
if (_acreEnabled && {_chestpackAcreRadios isNotEqualTo []}) then {
31+
if (_acreLoaded && {_chestpackAcreRadios isNotEqualTo []}) then {
3232
_preRadios = [_unit] call FUNC(acreGetUnitRadioIds);
3333
};
3434

35-
if (_acreEnabled) then {
35+
if (_acreLoaded) then {
3636
// Avoid setUnitLoadout when ACRE is running to prevent full radio re-init.
3737
_unit addBackpackGlobal _chestpack;
3838
private _backpack = backpackContainer _unit;
@@ -48,14 +48,14 @@ if (GVAR(isACEAXLoaded)) then {
4848
[_unit, [_unit] call aceax_gearinfo_fnc_getTextureOptions] call aceax_gearinfo_fnc_setTextureOptions;
4949
};
5050

51-
if (!_acreEnabled && {_shouldSwitchNVGs}) then {
51+
if (!_acreLoaded && {_shouldSwitchNVGs}) then {
5252
_unit action ["NVGoggles", _unit];
5353
};
5454
//prefilled versions of backpacks (ammo bearer, engineer, explosives, medic, repair, etc)
5555
//can be emptied and placed in unit's backpack
5656
//they must each be emptied when added
5757
//safe since game inventory won't let players add non-empty backpacks into their backpack
58-
if (!_acreEnabled) then {
58+
if (!_acreLoaded) then {
5959
[QGVAR(clearCargoBackpacks), [backpackContainer _unit]] call CBA_fnc_globalEvent;
6060
};
6161

@@ -66,7 +66,7 @@ private _backpack = backpackContainer _unit;
6666
} forEach _chestpackVariables;
6767

6868
// Restore ACRE radio settings for radios that were inside the pack when it was moved to chest.
69-
if (_acreEnabled && {_chestpackAcreRadios isNotEqualTo []}) then {
69+
if (_acreLoaded && {_chestpackAcreRadios isNotEqualTo []}) then {
7070
[_unit, _preRadios, _chestpackAcreRadios] call FUNC(acreRestoreRadioStates);
7171
};
7272

addons/main/functions/fnc_actionSwap.sqf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ private _chestpackVariables = [_unit] call FUNC(chestpackVariables);
3030
private _chestpackAcreRadios = [_unit] call FUNC(chestpackAcreRadios);
3131

3232
private _shouldSwitchNVGs = currentVisionMode _unit != 0;
33-
private _acreEnabled = [_unit] call FUNC(acreIsInitialized);
33+
private _acreLoaded = (missionNamespace getVariable [QGVAR(isACRELoaded), false]) && {!isNil "acre_api_fnc_getCurrentRadioList"};
3434

3535
//make sure the player has chest-pack and backpack
3636
if ((_backpack isEqualTo "") or ([_unit] call FUNC(chestpack)) isEqualTo "") exitWith {};
3737

3838
// If ACRE is running, capture per-radio state for radios inside the backpack that will become the new chestpack.
3939
// Also filter ACRE radio ID classnames out of the stored loadout to avoid re-adding IDed radios later.
40-
if (_acreEnabled) then {
40+
if (_acreLoaded) then {
4141
_backpackAcreRadios = [_unit, _backpackLoadoutRaw] call FUNC(acreCaptureRadioStatesFromLoadout);
4242
if !(isNil "acre_api_fnc_filterUnitLoadout") then {
4343
_unitLoadout = [_unitLoadout] call acre_api_fnc_filterUnitLoadout;
@@ -56,11 +56,11 @@ if (_acreEnabled) then {
5656
removeBackpackGlobal _unit;
5757

5858
private _preRadios = [];
59-
if (_acreEnabled && {_chestpackAcreRadios isNotEqualTo []}) then {
59+
if (_acreLoaded && {_chestpackAcreRadios isNotEqualTo []}) then {
6060
_preRadios = [_unit] call FUNC(acreGetUnitRadioIds);
6161
};
6262

63-
if (_acreEnabled) then {
63+
if (_acreLoaded) then {
6464
// Avoid setUnitLoadout when ACRE is running to prevent full radio re-init.
6565
_unit addBackpackGlobal _chestpack;
6666
private _backpackNew = backpackContainer _unit;
@@ -76,7 +76,7 @@ if (GVAR(isACEAXLoaded)) then {
7676
[_unit, [_unit] call aceax_gearinfo_fnc_getTextureOptions] call aceax_gearinfo_fnc_setTextureOptions;
7777
};
7878

79-
if (!_acreEnabled && {_shouldSwitchNVGs}) then {
79+
if (!_acreLoaded && {_shouldSwitchNVGs}) then {
8080
_unit action ["NVGoggles", _unit];
8181
};
8282

@@ -87,7 +87,7 @@ private _backpackNew = backpackContainer _unit;
8787
} forEach _chestpackVariables;
8888

8989
// Restore ACRE radio settings for radios that were inside the chestpack.
90-
if (_acreEnabled && {_chestpackAcreRadios isNotEqualTo []}) then {
90+
if (_acreLoaded && {_chestpackAcreRadios isNotEqualTo []}) then {
9191
[_unit, _preRadios, _chestpackAcreRadios] call FUNC(acreRestoreRadioStates);
9292
};
9393

0 commit comments

Comments
 (0)