Skip to content

Commit

Permalink
API - Add Function to set Channels on all Radios a Player is carrying (
Browse files Browse the repository at this point in the history
…#1302)

Co-authored-by: Timi007 <[email protected]>
Co-authored-by: Jouni Järvinen <[email protected]>
  • Loading branch information
3 people authored Jan 27, 2025
1 parent cb91e30 commit 090abc6
Show file tree
Hide file tree
Showing 11 changed files with 249 additions and 9 deletions.
1 change: 1 addition & 0 deletions addons/api/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class CfgFunctions {

PATHTO_FNC(setRadioChannel);
PATHTO_FNC(getRadioChannel);
PATHTO_FNC(setupRadios);

PATHTO_FNC(setRadioVolume);
PATHTO_FNC(getRadioVolume);
Expand Down
118 changes: 118 additions & 0 deletions addons/api/fnc_setupRadios.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#include "script_component.hpp"
/*
* Author: mrschick
* When run locally, it will set the currently carried radios to the selected channels.
*
* Arguments:
* [RadioSetting1, RadioSetting2, ...] <ARRAY>
*
* RadioSetting: [RadioType, Channel] or
* [RadioType, [Channel, Block]] or
* [RadioType, MHz] or
* [RadioType, [MHz, KHz]]
* 0: Radio Base Class <STRING>
* 1: Radio Channel/Block/Frequency <INTEGER> or <ARRAY>
*
* Return Value:
* Successful <BOOLEAN>
*
* Example:
* _success = [ ["ACRE_PRC343", [2,3]], ["ACRE_PRC152", 3], ["ACRE_PRC77", [31,15]] ] call acre_api_fnc_setupRadios;
* // Will set PRC343 to Ch2 Blk3, PRC152 to Ch3 and PRC77 to 31.15 MHz
*
* _success = [ ["ACRE_PRC343", 6], ["ACRE_PRC152", 2], ["ACRE_PRC152", 3] ] call acre_api_fnc_setupRadios;
* // Will set PRC343 to Ch6 Blk1, the first PRC152 to Ch2 and the second PRC152 to Ch3
*
* _success = [ ["ACRE_SEM52SL", 8], ["ACRE_SEM70", [34,075]] ] call acre_api_fnc_setupRadios;
* // Will set SEM52SL to Ch8 and SEM70 to 34.075 MHz
*
* Public: Yes
*/

private _settings = _this;

// Abort if argument is empty or not an array
if ((_settings isEqualTo []) || {!((_settings select 0) isEqualType [])}) exitWith {
WARNING_1("Attempted to import radio setup %1, aborting because it's empty or of the wrong format",_settings);
false
};

// Wait for radio initialization before attempting to iterate through them
[{
[] call EFUNC(api,isInitialized)
}, {
params ["_settings"];

private _radios = [] call EFUNC(sys_data,getPlayerRadioList);

// Abort if carrying no radios
if (_radios isEqualTo []) exitWith {
WARNING_1("Attempted to import radio setup %1, aborting due to no radios carried",_settings);
false
};

{ // iterate through carried radios
private _radio = _x;
private _radioBaseClass = [_radio] call EFUNC(sys_radio,getRadioBaseClassname);

// iterate through arguments and set up radio if baseclass matches
for "_i" from 0 to count(_settings)-1 do {
(_settings select _i) params ["_radioType", "_channel"];
private _eventData = [];

// Skip setting if its type doesn't match current radio baseclass
if (_radioType != _radioBaseClass) then { continue };

// Turn channel argument into an array of 1 or 2 numbers
if (_channel isEqualType []) then {
{ _eventData pushBack (_x) } forEach _channel;
} else {
_eventData = [_channel];
};

// Parse eventData to match the expected input for the respective radio's setCurrentChannel function
switch (_radioType) do {
case "ACRE_PRC343": {
if (count _eventData == 2) then { // set channel and block
_eventData = (((_eventData select 1) - 1) * 16) + (_eventData select 0) - 1;
} else { // set channel
_eventData = (_eventData select 0) - 1;
};
};
case "ACRE_PRC77": {
if (count _eventData < 2) then { // set only MHz, insert 0 to nullify KHz
_eventData pushBack 0;
} else {
if (_eventData select 1 > 0) then { // parse KHz if set by user
_eventData set [1, (floor ((_eventData select 1) / 5) min 19)];
};
};
_eventData set [0, (0 max ((_eventData select 0) - 30))];
};
case "ACRE_SEM70": {
if (count _eventData < 2) then { // set only MHz, insert 0 to nullify KHz
_eventData pushBack 0;
} else {
if (_eventData select 1 > 0) then { // parse KHz if set by user
_eventData set [1, (round ((_eventData select 1) / 25) min 39)];
};
};
_eventData set [0, (0 max ((_eventData select 0) - 30))];
};
default {
_eventData = (_eventData select 0) - 1;
};
};

[_radio, "setCurrentChannel", _eventData] call EFUNC(sys_data,dataEvent);

INFO_2("Applied radio setup %1 onto carried radio %2",_settings select _i,_radio);

// Delete applied setting and break out to handle next radio
_settings deleteAt _i;
break;
};
} forEach _radios;
}, [_settings]] call CBA_fnc_waitUntilAndExecute;

true
21 changes: 21 additions & 0 deletions addons/sys_core/CfgEden.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Cfg3DEN {
class Object {
class AttributeCategories {
class acre_attributes {
displayName = CSTRING(Options);
collapsed = 1;
class Attributes {};
};
};
};

class Group {
class AttributeCategories {
class acre_attributes {
displayName = CSTRING(Options);
collapsed = 1;
class Attributes {};
};
};
};
};
1 change: 1 addition & 0 deletions addons/sys_core/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class CfgPatches {
VERSION_CONFIG;
};
};
#include "CfgEden.hpp"
#include "CfgEventHandlers.hpp"
#include "CfgSounds.hpp"
#include "CfgVehicles.hpp"
Expand Down
5 changes: 5 additions & 0 deletions addons/sys_core/stringtable.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project name="ACRE">
<Package name="sys_core">
<Key ID="STR_ACRE_sys_core_Options">
<English>ACRE Options</English>
<German>ACRE-Optionen</German>
<Italian>Opzioni ACRE</Italian>
</Key>
<Key ID="STR_ACRE_sys_core_CategoryUI">
<English>ACRE2 UI</English>
<German>ACRE2 Nutzeroberfläche</German>
Expand Down
20 changes: 20 additions & 0 deletions addons/sys_radio/Cfg3DEN.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Cfg3DEN {
class Object {
class AttributeCategories {
class acre_attributes {
class Attributes {
class GVAR(edenSetup) {
property = QGVAR(edenSetup);
condition = "objectBrain";
control = "Edit";
typeName = "STRING";
displayName = CSTRING(3den_RadioSetup_DisplayName);
tooltip = CSTRING(3den_RadioSetup_Description);
defaultValue = "[[""ACRE_PRC343"",[1,1]],[""ACRE_PRC152"",1],[""ACRE_PRC117F"",1]]";
expression = QUOTE(_this setVariable [ARR_3(QQGVAR(setup),_value,true)]);
};
};
};
};
};
};
12 changes: 12 additions & 0 deletions addons/sys_radio/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,15 @@ if (!hasInterface) exitWith {};

// main inventory thread
[] call FUNC(monitorRadios); // OK

// Set up radios with EDEN-defined object attribute
private _setup = parseSimpleArray (acre_player getVariable [QGVAR(setup), "[]"]);
if (_setup isNotEqualTo []) then {
[{
[] call EFUNC(api,isInitialized)
}, {
params ["_setup"];
_setup call EFUNC(api,setupRadios);
INFO("Applying EDEN-Defined Radio Setup attribute to carried radios");
}, [_setup]] call CBA_fnc_waitUntilAndExecute;
};
1 change: 1 addition & 0 deletions addons/sys_radio/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ class CfgPatches {

PRELOAD_ADDONS;

#include "Cfg3DEN.hpp"
#include "CfgVehicles.hpp"
#include "CfgEventHandlers.hpp"
10 changes: 10 additions & 0 deletions addons/sys_radio/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,15 @@
<French>Retirer la poignée</French>
<Chinesesimp>取下手柄</Chinesesimp>
</Key>
<Key ID="STR_ACRE_sys_radio_3den_RadioSetup_DisplayName">
<English>Radio Channel Setup</English>
<German>Funkkanal-Einstellung</German>
<Italian>Canali radio preimpostati</Italian>
</Key>
<Key ID="STR_ACRE_sys_radio_3den_RadioSetup_Description">
<English>Array of Arrays (comma-separated) to set up radio channels of the given unit.\nIt's possible to set up multiple radios of the same type.\nSingular Examples:\n["ACRE_PRC343",1] -&gt; Channel 1, Block 1\n["ACRE_PRC343",[2,3]] -&gt; Channel 2, Block 3\n["ACRE_PRC148",5] -&gt; Channel 5 (same for PRC-148/152/117F, BF-888S and SEM52SL)\n["ACRE_PRC77",[31,15]] -&gt; 31.15 MHz\n["ACRE_SEM70",[34,075]] -&gt; 34.075 MHz\n["ACRE_BF888S",4],["ACRE_BF888S",5] -&gt; Set first BF-888S to Ch 4, second to Ch 5</English>
<German>Array von Arrays (kommagetrennt), um Funkgerätkanäle einer bestimmten Einheit einzustellen.\nEs ist möglich, mehrere Funkgeräte des gleichen Modells einzustellen.\nBeispiele:\n["ACRE_PRC343",1] -&gt; Kanal 1, Block 1\n["ACRE_PRC343",[2,3]] -&gt; Kanal 2, Block 3\n["ACRE_PRC148",5] -&gt; Kanal 5 (dasselbe gilt für PRC-148/152/117F, BF-888S und SEM 52 SL)\n["ACRE_PRC77",[31,15]] -&gt; 31.15 MHz\n["ACRE_SEM70",[34,075]] -&gt; 34.075 MHz\n["ACRE_BF888S",4],["ACRE_BF888S",5] -&gt; Setzt das erste BF-888S auf Kanal 4, das zweite auf Kanal 5</German>
<Italian>Array di Array (separati da virgola) per impostare i canali radio di una determinata unità.\nÈ possibile impostare molteplici radio dello stesso tipo.\nEsempi:\n["ACRE_PRC343",1] -&gt; Canale 1, Blocco 1\n["ACRE_PRC343",[2,3]] -&gt; Canale 2, Blocco 3\n["ACRE_PRC148",5] -&gt; Canale 5 (stesso formato per PRC-148/152/117F, BF-888S e SEM52SL)\n["ACRE_PRC77",[31,15]] -&gt; 31.15 MHz\n["ACRE_SEM70",[34,075]] -&gt; 34.075 MHz\n["ACRE_BF888S",4],["ACRE_BF888S",5] -&gt; Imposta la prima BF-888S su Ch 4, la seconda su Ch 5</Italian>
</Key>
</Package>
</Project>
29 changes: 20 additions & 9 deletions addons/sys_sem70/radio/fnc_setCurrentChannel.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,29 @@ private _manualChannel = HASH_GET(_radioData,"manualChannelSelection");
TRACE_1("ManualChannel",_manualChannel);

if (_manualChannel isEqualTo 1) then {
private _currentMHzFrequency = HASH_GET(_radioData,"MHzKnobPosition");
_currentMHzFrequency = _currentMHzFrequency + 30;
private _currentkHzFrequency = HASH_GET(_radioData,"kHzKnobPosition");
_currentkHzFrequency = _currentkHzFrequency * 25 / 1000;
private _newFreq = _currentMHzFrequency + _currentkHzFrequency;

private _channels = HASH_GET(_radioData,"channels");
private _channel = HASHLIST_SELECT(_channels,GVAR(manualChannel));

HASH_SET(_channel,"frequencyTX",_newFreq);
HASH_SET(_channel,"frequencyRX",_newFreq);
TRACE_3("",_currentMHzFrequency,_currentkHzFrequency,_newFreq);
if (_eventData isEqualType []) then { // if event data comes from a setChannel-type API in the [MHzKnobPos,KHzKnobPos] format
private _newFreq = ((_eventData select 0) + 30) + ((_eventData select 1) * 25 / 1000);

HASH_SET(_channel,"frequencyTX",_newFreq);
HASH_SET(_channel,"frequencyRX",_newFreq);
TRACE_1("",_newFreq);

HASH_SET(_radioData,"MHzKnobPosition",(_eventData select 0));
HASH_SET(_radioData,"kHzKnobPosition",(_eventData select 1));
} else {
private _currentMHzFrequency = HASH_GET(_radioData,"MHzKnobPosition");
_currentMHzFrequency = _currentMHzFrequency + 30;
private _currentkHzFrequency = HASH_GET(_radioData,"kHzKnobPosition");
_currentkHzFrequency = _currentkHzFrequency * 25 / 1000;
private _newFreq = _currentMHzFrequency + _currentkHzFrequency;

HASH_SET(_channel,"frequencyTX",_newFreq);
HASH_SET(_channel,"frequencyRX",_newFreq);
TRACE_3("",_currentMHzFrequency,_currentkHzFrequency,_newFreq);
};

[_radioID,"setChannelData", [GVAR(manualChannel), _channel]] call EFUNC(sys_data,dataEvent);

Expand Down
40 changes: 40 additions & 0 deletions docs/_includes/custom/functions-list-api.html
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,46 @@
```


---

### acre_api_fnc_setupRadios
__Description__

Takes an array of "Radio Settings" and matches those to the currently carried radios, setting each type of radio to the selected channel/block or frequency.

__Parameters__

Index | Description | Datatype(s) | Default Value
--- | --- | --- | ---
0-n | Radio Setting | ARRAY |

__Radio Setting Parameters__

Index | Description | Datatype(s) | Default Value
--- | --- | --- | ---
0 | Radio Baseclass the setting applies to | STRING |
1 | Single Channel number, [Channel,Block] or [MHz,KHz] arrays | NUMBER OR ARRAY |

__Return Value__

Description | Datatype(s)
--- | ---
Successful | BOOLEAN

__Example__

```sqf
_success = [ ["ACRE_PRC343", [2,3]], ["ACRE_PRC152", 3], ["ACRE_PRC77", [31,15]] ] call acre_api_fnc_setupRadios;
// Will set PRC343 to Ch2 Blk3, PRC152 to Ch3 and PRC77 to 31.15 MHz

_success = [ ["ACRE_PRC343", 6], ["ACRE_PRC152", 2], ["ACRE_PRC152", 3] ] call acre_api_fnc_setupRadios;
// Will set PRC343 to Ch6 Blk1, the first PRC152 to Ch2 and the second PRC152 to Ch3

_success = [ ["ACRE_SEM52SL", 8], ["ACRE_SEM70", [34,075]] ] call acre_api_fnc_setupRadios;
// Will set SEM52SL to Ch8 and SEM70 to 34.075 MHz
```


---

### acre_api_fnc_setPresetChannelData
Expand Down

0 comments on commit 090abc6

Please sign in to comment.