mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
908 lines
27 KiB
Lua
908 lines
27 KiB
Lua
---- **Ops** - Chief of Staff.
|
|
--
|
|
-- **Main Features:**
|
|
--
|
|
-- * Stuff
|
|
--
|
|
-- ===
|
|
--
|
|
-- ### Author: **funkyfranky**
|
|
-- @module Ops.Chief
|
|
-- @image OPS_Chief.png
|
|
|
|
|
|
--- CHIEF class.
|
|
-- @type CHIEF
|
|
-- @field #string ClassName Name of the class.
|
|
-- @field #number verbose Verbosity level.
|
|
-- @field #string lid Class id string for output to DCS log file.
|
|
-- @field #table missionqueue Mission 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 yellowzoneset Set of zones defining the extended border. Defcon is set to YELLOW if enemy activity is detected.
|
|
-- @field Core.Set#SET_ZONE engagezoneset Set of zones where enemies are actively engaged.
|
|
-- @field #string Defcon Defence condition.
|
|
-- @field Ops.Commander#COMMANDER commander Commander of assigned legions.
|
|
-- @extends Ops.Intelligence#INTEL
|
|
|
|
--- Be surprised!
|
|
--
|
|
-- ===
|
|
--
|
|
-- # The CHIEF Concept
|
|
--
|
|
-- The Chief of staff gathers intel and assigns missions (AUFTRAG) the airforce (WINGCOMMANDER), army (GENERAL) or navy (ADMIRAL).
|
|
--
|
|
-- **Note** that currently only assignments to airborne forces (WINGCOMMANDER) are implemented.
|
|
--
|
|
--
|
|
-- @field #CHIEF
|
|
CHIEF = {
|
|
ClassName = "CHIEF",
|
|
verbose = 0,
|
|
lid = nil,
|
|
targetqueue = {},
|
|
missionqueue = {},
|
|
borderzoneset = nil,
|
|
yellowzoneset = nil,
|
|
engagezoneset = nil,
|
|
}
|
|
|
|
--- Defence condition.
|
|
-- @type CHIEF.DEFCON
|
|
-- @field #string GREEN No enemy activities detected.
|
|
-- @field #string YELLOW Enemy near our border.
|
|
-- @field #string RED Enemy within our border.
|
|
CHIEF.DEFCON = {
|
|
GREEN="Green",
|
|
YELLOW="Yellow",
|
|
RED="Red",
|
|
}
|
|
|
|
--- Strategy.
|
|
-- @type CHIEF.Strategy
|
|
-- @field #string DEFENSIVE Only target in our own terretory are engaged.
|
|
-- @field #string OFFENSIVE Targets in own terretory and yellow zones are engaged.
|
|
-- @field #string AGGRESSIVE Targets in own terretroy, yellow zones and engage zones are engaged.
|
|
-- @field #string TOTALWAR Anything is engaged anywhere.
|
|
CHIEF.Strategy = {
|
|
DEFENSIVE="Defensive",
|
|
OFFENSIVE="Offensive",
|
|
AGGRESSIVE="Aggressive",
|
|
TOTALWAR="Total War"
|
|
}
|
|
|
|
--- CHIEF class version.
|
|
-- @field #string version
|
|
CHIEF.version="0.0.1"
|
|
|
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
-- TODO list
|
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
-- TODO: Capture OPSZONEs.
|
|
-- TODO: Get list of own assets and capabilities.
|
|
-- TODO: Get list/overview of enemy assets etc.
|
|
-- TODO: Put all contacts into target list. Then make missions from them.
|
|
-- TODO: Set of interesting zones.
|
|
-- TODO: Define A2A and A2G parameters.
|
|
-- DONE: Add/remove spawned flightgroups to detection set.
|
|
-- DONE: Borderzones.
|
|
-- NOGO: Maybe it's possible to preselect the assets for the mission.
|
|
|
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
-- Constructor
|
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
--- Create a new CHIEF object and start the FSM.
|
|
-- @param #CHIEF self
|
|
-- @param Core.Set#SET_GROUP AgentSet Set of agents (groups) providing intel. Default is an empty set.
|
|
-- @param #number Coalition Coalition side, e.g. `coaliton.side.BLUE`. Can also be passed as a string "red", "blue" or "neutral".
|
|
-- @return #CHIEF self
|
|
function CHIEF:New(AgentSet, Coalition)
|
|
|
|
-- Inherit everything from INTEL class.
|
|
local self=BASE:Inherit(self, INTEL:New(AgentSet, Coalition)) --#CHIEF
|
|
|
|
-- Set some string id for output to DCS.log file.
|
|
--self.lid=string.format("CHIEF | ")
|
|
|
|
self:SetBorderZones()
|
|
self:SetYellowZones()
|
|
|
|
self:SetThreatLevelRange()
|
|
|
|
self.Defcon=CHIEF.DEFCON.GREEN
|
|
|
|
-- Add FSM transitions.
|
|
-- From State --> Event --> To State
|
|
self:AddTransition("*", "AssignMissionAirforce", "*") -- Assign mission to a WINGCOMMANDER.
|
|
self:AddTransition("*", "AssignMissionNavy", "*") -- Assign mission to an ADMIRAL.
|
|
self:AddTransition("*", "AssignMissionArmy", "*") -- Assign mission to a GENERAL.
|
|
|
|
self:AddTransition("*", "MissionCancel", "*") -- Cancel mission.
|
|
|
|
self:AddTransition("*", "Defcon", "*") -- Change defence condition.
|
|
|
|
self:AddTransition("*", "Stategy", "*") -- Change strategy condition.
|
|
|
|
self:AddTransition("*", "DeclareWar", "*") -- Declare War.
|
|
|
|
------------------------
|
|
--- Pseudo Functions ---
|
|
------------------------
|
|
|
|
--- Triggers the FSM event "Start".
|
|
-- @function [parent=#CHIEF] Start
|
|
-- @param #CHIEF self
|
|
|
|
--- Triggers the FSM event "Start" after a delay.
|
|
-- @function [parent=#CHIEF] __Start
|
|
-- @param #CHIEF self
|
|
-- @param #number delay Delay in seconds.
|
|
|
|
|
|
--- Triggers the FSM event "Stop".
|
|
-- @param #CHIEF self
|
|
|
|
--- Triggers the FSM event "Stop" after a delay.
|
|
-- @function [parent=#CHIEF] __Stop
|
|
-- @param #CHIEF self
|
|
-- @param #number delay Delay in seconds.
|
|
|
|
|
|
--- Triggers the FSM event "Status".
|
|
-- @function [parent=#CHIEF] Status
|
|
-- @param #CHIEF self
|
|
|
|
--- Triggers the FSM event "Status" after a delay.
|
|
-- @function [parent=#CHIEF] __Status
|
|
-- @param #CHIEF self
|
|
-- @param #number delay Delay in seconds.
|
|
|
|
|
|
--- Triggers the FSM event "MissionCancel".
|
|
-- @function [parent=#CHIEF] MissionCancel
|
|
-- @param #CHIEF self
|
|
-- @param Ops.Auftrag#AUFTRAG Mission The mission.
|
|
|
|
--- On after "MissionCancel" event.
|
|
-- @function [parent=#CHIEF] OnAfterMissionCancel
|
|
-- @param #CHIEF self
|
|
-- @param #string From From state.
|
|
-- @param #string Event Event.
|
|
-- @param #string To To state.
|
|
-- @param Ops.Auftrag#AUFTRAG Mission The mission.
|
|
|
|
return self
|
|
end
|
|
|
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
-- User functions
|
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
--- Set this to be an air-to-any dispatcher, i.e. engaging air, ground and naval targets. This is the default anyway.
|
|
-- @param #CHIEF self
|
|
-- @return #CHIEF self
|
|
function CHIEF:SetAirToAny()
|
|
|
|
self:SetFilterCategory({})
|
|
|
|
return self
|
|
end
|
|
|
|
--- Set this to be an air-to-air dispatcher.
|
|
-- @param #CHIEF self
|
|
-- @return #CHIEF self
|
|
function CHIEF:SetAirToAir()
|
|
|
|
self:SetFilterCategory({Unit.Category.AIRPLANE, Unit.Category.HELICOPTER})
|
|
|
|
return self
|
|
end
|
|
|
|
--- Set this to be an air-to-ground dispatcher, i.e. engage only ground units
|
|
-- @param #CHIEF self
|
|
-- @return #CHIEF self
|
|
function CHIEF:SetAirToGround()
|
|
|
|
self:SetFilterCategory({Unit.Category.GROUND_UNIT})
|
|
|
|
return self
|
|
end
|
|
|
|
--- Set this to be an air-to-sea dispatcher, i.e. engage only naval units.
|
|
-- @param #CHIEF self
|
|
-- @return #CHIEF self
|
|
function CHIEF:SetAirToSea()
|
|
|
|
self:SetFilterCategory({Unit.Category.SHIP})
|
|
|
|
return self
|
|
end
|
|
|
|
--- Set this to be an air-to-surface dispatcher, i.e. engaging ground and naval groups.
|
|
-- @param #CHIEF self
|
|
-- @return #CHIEF self
|
|
function CHIEF:SetAirToSurface()
|
|
|
|
self:SetFilterCategory({Unit.Category.GROUND_UNIT, Unit.Category.SHIP})
|
|
|
|
return self
|
|
end
|
|
|
|
--- Set a threat level range that will be engaged. Threat level is a number between 0 and 10, where 10 is a very dangerous threat.
|
|
-- Targets with threat level 0 are usually harmless.
|
|
-- @param #CHIEF self
|
|
-- @param #number ThreatLevelMin Min threat level. Default 1.
|
|
-- @param #number ThreatLevelMax Max threat level. Default 10.
|
|
-- @return #CHIEF self
|
|
function CHIEF:SetThreatLevelRange(ThreatLevelMin, ThreatLevelMax)
|
|
|
|
self.threatLevelMin=ThreatLevelMin or 1
|
|
self.threatLevelMax=ThreatLevelMax or 10
|
|
|
|
return self
|
|
end
|
|
|
|
--- Set defence condition.
|
|
-- @param #CHIEF self
|
|
-- @param #string Defcon Defence condition. See @{#CHIEF.DEFCON}, e.g. `CHIEF.DEFCON.RED`.
|
|
-- @return #CHIEF self
|
|
function CHIEF:SetDefcon(Defcon)
|
|
|
|
self.Defcon=Defcon
|
|
--self:Defcon(Defcon)
|
|
|
|
return self
|
|
end
|
|
|
|
|
|
--- Set the wing commander for the airforce.
|
|
-- @param #CHIEF self
|
|
-- @param Ops.WingCommander#WINGCOMMANDER WingCommander The WINGCOMMANDER object.
|
|
-- @return #CHIEF self
|
|
function CHIEF:SetWingCommander(WingCommander)
|
|
|
|
self.commander=WingCommander
|
|
|
|
self.commander.chief=self
|
|
|
|
return self
|
|
end
|
|
|
|
--- Add mission to mission queue.
|
|
-- @param #CHIEF self
|
|
-- @param Ops.Auftrag#AUFTRAG Mission Mission to be added.
|
|
-- @return #CHIEF self
|
|
function CHIEF:AddMission(Mission)
|
|
|
|
Mission.chief=self
|
|
|
|
Mission.statusChief=AUFTRAG.Status.QUEUED
|
|
|
|
table.insert(self.missionqueue, Mission)
|
|
|
|
return self
|
|
end
|
|
|
|
--- Remove mission from queue.
|
|
-- @param #CHIEF self
|
|
-- @param Ops.Auftrag#AUFTRAG Mission Mission to be removed.
|
|
-- @return #CHIEF self
|
|
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
|
|
table.remove(self.missionqueue, i)
|
|
break
|
|
end
|
|
|
|
end
|
|
|
|
return self
|
|
end
|
|
|
|
--- Add target.
|
|
-- @param #CHIEF self
|
|
-- @param Ops.Target#TARGET Target Target object to be added.
|
|
-- @return #CHIEF self
|
|
function CHIEF:AddTarget(Target)
|
|
|
|
Target:SetPriority()
|
|
Target:SetImportance()
|
|
|
|
table.insert(self.targetqueue, Target)
|
|
|
|
return self
|
|
end
|
|
|
|
|
|
--- Set border zone set.
|
|
-- @param #CHIEF self
|
|
-- @param Core.Set#SET_ZONE BorderZoneSet Set of zones, defining our borders.
|
|
-- @return #CHIEF self
|
|
function CHIEF:SetBorderZones(BorderZoneSet)
|
|
|
|
-- Border zones.
|
|
self.borderzoneset=BorderZoneSet or SET_ZONE:New()
|
|
|
|
return self
|
|
end
|
|
|
|
--- Add a zone defining your territory.
|
|
-- @param #CHIEF self
|
|
-- @param Core.Zone#ZONE BorderZone The zone defining the border of your territory.
|
|
-- @return #CHIEF self
|
|
function CHIEF:AddBorderZone(BorderZone)
|
|
|
|
-- Add a border zone.
|
|
self.borderzoneset:AddZone(BorderZone)
|
|
|
|
return self
|
|
end
|
|
|
|
--- Set yellow zone set. Detected enemy troops in this zone will trigger defence condition YELLOW.
|
|
-- @param #CHIEF self
|
|
-- @param Core.Set#SET_ZONE YellowZoneSet Set of zones, defining our borders.
|
|
-- @return #CHIEF self
|
|
function CHIEF:SetYellowZones(YellowZoneSet)
|
|
|
|
-- Border zones.
|
|
self.yellowzoneset=YellowZoneSet or SET_ZONE:New()
|
|
|
|
return self
|
|
end
|
|
|
|
--- Add a zone defining an area outside your territory that is monitored for enemy activity.
|
|
-- @param #CHIEF self
|
|
-- @param Core.Zone#ZONE YellowZone The zone defining the border of your territory.
|
|
-- @return #CHIEF self
|
|
function CHIEF:AddYellowZone(YellowZone)
|
|
|
|
-- Add a border zone.
|
|
self.yellowzoneset:AddZone(YellowZone)
|
|
|
|
return self
|
|
end
|
|
|
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
-- Start & Status
|
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
--- On after Start event.
|
|
-- @param #CHIEF self
|
|
-- @param Wrapper.Group#GROUP Group Flight group.
|
|
-- @param #string From From state.
|
|
-- @param #string Event Event.
|
|
-- @param #string To To state.
|
|
function CHIEF:onafterStart(From, Event, To)
|
|
|
|
-- Short info.
|
|
local text=string.format("Starting Chief of Staff")
|
|
self:I(self.lid..text)
|
|
|
|
-- Start parent INTEL.
|
|
self:GetParent(self).onafterStart(self, From, Event, To)
|
|
|
|
-- Start commander.
|
|
if self.commander then
|
|
if self.commander:GetState()=="NotReadyYet" then
|
|
self.commander:Start()
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
--- On after "Status" event.
|
|
-- @param #CHIEF self
|
|
-- @param Wrapper.Group#GROUP Group Flight group.
|
|
-- @param #string From From state.
|
|
-- @param #string Event Event.
|
|
-- @param #string To To state.
|
|
function CHIEF:onafterStatus(From, Event, To)
|
|
|
|
-- Start parent INTEL.
|
|
self:GetParent(self).onafterStatus(self, From, Event, To)
|
|
|
|
-- FSM state.
|
|
local fsmstate=self:GetState()
|
|
|
|
|
|
-- Clean up missions where the contact was lost.
|
|
for _,_contact in pairs(self.ContactsLost) do
|
|
local contact=_contact --Ops.Intelligence#INTEL.Contact
|
|
|
|
if contact.mission and contact.mission:IsNotOver() then
|
|
|
|
-- Debug info.
|
|
local text=string.format("Lost contact to target %s! %s mission %s will be cancelled.", contact.groupname, contact.mission.type:upper(), contact.mission.name)
|
|
MESSAGE:New(text, 120, "CHIEF"):ToAll()
|
|
self:I(self.lid..text)
|
|
|
|
-- Cancel this mission.
|
|
contact.mission:Cancel()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- Create TARGETs for all new contacts.
|
|
local Nred=0 ; local Nyellow=0 ; local Nengage=0
|
|
for _,_contact in pairs(self.Contacts) do
|
|
local contact=_contact --Ops.Intelligence#INTEL.Contact
|
|
local group=contact.group --Wrapper.Group#GROUP
|
|
|
|
local inred=self:CheckGroupInBorder(group)
|
|
if inred then
|
|
Nred=Nred+1
|
|
end
|
|
|
|
local inyellow=self:CheckGroupInYellow(group)
|
|
if inyellow then
|
|
Nyellow=Nyellow+1
|
|
end
|
|
|
|
-- Is this a threat?
|
|
local threat=contact.threatlevel>=self.threatLevelMin and contact.threatlevel<=self.threatLevelMax
|
|
|
|
local redalert=true
|
|
if self.borderzoneset:Count()>0 then
|
|
redalert=inred
|
|
end
|
|
|
|
if redalert and threat and not contact.target then
|
|
|
|
local Target=TARGET:New(contact.group)
|
|
|
|
self:AddTarget(Target)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
---
|
|
-- Defcon
|
|
---
|
|
|
|
-- TODO: Need to introduce time check to avoid fast oscillation between different defcon states in case groups move in and out of the zones.
|
|
if Nred>0 then
|
|
self:SetDefcon(CHIEF.DEFCON.RED)
|
|
elseif Nyellow>0 then
|
|
self:SetDefcon(CHIEF.DEFCON.YELLOW)
|
|
else
|
|
self:SetDefcon(CHIEF.DEFCON.GREEN)
|
|
end
|
|
|
|
---
|
|
-- Check Target Queue
|
|
---
|
|
|
|
-- Check target queue and assign missions to new targets.
|
|
self:CheckTargetQueue()
|
|
|
|
|
|
---
|
|
-- Check Mission Queue
|
|
---
|
|
|
|
-- Check mission queue and assign one PLANNED mission.
|
|
self:CheckMissionQueue()
|
|
|
|
|
|
|
|
---
|
|
-- Info General
|
|
---
|
|
|
|
local Nassets=self.commander:CountAssets()
|
|
local Ncontacts=#self.contacts
|
|
local Nmissions=#self.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)
|
|
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
|
|
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 about contacts.
|
|
if #self.Contacts>0 then
|
|
local text="Contacts:"
|
|
for i,_contact in pairs(self.Contacts) do
|
|
local contact=_contact --Ops.Intelligence#INTEL.Contact
|
|
local mtext="N/A"
|
|
if contact.mission then
|
|
mtext=string.format("Mission %s (%s) %s", contact.mission.name, contact.mission.type, contact.mission.status:upper())
|
|
end
|
|
text=text..string.format("\n[%d] %s Type=%s (%s): Threat=%d Mission=%s", i, contact.groupname, contact.categoryname, contact.typename, contact.threatlevel, mtext)
|
|
end
|
|
self:I(self.lid..text)
|
|
end
|
|
|
|
---
|
|
-- Info Targets
|
|
---
|
|
|
|
if #self.targetqueue>0 then
|
|
local text="Targets:"
|
|
for i,_target in pairs(self.targetqueue) do
|
|
local target=_target --Ops.Target#TARGET
|
|
|
|
text=text..string.format("\n[%d] %s: Category=%s, prio=%d, importance=%d, alive=%s [%.1f/%.1f]",
|
|
i, target:GetName(), target.category, target.prio, target.importance or -1, tostring(target:IsAlive()), target:GetLife(), target:GetLife0())
|
|
|
|
end
|
|
self:I(self.lid..text)
|
|
end
|
|
|
|
---
|
|
-- Info Missions
|
|
---
|
|
|
|
-- Mission queue.
|
|
if #self.missionqueue>0 then
|
|
local text="Mission queue:"
|
|
for i,_mission in pairs(self.missionqueue) do
|
|
local mission=_mission --Ops.Auftrag#AUFTRAG
|
|
|
|
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)
|
|
end
|
|
self:I(self.lid..text)
|
|
end
|
|
|
|
end
|
|
|
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
-- FSM Events
|
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
--- On after "AssignMissionAssignAirforce" event.
|
|
-- @param #CHIEF self
|
|
-- @param #string From From state.
|
|
-- @param #string Event Event.
|
|
-- @param #string To To state.
|
|
-- @param Ops.Auftrag#AUFTRAG Mission The mission.
|
|
function CHIEF:onafterAssignMissionAirforce(From, Event, To, Mission)
|
|
|
|
if self.commander then
|
|
self:I(self.lid..string.format("Assigning mission %s (%s) to WINGCOMMANDER", Mission.name, Mission.type))
|
|
self.commander:AddMission(Mission)
|
|
else
|
|
self:E(self.lid..string.format("Mission cannot be assigned as no WINGCOMMANDER is defined."))
|
|
end
|
|
|
|
end
|
|
|
|
--- On after "MissionCancel" event.
|
|
-- @param #CHIEF self
|
|
-- @param #string From From state.
|
|
-- @param #string Event Event.
|
|
-- @param #string To To state.
|
|
-- @param Ops.Auftrag#AUFTRAG Mission The mission.
|
|
function CHIEF:onafterMissionCancel(From, Event, To, Mission)
|
|
|
|
-- Debug info.
|
|
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
|
|
|
|
-- Mission is still in planning stage. Should not have an airbase assigned ==> Just remove it form the queue.
|
|
self:RemoveMission(Mission)
|
|
|
|
-- Remove Mission from WC queue.
|
|
if Mission.wingcommander then
|
|
Mission.wingcommander:RemoveMission(Mission)
|
|
end
|
|
|
|
else
|
|
|
|
-- Wingcommander will cancel mission.
|
|
if Mission.wingcommander then
|
|
Mission.wingcommander:MissionCancel(Mission)
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
--- On before "Defcon" event.
|
|
-- @param #CHIEF self
|
|
-- @param #string From From state.
|
|
-- @param #string Event Event.
|
|
-- @param #string To To state.
|
|
-- @param #string Defcon New defence condition.
|
|
function CHIEF:onbeforeDefcon(From, Event, To, Defcon)
|
|
|
|
local gotit=false
|
|
for _,defcon in pairs(CHIEF.DEFCON) do
|
|
if defcon==Defcon then
|
|
gotit=true
|
|
end
|
|
end
|
|
|
|
if not gotit then
|
|
self:E(self.lid..string.format("ERROR: Unknown DEFCON specified! Dont know defcon=%s", tostring(Defcon)))
|
|
return false
|
|
end
|
|
|
|
-- Defcon did not change.
|
|
if Defcon==self.Defcon then
|
|
self:I(self.lid..string.format("Defcon %s unchanged. No processing transition.", tostring(Defcon)))
|
|
return false
|
|
end
|
|
|
|
return true
|
|
end
|
|
|
|
--- On after "Defcon" event.
|
|
-- @param #CHIEF self
|
|
-- @param #string From From state.
|
|
-- @param #string Event Event.
|
|
-- @param #string To To state.
|
|
-- @param #string Defcon New defence condition.
|
|
function CHIEF:onafterDefcon(From, Event, To, Defcon)
|
|
self:I(self.lid..string.format("Changing Defcon from %s --> %s", self.Defcon, Defcon))
|
|
|
|
-- Set new defcon.
|
|
self.Defcon=Defcon
|
|
end
|
|
|
|
--- On after "DeclareWar" event.
|
|
-- @param #CHIEF self
|
|
-- @param #string From From state.
|
|
-- @param #string Event Event.
|
|
-- @param #string To To state.
|
|
-- @param #CHIEF Chief The Chief we declared war on.
|
|
function CHIEF:onafterDeclareWar(From, Event, To, Chief)
|
|
|
|
if Chief then
|
|
self:AddWarOnChief(Chief)
|
|
end
|
|
|
|
end
|
|
|
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
-- Target Functions
|
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
--- Check mission queue and assign ONE planned mission.
|
|
-- @param #CHIEF self
|
|
function CHIEF:CheckTargetQueue()
|
|
|
|
-- TODO: Sort mission queue. wrt what? Threat level?
|
|
|
|
for _,_target in pairs(self.targetqueue) do
|
|
local target=_target --Ops.Target#TARGET
|
|
|
|
if target:IsAlive() and not target.mission then
|
|
|
|
-- TODO: stategry
|
|
self.strategy=CHIEF.Strategy.TOTALWAR
|
|
|
|
local valid=false
|
|
if self.strategy==CHIEF.Strategy.DEFENSIVE then
|
|
|
|
if self:CheckTargetInZones(target, self.borderzoneset) then
|
|
valid=true
|
|
end
|
|
|
|
elseif self.strategy==CHIEF.Strategy.OFFENSIVE then
|
|
|
|
if self:CheckTargetInZones(target, self.borderzoneset) or self:CheckTargetInZones(target, self.yellowzoneset) then
|
|
valid=true
|
|
end
|
|
|
|
elseif self.strategy==CHIEF.Strategy.AGGRESSIVE then
|
|
|
|
if self:CheckTargetInZones(target, self.borderzoneset) or self:CheckTargetInZones(target, self.yellowzoneset) or self:CheckTargetInZones(target, self.engagezoneset) then
|
|
valid=true
|
|
end
|
|
|
|
elseif self.strategy==CHIEF.Strategy.TOTALWAR then
|
|
valid=true
|
|
end
|
|
|
|
-- Valid target?
|
|
if valid then
|
|
|
|
-- Create mission
|
|
local mission=AUFTRAG:NewTargetAir(target)
|
|
|
|
if mission then
|
|
|
|
-- Set target mission entry.
|
|
target.mission=mission
|
|
|
|
-- Mission parameters.
|
|
mission.prio=target.prio
|
|
mission.importance=target.importance
|
|
|
|
-- Add mission to queue.
|
|
self:AddMission(mission)
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
-- 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.
|
|
-- @param #CHIEF self
|
|
-- @param Wrapper.Group#GROUP group The group.
|
|
-- @return #boolean If true, group is in any zone.
|
|
function CHIEF:CheckGroupInBorder(group)
|
|
|
|
local inside=self:CheckGroupInZones(group, self.borderzoneset)
|
|
|
|
return inside
|
|
end
|
|
|
|
--- Check if group is near our border (yellow zone).
|
|
-- @param #CHIEF self
|
|
-- @param Wrapper.Group#GROUP group The group.
|
|
-- @return #boolean If true, group is in any zone.
|
|
function CHIEF:CheckGroupInYellow(group)
|
|
|
|
-- Check inside yellow but not inside our border.
|
|
local inside=self:CheckGroupInZones(group, self.yellowzoneset) and not self:CheckGroupInZones(group, self.borderzoneset)
|
|
|
|
return inside
|
|
end
|
|
|
|
--- Check if group is inside a zone.
|
|
-- @param #CHIEF self
|
|
-- @param Wrapper.Group#GROUP group The group.
|
|
-- @param Core.Set#SET_ZONE zoneset Set of zones.
|
|
-- @return #boolean If true, group is in any zone.
|
|
function CHIEF:CheckGroupInZones(group, zoneset)
|
|
|
|
for _,_zone in pairs(zoneset.Set or {}) do
|
|
local zone=_zone --Core.Zone#ZONE
|
|
|
|
if group:IsPartlyOrCompletelyInZone(zone) then
|
|
return true
|
|
end
|
|
end
|
|
|
|
return false
|
|
end
|
|
|
|
--- Check if group is inside a zone.
|
|
-- @param #CHIEF self
|
|
-- @param Ops.Target#TARGET target The target.
|
|
-- @param Core.Set#SET_ZONE zoneset Set of zones.
|
|
-- @return #boolean If true, group is in any zone.
|
|
function CHIEF:CheckTargetInZones(target, zoneset)
|
|
|
|
for _,_zone in pairs(zoneset.Set or {}) do
|
|
local zone=_zone --Core.Zone#ZONE
|
|
|
|
if zone:IsCoordinateInZone(target:GetCoordinate()) then
|
|
return true
|
|
end
|
|
end
|
|
|
|
return false
|
|
end
|
|
|
|
--- Check resources.
|
|
-- @param #CHIEF self
|
|
-- @return #table
|
|
function CHIEF:CheckResources()
|
|
|
|
local capabilities={}
|
|
|
|
for _,MissionType in pairs(AUFTRAG.Type) do
|
|
capabilities[MissionType]=0
|
|
|
|
for _,_airwing in pairs(self.airwings) do
|
|
local airwing=_airwing --Ops.AirWing#AIRWING
|
|
|
|
-- Get Number of assets that can do this type of missions.
|
|
local _,assets=airwing:CanMission(MissionType)
|
|
|
|
-- Add up airwing resources.
|
|
capabilities[MissionType]=capabilities[MissionType]+#assets
|
|
end
|
|
|
|
end
|
|
|
|
return capabilities
|
|
end
|
|
|
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |