Merge branch 'develop' into FF/Fox2

This commit is contained in:
Frank
2020-01-06 23:20:55 +01:00
11 changed files with 304 additions and 59 deletions
+2 -2
View File
@@ -961,7 +961,7 @@ function FOX:onafterMissileLaunch(From, Event, To, missile)
end
if target then
self:I(self.lid..string.format("Missile %s with NO explicit target got closest unit to missile as target %s. Dist=%s m", missile.missileType, target:GetName(), tostring(mindist)))
self:T(self.lid..string.format("Missile %s with NO explicit target got closest unit to missile as target %s. Dist=%s m", missile.missileType, target:GetName(), tostring(mindist)))
end
end
@@ -1066,7 +1066,7 @@ function FOX:onafterMissileLaunch(From, Event, To, missile)
else
-- Destroy missile.
self:I(self.lid..string.format("Missile %s(%s) fired by %s has no current target. Checking back in 0.1 sec.", missile.missileType, missile.missileName, missile.shooterName))
self:T(self.lid..string.format("Missile %s(%s) fired by %s has no current target. Checking back in 0.1 sec.", missile.missileType, missile.missileName, missile.shooterName))
return timer.getTime()+0.1
-- No target ==> terminate timer.
@@ -22,7 +22,7 @@
--
-- The implementation is based on an idea and script by MBot. See the [DCS forum threat](https://forums.eagle.ru/showthread.php?t=107635) for details.
--
-- In addition to suppressing the fire, conditions can be specified which let the group retreat to a defined zone, move away from the attacker
-- In addition to suppressing the fire, conditions can be specified, which let the group retreat to a defined zone, move away from the attacker
-- or hide at a nearby scenery object.
--
-- ====
@@ -83,6 +83,8 @@
-- @field #string DefaultAlarmState Alarm state the group will go to when it is changed back from another state. Default is "Auto".
-- @field #string DefaultROE ROE the group will get once suppression is over. Default is "Free".
-- @field #boolean eventmoose If true, events are handled by MOOSE. If false, events are handled directly by DCS eventhandler. Default true.
-- @field Core.Zone#ZONE BattleZone
-- @field #boolean AutoEngage
-- @extends Core.Fsm#FSM_CONTROLLABLE
--
@@ -307,8 +309,7 @@ SUPPRESSION.version="0.9.3"
--- Creates a new AI_suppression object.
-- @param #SUPPRESSION self
-- @param Wrapper.Group#GROUP group The GROUP object for which suppression should be applied.
-- @return #SUPPRESSION SUPPRESSION object.
-- @return nil If group does not exist or is not a ground group.
-- @return #SUPPRESSION SUPPRESSION object or *nil* if group does not exist or is not a ground group.
function SUPPRESSION:New(group)
-- Inherits from FSM_CONTROLLABLE
@@ -333,18 +334,16 @@ function SUPPRESSION:New(group)
self:SetControllable(group)
-- Get DCS descriptors of group.
local DCSgroup=Group.getByName(group:GetName())
local DCSunit=DCSgroup:getUnit(1)
self.DCSdesc=DCSunit:getDesc()
self.DCSdesc=group:GetDCSDesc(1)
-- Get max speed the group can do and convert to km/h.
self.SpeedMax=self.DCSdesc.speedMaxOffRoad*3.6
self.SpeedMax=group:GetSpeedMax()
-- Set speed to maximum.
self.Speed=self.SpeedMax
-- Is this infantry or not.
self.IsInfantry=DCSunit:hasAttribute("Infantry")
self.IsInfantry=group:GetUnit(1):HasAttribute("Infantry")
-- Type of group.
self.Type=group:GetTypeName()
@@ -368,6 +367,7 @@ function SUPPRESSION:New(group)
self:AddTransition("TakingCover", "FightBack", "CombatReady")
self:AddTransition("FallingBack", "FightBack", "CombatReady")
self:AddTransition("Retreating", "Retreated", "Retreated")
self:AddTransition("*", "OutOfAmmo", "*")
self:AddTransition("*", "Dead", "*")
self:AddTransition("*", "Stop", "Stopped")
@@ -598,6 +598,24 @@ function SUPPRESSION:New(group)
-- @param #string To To state.
--- Trigger "OutOfAmmo" event.
-- @function [parent=#SUPPRESSION] OutOfAmmo
-- @param #SUPPRESSION self
--- Trigger "OutOfAmmo" event after a delay.
-- @function [parent=#SUPPRESSION] __OutOfAmmo
-- @param #SUPPRESSION self
-- @param #number Delay Delay in seconds.
--- User function for OnAfter "OutOfAmmo" event.
-- @function [parent=#SUPPRESSION] OnAfterOutOfAmmo
-- @param #SUPPRESSION self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable Controllable of the group.
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
--- Trigger "Dead" event.
-- @function [parent=#SUPPRESSION] Dead
-- @param #SUPPRESSION self
@@ -882,10 +900,11 @@ function SUPPRESSION:StatusReport(message)
local state=self.CurrentAlarmState
local life_min, life_max, life_ave, life_ave0, groupstrength=self:_GetLife()
local ammotot=group:GetAmmunition()
local detectedG=group:GetDetectedGroupSet():CountAlive()
local detectedU=group:GetDetectedUnitSet():Count()
local text=string.format("State %s, Units=%d/%d, ROE=%s, AlarmState=%s, Hits=%d, Life(min/max/ave/ave0)=%d/%d/%d/%d, Total Ammo=%d",
self:GetState(), nunits, self.IniGroupStrength, self.CurrentROE, self.CurrentAlarmState, self.Nhit, life_min, life_max, life_ave, life_ave0, ammotot)
local text=string.format("State %s, Units=%d/%d, ROE=%s, AlarmState=%s, Hits=%d, Life(min/max/ave/ave0)=%d/%d/%d/%d, Total Ammo=%d, Detected=%d/%d",
self:GetState(), nunits, self.IniGroupStrength, self.CurrentROE, self.CurrentAlarmState, self.Nhit, life_min, life_max, life_ave, life_ave0, ammotot, detectedG, detectedU)
MESSAGE:New(text, 10):ToAllIf(message or self.Debug)
self:I(self.lid..text)
@@ -997,12 +1016,12 @@ function SUPPRESSION:onafterStatus(Controllable, From, Event, To)
local nunits=group:CountAliveUnits()
-- Check if there are units.
if nunits>0 then
if nunits>0 then
-- Retreat if completely out of ammo and retreat zone defined.
local nammo=group:GetAmmunition()
if nammo==0 and self.RetreatZone then
self:Retreat()
if nammo==0 then
self:OutOfAmmo()
end
-- Status report.
@@ -1014,34 +1033,18 @@ function SUPPRESSION:onafterStatus(Controllable, From, Event, To)
end
else
-- Stop FSM as there are no units left.
self:Stop()
end
else
-- Stop FSM as there group object does not exist.
self:Stop()
end
end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Before "Hit" event. (Of course, this is not really before the group got hit.)
-- @param #SUPPRESSION self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable Controllable of the group.
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
-- @param Wrapper.Unit#UNIT Unit Unit that was hit.
-- @param Wrapper.Unit#UNIT AttackUnit Unit that attacked.
-- @return boolean
function SUPPRESSION:onbeforeHit(Controllable, From, Event, To, Unit, AttackUnit)
self:_EventFromTo("onbeforeHit", Event, From, To)
--local Tnow=timer.getTime()
--env.info(self.lid..string.format("Last hit = %s %s", tostring(self.LastHit), tostring(Tnow)))
return true
end
--- After "Hit" event.
-- @param #SUPPRESSION self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable Controllable of the group.
@@ -1312,6 +1315,25 @@ function SUPPRESSION:onafterTakeCover(Controllable, From, Event, To, Hideout)
end
--- After "OutOfAmmo" event. Triggered when group is completely out of ammo.
-- @param #SUPPRESSION self
-- @param Wrapper.Controllable#CONTROLLABLE Controllable Controllable of the group.
-- @param #string From From state.
-- @param #string Event Event.
-- @param #string To To state.
function SUPPRESSION:onafterOutOfAmmo(Controllable, From, Event, To)
self:_EventFromTo("onafterOutOfAmmo", Event, From, To)
-- Info to log.
self:I(self.lid..string.format("Out of ammo!"))
-- Order retreat if retreat zone was specified.
if self.RetreatZone then
self:Retreat()
end
end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Before "Retreat" event. We check that the group is not already retreating.
@@ -874,8 +874,16 @@ do -- ZONE_CAPTURE_COALITION
self:Capture()
end
-- Get red and blue unit sets.
local unitsetRed=self:GetScannedSetUnit():FilterCoalitions(coalition.side.RED):FilterActive(true):FilterOnce()
local unitsetBlu=self:GetScannedSetUnit():FilterCoalitions(coalition.side.BLUE):FilterActive(true):FilterOnce()
-- Count number of units.
local nRed=unitsetRed:Count()
local nBlu=unitsetBlu:Count()
-- Status text.
local text=string.format("CAPTURE ZONE %s: Owner=%s (Previous=%s): Status %s", self:GetZoneName(), self:GetCoalitionName(), UTILS.GetCoalitionName(self:GetPreviousCoalition()), State)
local text=string.format("CAPTURE ZONE %s: Owner=%s (Previous=%s): #blue=%d, #red=%d, Status %s", self:GetZoneName(), self:GetCoalitionName(), UTILS.GetCoalitionName(self:GetPreviousCoalition()), nBlu, nRed, State)
local NewState = self:GetState()
if NewState~=State then
text=text..string.format(" --> %s", NewState)