Skip to content

Commit

Permalink
Radio - Add radio item replacement CBA Setting (#1283)
Browse files Browse the repository at this point in the history
Co-authored-by: PabstMirror <[email protected]>
Co-authored-by: jonpas <[email protected]>
Co-authored-by: Freddo3000 <[email protected]>
  • Loading branch information
3 people authored Sep 27, 2023
1 parent c3f289a commit 5178ef6
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 57 deletions.
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

0 comments on commit 5178ef6

Please sign in to comment.