-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
1 parent
cb91e30
commit 090abc6
Showing
11 changed files
with
249 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {}; | ||
}; | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)]); | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters