Fix various bugs in RADIO

This is the first implementation that PLAY A SOUND !
The whole RADIO class isn't tested thoroughly though
This commit is contained in:
Grey-Echo 2017-03-10 23:33:21 +01:00
parent b75d90092d
commit 65c61a15b4
6 changed files with 54 additions and 38 deletions

View File

@ -18,9 +18,9 @@
--- The RADIO class --- The RADIO class
-- @type RADIO -- @type RADIO
-- @extends Core.Base#BASE -- @extends Core.Base#BASE
MESSAGE = { RADIO = {
ClassName = "RADIO", ClassName = "RADIO",
Positionable = POSITIONABLE:New(), Positionable,
FileName = "", FileName = "",
Frequency = 0, Frequency = 0,
Modulation = 0, Modulation = 0,
@ -37,20 +37,21 @@ MESSAGE = {
-- @return self -- @return self
-- @usage -- @usage
-- -- If you want to create a RADIO, you probably should use @{Positionable#POSITIONABLE.GetRadio} -- -- If you want to create a RADIO, you probably should use @{Positionable#POSITIONABLE.GetRadio}
function RADIO.New(positionable) function RADIO:New(positionable)
local self = BASE:Inherit( self, BASE:New() ) local self = BASE:Inherit( self, BASE:New() )
-- self:F( { MessageText, MessageDuration, MessageCategory } ) self:F(positionable)
self.Positionable = positionable self.Positionable = positionable
return self return self
end end
--- Add the 'l10n/DEFAULT/' in the file name if necessary --- Add the 'l10n/DEFAULT/' in the file name if necessary
-- @param #string File name -- @param #RADIO self
-- @return #string Corrected file name -- @param #string FileName Filename of the sound
-- @return #string FileName Corrected file name
-- @usage -- @usage
-- -- internal use only -- -- internal use only
function RADIO.VerifyFileName(filename) function RADIO:VerifyFileName(filename)
if filename:find("l10n/DEFAULT/") == nil then if filename:find("l10n/DEFAULT/") == nil then
filename = "l10n/DEFAULT/" .. filename filename = "l10n/DEFAULT/" .. filename
end end
@ -68,15 +69,16 @@ end
-- -- In this function the data is especially relevant if the broadcaster is anything but a UNIT or a GROUP, -- -- In this function the data is especially relevant if the broadcaster is anything but a UNIT or a GROUP,
-- -- but it will work with a UNIT or a GROUP anyway -- -- but it will work with a UNIT or a GROUP anyway
-- -- Only the RADIO and the Filename are mandatory -- -- Only the RADIO and the Filename are mandatory
function RADIO:NewTransmission(filename, frequency, mod, power) function RADIO:NewGenericTransmission(filename, frequency, mod, power)
self.FileName = RADIO.VerifyFile(filename) self:F2({self, filename, frequency, mod, power})
if frequency ~= nil then self.FileName = RADIO:VerifyFileName(filename)
if frequency ~= "" then
self.Frequecy = frequency * 1000 -- Convert to Hz self.Frequecy = frequency * 1000 -- Convert to Hz
end end
if mod ~= nil then if mod ~= 3 then
self.Modulation = mod self.Modulation = mod
end end
if power ~= nil then if power ~= 0 then
self.Power = power self.Power = power
end end
return self return self
@ -96,21 +98,22 @@ end
-- -- but it will work for any POSITIONABLE -- -- but it will work for any POSITIONABLE
-- -- Only the RADIO and the Filename are mandatory -- -- Only the RADIO and the Filename are mandatory
-- -- Loop : O is no loop, 1 is loop -- -- Loop : O is no loop, 1 is loop
function RADIO:NewTransmissionForUnit(filename, subtitle, subtitleDuraction, frequency, mod, loop) function RADIO:NewUnitTransmission(filename, subtitle, subtitleDuration, frequency, mod, loop)
self.FileName = RADIO.VerifyFile(filename) self:F2({filename, subtitle, subtitleDuration, frequency, mod, loop})
if subtitle ~= nil then self.FileName = RADIO:VerifyFileName(filename)
if subtitle ~= "" then
self.Subtitle = subtitle self.Subtitle = subtitle
end end
if subtitleDuration ~= nil then if subtitleDuration ~= 0 then
self.SubtitleDuration = subtitleDuration self.SubtitleDuration = subtitleDuration
end end
if frequency ~= nil then if frequency ~= 0 then
self.Frequecy = frequency * 1000 -- Convert to Hz self.Frequency = frequency * 1000 -- Convert to Hz
end end
if mod ~= nil then if mod ~= 3 then
self.Modulation = mod self.Modulation = mod
end end
if loop ~= nil then if loop ~= 3 then
self.Loop = loop self.Loop = loop
end end
return self return self
@ -127,13 +130,14 @@ end
-- -- If your POSITIONABLE is a UNIT or a GROUP, the Power is ignored. -- -- If your POSITIONABLE is a UNIT or a GROUP, the Power is ignored.
-- -- If your POSITIONABLE is not a UNIT or a GROUP, the Subtitle, SubtitleDuration and Loop are ignored -- -- If your POSITIONABLE is not a UNIT or a GROUP, the Subtitle, SubtitleDuration and Loop are ignored
function RADIO:Broadcast() function RADIO:Broadcast()
self:F()
-- If the POSITIONABLE is actually a Unit or a Group, use the more complicated DCS function -- If the POSITIONABLE is actually a Unit or a Group, use the more complicated DCS function
if Positionable.ClassName == "UNIT" or Positionable.ClassName == "GROUP" then if self.Positionable.ClassName == "UNIT" or self.Positionable.ClassName == "GROUP" then
-- If the user didn't change the frequency, he wants to use the on defined in the Mission Editor. -- If the user didn't change the frequency, he wants to use the on defined in the Mission Editor.
-- Else we set the frequency of the UNIT or the GROUP in DCS -- Else we set the frequency of the UNIT or the GROUP in DCS
if self.Frequency == 0 then if self.Frequency ~= 0 then
self.Positionable:GetDCSUnit():getController():setCommand({ self.Positionable:GetDCSObject():getController():setCommand({
id = 'SetFrequency', id = "SetFrequency",
params = { params = {
frequency = self.Frequency, frequency = self.Frequency,
modulation = self.Modulation, modulation = self.Modulation,
@ -141,7 +145,7 @@ function RADIO:Broadcast()
}) })
end end
self.Positionable:GetDCSUnit():getController():setCommand({ self.Positionable:GetDCSObject():getController():setCommand({
id = "TransmitMessage", id = "TransmitMessage",
params = { params = {
file = self.FileName, file = self.FileName,
@ -152,7 +156,7 @@ function RADIO:Broadcast()
}) })
else else
-- If the POSITIONABLE is anything else, we revert to the general function -- If the POSITIONABLE is anything else, we revert to the general function
trigger.action.radioTransmission(ClassName, self.Positionable:PositionVec3(), Modulation, 1, Frequency, Power) trigger.action.radioTransmission(self.FileName, self.Positionable:PositionVec3(), self.Modulation, 1, self.Frequency, self.Power)
end end
return self return self
end end

View File

@ -433,10 +433,10 @@ function POSITIONABLE:Message( Message, Duration, Name )
end end
--- Create a @{Radio#RADIO}, to allow radio transmission for this POSITIONABLE --- Create a @{Radio#RADIO}, to allow radio transmission for this POSITIONABLE
-- Set parameters with the methods provided, then use @{Radio#RADIO.Broadcast} to actually broadcast the message -- Set parameters with the methods provided, then use RADIO:Broadcast() to actually broadcast the message
-- @param self -- @param #POSITIONABLE self
-- @return #RADIO -- @return #RADIO Radio
function POSITIONABLE:GetRadio() function POSITIONABLE:GetRadio()
local Radio = RADIO.New(self) self:F2(self)
return Radio return RADIO:New(self)
end end

View File

@ -1,5 +1,5 @@
env.info( '*** MOOSE DYNAMIC INCLUDE START *** ' ) env.info( '*** MOOSE DYNAMIC INCLUDE START *** ' )
env.info( 'Moose Generation Timestamp: 20170308_1432' ) env.info( 'Moose Generation Timestamp: 20170308_2255' )
local base = _G local base = _G

View File

@ -1,5 +1,5 @@
env.info( '*** MOOSE DYNAMIC INCLUDE START *** ' ) env.info( '*** MOOSE DYNAMIC INCLUDE START *** ' )
env.info( 'Moose Generation Timestamp: 20170308_1432' ) env.info( 'Moose Generation Timestamp: 20170308_2255' )
local base = _G local base = _G

View File

@ -1,6 +1,18 @@
BASE:TraceAll(1)
BASE:TraceLevel(3)
local Player = UNIT:FindByName("Player") local Player = UNIT:FindByName("Player")
Player:MessageToAll("MainScript Started", 10, "") Player:MessageToAll("MainScript Started 2", 10, "")
local PlayerRadio = Player:GetRadio() local Transmiter = UNIT:FindByName("Transmiter")
PlayerRadio:NewTransmission("Noise.ogg", "Subtitle", 10, 251000, 0, 0)
PlayerRadio:Broadcast() local TransmiterRadio = Transmiter:GetRadio()
TransmiterRadio:NewUnitTransmission("Noise.ogg", "Subtitle", 10, 251000, 0, 0)
TransmiterRadio:E({
TransmiterRadio.Positionable,
TransmiterRadio.FileName,
TransmiterRadio.Subtitle,
TransmiterRadio.SubtitleDuration,
TransmiterRadio.Frequency,
TransmiterRadio.Modulation,
})
TransmiterRadio:Broadcast()