mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
OPS Chief
- Removed mission queue. Now done via COMMANDER - MissionCancel is buggy
This commit is contained in:
parent
1b0ad13529
commit
a8a8dcff3f
@ -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
|
|
||||||
|
|
||||||
if self.commander then
|
elseif 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
|
|
||||||
|
|
||||||
if #self.legions>0 then
|
elseif self.legions then
|
||||||
|
|
||||||
for _,_legion in pairs(self.legions) do
|
-- Loop over all LEGIONs.
|
||||||
|
for _,_legion in pairs(self.legions or {}) 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,14 +3006,17 @@ 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.
|
||||||
|
|||||||
@ -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,10 +275,8 @@ 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
|
Mission.chief=nil
|
||||||
local mission=_mission --Ops.Auftrag#AUFTRAG
|
|
||||||
|
self.commander:RemoveMission(Mission)
|
||||||
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
|
|
||||||
table.remove(self.missionqueue, i)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
@ -412,7 +398,10 @@ 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
|
||||||
local contact=_contact --Ops.Intelligence#INTEL.Contact
|
local contact=_contact --Ops.Intelligence#INTEL.Contact
|
||||||
@ -426,10 +415,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
|
||||||
@ -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
|
||||||
---
|
---
|
||||||
|
|
||||||
local Nassets=self.commander:CountAssets()
|
if self.verbose>=1 then
|
||||||
local Ncontacts=#self.contacts
|
local Nassets=self.commander:CountAssets()
|
||||||
local Nmissions=#self.missionqueue
|
local Ncontacts=#self.contacts
|
||||||
local Ntargets=#self.targetqueue
|
local Nmissions=#self.commander.missionqueue
|
||||||
|
local Ntargets=#self.targetqueue
|
||||||
-- 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)
|
-- Info message
|
||||||
self:I(self.lid..text)
|
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)
|
||||||
---
|
|
||||||
-- 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
|
||||||
|
|
||||||
@ -735,8 +720,10 @@ function CHIEF:CheckTargetQueue()
|
|||||||
|
|
||||||
-- Valid target?
|
-- Valid target?
|
||||||
if valid then
|
if valid then
|
||||||
|
|
||||||
|
--TODO: Create a good mission, which can be passed on to the COMMANDER.
|
||||||
|
|
||||||
-- Create mission
|
-- 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
|
||||||
|
|||||||
@ -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.
|
||||||
local text=string.format("Status %s: Legions=%d, Missions=%d", fsmstate, #self.legions, #self.missionqueue)
|
if self.verbose>=1 then
|
||||||
self:I(self.lid..text)
|
local text=string.format("Status %s: Legions=%d, Missions=%d", fsmstate, #self.legions, #self.missionqueue)
|
||||||
|
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,61 +305,59 @@ function COMMANDER:onafterStatus(From, Event, To)
|
|||||||
self:I(self.lid..text)
|
self:I(self.lid..text)
|
||||||
|
|
||||||
|
|
||||||
local assets={}
|
if self.verbose>=3 then
|
||||||
|
|
||||||
local Ntotal=0
|
-- Count numbers
|
||||||
local Nspawned=0
|
local Ntotal=0
|
||||||
local Nrequested=0
|
local Nspawned=0
|
||||||
local Nreserved=0
|
local Nrequested=0
|
||||||
local Nstock=0
|
local Nreserved=0
|
||||||
|
local Nstock=0
|
||||||
local text="===========================================\n"
|
|
||||||
text=text.."Assets:"
|
local text="\n===========================================\n"
|
||||||
for _,_legion in pairs(self.legions) do
|
text=text.."Assets:"
|
||||||
local legion=_legion --Ops.Legion#LEGION
|
for _,_legion in pairs(self.legions) do
|
||||||
|
local legion=_legion --Ops.Legion#LEGION
|
||||||
for _,_cohort in pairs(legion.cohorts) do
|
|
||||||
local cohort=_cohort --Ops.Cohort#COHORT
|
for _,_cohort in pairs(legion.cohorts) do
|
||||||
|
local cohort=_cohort --Ops.Cohort#COHORT
|
||||||
for _,_asset in pairs(cohort.assets) do
|
|
||||||
local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem
|
|
||||||
|
|
||||||
table.insert(assets, asset)
|
for _,_asset in pairs(cohort.assets) do
|
||||||
|
local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem
|
||||||
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))
|
-- Text.
|
||||||
|
text=text..string.format("\n- %s [UID=%d] Legion=%s, Cohort=%s: Spawned=%s, Requested=%s [RID=%s], Reserved=%s",
|
||||||
if asset.spawned then
|
asset.spawngroupname, asset.uid, legion.alias, cohort.name, tostring(asset.spawned), tostring(asset.requested), tostring(asset.rid), tostring(asset.isReserved))
|
||||||
Nspawned=Nspawned+1
|
|
||||||
|
if asset.spawned then
|
||||||
|
Nspawned=Nspawned+1
|
||||||
|
end
|
||||||
|
if asset.requested then
|
||||||
|
Nrequested=Nrequested+1
|
||||||
|
end
|
||||||
|
if asset.isReserved then
|
||||||
|
Nreserved=Nreserved+1
|
||||||
|
end
|
||||||
|
if not (asset.spawned or asset.requested or asset.isReserved) then
|
||||||
|
Nstock=Nstock+1
|
||||||
|
end
|
||||||
|
|
||||||
|
Ntotal=Ntotal+1
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if asset.requested then
|
|
||||||
Nrequested=Nrequested+1
|
|
||||||
end
|
|
||||||
|
|
||||||
if asset.isReserved then
|
|
||||||
Nreserved=Nreserved+1
|
|
||||||
end
|
|
||||||
|
|
||||||
if not (asset.spawned or asset.requested or asset.isReserved) then
|
|
||||||
Nstock=Nstock+1
|
|
||||||
end
|
|
||||||
|
|
||||||
Ntotal=Ntotal+1
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
text=text.."\n-------------------------------------------"
|
||||||
|
text=text..string.format("\nNstock = %d", Nstock)
|
||||||
|
text=text..string.format("\nNreserved = %d", Nreserved)
|
||||||
|
text=text..string.format("\nNrequested = %d", Nrequested)
|
||||||
|
text=text..string.format("\nNspawned = %d", Nspawned)
|
||||||
|
text=text..string.format("\nNtotal = %d (=%d)", Ntotal, Nstock+Nspawned+Nrequested+Nreserved)
|
||||||
|
text=text.."\n==========================================="
|
||||||
|
self:I(self.lid..text)
|
||||||
end
|
end
|
||||||
text=text.."\n-------------------------------------------"
|
|
||||||
text=text..string.format("\nNstock = %d", Nstock)
|
|
||||||
text=text..string.format("\nNreserved = %d", Nreserved)
|
|
||||||
text=text..string.format("\nNrequested = %d", Nrequested)
|
|
||||||
text=text..string.format("\nNspawned = %d", Nspawned)
|
|
||||||
text=text..string.format("\nNtotal = %d (=%d)", Ntotal, Nstock+Nspawned+Nrequested+Nreserved)
|
|
||||||
text=text.."\n==========================================="
|
|
||||||
self:I(self.lid..text)
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -341,19 +366,15 @@ 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)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -843,8 +843,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
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user