mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
AUTOLASE - added Cancel FSM to stop, docu changes, option to notify pilots in the set only
This commit is contained in:
parent
4c3a97e2b2
commit
cd79c57a27
@ -1,19 +1,31 @@
|
|||||||
--- **Functional** - Autolase targets in the field.
|
--- **Functional** - Autolase targets in the field.
|
||||||
--
|
--
|
||||||
|
-- ===
|
||||||
|
--
|
||||||
|
-- **AUOTLASE** - Autolase targets in the field.
|
||||||
|
--
|
||||||
|
-- ===
|
||||||
|
--
|
||||||
|
-- ## Missions:
|
||||||
|
--
|
||||||
|
-- ### [Autolase](https://github.com/FlightControl-Master/MOOSE_MISSIONS/tree/develop/)
|
||||||
|
--
|
||||||
|
-- ===
|
||||||
|
--
|
||||||
-- **Main Features:**
|
-- **Main Features:**
|
||||||
--
|
--
|
||||||
-- * Detect and lase contacts automatically
|
-- * Detect and lase contacts automatically
|
||||||
-- * Targets are lased by threat priority order
|
-- * Targets are lased by threat priority order
|
||||||
-- * Use FSM events to link functionality into your scripts
|
-- * Use FSM events to link functionality into your scripts
|
||||||
-- * Easy setup
|
-- * Easy setup
|
||||||
--
|
--
|
||||||
-- ===
|
-- ===
|
||||||
--
|
--
|
||||||
-- ### Author: **applevangelist**
|
-- ### Author: **applevangelist**
|
||||||
-- @module Functional.Autolase
|
-- @module Functional.Autolase
|
||||||
-- @image Designation.JPG
|
-- @image Designation.JPG
|
||||||
--
|
|
||||||
-- Date: 01 Oct 2021
|
-- Date: Oct 2021
|
||||||
|
|
||||||
---
|
---
|
||||||
--- Class AUTOLASE
|
--- Class AUTOLASE
|
||||||
@ -66,20 +78,16 @@
|
|||||||
-- :InitLimit(1,0)
|
-- :InitLimit(1,0)
|
||||||
-- :SpawnScheduled(30,0.5)
|
-- :SpawnScheduled(30,0.5)
|
||||||
--
|
--
|
||||||
-- ## 2.6 Example - Inform pilots about a new target:
|
-- ## 2.6 Example - Inform pilots about events:
|
||||||
--
|
--
|
||||||
-- function autolaser:OnAfterLasing(From,Event,To,LaserSpot)
|
-- autolaser:SetNotifyPilots(true) -- defaults to true, also shown if debug == true
|
||||||
-- local laserspot = LaserSpot -- #AUTOLASE.LaserSpot
|
-- -- Note - message are shown to pilots in the #SET_CLIENT only if using the pilotset option, else to the coalition.
|
||||||
-- local text = string.format("%s is lasing %s code %d\nat %s",laserspot.reccename,laserspot.unittype,laserspot.lasercode,laserspot.location)
|
|
||||||
-- local m = MESSAGE:New(text,15,"Autolase"):ToAll()
|
|
||||||
-- return self
|
|
||||||
-- end
|
|
||||||
--
|
--
|
||||||
-- @field #AUTOLASE
|
-- @field #AUTOLASE
|
||||||
AUTOLASE = {
|
AUTOLASE = {
|
||||||
ClassName = "AUTOLASE",
|
ClassName = "AUTOLASE",
|
||||||
lid = "",
|
lid = "",
|
||||||
verbose = 2,
|
verbose = 0,
|
||||||
alias = "",
|
alias = "",
|
||||||
debug = false,
|
debug = false,
|
||||||
}
|
}
|
||||||
@ -98,7 +106,7 @@ AUTOLASE = {
|
|||||||
|
|
||||||
--- AUTOLASE class version.
|
--- AUTOLASE class version.
|
||||||
-- @field #string version
|
-- @field #string version
|
||||||
AUTOLASE.version = "0.0.1"
|
AUTOLASE.version = "0.0.2"
|
||||||
|
|
||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
-- Begin Functional.Autolase.lua
|
-- Begin Functional.Autolase.lua
|
||||||
@ -169,6 +177,7 @@ function AUTOLASE:New(RecceSet, Coalition, Alias, PilotSet)
|
|||||||
self.reporttimelong = 30
|
self.reporttimelong = 30
|
||||||
self.smoketargets = false
|
self.smoketargets = false
|
||||||
self.smokecolor = SMOKECOLOR.Red
|
self.smokecolor = SMOKECOLOR.Red
|
||||||
|
self.notifypilots = true
|
||||||
|
|
||||||
-- Set some string id for output to DCS.log file.
|
-- Set some string id for output to DCS.log file.
|
||||||
self.lid=string.format("AUTOLASE %s (%s) | ", self.alias, self.coalition and UTILS.GetCoalitionName(self.coalition) or "unknown")
|
self.lid=string.format("AUTOLASE %s (%s) | ", self.alias, self.coalition and UTILS.GetCoalitionName(self.coalition) or "unknown")
|
||||||
@ -181,6 +190,7 @@ function AUTOLASE:New(RecceSet, Coalition, Alias, PilotSet)
|
|||||||
self:AddTransition("*", "TargetDestroyed", "*") -- Target destroyed
|
self:AddTransition("*", "TargetDestroyed", "*") -- Target destroyed
|
||||||
self:AddTransition("*", "RecceKIA", "*") -- Recce KIA
|
self:AddTransition("*", "RecceKIA", "*") -- Recce KIA
|
||||||
self:AddTransition("*", "LaserTimeout", "*") -- Laser timed out
|
self:AddTransition("*", "LaserTimeout", "*") -- Laser timed out
|
||||||
|
self:AddTransition("*", "Cancel", "*") -- Stop Autolase
|
||||||
|
|
||||||
-- Menu Entry
|
-- Menu Entry
|
||||||
if not PilotSet then
|
if not PilotSet then
|
||||||
@ -195,7 +205,7 @@ function AUTOLASE:New(RecceSet, Coalition, Alias, PilotSet)
|
|||||||
self:SetClusterAnalysis(false, false)
|
self:SetClusterAnalysis(false, false)
|
||||||
|
|
||||||
self:__Start(2)
|
self:__Start(2)
|
||||||
self:__Monitor(-5)
|
self:__Monitor(math.random(5,10))
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@ -204,12 +214,21 @@ function AUTOLASE:New(RecceSet, Coalition, Alias, PilotSet)
|
|||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
--- Triggers the FSM event "Monitor".
|
--- Triggers the FSM event "Monitor".
|
||||||
-- @function [parent=#INTEL] Status
|
-- @function [parent=#AUTOLASE] Status
|
||||||
-- @param #INTEL self
|
-- @param #AUTOLASE self
|
||||||
|
|
||||||
--- Triggers the FSM event "Monitor" after a delay.
|
--- Triggers the FSM event "Monitor" after a delay.
|
||||||
-- @function [parent=#INTEL] __Status
|
-- @function [parent=#AUTOLASE] __Status
|
||||||
-- @param #INTEL self
|
-- @param #AUTOLASE self
|
||||||
|
-- @param #number delay Delay in seconds.
|
||||||
|
|
||||||
|
--- Triggers the FSM event "Cancel".
|
||||||
|
-- @function [parent=#AUTOLASE] Cancel
|
||||||
|
-- @param #AUTOLASE self
|
||||||
|
|
||||||
|
--- Triggers the FSM event "Cancel" after a delay.
|
||||||
|
-- @function [parent=#AUTOLASE] __Cancel
|
||||||
|
-- @param #AUTOLASE self
|
||||||
-- @param #number delay Delay in seconds.
|
-- @param #number delay Delay in seconds.
|
||||||
|
|
||||||
--- On After "RecceKIA" event.
|
--- On After "RecceKIA" event.
|
||||||
@ -270,7 +289,7 @@ function AUTOLASE:SetPilotMenu()
|
|||||||
local Unit = _unit -- Wrapper.Unit#UNIT
|
local Unit = _unit -- Wrapper.Unit#UNIT
|
||||||
if Unit and Unit:IsAlive() then
|
if Unit and Unit:IsAlive() then
|
||||||
local Group = Unit:GetGroup()
|
local Group = Unit:GetGroup()
|
||||||
local lasemenu = MENU_GROUP_COMMAND:New(Group,"Autolase",nil,self.ShowStatus,self,Group)
|
local lasemenu = MENU_GROUP_COMMAND:New(Group,"Autolase Status",nil,self.ShowStatus,self,Group)
|
||||||
lasemenu:Refresh()
|
lasemenu:Refresh()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -310,6 +329,15 @@ function AUTOLASE:SetMaxLasingTargets(Number)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Function set notify pilots on events
|
||||||
|
-- @param #AUTOLASE self
|
||||||
|
-- @param #boolean OnOff Switch messaging on (true) or off (false)
|
||||||
|
-- @return #AUTOLASE self
|
||||||
|
function AUTOLASE:SetNotifyPilots(OnOff)
|
||||||
|
self.notifypilots = OnOff and true
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
--- (User) Function to set a specific code to a Recce.
|
--- (User) Function to set a specific code to a Recce.
|
||||||
-- @param #AUTOLASE self
|
-- @param #AUTOLASE self
|
||||||
-- @param #string RecceName Name of the Recce
|
-- @param #string RecceName Name of the Recce
|
||||||
@ -458,6 +486,29 @@ function AUTOLASE:ShowStatus(Group)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- (Internal) Function to show messages.
|
||||||
|
-- @param #AUTOLASE self
|
||||||
|
-- @param #string Message The message to be sent
|
||||||
|
-- @param #number Duration Duration in seconds
|
||||||
|
-- @return #AUTOLASE self
|
||||||
|
function AUTOLASE:NotifyPilots(Message,Duration)
|
||||||
|
if self.usepilotset then
|
||||||
|
local pilotset = self.pilotset:GetSetObjects() --#table
|
||||||
|
for _,_pilot in pairs(pilotset) do
|
||||||
|
local pilot = _pilot -- Wrapper.Unit#UNIT
|
||||||
|
if pilot and pilot:IsAlive() then
|
||||||
|
local Group = pilot:GetGroup()
|
||||||
|
local m = MESSAGE:New(Message,Duration,"Autolase"):ToGroup(Group)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif not self.debug then
|
||||||
|
local m = MESSAGE:New(Message,Duration,"Autolase"):ToCoalition(self.coalition)
|
||||||
|
else
|
||||||
|
local m = MESSAGE:New(Message,Duration,"Autolase"):ToAll()
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
-- FSM Functions
|
-- FSM Functions
|
||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
@ -474,6 +525,8 @@ function AUTOLASE:onafterMonitor(From, Event, To)
|
|||||||
-- Housekeeping
|
-- Housekeeping
|
||||||
local countlases = self:CleanCurrentLasing()
|
local countlases = self:CleanCurrentLasing()
|
||||||
|
|
||||||
|
self:SetPilotMenu()
|
||||||
|
|
||||||
local detecteditems = self.Contacts or {} -- #table of Ops.Intelligence#INTEL.Contact
|
local detecteditems = self.Contacts or {} -- #table of Ops.Intelligence#INTEL.Contact
|
||||||
local groupsbythreat = {}
|
local groupsbythreat = {}
|
||||||
--self:T("Detected Items:")
|
--self:T("Detected Items:")
|
||||||
@ -596,7 +649,7 @@ function AUTOLASE:onafterMonitor(From, Event, To)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self:__Monitor(-20)
|
self:__Monitor(-30)
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -609,8 +662,10 @@ end
|
|||||||
-- @return #AUTOLASE self
|
-- @return #AUTOLASE self
|
||||||
function AUTOLASE:onbeforeRecceKIA(From,Event,To,RecceName)
|
function AUTOLASE:onbeforeRecceKIA(From,Event,To,RecceName)
|
||||||
self:T({From, Event, To, RecceName})
|
self:T({From, Event, To, RecceName})
|
||||||
local text = string.format("Recce %s KIA!",RecceName)
|
if self.notifypilots or self.debug then
|
||||||
local m = MESSAGE:New(text,self.reporttimeshort,"Autolase"):ToAllIf(self.debug)
|
local text = string.format("Recce %s KIA!",RecceName)
|
||||||
|
self:NotifyPilots(text,self.reporttimeshort)
|
||||||
|
end
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -624,8 +679,10 @@ end
|
|||||||
-- @return #AUTOLASE self
|
-- @return #AUTOLASE self
|
||||||
function AUTOLASE:onbeforeTargetDestroyed(From,Event,To,UnitName,RecceName)
|
function AUTOLASE:onbeforeTargetDestroyed(From,Event,To,UnitName,RecceName)
|
||||||
self:T({From, Event, To, UnitName, RecceName})
|
self:T({From, Event, To, UnitName, RecceName})
|
||||||
local text = string.format("Unit %s destroyed! Good job!",UnitName)
|
if self.notifypilots or self.debug then
|
||||||
local m = MESSAGE:New(text,self.reporttimeshort,"Autolase"):ToAllIf(self.debug)
|
local text = string.format("Unit %s destroyed! Good job!",UnitName)
|
||||||
|
self:NotifyPilots(text,self.reporttimeshort)
|
||||||
|
end
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -639,8 +696,10 @@ end
|
|||||||
-- @return #AUTOLASE self
|
-- @return #AUTOLASE self
|
||||||
function AUTOLASE:onbeforeTargetLost(From,Event,To,UnitName,RecceName)
|
function AUTOLASE:onbeforeTargetLost(From,Event,To,UnitName,RecceName)
|
||||||
self:T({From, Event, To, UnitName,RecceName})
|
self:T({From, Event, To, UnitName,RecceName})
|
||||||
local text = string.format("%s lost sight of unit %s.",RecceName,UnitName)
|
if self.notifypilots or self.debug then
|
||||||
local m = MESSAGE:New(text,self.reporttimeshort,"Autolase"):ToAllIf(self.debug)
|
local text = string.format("%s lost sight of unit %s.",RecceName,UnitName)
|
||||||
|
self:NotifyPilots(text,self.reporttimeshort)
|
||||||
|
end
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -654,8 +713,10 @@ end
|
|||||||
-- @return #AUTOLASE self
|
-- @return #AUTOLASE self
|
||||||
function AUTOLASE:onbeforeLaserTimeout(From,Event,To,UnitName,RecceName)
|
function AUTOLASE:onbeforeLaserTimeout(From,Event,To,UnitName,RecceName)
|
||||||
self:T({From, Event, To, UnitName,RecceName})
|
self:T({From, Event, To, UnitName,RecceName})
|
||||||
local text = string.format("%s laser timeout on unit %s.",RecceName,UnitName)
|
if self.notifypilots or self.debug then
|
||||||
local m = MESSAGE:New(text,self.reporttimeshort,"Autolase"):ToAllIf(self.debug)
|
local text = string.format("%s laser timeout on unit %s.",RecceName,UnitName)
|
||||||
|
self:NotifyPilots(text,self.reporttimeshort)
|
||||||
|
end
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -668,9 +729,23 @@ end
|
|||||||
-- @return #AUTOLASE self
|
-- @return #AUTOLASE self
|
||||||
function AUTOLASE:onbeforeLasing(From,Event,To,LaserSpot)
|
function AUTOLASE:onbeforeLasing(From,Event,To,LaserSpot)
|
||||||
self:T({From, Event, To, LaserSpot.unittype})
|
self:T({From, Event, To, LaserSpot.unittype})
|
||||||
local laserspot = LaserSpot -- #AUTOLASE.LaserSpot
|
if self.notifypilots or self.debug then
|
||||||
local text = string.format("%s is lasing %s code %d\nat %s",laserspot.reccename,laserspot.unittype,laserspot.lasercode,laserspot.location)
|
local laserspot = LaserSpot -- #AUTOLASE.LaserSpot
|
||||||
local m = MESSAGE:New(text,self.reporttimeshort,"Autolase"):ToAllIf(self.debug)
|
local text = string.format("%s is lasing %s code %d\nat %s",laserspot.reccename,laserspot.unittype,laserspot.lasercode,laserspot.location)
|
||||||
|
self:NotifyPilots(text,self.reporttimeshort)
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
--- (Internal) FSM Function onbeforeCancel
|
||||||
|
-- @param #AUTOLASE self
|
||||||
|
-- @param #string From The from state
|
||||||
|
-- @param #string Event The event
|
||||||
|
-- @param #string To The to state
|
||||||
|
-- @return #AUTOLASE self
|
||||||
|
function AUTOLASE:onbeforeCancel(From,Event,To)
|
||||||
|
self:UnHandleEvent(EVENTS.PlayerEnterAircraft)
|
||||||
|
self:__Stop(2)
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user