OPS Chief

- Removed mission queue. Now done via COMMANDER
- MissionCancel is buggy
This commit is contained in:
Frank 2021-08-26 23:24:11 +02:00
parent 1b0ad13529
commit a8a8dcff3f
5 changed files with 193 additions and 226 deletions

View File

@ -110,7 +110,7 @@
-- @field #number missionAltitude Mission altitude in meters. -- @field #number missionAltitude Mission altitude in meters.
-- @field #number missionSpeed Mission speed in km/h. -- @field #number missionSpeed Mission speed in km/h.
-- @field #number missionFraction Mission coordiante fraction. Default is 0.5. -- @field #number missionFraction Mission coordiante fraction. Default is 0.5.
-- @field #number missionRange Mission range in meters. Used in AIRWING class. -- @field #number missionRange Mission range in meters. Used by LEGION classes (AIRWING, BRIGADE, ...).
-- @field Core.Point#COORDINATE missionWaypointCoord Mission waypoint coordinate. -- @field Core.Point#COORDINATE missionWaypointCoord Mission waypoint coordinate.
-- @field Core.Point#COORDINATE missionEgressCoord Mission egress waypoint coordinate. -- @field Core.Point#COORDINATE missionEgressCoord Mission egress waypoint coordinate.
-- --
@ -463,6 +463,7 @@ AUFTRAG.version="0.7.1"
-- TODO list -- TODO list
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO: Replace engageRange by missionRange. Here and in other classes. CTRL+H is your friend!
-- TODO: Missions can be assigned to multiple legions. -- TODO: Missions can be assigned to multiple legions.
-- TODO: Mission success options damaged, destroyed. -- TODO: Mission success options damaged, destroyed.
-- TODO: F10 marker to create new missions. -- TODO: F10 marker to create new missions.
@ -1552,7 +1553,7 @@ function AUFTRAG:SetPriority(Prio, Urgent, Importance)
return self return self
end end
--- Set how many times the mission is repeated. Only valid if the mission is handled by an AIRWING or higher level. --- Set how many times the mission is repeated. Only valid if the mission is handled by a LEGION (AIRWING, BRIGADE, ...) or higher level.
-- @param #AUFTRAG self -- @param #AUFTRAG self
-- @param #number Nrepeat Number of repeats. Default 0. -- @param #number Nrepeat Number of repeats. Default 0.
-- @return #AUFTRAG self -- @return #AUFTRAG self
@ -1561,7 +1562,7 @@ function AUFTRAG:SetRepeat(Nrepeat)
return self return self
end end
--- Set how many times the mission is repeated if it fails. Only valid if the mission is handled by an AIRWING or higher level. --- Set how many times the mission is repeated if it fails. Only valid if the mission is handled by a LEGION (AIRWING, BRIGADE, ...) or higher level.
-- @param #AUFTRAG self -- @param #AUFTRAG self
-- @param #number Nrepeat Number of repeats. Default 0. -- @param #number Nrepeat Number of repeats. Default 0.
-- @return #AUFTRAG self -- @return #AUFTRAG self
@ -1570,7 +1571,7 @@ function AUFTRAG:SetRepeatOnFailure(Nrepeat)
return self return self
end end
--- Set how many times the mission is repeated if it was successful. Only valid if the mission is handled by an AIRWING or higher level. --- Set how many times the mission is repeated if it was successful. Only valid if the mission is handled by a LEGION (AIRWING, BRIGADE, ...) or higher level.
-- @param #AUFTRAG self -- @param #AUFTRAG self
-- @param #number Nrepeat Number of repeats. Default 0. -- @param #number Nrepeat Number of repeats. Default 0.
-- @return #AUFTRAG self -- @return #AUFTRAG self
@ -1579,7 +1580,7 @@ function AUFTRAG:SetRepeatOnSuccess(Nrepeat)
return self return self
end end
--- Define how many assets are required to do the job. Only valid if the mission is handled by an AIRWING, BRIGADE etc or higher level. --- Define how many assets are required to do the job. Only valid if the mission is handled by a LEGION (AIRWING, BRIGADE, ...) or higher level.
-- @param #AUFTRAG self -- @param #AUFTRAG self
-- @param #number Nassets Number of asset groups. Default 1. -- @param #number Nassets Number of asset groups. Default 1.
-- @return #AUFTRAG self -- @return #AUFTRAG self
@ -2977,25 +2978,27 @@ function AUFTRAG:onafterCancel(From, Event, To)
if self.chief then if self.chief then
-- Debug info.
self:T(self.lid..string.format("CHIEF will cancel the mission. Will wait for mission DONE before evaluation!")) self:T(self.lid..string.format("CHIEF will cancel the mission. Will wait for mission DONE before evaluation!"))
-- CHIEF will cancel the mission.
self.chief:MissionCancel(self) self.chief:MissionCancel(self)
end elseif self.commander then
if self.commander then
-- Debug info.
self:T(self.lid..string.format("COMMANDER will cancel the mission. Will wait for mission DONE before evaluation!")) self:T(self.lid..string.format("COMMANDER will cancel the mission. Will wait for mission DONE before evaluation!"))
-- COMMANDER will cancel the mission.
self.commander:MissionCancel(self) self.commander:MissionCancel(self)
end elseif self.legions then
if #self.legions>0 then -- Loop over all LEGIONs.
for _,_legion in pairs(self.legions or {}) do
for _,_legion in pairs(self.legions) do
local legion=_legion --Ops.Legion#LEGION local legion=_legion --Ops.Legion#LEGION
-- Debug info.
self:T(self.lid..string.format("LEGION %s will cancel the mission. Will wait for mission DONE before evaluation!", legion.alias)) self:T(self.lid..string.format("LEGION %s will cancel the mission. Will wait for mission DONE before evaluation!", legion.alias))
-- Legion will cancel all flight missions and remove queued request from warehouse queue. -- Legion will cancel all flight missions and remove queued request from warehouse queue.
@ -3003,16 +3006,19 @@ function AUFTRAG:onafterCancel(From, Event, To)
end end
end else
-- Debug info.
self:T(self.lid..string.format("No legion, commander or chief. Attached flights will cancel the mission on their own. Will wait for mission DONE before evaluation!")) self:T(self.lid..string.format("No legion, commander or chief. Attached flights will cancel the mission on their own. Will wait for mission DONE before evaluation!"))
-- Loop over all groups.
for _,_groupdata in pairs(self.groupdata or {}) do for _,_groupdata in pairs(self.groupdata or {}) do
local groupdata=_groupdata --#AUFTRAG.GroupData local groupdata=_groupdata --#AUFTRAG.GroupData
groupdata.opsgroup:MissionCancel(self) groupdata.opsgroup:MissionCancel(self)
end end
end
-- Special mission states. -- Special mission states.
if self:IsPlanned() or self:IsQueued() or self:IsRequested() or Ngroups==0 then if self:IsPlanned() or self:IsQueued() or self:IsRequested() or Ngroups==0 then
self:T(self.lid..string.format("Cancelled mission was in %s stage with %d groups assigned and alive. Call it done!", self.status, Ngroups)) self:T(self.lid..string.format("Cancelled mission was in %s stage with %d groups assigned and alive. Call it done!", self.status, Ngroups))

