Merge pull request #1528 from FlightControl-Master/AA-2

Update Shorad.lua
This commit is contained in:
Applevangelist 2021-05-01 17:27:22 +02:00 committed by GitHub
commit 22ec94b374
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,7 +18,7 @@
-- @module Functional.Shorad -- @module Functional.Shorad
-- @image Functional.Shorad.jpg -- @image Functional.Shorad.jpg
-- --
-- Date: Feb 2021 -- Date: May 2021
------------------------------------------------------------------------- -------------------------------------------------------------------------
--- **SHORAD** class, extends Core.Base#BASE --- **SHORAD** class, extends Core.Base#BASE
@ -38,7 +38,7 @@
-- @field #boolean DefendMavs Default true, intercept incoming AG-Missiles -- @field #boolean DefendMavs Default true, intercept incoming AG-Missiles
-- @field #number DefenseLowProb Default 70, minimum detection limit -- @field #number DefenseLowProb Default 70, minimum detection limit
-- @field #number DefenseHighProb Default 90, maximim detection limit -- @field #number DefenseHighProb Default 90, maximim detection limit
-- @field #boolean UseAIOnOff Decide if we are using AI on/off (true) or AlarmState red/green (default). -- @field #boolean UseEmOnOff Decide if we are using Emission on/off (default) or AlarmState red/green.
-- @extends Core.Base#BASE -- @extends Core.Base#BASE
--- *Good friends are worth defending.* Mr Tushman, Wonder (the Movie) --- *Good friends are worth defending.* Mr Tushman, Wonder (the Movie)
@ -96,7 +96,7 @@ SHORAD = {
DefendMavs = true, DefendMavs = true,
DefenseLowProb = 70, DefenseLowProb = 70,
DefenseHighProb = 90, DefenseHighProb = 90,
UseAIOnOff = false, UseEmOnOff = true,
} }
----------------------------------------------------------------------- -----------------------------------------------------------------------
@ -176,8 +176,8 @@ do
self.DefendMavs = true self.DefendMavs = true
self.DefenseLowProb = 70 -- probability to detect a missile shot, low margin self.DefenseLowProb = 70 -- probability to detect a missile shot, low margin
self.DefenseHighProb = 90 -- probability to detect a missile shot, high margin self.DefenseHighProb = 90 -- probability to detect a missile shot, high margin
self.UseAIOnOff = false -- Decide if we are using AI on/off (true) or AlarmState red/green (default) self.UseEmOnOff = true -- Decide if we are using Emission on/off (default) or AlarmState red/green
self:I("*** SHORAD - Started Version 0.1.0") self:I("*** SHORAD - Started Version 0.2.1")
-- Set the string id for output to DCS.log file. -- Set the string id for output to DCS.log file.
self.lid=string.format("SHORAD %s | ", self.name) self.lid=string.format("SHORAD %s | ", self.name)
self:_InitState() self:_InitState()
@ -192,8 +192,9 @@ do
self:T({set = set}) self:T({set = set})
local aliveset = set:GetAliveSet() --#table local aliveset = set:GetAliveSet() --#table
for _,_group in pairs (aliveset) do for _,_group in pairs (aliveset) do
if self.UseAIOnOff then if self.UseEmOnOff then
_group:SetAIOff() --_group:SetAIOff()
_group:EnableEmission(false)
else else
_group:OptionAlarmStateGreen() --Wrapper.Group#GROUP _group:OptionAlarmStateGreen() --Wrapper.Group#GROUP
end end
@ -279,11 +280,11 @@ do
self.Radius = radius self.Radius = radius
end end
--- Set using AI on/off instead of changing alarm state --- Set using Emission on/off instead of changing alarm state
-- @param #SHORAD self -- @param #SHORAD self
-- @param #boolean switch Decide if we are changing alarm state or AI state -- @param #boolean switch Decide if we are changing alarm state or AI state
function SHORAD:SetUsingAIOnOff(switch) function SHORAD:SetUsingEmOnOff(switch)
self.UseAIOnOff = switch or false self.UseEmOnOff = switch or false
end end
--- Check if a HARM was fired --- Check if a HARM was fired
@ -410,8 +411,9 @@ do
local function SleepShorad(group) local function SleepShorad(group)
local groupname = group:GetName() local groupname = group:GetName()
self.ActiveGroups[groupname] = nil self.ActiveGroups[groupname] = nil
if self.UseAIOnOff then if self.UseEmOnOff then
group:SetAIOff() group:EnableEmission(false)
--group:SetAIOff()
else else
group:OptionAlarmStateGreen() group:OptionAlarmStateGreen()
end end
@ -425,8 +427,9 @@ do
local text = string.format("Waking up SHORAD %s", _group:GetName()) local text = string.format("Waking up SHORAD %s", _group:GetName())
self:T(text) self:T(text)
local m = MESSAGE:New(text,10,"SHORAD"):ToAllIf(self.debug) local m = MESSAGE:New(text,10,"SHORAD"):ToAllIf(self.debug)
if self.UseAIOnOff then if self.UseEmOnOff then
_group:SetAIOn() _group:SetAIOn()
_group:EnableEmission(true)
end end
_group:OptionAlarmStateRed() _group:OptionAlarmStateRed()
local groupname = _group:GetName() local groupname = _group:GetName()
@ -461,23 +464,31 @@ do
end end
local text = string.format("%s Missile Launched = %s | Detected probability state is %s", self.lid, ShootingWeaponName, DetectedText) local text = string.format("%s Missile Launched = %s | Detected probability state is %s", self.lid, ShootingWeaponName, DetectedText)
self:T( text ) self:T( text )
local m = MESSAGE:New(text,15,"Info"):ToAllIf(self.debug) local m = MESSAGE:New(text,10,"Info"):ToAllIf(self.debug)
-- --
if (self:_CheckHarms(ShootingWeaponName) or self:_CheckMavs(ShootingWeaponName)) and IsDetected then if (self:_CheckHarms(ShootingWeaponName) or self:_CheckMavs(ShootingWeaponName)) and IsDetected then
-- get target data -- get target data
local targetdata = EventData.Weapon:getTarget() -- Identify target local targetdata = EventData.Weapon:getTarget() -- Identify target
local targetunitname = Unit.getName(targetdata) -- Unit name local targetunit = UNIT:Find(targetdata)
local targetgroup = Unit.getGroup(Weapon.getTarget(ShootingWeapon)) --targeted group --local targetunitname = Unit.getName(targetdata) -- Unit name
local targetgroupname = targetgroup:getName() -- group name if targetunit and targetunit:IsAlive() then
-- check if we or a SAM site are the target local targetunitname = targetunit:GetName()
--local TargetGroup = EventData.TgtGroup -- Wrapper.Group#GROUP --local targetgroup = Unit.getGroup(Weapon.getTarget(ShootingWeapon)) --targeted group
local shotatus = self:_CheckShotAtShorad(targetgroupname) --#boolean local targetgroup = targetunit:GetGroup()
local shotatsams = self:_CheckShotAtSams(targetgroupname) --#boolean local targetgroupname = targetgroup:GetName() -- group name
-- if being shot at, find closest SHORADs to activate local text = string.format("%s Missile Target = %s", self.lid, tostring(targetgroupname))
if shotatsams or shotatus then self:T( text )
self:T({shotatsams=shotatsams,shotatus=shotatus}) local m = MESSAGE:New(text,10,"Info"):ToAllIf(self.debug)
self:WakeUpShorad(targetgroupname, self.Radius, self.ActiveTimer) -- check if we or a SAM site are the target
end --local TargetGroup = EventData.TgtGroup -- Wrapper.Group#GROUP
local shotatus = self:_CheckShotAtShorad(targetgroupname) --#boolean
local shotatsams = self:_CheckShotAtSams(targetgroupname) --#boolean
-- if being shot at, find closest SHORADs to activate
if shotatsams or shotatus then
self:T({shotatsams=shotatsams,shotatus=shotatus})
self:WakeUpShorad(targetgroupname, self.Radius, self.ActiveTimer)
end
end
end end
end end
end end