Support for UNIT and GROUP in RADIO:SetTransmission() + indentation

This commit is contained in:
Grey-Echo 2017-03-10 23:34:24 +01:00
parent 396aa38c18
commit 4655a6413d

View File

@ -19,15 +19,15 @@
-- @type RADIO -- @type RADIO
-- @extends Core.Base#BASE -- @extends Core.Base#BASE
RADIO = { RADIO = {
ClassName = "RADIO", ClassName = "RADIO",
Positionable, Positionable,
FileName = "", FileName = "",
Frequency = 0, Frequency = 0,
Modulation = radio.modulation.AM, Modulation = radio.modulation.AM,
Subtitle = "", Subtitle = "",
SubtitleDuration = 0, SubtitleDuration = 0,
Power = 100, Power = 100,
Loop = 0, Loop = 0,
} }
--- Create a new RADIO Object. This doesn't broadcast a transmission, though, use @{#RADIO.Broadcast} to actually broadcast --- Create a new RADIO Object. This doesn't broadcast a transmission, though, use @{#RADIO.Broadcast} to actually broadcast
@ -37,15 +37,15 @@ RADIO = {
-- @usage -- @usage
-- -- If you want to create a RADIO, you probably should use @{Wrapper.Positionable#POSITIONABLE.GetRadio} instead -- -- If you want to create a RADIO, you probably should use @{Wrapper.Positionable#POSITIONABLE.GetRadio} instead
function RADIO:New(positionable) function RADIO:New(positionable)
local self = BASE:Inherit( self, BASE:New() ) local self = BASE:Inherit( self, BASE:New() )
self:F(positionable) self:F(positionable)
if positionable:GetPointVec2() ~= nil then -- It's stupid, but the only way I found to make sure positionable is valid if positionable:GetPointVec2() ~= nil then -- It's stupid, but the only way I found to make sure positionable is valid
self.Positionable = positionable self.Positionable = positionable
return self return self
else else
self:E({"The passed positionable is invalid, no RADIO created", positionable}) self:E({"The passed positionable is invalid, no RADIO created", positionable})
return nil return nil
end end
end end
--- Check validity of the filename passed and sets RADIO.FileName --- Check validity of the filename passed and sets RADIO.FileName
@ -58,9 +58,9 @@ function RADIO:SetFileName(filename)
if type(filename) == "string" then if type(filename) == "string" then
if filename:find(".ogg") ~= nil or filename:find(".wav") ~= nil then if filename:find(".ogg") ~= nil or filename:find(".wav") ~= nil then
if filename:find("l10n/DEFAULT/") == nil then if filename:find("l10n/DEFAULT/") == nil then
filename = "l10n/DEFAULT/" .. filename filename = "l10n/DEFAULT/" .. filename
self.FileName = filename self.FileName = filename
return self return self
end end
end end
end end
@ -76,8 +76,19 @@ end
function RADIO:SetFrequency(frequency) function RADIO:SetFrequency(frequency)
self:F(frequency) self:F(frequency)
if type(frequency) == "number" then if type(frequency) == "number" then
-- If frequency is in range
if (frequency >= 30 and frequency < 88) or (frequency >= 108 and frequency < 152) or (frequency >= 225 and frequency < 400) then if (frequency >= 30 and frequency < 88) or (frequency >= 108 and frequency < 152) or (frequency >= 225 and frequency < 400) then
self.Frequency = frequency * 1000 -- Coversion in Hz self.Frequency = frequency * 1000 -- Coversion in Hz
-- If the RADIO is attached to a UNIT or a GROUP, we need to send the DCS Command "SetFrequency" to change the UNIT or GROUP frequency
if self.Positionable.ClassName == "UNIT" or self.Positionable.ClassName == "GROUP" then
self.Positionable:GetDCSObject():getController():setCommand({
id = "SetFrequency",
params = {
frequency = self.Frequency,
modulation = self.Modulation,
}
})
end
return self return self
end end
end end
@ -93,10 +104,10 @@ end
function RADIO:SetModulation(modulation) function RADIO:SetModulation(modulation)
self:F(modulation) self:F(modulation)
if type(modulation) == "number" then if type(modulation) == "number" then
if modulation == radio.modulation.AM or modulation == radio.modulation.FM then --TODO Maybe make this future proof if ED decides to add an other modulation ? if modulation == radio.modulation.AM or modulation == radio.modulation.FM then --TODO Maybe make this future proof if ED decides to add an other modulation ?
self.Modulation = modulation self.Modulation = modulation
return self return self
end end
end end
self:E({"Modulation is invalid. Use DCS's enum radio.modulation. Modulation unchanged.", self.Modulation}) self:E({"Modulation is invalid. Use DCS's enum radio.modulation. Modulation unchanged.", self.Modulation})
return self return self
@ -111,9 +122,9 @@ function RADIO:SetPower(power)
self:F(power) self:F(power)
if type(power) == "number" then if type(power) == "number" then
if math.floor(math.abs(power)) == power then if math.floor(math.abs(power)) == power then
self.Power = power --TODO Find what is the maximum power allowed by DCS and limit power to that self.Power = power --TODO Find what is the maximum power allowed by DCS and limit power to that
return self return self
end end
end end
self:E({"Power is invalid. Power unchanged.", self.Power}) self:E({"Power is invalid. Power unchanged.", self.Power})
return self return self
@ -127,8 +138,8 @@ end
function RADIO:SetLoop(loop) function RADIO:SetLoop(loop)
self:F(loop) self:F(loop)
if type(loop) == "boolean" then if type(loop) == "boolean" then
self.Loop = loop self.Loop = loop
return self return self
end end
self:E({"Loop is invalid. Loop unchanged.", self.Loop}) self:E({"Loop is invalid. Loop unchanged.", self.Loop})
return self return self
@ -170,9 +181,9 @@ end
-- -- 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:NewGenericTransmission(...) function RADIO:NewGenericTransmission(...)
self:F(arg) self:F(arg)
return self return self
end end
@ -192,9 +203,9 @@ end
-- -- Loop : O is no loop, 1 is loop -- -- Loop : O is no loop, 1 is loop
-- -- @TODO : Verify the type of passed args and throw errors when necessary -- -- @TODO : Verify the type of passed args and throw errors when necessary
function RADIO:NewUnitTransmission(...) function RADIO:NewUnitTransmission(...)
self:F(arg) self:F(arg)
return self return self
end end
--- Actually Broadcast the transmission --- Actually Broadcast the transmission
@ -208,33 +219,21 @@ 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() 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 self.Positionable.ClassName == "UNIT" or self.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. self.Positionable:GetDCSObject():getController():setCommand({
-- Else we set the frequency of the UNIT or the GROUP in DCS id = "TransmitMessage",
if self.Frequency ~= 0 then params = {
self.Positionable:GetDCSObject():getController():setCommand({ file = self.FileName,
id = "SetFrequency", duration = self.SubtitleDuration,
params = { subtitle = self.Subtitle,
frequency = self.Frequency, loop = self.Loop,
modulation = self.Modulation, }
} })
}) else
end -- If the POSITIONABLE is anything else, we revert to the general function
trigger.action.radioTransmission(self.FileName, self.Positionable:GetPositionVec3(), self.Modulation, false, self.Frequency, self.Power)
self.Positionable:GetDCSObject():getController():setCommand({ end
id = "TransmitMessage", return self
params = {
file = self.FileName,
duration = self.SubtitleDuration,
subtitle = self.Subtitle,
loop = self.Loop,
}
})
else
-- If the POSITIONABLE is anything else, we revert to the general function
trigger.action.radioTransmission(self.FileName, self.Positionable:GetPositionVec3(), self.Modulation, false, self.Frequency, self.Power)
end
return self
end end