View File

@ -16,7 +16,6 @@
-- @field #string ClassName Name of the class. -- @field #string ClassName Name of the class.
-- @field #number verbose Verbosity level. -- @field #number verbose Verbosity level.
-- @field #string lid Class id string for output to DCS log file. -- @field #string lid Class id string for output to DCS log file.
-- @field #table missionqueue Mission queue.
-- @field #table targetqueue Target queue. -- @field #table targetqueue Target queue.
-- @field Core.Set#SET_ZONE borderzoneset Set of zones defining the border of our territory. -- @field Core.Set#SET_ZONE borderzoneset Set of zones defining the border of our territory.
-- @field Core.Set#SET_ZONE yellowzoneset Set of zones defining the extended border. Defcon is set to YELLOW if enemy activity is detected. -- @field Core.Set#SET_ZONE yellowzoneset Set of zones defining the extended border. Defcon is set to YELLOW if enemy activity is detected.
@ -42,7 +41,6 @@ CHIEF = {
verbose = 0, verbose = 0,
lid = nil, lid = nil,
targetqueue = {}, targetqueue = {},
missionqueue = {},
borderzoneset = nil, borderzoneset = nil,
yellowzoneset = nil, yellowzoneset = nil,
engagezoneset = nil, engagezoneset = nil,
@ -80,6 +78,7 @@ CHIEF.version="0.0.1"
-- TODO list -- TODO list
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO: Create a good mission, which can be passed on to the COMMANDER.
-- TODO: Capture OPSZONEs. -- TODO: Capture OPSZONEs.
-- TODO: Get list of own assets and capabilities. -- TODO: Get list of own assets and capabilities.
-- TODO: Get list/overview of enemy assets etc. -- TODO: Get list/overview of enemy assets etc.
@ -112,6 +111,9 @@ function CHIEF:New(AgentSet, Coalition)
self:SetThreatLevelRange() self:SetThreatLevelRange()
-- Create a new COMMANDER.
self.commander=COMMANDER:New()
self.Defcon=CHIEF.DEFCON.GREEN self.Defcon=CHIEF.DEFCON.GREEN
-- Add FSM transitions. -- Add FSM transitions.
@ -258,20 +260,14 @@ function CHIEF:SetDefcon(Defcon)
end end
--- Set the wing commander for the airforce. --- Get the commander.
-- @param #CHIEF self -- @param #CHIEF self
-- @param Ops.WingCommander#WINGCOMMANDER WingCommander The WINGCOMMANDER object. -- @return Ops.Commander#COMMANDER The commander.
-- @return #CHIEF self function CHIEF:GetCommander()
function CHIEF:SetWingCommander(WingCommander) return self.commander
self.commander=WingCommander
self.commander.chief=self
return self
end end
--- Add mission to mission queue. --- Add mission to mission queue of the COMMANDER.
-- @param #CHIEF self -- @param #CHIEF self
-- @param Ops.Auftrag#AUFTRAG Mission Mission to be added. -- @param Ops.Auftrag#AUFTRAG Mission Mission to be added.
-- @return #CHIEF self -- @return #CHIEF self
@ -279,9 +275,7 @@ function CHIEF:AddMission(Mission)
Mission.chief=self Mission.chief=self
Mission.statusChief=AUFTRAG.Status.QUEUED self.commander:AddMission(Mission)
table.insert(self.missionqueue, Mission)
return self return self
end end
@ -292,17 +286,9 @@ end
-- @return #CHIEF self -- @return #CHIEF self
function CHIEF:RemoveMission(Mission) function CHIEF:RemoveMission(Mission)
for i,_mission in pairs(self.missionqueue) do
local mission=_mission --Ops.Auftrag#AUFTRAG
if mission.auftragsnummer==Mission.auftragsnummer then
self:I(self.lid..string.format("Removing mission %s (%s) status=%s from queue", Mission.name, Mission.type, Mission.status))
Mission.chief=nil Mission.chief=nil
table.remove(self.missionqueue, i)
break
end
end self.commander:RemoveMission(Mission)
return self return self
end end
@ -412,6 +398,9 @@ function CHIEF:onafterStatus(From, Event, To)
-- FSM state. -- FSM state.
local fsmstate=self:GetState() local fsmstate=self:GetState()
---
-- CONTACTS: Mission Cleanup
---
-- Clean up missions where the contact was lost. -- Clean up missions where the contact was lost.
for _,_contact in pairs(self.ContactsLost) do for _,_contact in pairs(self.ContactsLost) do
@ -427,10 +416,16 @@ function CHIEF:onafterStatus(From, Event, To)
-- Cancel this mission. -- Cancel this mission.
contact.mission:Cancel() contact.mission:Cancel()
-- TODO: contact.target
end end
end end
---
-- CONTACTS: Create new TARGETS
---
-- Create TARGETs for all new contacts. -- Create TARGETs for all new contacts.
local Nred=0 ; local Nyellow=0 ; local Nengage=0 local Nred=0 ; local Nyellow=0 ; local Nengage=0
for _,_contact in pairs(self.Contacts) do for _,_contact in pairs(self.Contacts) do
@ -485,57 +480,28 @@ function CHIEF:onafterStatus(From, Event, To)
-- Check target queue and assign missions to new targets. -- Check target queue and assign missions to new targets.
self:CheckTargetQueue() self:CheckTargetQueue()
---
-- Check Mission Queue
---
-- Check mission queue and assign one PLANNED mission.
self:CheckMissionQueue()
--- ---
-- Info General -- Info General
--- ---
if self.verbose>=1 then
local Nassets=self.commander:CountAssets() local Nassets=self.commander:CountAssets()
local Ncontacts=#self.contacts local Ncontacts=#self.contacts
local Nmissions=#self.missionqueue local Nmissions=#self.commander.missionqueue
local Ntargets=#self.targetqueue local Ntargets=#self.targetqueue
-- Info message -- Info message
local text=string.format("Defcon=%s Assets=%d, Contacts: Total=%d Yellow=%d Red=%d, Targets=%d, Missions=%d", self.Defcon, Nassets, Ncontacts, Nyellow, Nred, Ntargets, Nmissions) local text=string.format("Defcon=%s Assets=%d, Contacts: Total=%d Yellow=%d Red=%d, Targets=%d, Missions=%d", self.Defcon, Nassets, Ncontacts, Nyellow, Nred, Ntargets, Nmissions)
self:I(self.lid..text) self:I(self.lid..text)
---
-- Info Assets
---
local text="Assets:"
for _,missiontype in pairs(AUFTRAG.Type) do
local N=self.commander:CountAssets(nil, missiontype)
if N>0 then
text=text..string.format("\n- %s %d", missiontype, N)
end end
end
self:I(self.lid..text)
local text="Assets:"
for _,attribute in pairs(WAREHOUSE.Attribute) do
local N=self.commander:CountAssets(nil, nil, attribute)
if N>0 or self.verbose>=10 then
text=text..string.format("\n- %s %d", attribute, N)
end
end
self:I(self.lid..text)
--- ---
-- Info Contacts -- Info Contacts
--- ---
-- Info about contacts. -- Info about contacts.
if #self.Contacts>0 then if self.verbose>=2 and #self.Contacts>0 then
local text="Contacts:" local text="Contacts:"
for i,_contact in pairs(self.Contacts) do for i,_contact in pairs(self.Contacts) do
local contact=_contact --Ops.Intelligence#INTEL.Contact local contact=_contact --Ops.Intelligence#INTEL.Contact
@ -552,7 +518,7 @@ function CHIEF:onafterStatus(From, Event, To)
-- Info Targets -- Info Targets
--- ---
if #self.targetqueue>0 then if self.verbose>=3 and #self.targetqueue>0 then
local text="Targets:" local text="Targets:"
for i,_target in pairs(self.targetqueue) do for i,_target in pairs(self.targetqueue) do
local target=_target --Ops.Target#TARGET local target=_target --Ops.Target#TARGET
@ -569,7 +535,7 @@ function CHIEF:onafterStatus(From, Event, To)
--- ---
-- Mission queue. -- Mission queue.
if #self.missionqueue>0 then if self.verbose>=4 and #self.commander.missionqueue>0 then
local text="Mission queue:" local text="Mission queue:"
for i,_mission in pairs(self.missionqueue) do for i,_mission in pairs(self.missionqueue) do
local mission=_mission --Ops.Auftrag#AUFTRAG local mission=_mission --Ops.Auftrag#AUFTRAG
@ -581,6 +547,30 @@ function CHIEF:onafterStatus(From, Event, To)
self:I(self.lid..text) self:I(self.lid..text)
end end
---
-- Info Assets
---
if self.verbose>=5 then
local text="Assets:"
for _,missiontype in pairs(AUFTRAG.Type) do
local N=self.commander:CountAssets(nil, missiontype)
if N>0 then
text=text..string.format("\n- %s %d", missiontype, N)
end
end
self:I(self.lid..text)
local text="Assets:"
for _,attribute in pairs(WAREHOUSE.Attribute) do
local N=self.commander:CountAssets(nil, nil, attribute)
if N>0 or self.verbose>=10 then
text=text..string.format("\n- %s %d", attribute, N)
end
end
self:I(self.lid..text)
end
end end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@ -615,21 +605,16 @@ function CHIEF:onafterMissionCancel(From, Event, To, Mission)
-- Debug info. -- Debug info.
self:I(self.lid..string.format("Cancelling mission %s (%s) in status %s", Mission.name, Mission.type, Mission.status)) self:I(self.lid..string.format("Cancelling mission %s (%s) in status %s", Mission.name, Mission.type, Mission.status))
if Mission.status==AUFTRAG.Status.PLANNED then if Mission:IsPlanned() then
-- Mission is still in planning stage. Should not have an airbase assigned ==> Just remove it form the queue. -- Mission is still in planning stage. Should not have any LEGIONS assigned ==> Just remove it form the COMMANDER queue.
self:RemoveMission(Mission) self:RemoveMission(Mission)
-- Remove Mission from WC queue.
if Mission.wingcommander then
Mission.wingcommander:RemoveMission(Mission)
end
else else
-- Wingcommander will cancel mission. -- COMMANDER will cancel mission.
if Mission.wingcommander then if Mission.commander then
Mission.wingcommander:MissionCancel(Mission) Mission.commander:MissionCancel(Mission)
end end
end end
@ -658,7 +643,7 @@ function CHIEF:onbeforeDefcon(From, Event, To, Defcon)
-- Defcon did not change. -- Defcon did not change.
if Defcon==self.Defcon then if Defcon==self.Defcon then
self:I(self.lid..string.format("Defcon %s unchanged. No processing transition.", tostring(Defcon))) self:I(self.lid..string.format("Defcon %s unchanged. Not processing transition!", tostring(Defcon)))
return false return false
end end
@ -736,7 +721,9 @@ function CHIEF:CheckTargetQueue()
-- Valid target? -- Valid target?
if valid then if valid then
-- Create mission --TODO: Create a good mission, which can be passed on to the COMMANDER.
-- Create mission.
local mission=AUFTRAG:NewTargetAir(target) local mission=AUFTRAG:NewTargetAir(target)
if mission then if mission then
@ -748,7 +735,7 @@ function CHIEF:CheckTargetQueue()
mission.prio=target.prio mission.prio=target.prio
mission.importance=target.importance mission.importance=target.importance
-- Add mission to queue. -- Add mission to COMMANDER queue.
self:AddMission(mission) self:AddMission(mission)
end end
@ -763,62 +750,6 @@ end
-- Resources -- Resources
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Check mission queue and assign ONE planned mission.
-- @param #CHIEF self
function CHIEF:CheckMissionQueue()
-- TODO: Sort mission queue. wrt what? Threat level?
for _,_mission in pairs(self.missionqueue) do
local mission=_mission --Ops.Auftrag#AUFTRAG
-- We look for PLANNED missions.
if mission:IsPlanned() then
---
-- PLANNNED Mission
---
-- Check if there is an airwing that can do the mission.
local legions=self.commander:GetLegionsForMission(mission)
if airwing then
-- Add mission to airwing.
self:AssignMissionAirforce(mission)
return
else
self:T(self.lid.."NO airwing")
end
else
---
-- Missions NOT in PLANNED state
---
end
end
end
--- Check all airwings if they are able to do a specific mission type at a certain location with a given number of assets.
-- @param #CHIEF self
-- @param Ops.Auftrag#AUFTRAG Mission The mission.
-- @return #table The best LEGIONs for this mission or `nil`.
function CHIEF:GetAirwingForMission(Mission)
if self.commander then
local legions=self.commander:GetLegionsForMission(Mission)
return legions
end
return nil
end
--- Check if group is inside our border. --- Check if group is inside our border.
-- @param #CHIEF self -- @param #CHIEF self
-- @param Wrapper.Group#GROUP group The group. -- @param Wrapper.Group#GROUP group The group.
@ -878,11 +809,17 @@ function CHIEF:CheckTargetInZones(target, zoneset)
return false return false
end end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Resources
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Check resources. --- Check resources.
-- @param #CHIEF self -- @param #CHIEF self
-- @return #table -- @return #table
function CHIEF:CheckResources() function CHIEF:CheckResources()
-- TODO: look at lower classes to do this! it's all there...
local capabilities={} local capabilities={}
for _,MissionType in pairs(AUFTRAG.Type) do for _,MissionType in pairs(AUFTRAG.Type) do

View File

@ -34,6 +34,7 @@
-- @field #COMMANDER -- @field #COMMANDER
COMMANDER = { COMMANDER = {
ClassName = "COMMANDER", ClassName = "COMMANDER",
verbose = 0,
legions = {}, legions = {},
missionqueue = {}, missionqueue = {},
} }
@ -76,8 +77,8 @@ function COMMANDER:New()
self:AddTransition("*", "Status", "*") -- Status report. self:AddTransition("*", "Status", "*") -- Status report.
self:AddTransition("*", "Stop", "Stopped") -- Stop COMMANDER. self:AddTransition("*", "Stop", "Stopped") -- Stop COMMANDER.
self:AddTransition("*", "MissionAssign", "*") -- Mission was assigned to a LEGION. self:AddTransition("*", "MissionAssign", "*") -- Mission is assigned to a or multiple LEGIONs.
self:AddTransition("*", "MissionCancel", "*") -- Cancel mission. self:AddTransition("*", "MissionCancel", "*") -- COMMANDER cancels a mission.
------------------------ ------------------------
--- Pseudo Functions --- --- Pseudo Functions ---
@ -92,6 +93,7 @@ function COMMANDER:New()
-- @param #COMMANDER self -- @param #COMMANDER self
-- @param #number delay Delay in seconds. -- @param #number delay Delay in seconds.
--- Triggers the FSM event "Stop". Stops the COMMANDER. --- Triggers the FSM event "Stop". Stops the COMMANDER.
-- @param #COMMANDER self -- @param #COMMANDER self
@ -100,6 +102,7 @@ function COMMANDER:New()
-- @param #COMMANDER self -- @param #COMMANDER self
-- @param #number delay Delay in seconds. -- @param #number delay Delay in seconds.
--- Triggers the FSM event "Status". --- Triggers the FSM event "Status".
-- @function [parent=#COMMANDER] Status -- @function [parent=#COMMANDER] Status
-- @param #COMMANDER self -- @param #COMMANDER self
@ -116,6 +119,13 @@ function COMMANDER:New()
-- @param Ops.Legion#LEGION Legion The Legion. -- @param Ops.Legion#LEGION Legion The Legion.
-- @param Ops.Auftrag#AUFTRAG Mission The mission. -- @param Ops.Auftrag#AUFTRAG Mission The mission.
--- Triggers the FSM event "MissionAssign" after a delay.
-- @function [parent=#COMMANDER] __MissionAssign
-- @param #COMMANDER self
-- @param #number delay Delay in seconds.
-- @param Ops.Legion#LEGION Legion The Legion.
-- @param Ops.Auftrag#AUFTRAG Mission The mission.
--- On after "MissionAssign" event. --- On after "MissionAssign" event.
-- @function [parent=#COMMANDER] OnAfterMissionAssign -- @function [parent=#COMMANDER] OnAfterMissionAssign
-- @param #COMMANDER self -- @param #COMMANDER self
@ -131,6 +141,12 @@ function COMMANDER:New()
-- @param #COMMANDER self -- @param #COMMANDER self
-- @param Ops.Auftrag#AUFTRAG Mission The mission. -- @param Ops.Auftrag#AUFTRAG Mission The mission.
--- Triggers the FSM event "MissionCancel" after a delay.
-- @function [parent=#COMMANDER] __MissionCancel
-- @param #COMMANDER self
-- @param #number delay Delay in seconds.
-- @param Ops.Auftrag#AUFTRAG Mission The mission.
--- On after "MissionCancel" event. --- On after "MissionCancel" event.
-- @function [parent=#COMMANDER] OnAfterMissionCancel -- @function [parent=#COMMANDER] OnAfterMissionCancel
-- @param #COMMANDER self -- @param #COMMANDER self
@ -146,6 +162,15 @@ end
-- User functions -- User functions
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Set verbosity level.
-- @param #COMMANDER self
-- @param #number VerbosityLevel Level of output (higher=more). Default 0.
-- @return #COMMANDER self
function COMMANDER:SetVerbosity(VerbosityLevel)
self.verbose=VerbosityLevel or 0
return self
end
--- Add an AIRWING to the commander. --- Add an AIRWING to the commander.
-- @param #COMMANDER self -- @param #COMMANDER self
-- @param Ops.AirWing#AIRWING Airwing The airwing to add. -- @param Ops.AirWing#AIRWING Airwing The airwing to add.
@ -248,8 +273,10 @@ function COMMANDER:onafterStatus(From, Event, To)
local fsmstate=self:GetState() local fsmstate=self:GetState()
-- Status. -- Status.
if self.verbose>=1 then
local text=string.format("Status %s: Legions=%d, Missions=%d", fsmstate, #self.legions, #self.missionqueue) local text=string.format("Status %s: Legions=%d, Missions=%d", fsmstate, #self.legions, #self.missionqueue)
self:I(self.lid..text) self:I(self.lid..text)
end
-- Check mission queue and assign one PLANNED mission. -- Check mission queue and assign one PLANNED mission.
self:CheckMissionQueue() self:CheckMissionQueue()
@ -258,7 +285,7 @@ function COMMANDER:onafterStatus(From, Event, To)
-- LEGIONS -- LEGIONS
--- ---
if #self.legions>0 then if self.verbose>=2 and #self.legions>0 then
local text="Legions:" local text="Legions:"
for _,_legion in pairs(self.legions) do for _,_legion in pairs(self.legions) do
@ -278,15 +305,16 @@ function COMMANDER:onafterStatus(From, Event, To)
self:I(self.lid..text) self:I(self.lid..text)
local assets={} if self.verbose>=3 then
-- Count numbers
local Ntotal=0 local Ntotal=0
local Nspawned=0 local Nspawned=0
local Nrequested=0 local Nrequested=0
local Nreserved=0 local Nreserved=0
local Nstock=0 local Nstock=0
local text="===========================================\n" local text="\n===========================================\n"
text=text.."Assets:" text=text.."Assets:"
for _,_legion in pairs(self.legions) do for _,_legion in pairs(self.legions) do
local legion=_legion --Ops.Legion#LEGION local legion=_legion --Ops.Legion#LEGION
@ -297,23 +325,19 @@ function COMMANDER:onafterStatus(From, Event, To)
for _,_asset in pairs(cohort.assets) do for _,_asset in pairs(cohort.assets) do
local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem
table.insert(assets, asset) -- Text.
text=text..string.format("\n- %s [UID=%d] Legion=%s, Cohort=%s: Spawned=%s, Requested=%s [RID=%s], Reserved=%s", text=text..string.format("\n- %s [UID=%d] Legion=%s, Cohort=%s: Spawned=%s, Requested=%s [RID=%s], Reserved=%s",
asset.spawngroupname, asset.uid, legion.alias, cohort.name, tostring(asset.spawned), tostring(asset.requested), tostring(asset.rid), tostring(asset.isReserved)) asset.spawngroupname, asset.uid, legion.alias, cohort.name, tostring(asset.spawned), tostring(asset.requested), tostring(asset.rid), tostring(asset.isReserved))
if asset.spawned then if asset.spawned then
Nspawned=Nspawned+1 Nspawned=Nspawned+1
end end
if asset.requested then if asset.requested then
Nrequested=Nrequested+1 Nrequested=Nrequested+1
end end
if asset.isReserved then if asset.isReserved then
Nreserved=Nreserved+1 Nreserved=Nreserved+1
end end
if not (asset.spawned or asset.requested or asset.isReserved) then if not (asset.spawned or asset.requested or asset.isReserved) then
Nstock=Nstock+1 Nstock=Nstock+1
end end
@ -333,6 +357,7 @@ function COMMANDER:onafterStatus(From, Event, To)
text=text..string.format("\nNtotal = %d (=%d)", Ntotal, Nstock+Nspawned+Nrequested+Nreserved) text=text..string.format("\nNtotal = %d (=%d)", Ntotal, Nstock+Nspawned+Nrequested+Nreserved)
text=text.."\n===========================================" text=text.."\n==========================================="
self:I(self.lid..text) self:I(self.lid..text)
end
end end
@ -341,18 +366,14 @@ function COMMANDER:onafterStatus(From, Event, To)
--- ---
-- Mission queue. -- Mission queue.
if #self.missionqueue>0 then if self.verbose>=2 and #self.missionqueue>0 then
local text="Mission queue:" local text="Mission queue:"
for i,_mission in pairs(self.missionqueue) do for i,_mission in pairs(self.missionqueue) do
local mission=_mission --Ops.Auftrag#AUFTRAG local mission=_mission --Ops.Auftrag#AUFTRAG
local target=mission:GetTargetName() or "unknown" local target=mission:GetTargetName() or "unknown"
text=text..string.format("\n[%d] %s (%s): status=%s, target=%s", i, mission.name, mission.type, mission.status, target) text=text..string.format("\n[%d] %s (%s): status=%s, target=%s", i, mission.name, mission.type, mission.status, target)
end end
self:I(self.lid..text) self:I(self.lid..text)
end end
self:__Status(-30) self:__Status(-30)

View File

@ -844,8 +844,6 @@ function FLIGHTGROUP:Status()
-- FSM state. -- FSM state.
local fsmstate=self:GetState() local fsmstate=self:GetState()
env.info(self.lid.."FF status="..fsmstate)
-- Update position. -- Update position.
self:_UpdatePosition() self:_UpdatePosition()
@ -899,10 +897,13 @@ function FLIGHTGROUP:Status()
local dest=self.destbase and self.destbase:GetName() or "unknown" local dest=self.destbase and self.destbase:GetName() or "unknown"
local fc=self.flightcontrol and self.flightcontrol.airbasename or "N/A" local fc=self.flightcontrol and self.flightcontrol.airbasename or "N/A"
local curr=self.currbase and self.currbase:GetName() or "N/A" local curr=self.currbase and self.currbase:GetName() or "N/A"
local nelem=self:CountElements()
local Nelem=#self.elements
local ndetected=self.detectionOn and tostring(self.detectedunits:Count()) or "OFF"
local text=string.format("Status %s [%d/%d]: Tasks=%d, Missions=%s, Waypoint=%d/%d [%s], Detected=%d, Home=%s, Destination=%s, Current=%s, FC=%s", local text=string.format("Status %s [%d/%d]: Tasks=%d, Missions=%s, Waypoint=%d/%d [%s], Detected=%s, Home=%s, Destination=%s, Current=%s, FC=%s",
fsmstate, #self.elements, #self.elements, nTaskTot, nMissions, self.currentwp or 0, self.waypoints and #self.waypoints or 0, tostring(self.passedfinalwp), fsmstate, nelem, Nelem, nTaskTot, nMissions, self.currentwp or 0, self.waypoints and #self.waypoints or 0, tostring(self.passedfinalwp),
self.detectedunits:Count(), home, dest, curr, fc) ndetected, home, dest, curr, fc)
self:I(self.lid..text) self:I(self.lid..text)
end end

View File

@ -785,10 +785,12 @@ function LEGION:onafterMissionCancel(From, Event, To, Mission)
opsgroup:MissionCancel(Mission) opsgroup:MissionCancel(Mission)
end end
-- TODO: remove asset from mission -- Remove asset from mission.
Mission:DelAsset(asset)
-- Not requested any more (if it was). -- Not requested any more (if it was).
asset.requested=nil asset.requested=nil
asset.isReserved=nil
end end
end end