Skip to content

Commit 090abc6

Browse files
mrschickTimi007rautamiekka
authored
API - Add Function to set Channels on all Radios a Player is carrying (#1302)
Co-authored-by: Timi007 <[email protected]> Co-authored-by: Jouni Järvinen <[email protected]>
1 parent cb91e30 commit 090abc6

File tree

11 files changed

+249
-9
lines changed

11 files changed

+249
-9
lines changed

addons/api/CfgFunctions.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class CfgFunctions {
4646

4747
PATHTO_FNC(setRadioChannel);
4848
PATHTO_FNC(getRadioChannel);
49+
PATHTO_FNC(setupRadios);
4950

5051
PATHTO_FNC(setRadioVolume);
5152
PATHTO_FNC(getRadioVolume);

addons/api/fnc_setupRadios.sqf

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#include "script_component.hpp"
2+
/*
3+
* Author: mrschick
4+
* When run locally, it will set the currently carried radios to the selected channels.
5+
*
6+
* Arguments:
7+
* [RadioSetting1, RadioSetting2, ...] <ARRAY>
8+
*
9+
* RadioSetting: [RadioType, Channel] or
10+
* [RadioType, [Channel, Block]] or
11+
* [RadioType, MHz] or
12+
* [RadioType, [MHz, KHz]]
13+
* 0: Radio Base Class <STRING>
14+
* 1: Radio Channel/Block/Frequency <INTEGER> or <ARRAY>
15+
*
16+
* Return Value:
17+
* Successful <BOOLEAN>
18+
*
19+
* Example:
20+
* _success = [ ["ACRE_PRC343", [2,3]], ["ACRE_PRC152", 3], ["ACRE_PRC77", [31,15]] ] call acre_api_fnc_setupRadios;
21+
* // Will set PRC343 to Ch2 Blk3, PRC152 to Ch3 and PRC77 to 31.15 MHz
22+
*
23+
* _success = [ ["ACRE_PRC343", 6], ["ACRE_PRC152", 2], ["ACRE_PRC152", 3] ] call acre_api_fnc_setupRadios;
24+
* // Will set PRC343 to Ch6 Blk1, the first PRC152 to Ch2 and the second PRC152 to Ch3
25+
*
26+
* _success = [ ["ACRE_SEM52SL", 8], ["ACRE_SEM70", [34,075]] ] call acre_api_fnc_setupRadios;
27+
* // Will set SEM52SL to Ch8 and SEM70 to 34.075 MHz
28+
*
29+
* Public: Yes
30+
*/
31+
32+
private _settings = _this;
33+
34+
// Abort if argument is empty or not an array
35+
if ((_settings isEqualTo []) || {!((_settings select 0) isEqualType [])}) exitWith {
36+
WARNING_1("Attempted to import radio setup %1, aborting because it's empty or of the wrong format",_settings);
37+
false
38+
};
39+
40+
// Wait for radio initialization before attempting to iterate through them
41+
[{
42+
[] call EFUNC(api,isInitialized)
43+
}, {
44+
params ["_settings"];
45+
46+
private _radios = [] call EFUNC(sys_data,getPlayerRadioList);
47+
48+
// Abort if carrying no radios
49+
if (_radios isEqualTo []) exitWith {
50+
WARNING_1("Attempted to import radio setup %1, aborting due to no radios carried",_settings);
51+
false
52+
};
53+
54+
{ // iterate through carried radios
55+
private _radio = _x;
56+
private _radioBaseClass = [_radio] call EFUNC(sys_radio,getRadioBaseClassname);
57+
58+
// iterate through arguments and set up radio if baseclass matches
59+
for "_i" from 0 to count(_settings)-1 do {
60+
(_settings select _i) params ["_radioType", "_channel"];
61+
private _eventData = [];
62+
63+
// Skip setting if its type doesn't match current radio baseclass
64+
if (_radioType != _radioBaseClass) then { continue };
65+
66+
// Turn channel argument into an array of 1 or 2 numbers
67+
if (_channel isEqualType []) then {
68+
{ _eventData pushBack (_x) } forEach _channel;
69+
} else {
70+
_eventData = [_channel];
71+
};
72+
73+
// Parse eventData to match the expected input for the respective radio's setCurrentChannel function
74+
switch (_radioType) do {
75+
case "ACRE_PRC343": {
76+
if (count _eventData == 2) then { // set channel and block
77+
_eventData = (((_eventData select 1) - 1) * 16) + (_eventData select 0) - 1;
78+
} else { // set channel
79+
_eventData = (_eventData select 0) - 1;
80+
};
81+
};
82+
case "ACRE_PRC77": {
83+
if (count _eventData < 2) then { // set only MHz, insert 0 to nullify KHz
84+
_eventData pushBack 0;
85+
} else {
86+
if (_eventData select 1 > 0) then { // parse KHz if set by user
87+
_eventData set [1, (floor ((_eventData select 1) / 5) min 19)];
88+
};
89+
};
90+
_eventData set [0, (0 max ((_eventData select 0) - 30))];
91+
};
92+
case "ACRE_SEM70": {
93+
if (count _eventData < 2) then { // set only MHz, insert 0 to nullify KHz
94+
_eventData pushBack 0;
95+
} else {
96+
if (_eventData select 1 > 0) then { // parse KHz if set by user
97+
_eventData set [1, (round ((_eventData select 1) / 25) min 39)];
98+
};
99+
};
100+
_eventData set [0, (0 max ((_eventData select 0) - 30))];
101+
};
102+
default {
103+
_eventData = (_eventData select 0) - 1;
104+
};
105+
};
106+
107+
[_radio, "setCurrentChannel", _eventData] call EFUNC(sys_data,dataEvent);
108+
109+
INFO_2("Applied radio setup %1 onto carried radio %2",_settings select _i,_radio);
110+
111+
// Delete applied setting and break out to handle next radio
112+
_settings deleteAt _i;
113+
break;
114+
};
115+
} forEach _radios;
116+
}, [_settings]] call CBA_fnc_waitUntilAndExecute;
117+
118+
true

addons/sys_core/CfgEden.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Cfg3DEN {
2+
class Object {
3+
class AttributeCategories {
4+
class acre_attributes {
5+
displayName = CSTRING(Options);
6+
collapsed = 1;
7+
class Attributes {};
8+
};
9+
};
10+
};
11+
12+
class Group {
13+
class AttributeCategories {
14+
class acre_attributes {
15+
displayName = CSTRING(Options);
16+
collapsed = 1;
17+
class Attributes {};
18+
};
19+
};
20+
};
21+
};

addons/sys_core/config.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class CfgPatches {
1212
VERSION_CONFIG;
1313
};
1414
};
15+
#include "CfgEden.hpp"
1516
#include "CfgEventHandlers.hpp"
1617
#include "CfgSounds.hpp"
1718
#include "CfgVehicles.hpp"

addons/sys_core/stringtable.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project name="ACRE">
33
<Package name="sys_core">
4+
<Key ID="STR_ACRE_sys_core_Options">
5+
<English>ACRE Options</English>
6+
<German>ACRE-Optionen</German>
7+
<Italian>Opzioni ACRE</Italian>
8+
</Key>
49
<Key ID="STR_ACRE_sys_core_CategoryUI">
510
<English>ACRE2 UI</English>
611
<German>ACRE2 Nutzeroberfläche</German>

addons/sys_radio/Cfg3DEN.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Cfg3DEN {
2+
class Object {
3+
class AttributeCategories {
4+
class acre_attributes {
5+
class Attributes {
6+
class GVAR(edenSetup) {
7+
property = QGVAR(edenSetup);
8+
condition = "objectBrain";
9+
control = "Edit";
10+
typeName = "STRING";
11+
displayName = CSTRING(3den_RadioSetup_DisplayName);
12+
tooltip = CSTRING(3den_RadioSetup_Description);
13+
defaultValue = "[[""ACRE_PRC343"",[1,1]],[""ACRE_PRC152"",1],[""ACRE_PRC117F"",1]]";
14+
expression = QUOTE(_this setVariable [ARR_3(QQGVAR(setup),_value,true)]);
15+
};
16+
};
17+
};
18+
};
19+
};
20+
};

addons/sys_radio/XEH_postInit.sqf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,15 @@ if (!hasInterface) exitWith {};
2828

2929
// main inventory thread
3030
[] call FUNC(monitorRadios); // OK
31+
32+
// Set up radios with EDEN-defined object attribute
33+
private _setup = parseSimpleArray (acre_player getVariable [QGVAR(setup), "[]"]);
34+
if (_setup isNotEqualTo []) then {
35+
[{
36+
[] call EFUNC(api,isInitialized)
37+
}, {
38+
params ["_setup"];
39+
_setup call EFUNC(api,setupRadios);
40+
INFO("Applying EDEN-Defined Radio Setup attribute to carried radios");
41+
}, [_setup]] call CBA_fnc_waitUntilAndExecute;
42+
};

addons/sys_radio/config.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ class CfgPatches {
1616

1717
PRELOAD_ADDONS;
1818

19+
#include "Cfg3DEN.hpp"
1920
#include "CfgVehicles.hpp"
2021
#include "CfgEventHandlers.hpp"

addons/sys_radio/stringtable.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,5 +242,15 @@
242242
<French>Retirer la poignée</French>
243243
<Chinesesimp>取下手柄</Chinesesimp>
244244
</Key>
245+
<Key ID="STR_ACRE_sys_radio_3den_RadioSetup_DisplayName">
246+
<English>Radio Channel Setup</English>
247+
<German>Funkkanal-Einstellung</German>
248+
<Italian>Canali radio preimpostati</Italian>
249+
</Key>
250+
<Key ID="STR_ACRE_sys_radio_3den_RadioSetup_Description">
251+
<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>
252+
<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>
253+
<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>
254+
</Key>
245255
</Package>
246256
</Project>

addons/sys_sem70/radio/fnc_setCurrentChannel.sqf

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,29 @@ private _manualChannel = HASH_GET(_radioData,"manualChannelSelection");
4444
TRACE_1("ManualChannel",_manualChannel);
4545

4646
if (_manualChannel isEqualTo 1) then {
47-
private _currentMHzFrequency = HASH_GET(_radioData,"MHzKnobPosition");
48-
_currentMHzFrequency = _currentMHzFrequency + 30;
49-
private _currentkHzFrequency = HASH_GET(_radioData,"kHzKnobPosition");
50-
_currentkHzFrequency = _currentkHzFrequency * 25 / 1000;
51-
private _newFreq = _currentMHzFrequency + _currentkHzFrequency;
52-
5347
private _channels = HASH_GET(_radioData,"channels");
5448
private _channel = HASHLIST_SELECT(_channels,GVAR(manualChannel));
5549

56-
HASH_SET(_channel,"frequencyTX",_newFreq);
57-
HASH_SET(_channel,"frequencyRX",_newFreq);
58-
TRACE_3("",_currentMHzFrequency,_currentkHzFrequency,_newFreq);
50+
if (_eventData isEqualType []) then { // if event data comes from a setChannel-type API in the [MHzKnobPos,KHzKnobPos] format
51+
private _newFreq = ((_eventData select 0) + 30) + ((_eventData select 1) * 25 / 1000);
52+
53+
HASH_SET(_channel,"frequencyTX",_newFreq);
54+
HASH_SET(_channel,"frequencyRX",_newFreq);
55+
TRACE_1("",_newFreq);
56+
57+
HASH_SET(_radioData,"MHzKnobPosition",(_eventData select 0));
58+
HASH_SET(_radioData,"kHzKnobPosition",(_eventData select 1));
59+
} else {
60+
private _currentMHzFrequency = HASH_GET(_radioData,"MHzKnobPosition");
61+
_currentMHzFrequency = _currentMHzFrequency + 30;
62+
private _currentkHzFrequency = HASH_GET(_radioData,"kHzKnobPosition");
63+
_currentkHzFrequency = _currentkHzFrequency * 25 / 1000;
64+
private _newFreq = _currentMHzFrequency + _currentkHzFrequency;
65+
66+
HASH_SET(_channel,"frequencyTX",_newFreq);
67+
HASH_SET(_channel,"frequencyRX",_newFreq);
68+
TRACE_3("",_currentMHzFrequency,_currentkHzFrequency,_newFreq);
69+
};
5970

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

0 commit comments

Comments
 (0)