Fixed bugs with new option table.

This commit is contained in:
Frank
2020-08-01 00:25:12 +02:00
parent 286e34e057
commit 775b9e9fde
7 changed files with 93 additions and 76 deletions

View File

@@ -1392,8 +1392,8 @@ function FLIGHTGROUP:onafterSpawned(From, Event, To)
if self.ai then
-- Set default ROE and ROT options.
self:SetOptionROE(self.roe)
self:SetOptionROT(self.rot)
self:SwitchROE(self.option.ROE)
self:SwitchROT(self.option.ROT)
-- TODO: make this input.
self.group:SetOption(AI.Option.Air.id.PROHIBIT_JETT, true)
@@ -1402,18 +1402,19 @@ function FLIGHTGROUP:onafterSpawned(From, Event, To)
--self.group:SetOption(AI.Option.Air.id.RADAR_USING, AI.Option.Air.val.RADAR_USING.FOR_CONTINUOUS_SEARCH)
-- Turn TACAN beacon on.
if self.tacanChannelDefault then
self:SwitchTACANOn(self.tacanChannelDefault, self.tacanMorseDefault)
if self.tacanDefault.Channel then
self:SwitchTACAN(self.tacanDefault.Channel, self.tacanDefault.Morse)
end
-- Turn on the radio.
if self.radioFreqDefault then
self:SwitchRadioOn(self.radioFreqDefault, self.radioModuDefault)
if self.radioDefault.Freq then
self:SwitchRadio(self.radioDefault.Freq, self.radioDefault.Modu)
end
-- Set callsign.
if self.callsignNameDefault then
if self.callsignDefault.Name then
self:SwitchCallsign(self.callsignNameDefault, self.callsignNumberDefault)
else
end
-- Update route.
@@ -2510,36 +2511,28 @@ function FLIGHTGROUP:_InitGroup()
-- Radio parameters from template.
self.radioOn=self.template.communication
self.radioFreq=self.template.frequency
self.radioModu=self.template.modulation
-- If not set by the use explicitly yet, we take the template values as defaults.
if not self.radioFreqDefault then
self.radioFreqDefault=self.radioFreq
self.radioModuDefault=self.radioModu
end
self.radio.Freq=self.template.frequency
self.radio.Modu=self.template.modulation
self.radioDefault.Freq=self.radio.Freq
self.radioDefault.Modu=self.radio.Modu
-- Set default formation.
if not self.formationDefault then
if self.ishelo then
self.formationDefault=ENUMS.Formation.RotaryWing.EchelonLeft.D300
else
self.formationDefault=ENUMS.Formation.FixedWing.EchelonLeft.Group
end
if self.ishelo then
self.optionDefault.Formation=ENUMS.Formation.RotaryWing.EchelonLeft.D300
else
self.optionDefault.Formation=ENUMS.Formation.FixedWing.EchelonLeft.Group
end
-- Is this purely AI?
self.ai=not self:_IsHuman(self.group)
-- Create Menu.
if not self.ai then
self.menu=self.menu or {}
self.menu.atc=self.menu.atc or {}
self.menu.atc.root=self.menu.atc.root or MENU_GROUP:New(self.group, "ATC")
end
-- Switch to default formation.
-- TODO: Should this be moved to onafterspawned?
self:SwitchFormation(self.formationDefault)
-- Add elemets.
for _,unit in pairs(self.group:GetUnits()) do
local element=self:AddElementByName(unit:GetName())
@@ -2573,7 +2566,7 @@ function FLIGHTGROUP:_InitGroup()
text=text..string.format("Helicopter = %s\n", tostring(self.group:IsHelicopter()))
text=text..string.format("Elements = %d\n", #self.elements)
text=text..string.format("Waypoints = %d\n", #self.waypoints)
text=text..string.format("Radio = %.1f MHz %s %s\n", self.radioFreq, UTILS.GetModulationName(self.radioModu), tostring(self.radioOn))
text=text..string.format("Radio = %.1f MHz %s %s\n", self.radio.Freq, UTILS.GetModulationName(self.radio.Modu), tostring(self.radioOn))
text=text..string.format("Ammo = %d (G=%d/R=%d/B=%d/M=%d)\n", self.ammo.Total, self.ammo.Guns, self.ammo.Rockets, self.ammo.Bombs, self.ammo.Missiles)
text=text..string.format("FSM state = %s\n", self:GetState())
text=text..string.format("Is alive = %s\n", tostring(self.group:IsAlive()))
@@ -2965,28 +2958,34 @@ end
--- Add an AIR waypoint to the flight plan.
-- @param #FLIGHTGROUP self
-- @param Core.Point#COORDINATE coordinate The coordinate of the waypoint. Use COORDINATE:SetAltitude(altitude) to define the altitude.
-- @param #number speed Speed in knots. Default 350 kts.
-- @param #number wpnumber Waypoint number. Default at the end.
-- @param #boolean updateroute If true or nil, call UpdateRoute. If false, no call.
-- @param #number Speed Speed in knots. Default 350 kts.
-- @param #number AfterWaypointWithID Insert waypoint after waypoint given ID. Default is to insert as last waypoint.
-- @param #boolean Updateroute If true or nil, call UpdateRoute. If false, no call.
-- @return Ops.OpsGroup#OPSGROUP.Waypoint Waypoint table.
function FLIGHTGROUP:AddWaypoint(coordinate, speed, wpnumber, updateroute)
function FLIGHTGROUP:AddWaypoint(Coordinate, Speed, AfterWaypointWithID, Updateroute)
-- Waypoint number. Default is at the end.
wpnumber=wpnumber or #self.waypoints+1
-- Set waypoint index.
local wpnumber=#self.waypoints+1
if wpnumber then
local index=self:GetWaypointIndex(AfterWaypointWithID)
if index then
wpnumber=index+1
end
end
if wpnumber>self.currentwp then
self.passedfinalwp=false
end
-- Speed in knots.
speed=speed or 350
Speed=Speed or 350
-- Speed at waypoint.
local speedkmh=UTILS.KnotsToKmph(speed)
local speedkmh=UTILS.KnotsToKmph(Speed)
-- Create air waypoint.
local name=string.format("Added Waypoint #%d", wpnumber)
local wp=coordinate:WaypointAir(COORDINATE.WaypointAltType.BARO, COORDINATE.WaypointType.TurningPoint, COORDINATE.WaypointAction.TurningPoint, speedkmh, true, nil, {}, name)
local wp=Coordinate:WaypointAir(COORDINATE.WaypointAltType.BARO, COORDINATE.WaypointType.TurningPoint, COORDINATE.WaypointAction.TurningPoint, speedkmh, true, nil, {}, name)
-- Create waypoint data table.
local waypoint=self:_CreateWaypoint(wp)
@@ -2995,10 +2994,10 @@ function FLIGHTGROUP:AddWaypoint(coordinate, speed, wpnumber, updateroute)
self:_AddWaypoint(waypoint, wpnumber)
-- Debug info.
self:T(self.lid..string.format("Adding AIR waypoint #%d, speed=%.1f knots. Last waypoint passed was #%s. Total waypoints #%d", wpnumber, speed, self.currentwp, #self.waypoints))
self:T(self.lid..string.format("Adding AIR waypoint #%d, speed=%.1f knots. Last waypoint passed was #%s. Total waypoints #%d", wpnumber, Speed, self.currentwp, #self.waypoints))
-- Update route.
if updateroute==nil or updateroute==true then
if Updateroute==nil or Updateroute==true then
self:__UpdateRoute(-1)
end

View File

@@ -550,8 +550,8 @@ function NAVYGROUP:onafterSpawned(From, Event, To)
if self.ai then
-- Set default ROE and Alarmstate options.
self:SetOptionROE(self.roe)
self:SetOptionAlarmstate(self.alarmstate)
self:SwitchROE(self.option.ROE)
self:SwitchAlarmstate(self.option.Alarm)
end

View File

@@ -52,8 +52,9 @@
-- @field Core.Point#COORDINATE position Position of the group at last status check.
-- @field #number traveldist Distance traveled in meters. This is a lower bound!
-- @field #number traveltime Time.
-- @field #boolean ispathfinding If true, group is on pathfinding route.
--
-- @field Core.Astar#ASTAR Astar path finding.
-- @field #boolean ispathfinding If true, group is on pathfinding route.
--
-- @field #OPSGROUP.Radio radio Current radio settings.
-- @field #OPSGROUP.Radio radioDefault Default radio settings.
@@ -69,9 +70,10 @@
-- @field #boolean iclsOn If true, ICLS is currently active.
--
-- @field #OPSGROUP.Option option Current optional settings.
-- @field #OPSGROUP.Option optionDefault Default option settings.
-- @field #OPSGROUP.Option optionDefault Default option settings.
--
-- @field Core.Astar#ASTAR Astar path finding.
-- @field #OPSGROUP.Callsign callsign Current callsign settings.
-- @field #OPSGROUP.Callsign callsignDefault Default callsign settings.
--
-- @extends Core.Fsm#FSM
@@ -2763,7 +2765,7 @@ function OPSGROUP:SwitchROE(roe)
self.group:OptionROE(self.option.ROE)
self:I(self.lid..string.format("Setting current ROE=%d (0=WeaponFree, 1=OpenFireWeaponFree, 2=OpenFire, 3=ReturnFire, 4=WeaponHold)", self.roe))
self:I(self.lid..string.format("Setting current ROE=%d (0=WeaponFree, 1=OpenFireWeaponFree, 2=OpenFire, 3=ReturnFire, 4=WeaponHold)", self.option.ROE))
else
-- TODO WARNING
end
@@ -2799,7 +2801,7 @@ function OPSGROUP:SwitchROT(rot)
self.group:OptionROT(self.option.ROT)
self:T2(self.lid..string.format("Setting current ROT=%d (0=NoReaction, 1=Passive, 2=Evade, 3=ByPass, 4=AllowAbort)", self.rot))
self:T2(self.lid..string.format("Setting current ROT=%d (0=NoReaction, 1=Passive, 2=Evade, 3=ByPass, 4=AllowAbort)", self.option.ROT))
else
-- TODO WARNING
end
@@ -2880,10 +2882,11 @@ end
--- Activate TACAN beacon.
-- @param #OPSGROUP self
-- @param #number TACANChannel TACAN Channel.
-- @param #string TACANMorse TACAN morse code.
-- @param #number Channel TACAN Channel.
-- @param #string Morse TACAN morse code.
-- @param #string Band TACAN channel mode "X" or "Y". Default is "Y" for aircraft and "X" for ground and naval groups.
-- @return #OPSGROUP self
function OPSGROUP:SwitchTACAN(TACANChannel, TACANMorse)
function OPSGROUP:SwitchTACAN(Channel, Morse, Band)
if self:IsAlive() then
@@ -2891,21 +2894,36 @@ function OPSGROUP:SwitchTACAN(TACANChannel, TACANMorse)
if unit and unit:IsAlive() then
local Type=4
local System=5
local UnitID=unit:GetID()
local TACANMode="Y"
local Frequency=UTILS.TACANToFrequency(TACANChannel, TACANMode)
unit:CommandActivateBeacon(Type, System, Frequency, UnitID, TACANChannel, TACANMode, true, TACANMorse, true)
local Type=BEACON.Type.TACAN
local System=BEACON.System.TACAN
--local TACANMode="Y"
if self.isAircraft then
Type=4
System=5
Band=Band or "Y"
else
Band=Band or "X"
end
-- Tacan frequency.
local Frequency=UTILS.TACANToFrequency(Channel, Band)
unit:CommandActivateBeacon(Type, System, Frequency, UnitID, Channel, Band, true, Morse, true)
self.tacanBeacon=unit
self.tacanChannel=TACANChannel
self.tacanMorse=TACANMorse
self.tacan.Channel=Channel
self.tacan.Morse=Morse
self.tacan.Band=Band
self.tacan.UnitName=unit:GetName()
-- TACAN is now on.
self.tacanOn=true
self:I(self.lid..string.format("Switching TACAN to Channel %dY Morse %s", self.tacanChannel, tostring(self.tacanMorse)))
self:I(self.lid..string.format("Switching TACAN to Channel %d%s Morse %s on unit %s", self.tacan.Channel, self.tacan.Band, tostring(self.tacan.Morse), self.tacan.UnitName))
end
@@ -2963,7 +2981,7 @@ function OPSGROUP:SwitchRadio(Frequency, Modulation)
local group=self.group --Wrapper.Group#GROUP
if not self.radioOn then
if self.isAircraft and not self.radioOn then
group:SetOption(AI.Option.Air.id.SILENCE, false)
end
@@ -2975,7 +2993,7 @@ function OPSGROUP:SwitchRadio(Frequency, Modulation)
-- Radio is on.
self.radioOn=true
self:I(self.lid..string.format("Switching radio to frequency %.3f MHz %s", self.radioFreq, UTILS.GetModulationName(self.radioModu)))
self:I(self.lid..string.format("Switching radio to frequency %.3f MHz %s", self.radio.Freq, UTILS.GetModulationName(self.radio.Modu)))
end