This commit is contained in:
Frank 2020-09-02 00:05:05 +02:00
parent eb86d59203
commit 444cc43971
4 changed files with 91 additions and 28 deletions

View File

@ -798,6 +798,9 @@ function ARMYGROUP:_InitGroup()
self.radio.Freq=133 self.radio.Freq=133
self.radio.Modu=radio.modulation.AM self.radio.Modu=radio.modulation.AM
-- Set default radio.
self:SetDefaultRadio(self.radio.Freq, self.radio.Modu, self.radio.On)
-- Set default formation from first waypoint. -- Set default formation from first waypoint.
self.option.Formation=self:GetWaypoint(1).action self.option.Formation=self:GetWaypoint(1).action
self.optionDefault.Formation=self.option.Formation self.optionDefault.Formation=self.option.Formation

View File

@ -2543,11 +2543,17 @@ function FLIGHTGROUP:_InitGroup()
self.ammo=self:GetAmmoTot() self.ammo=self:GetAmmoTot()
-- Radio parameters from template. -- Radio parameters from template.
self.radio.On=self.template.communication self.radio.Freq=tonumber(self.template.frequency)
self.radio.Freq=self.template.frequency self.radio.Modu=tonumber(self.template.modulation)
self.radio.Modu=self.template.modulation local on=tostring(self.template.communication):lower()
if on=="true" then
self.radio.On=true
else
self.radio.On=false
end
self.radioDefault=UTILS.DeepCopy(self.radio) -- Set default radio.
self:SetDefaultRadio(self.radio.Freq, self.radio.Modu, self.radio.On)
--TODO callsign from template or getCallsign --TODO callsign from template or getCallsign
self.callsign.NumberSquad=self.template.units[1].callsign[1] self.callsign.NumberSquad=self.template.units[1].callsign[1]

View File

@ -96,6 +96,8 @@ function NAVYGROUP:New(GroupName)
-- Defaults -- Defaults
self:SetDetection() self:SetDetection()
self:SetDefaultROE()
self:SetDefaultAlarmstate()
self:SetPatrolAdInfinitum(true) self:SetPatrolAdInfinitum(true)
self:SetPathfinding(false) self:SetPathfinding(false)
@ -1135,6 +1137,9 @@ function NAVYGROUP:_InitGroup()
self.radio.Freq=tonumber(self.template.units[1].frequency)/1000000 self.radio.Freq=tonumber(self.template.units[1].frequency)/1000000
self.radio.Modu=tonumber(self.template.units[1].modulation) self.radio.Modu=tonumber(self.template.units[1].modulation)
-- Set default radio.
self:SetDefaultRadio(self.radio.Freq, self.radio.Modu, self.radio.On)
-- Set default formation. No really applicable for ships. -- Set default formation. No really applicable for ships.
self.optionDefault.Formation="Off Road" self.optionDefault.Formation="Off Road"
self.option.Formation=self.optionDefault.Formation self.option.Formation=self.optionDefault.Formation

View File

