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

Radio - Add radio item replacement CBA Setting #1283

Merged
merged 27 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
13ebd10
Replace monitorRadios PFH with loadout EH
Freddo3000 Aug 17, 2020
c823fe0
Add default radio replacement setting
Freddo3000 Aug 17, 2020
465b878
Tweaks
Freddo3000 Aug 18, 2020
3b9e2fa
localization
Freddo3000 Aug 18, 2020
7f1b494
Obsolete fnc_setItemRadioReplacement
Freddo3000 Aug 18, 2020
d5d0e49
Ensure fnc_getAllRadios is present
Freddo3000 Aug 18, 2020
5f77992
Removed comment
Freddo3000 Aug 22, 2020
8c7ff00
Move fnc_getAllRadios from api to sys_core
Freddo3000 Aug 22, 2020
04b6dc6
Add another trigger for monitorRadiosHandler
Freddo3000 Aug 22, 2020
0c2a072
Merge branch 'master' into tweakItemRadio
Freddo3000 Aug 22, 2020
d330cd0
Update addons/sys_radio/initSettings.sqf
Freddo3000 Dec 14, 2020
bc158ee
Change to use CBA_settings_fnc_set
Freddo3000 Dec 14, 2020
996318b
Tweak basicMissionSetup
Freddo3000 Dec 14, 2020
4b0ef05
Add to ace_arsenal_displayClosed eventhandler
Freddo3000 Dec 14, 2020
c0dc120
Merge branch 'master' into tweakItemRadio
jonpas Jun 14, 2023
dd759a2
Deprecate instead of obsolete setItemRadioReplacement API, Cleanup
jonpas Jun 14, 2023
d6fa737
Merge branch 'master' into tweakItemRadio
jonpas Sep 10, 2023
4bbb8eb
Revert inventory monitoring PFH switch to CBA loadout EH
jonpas Sep 14, 2023
f02d31f
Remove weird defines
jonpas Sep 14, 2023
9189111
Fix missing defines
jonpas Sep 14, 2023
6b9a7b6
Fix missing defines more
jonpas Sep 14, 2023
57a8f0e
Merge branch 'master' into improve/radio-replacement
jonpas Sep 26, 2023
3fbc126
Fix missing ACRE_COMPONENT_RADIO define
jonpas Sep 26, 2023
586a94d
Fix setting being LIST but expecting string
jonpas Sep 26, 2023
df95388
Adapt deprecated function as well
jonpas Sep 26, 2023
104ed5d
Move include to correct component
jonpas Sep 26, 2023
4bf9606
Fix all issues
jonpas Sep 27, 2023
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
19 changes: 9 additions & 10 deletions addons/api/CfgAcreAPI.hpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
#define true 1
#define false 0
// WIP concept
class CfgAcreAPI {
class RadioAPIFunctions {
class setChannel {
required = true;
required = 1;
};
class setVolume {
required = true;
required = 1;
};
class setTransmitPower {
required = false;
required = 0;
defaultFunction = QFUNC(api_setTransmitPower);
};
class toggleOnOff {
required = false;
required = 0;
defaultFunction = QFUNC(api_toggleOnOffState);
};
class getOnOffState {
required = false;
required = 0;
defaultFunction = QFUNC(api_getOnOffState);
};
class getVolume {
required = true;
required = 1;
};
class getChannel {
required = true;
required = 1;
};
class getTransmitPower {
required = true;
required = 1;
};
};
};
8 changes: 4 additions & 4 deletions addons/api/CfgModules.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,28 +98,28 @@ class CfgVehicles {
displayName = "Signal Loss";
description = "Set to false to disable signal and terrain loss values";
typeName = "BOOL";
defaultValue = true;
defaultValue = 1;
class values { };
};
class FullDuplex {
displayName = "Full-Duplex Transmissions";
description = "Set to true to enable full-duplex, or multiple people transmitting";
typeName = "BOOL";
defaultValue = false;
defaultValue = 0;
class values { };
};
class Interference {
displayName = "Signal Interference";
description = "Set to false to disable the interference from multiple transmitters";
typeName = "BOOL";
defaultValue = true;
defaultValue = 1;
class values { };
};
class IgnoreAntennaDirection {
displayName = "Ignore Antenna Direction";
description = "Set to true to disable loss due to antenna directional radiation patterns.";
typeName = "BOOL";
defaultValue = false;
defaultValue = 0;
class values { };
};
};
Expand Down
3 changes: 2 additions & 1 deletion addons/api/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class CfgPatches {
"acre_sys_prc77",
"acre_sys_prc343",
"acre_sys_core",
"acre_sys_godmode"
"acre_sys_godmode",
"acre_sys_radio"
};
author = ECSTRING(main,Author);
authors[] = {"Jaynus", "Nou"};
Expand Down
7 changes: 4 additions & 3 deletions addons/api/fnc_basicMissionSetup.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,15 @@ private _addRadios = {
_player setVariable [QGVAR(basicMissionSetup), true, true];

private _cleanRadioList = [];
if !("ACRE_PRC343" in _defaultRadios) then {
private _defaultRadio = EGVAR(sys_radio,defaultRadio);
if !(_defaultRadio in _defaultRadios) then {
[_player, "ItemRadio"] call EFUNC(sys_core,removeGear);
[_player, "ACRE_PRC343"] call EFUNC(sys_core,removeGear);
[_player, _defaultRadio] call EFUNC(sys_core,removeGear);
_cleanRadioList = _defaultRadios;
} else {
private _countDefaultRadios = 0;
{
if (_x == "ACRE_PRC343") then {
if (_x == _defaultRadio) then {
_countDefaultRadios = _countDefaultRadios + 1;
if (_countDefaultRadios > 1) then {
_cleanRadioList pushBack _x;
Expand Down
23 changes: 1 addition & 22 deletions addons/api/fnc_getAllRadios.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,4 @@
* Public: Yes
*/

// Return cached if already ran
if (!isNil QGVAR(allRadios)) exitWith {
GVAR(allRadios)
};

// Compile and cache for later calls
private _classes = [];
private _names = [];
{
private _isRadio = getNumber (_x >> "type") == ACRE_COMPONENT_RADIO;
private _hasComponents = getArray (_x >> "defaultComponents") isNotEqualTo []; // Only non-base classes have that
private _name = getText (_x >> "name");

// Has name and isAcre, assume valid radio class
if (_isRadio && {_hasComponents} && {_name != ""}) then {
_classes pushBack (configName _x);
_names pushBack _name;
};
} forEach ("true" configClasses (configFile >> "CfgAcreComponents"));

GVAR(allRadios) = [_classes, _names];
GVAR(allRadios)
[] call EFUNC(sys_core,getAllRadios)
5 changes: 4 additions & 1 deletion addons/api/fnc_setItemRadioReplacement.sqf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "script_component.hpp"
/*
* Author: ACRE2Team
* DEPRECATED! Replaced by CBA Setting.
* Set the radio type to replace "ItemRadio" in unit inventories. By default this is the "ACRE_PRC343"
*
* Arguments:
Expand All @@ -15,8 +16,10 @@
* Public: Yes
*/

ACRE_DEPRECATED(QFUNC(setItemRadioReplacement),"2.12","CBA Setting")

params ["_radioType"];

EGVAR(sys_radio,defaultItemRadioType) = _radioType;
[QEGVAR(sys_radio,defaultRadio), _radioType, 1, "mission"] call CBA_settings_fnc_set;

true
1 change: 1 addition & 0 deletions addons/sys_core/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ PREP(canUnderstand);
PREP(cycleLanguage);
PREP(findOcclusion);
PREP(getAlive);
PREP(getAllRadios);
PREP(getClientIdLoop);
PREP(getCompartment);
PREP(getDescriptiveName);
Expand Down
40 changes: 40 additions & 0 deletions addons/sys_core/fnc_getAllRadios.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "script_component.hpp"
/*
* Author: ACRE2Team
* Returns all radios defined in CfgAcreRadios. Caches result for future calls.
*
* Arguments:
* None
*
* Return Value:
* 0: Radio Class Names <ARRAY>
* 1: Radio Display Names <ARRAY>
*
* Example:
* [] call acre_sys_core_fnc_getAllRadios;
*
* Public: No
*/

// Return cached if already ran
if (!isNil QGVAR(allRadios)) exitWith {
GVAR(allRadios)
};

// Compile and cache for later calls
private _classes = [];
private _names = [];
{
private _isRadio = getNumber (_x >> "type") == ACRE_COMPONENT_RADIO;
private _hasComponents = getArray (_x >> "defaultComponents") isNotEqualTo []; // Only non-base classes have that
private _name = getText (_x >> "name");

// Has name and isAcre, assume valid radio class
if (_isRadio && {_hasComponents} && {_name != ""}) then {
_classes pushBack (configName _x);
_names pushBack _name;
};
} forEach ("true" configClasses (configFile >> "CfgAcreComponents"));

GVAR(allRadios) = [_classes, _names];
GVAR(allRadios)
2 changes: 2 additions & 0 deletions addons/sys_core/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include "\idi\acre\addons\main\script_macros.hpp"

#include "\idi\acre\addons\sys_components\script_acre_component_defines.hpp"

#define ACRE_REVEAL_AMOUNT 1.6

#define MAX_DIRECT_RANGE 300
Expand Down
11 changes: 4 additions & 7 deletions addons/sys_radio/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ GVAR(radioUniqueCache) = HASH_CREATE;
GVAR(radioBaseClassCache) = HASH_CREATE;
GVAR(radioIsBaseClassCache) = HASH_CREATE;

GVAR(defaultRadios) = [] call EFUNC(sys_core,getAllRadios);

if (hasInterface) then {
//DGVAR(workingRadioList) = [];
DGVAR(currentRadioList) = [];
Expand All @@ -30,13 +32,8 @@ if (hasInterface) then {

DVAR(ACRE_ACTIVE_RADIO) = "";
DVAR(ACRE_SPECTATOR_RADIOS) = [];

// this isn't used anymore i do not think?
// acre_player setVariable [QGVAR(currentRadioList), []];

if (isNil QGVAR(defaultItemRadioType)) then {
GVAR(defaultItemRadioType) = "ACRE_PRC343";
};
};

#include "initSettings.sqf"

ADDON = true;
8 changes: 6 additions & 2 deletions addons/sys_radio/fnc_monitorRadios.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ GVAR(requestingNewId) = false;

LOG("Monitor Inventory Starting");

[{ACRE_DATA_SYNCED && {(!isNil "ACRE_SERVER_INIT")} && {time >= 1}},{
[{
ACRE_DATA_SYNCED &&
{!isNil "ACRE_SERVER_INIT"} &&
{time >= 1}
}, {
[DFUNC(monitorRadiosPFH), 0.25, []] call CBA_fnc_addPerFrameHandler;
},[]] call CBA_fnc_waitUntilAndExecute;
}, []] call CBA_fnc_waitUntilAndExecute;
26 changes: 19 additions & 7 deletions addons/sys_radio/fnc_monitorRadiosPFH.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,29 @@ private _currentUniqueItems = [];
if (GVAR(requestingNewId)) exitWith { };
private _radio = _x;
private _hasUnique = _radio call EFUNC(sys_radio,isBaseClassRadio);
if (_hasUnique || {_radio == "ItemRadio"}) then {

GVAR(requestingNewId) = true;
if (_radio == "ItemRadio") then {
_radio = GVAR(defaultItemRadioType);
if (_radio == "ItemRadio") then {
private _defaultRadio = GVAR(defaultRadio);
if (_defaultRadio != "") then {
// Replace vanilla radio item
_radio = _defaultRadio;
GVAR(requestingNewId) = true;
[acre_player, "ItemRadio", _radio] call EFUNC(sys_core,replaceGear);
["acre_getRadioId", [acre_player, _radio, QGVAR(returnRadioId)]] call CALLSTACK(CBA_fnc_serverEvent);
TRACE_1("Getting ID for ItemRadio replacement",_radio);
} else {
// Vanilla radio item replacement disabled, simply remove it.
[acre_player, "ItemRadio"] call EFUNC(sys_core,removeGear);
TRACE_1("Removing ItemRadio",_radio);
};
} else {
if (_hasUnique) then {
GVAR(requestingNewId) = true;
["acre_getRadioId", [acre_player, _radio, QGVAR(returnRadioId)]] call CALLSTACK(CBA_fnc_serverEvent);
TRACE_1("Getting ID for", _radio);
};
TRACE_1("Getting ID for", _radio);

["acre_getRadioId", [acre_player, _radio, QGVAR(returnRadioId)]] call CALLSTACK(CBA_fnc_serverEvent);
};

private _isUnique = _radio call EFUNC(sys_radio,isUniqueRadio);
if (_isUnique) then {
if !([_radio] call EFUNC(sys_data,isRadioInitialized)) then {
Expand Down
12 changes: 12 additions & 0 deletions addons/sys_radio/initSettings.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
QGVAR(defaultRadio),
"LIST",
[LLSTRING(DefaultRadio_DisplayName), LLSTRING(DefaultRadio_Description)],
"ACRE2",
[
[""] + (GVAR(defaultRadios) select 0),
[localize "str_a3_cfgglasses_none0"] + (GVAR(defaultRadios) select 1),
((GVAR(defaultRadios) select 0) find "ACRE_PRC343") + 1
],
true
] call CBA_fnc_addSetting;
6 changes: 6 additions & 0 deletions addons/sys_radio/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@
<Portuguese>Rádio configurado a %1</Portuguese>
<Turkish>Telsiz Ayarı Şuna Atandı: %1</Turkish>
</Key>
<Key ID="STR_ACRE_sys_radio_DefaultRadio_DisplayName">
<English>Radio Item Replacement</English>
</Key>
<Key ID="STR_ACRE_sys_radio_DefaultRadio_Description">
<English>Default radio inventory items will be replaced with this type of radio.</English>
</Key>
<Key ID="STR_ACRE_sys_radio_ui_ChangeVolume">
<English>Change Volume</English>
</Key>
Expand Down