@ -665,11 +665,18 @@ end
--- Check if this group is currently "uncontrolled" and needs to be "started" to begin its route. --- Check if this group is currently "uncontrolled" and needs to be "started" to begin its route.
-- @param #OPSGROUP self -- @param #OPSGROUP self
-- @return #boolean If this group uncontrolled. -- @return #boolean If true, this group uncontrolled.
function OPSGROUP:IsUncontrolled() function OPSGROUP:IsUncontrolled()
return self.isUncontrolled return self.isUncontrolled
end end
--- Check if this group has passed its final waypoint.
-- @param #OPSGROUP self
-- @return #boolean If true, this group has passed the final waypoint.
function OPSGROUP:HasPassedFinalWaypoint()
return self.passedfinalwp
end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Waypoint Functions -- Waypoint Functions
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@ -2995,13 +3002,13 @@ end
--- Set current ROE for the group. --- Set current ROE for the group.
-- @param #OPSGROUP self -- @param #OPSGROUP self
-- @param #string roe ROE of group. Default is `ENUMS.ROE.ReturnFire`. -- @param #string roe ROE of group. Default is value set in `SetDefaultROE` (usually `ENUMS.ROE.ReturnFire`).
-- @return #OPSGROUP self -- @return #OPSGROUP self
function OPSGROUP:SwitchROE(roe) function OPSGROUP:SwitchROE(roe)
if self:IsAlive() or self:IsInUtero() then if self:IsAlive() or self:IsInUtero() then
self.option.ROE=roe or ENUMS.ROE.ReturnFire self.option.ROE=roe or self.optionDefault.ROE
if self:IsInUtero() then if self:IsInUtero() then
self:T2(self.lid..string.format("Setting current ROE=%d when GROUP is SPAWNED", self.option.ROE)) self:T2(self.lid..string.format("Setting current ROE=%d when GROUP is SPAWNED", self.option.ROE))
@ -3009,7 +3016,7 @@ function OPSGROUP:SwitchROE(roe)
self.group:OptionROE(roe) self.group:OptionROE(roe)
self:I(self.lid..string.format("Setting current ROE=%d (0=WeaponFree, 1=OpenFireWeaponFree, 2=OpenFire, 3=ReturnFire, 4=WeaponHold)", self.option.ROE)) self:I(self.lid..string.format("Setting current ROE=%d (%s)", self.option.ROE, self:_GetROEName(self.option.ROE)))
end end
@ -3020,6 +3027,24 @@ function OPSGROUP:SwitchROE(roe)
return self return self
end end
--- Set current ROE for the group.
-- @param #OPSGROUP self
function OPSGROUP:_GetROEName(roe)
local name="unknown"
if roe==0 then
name="Weapon Free"
elseif roe==1 then
name="Open Fire/Weapon Free"
elseif roe==2 then
name="Open Fire"
elseif roe==3 then
name="Return Fire"
elseif roe==4 then
name="Weapon Hold"
end
return name
end
--- Get current ROE of the group. --- Get current ROE of the group.
-- @param #OPSGROUP self -- @param #OPSGROUP self
-- @return #number Current ROE. -- @return #number Current ROE.
@ -3038,13 +3063,13 @@ end
--- Set ROT for the group. --- Set ROT for the group.
-- @param #OPSGROUP self -- @param #OPSGROUP self
-- @param #string rot ROT of group. Default is `ENUMS.ROT.PassiveDefense`. -- @param #string rot ROT of group. Default is value set in `:SetDefaultROT` (usually `ENUMS.ROT.PassiveDefense`).
-- @return #OPSGROUP self -- @return #OPSGROUP self
function OPSGROUP:SwitchROT(rot) function OPSGROUP:SwitchROT(rot)
if self:IsAlive() or self:IsInUtero() then if self:IsAlive() or self:IsInUtero() then
self.option.ROT=rot or ENUMS.ROT.PassiveDefense self.option.ROT=rot or self.optionDefault.ROT
if self:IsInUtero() then if self:IsInUtero() then
self:T2(self.lid..string.format("Setting current ROT=%d when GROUP is SPAWNED", self.option.ROT)) self:T2(self.lid..string.format("Setting current ROT=%d when GROUP is SPAWNED", self.option.ROT))
@ -3350,12 +3375,18 @@ end
-- @param #OPSGROUP self -- @param #OPSGROUP self
-- @param #number Frequency Radio frequency in MHz. Default 251 MHz. -- @param #number Frequency Radio frequency in MHz. Default 251 MHz.
-- @param #number Modulation Radio modulation. Default `radio.Modulation.AM`. -- @param #number Modulation Radio modulation. Default `radio.Modulation.AM`.
-- @param #boolean OffSwitch If true, radio is OFF by default.
-- @return #OPSGROUP self -- @return #OPSGROUP self
function OPSGROUP:SetDefaultRadio(Frequency, Modulation) function OPSGROUP:SetDefaultRadio(Frequency, Modulation, OffSwitch)
self.radioDefault={} self.radioDefault={}
self.radioDefault.Freq=Frequency or 251 self.radioDefault.Freq=Frequency or 251
self.radioDefault.Modu=Modulation or radio.modulation.AM self.radioDefault.Modu=Modulation or radio.modulation.AM
if OffSwitch then
self.radioDefault.On=false
else
self.radioDefault.On=true
end
return self return self
end end
@ -3364,21 +3395,22 @@ end
-- @param #OPSGROUP self -- @param #OPSGROUP self
-- @return #number Radio frequency in MHz or nil. -- @return #number Radio frequency in MHz or nil.
-- @return #number Radio modulation or nil. -- @return #number Radio modulation or nil.
-- @return #boolean If true, the radio is on. Otherwise, radio is turned off.
function OPSGROUP:GetRadio() function OPSGROUP:GetRadio()
return self.radio.Freq, self.radio.Modu return self.radio.Freq, self.radio.Modu, self.radio.On
end end
--- Turn radio on or switch frequency/modulation. --- Turn radio on or switch frequency/modulation.
-- @param #OPSGROUP self -- @param #OPSGROUP self
-- @param #number Frequency Radio frequency in MHz. Default is 127.5 MHz. -- @param #number Frequency Radio frequency in MHz. Default is value set in `SetDefaultRadio` (usually 251 MHz).
-- @param #number Modulation Radio modulation. Default `radio.Modulation.AM`. -- @param #number Modulation Radio modulation. Default is value set in `SetDefaultRadio` (usually `radio.Modulation.AM`).
-- @return #OPSGROUP self -- @return #OPSGROUP self
function OPSGROUP:SwitchRadio(Frequency, Modulation) function OPSGROUP:SwitchRadio(Frequency, Modulation)
if self:IsAlive() or self:IsInUtero() then if self:IsAlive() or self:IsInUtero() then
Frequency=Frequency or 127.5 Frequency=Frequency or self.radioDefault.Freq
Modulation=Modulation or radio.modulation.AM Modulation=Modulation or self.radioDefault.Modu
local group=self.group --Wrapper.Group#GROUP local group=self.group --Wrapper.Group#GROUP
@ -3386,11 +3418,27 @@ function OPSGROUP:SwitchRadio(Frequency, Modulation)
group:SetOption(AI.Option.Air.id.SILENCE, false) group:SetOption(AI.Option.Air.id.SILENCE, false)
end end
-- Set radio -- Backup last radio settings.
if self.radio then
self.radioLast=UTILS.DeepCopy(self.radio)
end
-- Set current radio.
self.radio.Freq=Frequency self.radio.Freq=Frequency
self.radio.Modu=Modulation self.radio.Modu=Modulation
self.radio.On=true self.radio.On=true
-- Only switch radio if different.
if self.radio.Freq~=self.radioLast.Freq or self.radio.Modu~=self.radioLast.Modu then
--[[
local text=string.format("\nRadio Freq=%.3f %.3f", self.radio.Freq, self.radioLast.Freq)
text=text..string.format("\nRadio Modu=%d %d", self.radio.Modu, self.radioLast.Modu)
text=text..string.format("\nRadio OnOf=%s %s", tostring(self.radio.On), tostring(self.radioLast.On))
text=text..string.format("\nRadio %s", tostring(self.radio==self.radioLast))
self:I(self.lid..text)
]]
if self:IsInUtero() then if self:IsInUtero() then
self:T2(self.lid..string.format("Switching radio to frequency %.3f MHz %s when GROUP is SPAWNED", self.radio.Freq, UTILS.GetModulationName(self.radio.Modu))) self:T2(self.lid..string.format("Switching radio to frequency %.3f MHz %s when GROUP is SPAWNED", self.radio.Freq, UTILS.GetModulationName(self.radio.Modu)))
else else
@ -3402,6 +3450,10 @@ function OPSGROUP:SwitchRadio(Frequency, Modulation)
end end
else
self:T(self.lid.."INFO: Current radio not switched as freq/modulation did not change")
end
else else
self:E(self.lid.."ERROR: Cound not set Radio! Group is not alive") self:E(self.lid.."ERROR: Cound not set Radio! Group is not alive")
end end
@ -3421,9 +3473,6 @@ function OPSGROUP:TurnOffRadio()
-- Set group to be silient. -- Set group to be silient.
self.group:SetOption(AI.Option.Air.id.SILENCE, true) self.group:SetOption(AI.Option.Air.id.SILENCE, true)
--self.radio.Freq=nil
--self.radio.Modu=nil
-- Radio is off. -- Radio is off.
self.radio.On=false self.radio.On=false