This commit is contained in:
FlightControl 2019-01-27 17:19:41 +01:00
parent 1c063ca308
commit 77bee89ea5
6 changed files with 143 additions and 120 deletions

View File

@ -74,61 +74,60 @@ function AI_A2G_BAI:onafterEngage( DefenderGroup, From, Event, To, AttackSetUnit
if DefenderGroup:IsAlive() then if DefenderGroup:IsAlive() then
local EngageAltitude = math.random( self.EngageFloorAltitude, self.EngageCeilingAltitude )
local EngageSpeed = math.random( self.EngageMinSpeed, self.EngageMaxSpeed )
-- Determine the distance to the target. -- Determine the distance to the target.
-- If it is less than 10km, then attack without a route. -- If it is less than 10km, then attack without a route.
-- Otherwise perform a route attack. -- Otherwise perform a route attack.
local DefenderCoord = DefenderGroup:GetPointVec3() local DefenderCoord = DefenderGroup:GetPointVec3()
DefenderCoord:SetY( math.random( self.EngageFloorAltitude, self.EngageCeilingAltitude ) ) -- Ground targets don't have an altitude. DefenderCoord:SetY( EngageAltitude ) -- Ground targets don't have an altitude.
local TargetCoord = self.AttackSetUnit:GetFirst():GetPointVec3() local TargetCoord = self.AttackSetUnit:GetFirst():GetPointVec3()
TargetCoord:SetY( math.random( self.EngageFloorAltitude, self.EngageCeilingAltitude ) ) -- Ground targets don't have an altitude. TargetCoord:SetY( EngageAltitude ) -- Ground targets don't have an altitude.
local TargetDistance = DefenderCoord:Get2DDistance( TargetCoord ) local TargetDistance = DefenderCoord:Get2DDistance( TargetCoord )
local EngageRoute = {} local EngageRoute = {}
local ToTargetSpeed = math.random( self.EngageMinSpeed, self.EngageMaxSpeed )
--- Calculate the target route point. --- Calculate the target route point.
local FromWP = DefenderCoord:WaypointAir( local FromWP = DefenderCoord:WaypointAir(
self.PatrolAltType or "RADIO", self.PatrolAltType or "RADIO",
POINT_VEC3.RoutePointType.TurningPoint, POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint, POINT_VEC3.RoutePointAction.TurningPoint,
ToTargetSpeed, EngageSpeed,
true true
) )
EngageRoute[#EngageRoute+1] = FromWP EngageRoute[#EngageRoute+1] = FromWP
local ToCoord = self.AttackSetUnit:GetFirst():GetCoordinate() self:SetTargetDistance( TargetCoord ) -- For RTB status check
self:SetTargetDistance( ToCoord ) -- For RTB status check
local FromEngageAngle = ToCoord:GetAngleDegrees( ToCoord:GetDirectionVec3( DefenderCoord ) ) local FromEngageAngle = TargetCoord:GetAngleDegrees( TargetCoord:GetDirectionVec3( DefenderCoord ) )
local EngageDistance = ( DefenderGroup:IsHelicopter() and 5000 ) or ( DefenderGroup:IsAirPlane() and 10000 ) local EngageDistance = ( DefenderGroup:IsHelicopter() and 5000 ) or ( DefenderGroup:IsAirPlane() and 10000 )
--- Create a route point of type air. --- Create a route point of type air.
local ToWP = ToCoord:Translate( EngageDistance, FromEngageAngle ):WaypointAir( local ToWP = TargetCoord:Translate( EngageDistance, FromEngageAngle ):WaypointAir(
self.PatrolAltType or "RADIO", self.PatrolAltType or "RADIO",
POINT_VEC3.RoutePointType.TurningPoint, POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint, POINT_VEC3.RoutePointAction.TurningPoint,
ToTargetSpeed, EngageSpeed,
true true
) )
self:F( { Angle = FromEngageAngle, ToTargetSpeed = ToTargetSpeed } )
self:F( { self.EngageMinSpeed, self.EngageMaxSpeed, ToTargetSpeed } )
EngageRoute[#EngageRoute+1] = ToWP EngageRoute[#EngageRoute+1] = ToWP
local AttackTasks = {} local AttackTasks = {}
for AttackUnitID, AttackUnit in pairs( self.AttackSetUnit:GetSet() ) do for OrderedID, AttackUnit in ipairs( self.AttackSetUnit:GetSetPerThreatLevel( 10, 0 ) ) do
if AttackUnit then
if AttackUnit:IsAlive() and AttackUnit:IsGround() then if AttackUnit:IsAlive() and AttackUnit:IsGround() then
self:T( { "Engage Unit evaluation:", AttackUnit:GetName(), AttackUnit:IsAlive(), AttackUnit:IsGround() } ) self:T( { "BAI Unit:", AttackUnit:GetName() } )
self:T( { "Eliminating Unit:", AttackUnit:GetName() } ) AttackTasks[#AttackTasks+1] = DefenderGroup:TaskAttackUnit( AttackUnit, false, false, nil, nil, EngageAltitude )
AttackTasks[#AttackTasks+1] = DefenderGroup:TaskAttackUnit( AttackUnit ) break
end
end end
end end
@ -139,6 +138,7 @@ function AI_A2G_BAI:onafterEngage( DefenderGroup, From, Event, To, AttackSetUnit
else else
DefenderGroup:OptionROEOpenFire() DefenderGroup:OptionROEOpenFire()
DefenderGroup:OptionROTEvadeFire() DefenderGroup:OptionROTEvadeFire()
DefenderGroup:OptionKeepWeaponsOnThreat()
AttackTasks[#AttackTasks+1] = DefenderGroup:TaskFunction( "AI_A2G_ENGAGE.EngageRoute", self ) AttackTasks[#AttackTasks+1] = DefenderGroup:TaskFunction( "AI_A2G_ENGAGE.EngageRoute", self )
EngageRoute[#EngageRoute].task = DefenderGroup:TaskCombo( AttackTasks ) EngageRoute[#EngageRoute].task = DefenderGroup:TaskCombo( AttackTasks )

View File

@ -74,29 +74,26 @@ function AI_A2G_CAS:onafterEngage( DefenderGroup, From, Event, To, AttackSetUnit
if DefenderGroup:IsAlive() then if DefenderGroup:IsAlive() then
-- Determine the distance to the target. local EngageAltitude = math.random( self.EngageFloorAltitude, self.EngageCeilingAltitude )
-- If it is less than 10km, then attack without a route. local EngageSpeed = math.random( self.EngageMinSpeed, self.EngageMaxSpeed )
-- Otherwise perform a route attack.
local DefenderCoord = DefenderGroup:GetPointVec3() local DefenderCoord = DefenderGroup:GetPointVec3()
DefenderCoord:SetY( math.random( self.EngageFloorAltitude, self.EngageCeilingAltitude ) ) -- Ground targets don't have an altitude. DefenderCoord:SetY( EngageAltitude ) -- Ground targets don't have an altitude.
local TargetCoord = self.AttackSetUnit:GetFirst():GetPointVec3() local TargetCoord = self.AttackSetUnit:GetFirst():GetPointVec3()
TargetCoord:SetY( math.random( self.EngageFloorAltitude, self.EngageCeilingAltitude ) ) -- Ground targets don't have an altitude. TargetCoord:SetY( EngageAltitude ) -- Ground targets don't have an altitude.
local TargetDistance = DefenderCoord:Get2DDistance( TargetCoord ) local TargetDistance = DefenderCoord:Get2DDistance( TargetCoord )
local EngageRoute = {} local EngageRoute = {}
local ToTargetSpeed = math.random( self.EngageMinSpeed, self.EngageMaxSpeed )
--- Calculate the target route point. --- Calculate the target route point.
local FromWP = DefenderCoord:WaypointAir( local FromWP = DefenderCoord:WaypointAir(
self.PatrolAltType or "RADIO", self.PatrolAltType or "RADIO",
POINT_VEC3.RoutePointType.TurningPoint, POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint, POINT_VEC3.RoutePointAction.TurningPoint,
ToTargetSpeed, EngageSpeed,
true true
) )
@ -108,25 +105,25 @@ function AI_A2G_CAS:onafterEngage( DefenderGroup, From, Event, To, AttackSetUnit
local EngageDistance = ( DefenderGroup:IsHelicopter() and 5000 ) or ( DefenderGroup:IsAirPlane() and 10000 ) local EngageDistance = ( DefenderGroup:IsHelicopter() and 5000 ) or ( DefenderGroup:IsAirPlane() and 10000 )
--- Create a route point of type air. --- Create a route point of type air.
local ToWP = TargetCoord:Translate( EngageDistance, FromEngageAngle ):WaypointAir( local ToWP = TargetCoord:Translate( EngageDistance, FromEngageAngle, true ):WaypointAir(
self.PatrolAltType or "RADIO", self.PatrolAltType or "RADIO",
POINT_VEC3.RoutePointType.TurningPoint, POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint, POINT_VEC3.RoutePointAction.TurningPoint,
ToTargetSpeed, EngageSpeed,
true true
) )
self:F( { Angle = FromEngageAngle, ToTargetSpeed = ToTargetSpeed } )
self:F( { self.EngageMinSpeed, self.EngageMaxSpeed, ToTargetSpeed } )
EngageRoute[#EngageRoute+1] = ToWP EngageRoute[#EngageRoute+1] = ToWP
local AttackTasks = {} local AttackTasks = {}
for AttackUnitID, AttackUnit in pairs( self.AttackSetUnit:GetSet() ) do for OrderedID, AttackUnit in ipairs( self.AttackSetUnit:GetSetPerThreatLevel( 10, 0 ) ) do
if AttackUnit then
if AttackUnit:IsAlive() and AttackUnit:IsGround() then if AttackUnit:IsAlive() and AttackUnit:IsGround() then
self:T( { "Eliminating Unit:", AttackUnit:GetName() } ) self:F( { "CAS Unit:", AttackUnit:GetName() } )
AttackTasks[#AttackTasks+1] = DefenderGroup:TaskAttackUnit( AttackUnit ) AttackTasks[#AttackTasks+1] = DefenderGroup:TaskAttackUnit( AttackUnit, false, false, nil, nil, EngageAltitude )
break
end
end end
end end
@ -137,6 +134,7 @@ function AI_A2G_CAS:onafterEngage( DefenderGroup, From, Event, To, AttackSetUnit
else else
DefenderGroup:OptionROEOpenFire() DefenderGroup:OptionROEOpenFire()
DefenderGroup:OptionROTEvadeFire() DefenderGroup:OptionROTEvadeFire()
DefenderGroup:OptionKeepWeaponsOnThreat()
AttackTasks[#AttackTasks+1] = DefenderGroup:TaskFunction( "AI_A2G_ENGAGE.EngageRoute", self ) AttackTasks[#AttackTasks+1] = DefenderGroup:TaskFunction( "AI_A2G_ENGAGE.EngageRoute", self )
EngageRoute[#EngageRoute].task = DefenderGroup:TaskCombo( AttackTasks ) EngageRoute[#EngageRoute].task = DefenderGroup:TaskCombo( AttackTasks )

View File

@ -129,19 +129,19 @@ function AI_A2G_SEAD:onafterEngage( DefenderGroup, From, Event, To, AttackSetUni
-- If it is less than 50km, then attack without a route. -- If it is less than 50km, then attack without a route.
-- Otherwise perform a route attack. -- Otherwise perform a route attack.
local EngageAltitude = math.random( self.EngageFloorAltitude, self.EngageCeilingAltitude )
local EngageSpeed = math.random( self.EngageMinSpeed, self.EngageMaxSpeed )
local DefenderCoord = DefenderGroup:GetPointVec3() local DefenderCoord = DefenderGroup:GetPointVec3()
DefenderCoord:SetY( math.random( self.EngageFloorAltitude, self.EngageCeilingAltitude ) ) -- Ground targets don't have an altitude. DefenderCoord:SetY( EngageAltitude ) -- Ground targets don't have an altitude.
local TargetCoord = self.AttackSetUnit:GetFirst():GetPointVec3() local TargetCoord = self.AttackSetUnit:GetFirst():GetPointVec3()
TargetCoord:SetY( math.random( self.EngageFloorAltitude, self.EngageCeilingAltitude ) ) -- Ground targets don't have an altitude. TargetCoord:SetY( EngageAltitude ) -- Ground targets don't have an altitude.
local TargetDistance = DefenderCoord:Get2DDistance( TargetCoord ) local TargetDistance = DefenderCoord:Get2DDistance( TargetCoord )
-- if TargetDistance >= 50000 then
local EngageRoute = {} local EngageRoute = {}
local ToTargetSpeed = math.random( self.EngageMinSpeed, self.EngageMaxSpeed )
--- Calculate the target route point. --- Calculate the target route point.
@ -149,41 +149,40 @@ function AI_A2G_SEAD:onafterEngage( DefenderGroup, From, Event, To, AttackSetUni
self.PatrolAltType or "RADIO", self.PatrolAltType or "RADIO",
POINT_VEC3.RoutePointType.TurningPoint, POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint, POINT_VEC3.RoutePointAction.TurningPoint,
ToTargetSpeed, EngageSpeed,
true true
) )
EngageRoute[#EngageRoute+1] = FromWP EngageRoute[#EngageRoute+1] = FromWP
local ToCoord = self.AttackSetUnit:GetFirst():GetCoordinate() self:SetTargetDistance( TargetCoord ) -- For RTB status check
self:SetTargetDistance( ToCoord ) -- For RTB status check
local FromEngageAngle = ToCoord:GetAngleDegrees( ToCoord:GetDirectionVec3( DefenderCoord ) ) local FromEngageAngle = TargetCoord:GetAngleDegrees( TargetCoord:GetDirectionVec3( DefenderCoord ) )
local EngageDistance = ( DefenderGroup:IsHelicopter() and 5000 ) or ( DefenderGroup:IsAirPlane() and 25000 ) local EngageDistance = ( DefenderGroup:IsHelicopter() and 5000 ) or ( DefenderGroup:IsAirPlane() and 25000 )
--- Create a route point of type air, 50km from the center of the attack point. --- Create a route point of type air, 50km from the center of the attack point.
local ToWP = ToCoord:Translate( EngageDistance, FromEngageAngle ):WaypointAir(
local ToWP = TargetCoord:Translate( EngageDistance, FromEngageAngle, true ):WaypointAir(
self.PatrolAltType or "RADIO", self.PatrolAltType or "RADIO",
POINT_VEC3.RoutePointType.TurningPoint, POINT_VEC3.RoutePointType.TurningPoint,
POINT_VEC3.RoutePointAction.TurningPoint, POINT_VEC3.RoutePointAction.TurningPoint,
ToTargetSpeed, EngageSpeed,
true true
) )
self:F( { Angle = FromEngageAngle, ToTargetSpeed = ToTargetSpeed } )
self:F( { self.EngageMinSpeed, self.EngageMaxSpeed, ToTargetSpeed } )
EngageRoute[#EngageRoute+1] = ToWP EngageRoute[#EngageRoute+1] = ToWP
local AttackTasks = {} local AttackTasks = {}
for AttackUnitID, AttackUnit in pairs( self.AttackSetUnit:GetSet() ) do for OrderedID, AttackUnit in ipairs( self.AttackSetUnit:GetSetPerThreatLevel( 10, 0 ) ) do
if AttackUnit then
if AttackUnit:IsAlive() and AttackUnit:IsGround() then if AttackUnit:IsAlive() and AttackUnit:IsGround() then
self:T( { "Engage Unit evaluation:", AttackUnit:GetName(), AttackUnit:IsAlive(), AttackUnit:IsGround() } )
local HasRadar = AttackUnit:HasSEAD() local HasRadar = AttackUnit:HasSEAD()
if HasRadar then if HasRadar then
self:T( { "Eliminating Unit:", AttackUnit:GetName() } ) self:F( { "SEAD Unit:", AttackUnit:GetName() } )
AttackTasks[#AttackTasks+1] = DefenderGroup:TaskAttackUnit( AttackUnit ) AttackTasks[#AttackTasks+1] = DefenderGroup:TaskAttackUnit( AttackUnit, false, false, nil, nil, EngageAltitude )
break
end
end end
end end
end end
@ -204,28 +203,6 @@ function AI_A2G_SEAD:onafterEngage( DefenderGroup, From, Event, To, AttackSetUni
DefenderGroup:Route( EngageRoute, self.TaskDelay ) DefenderGroup:Route( EngageRoute, self.TaskDelay )
-- else
-- local AttackTasks = {}
-- --local AttackUnit = self.AttackSetUnit:GetRandom() -- Wrapper.Unit#UNIT
-- for AttackUnitID, AttackUnit in pairs( self.AttackSetUnit:GetSet() ) do
-- if AttackUnit:IsAlive() and AttackUnit:IsGround() then
-- local HasRadar = AttackUnit:HasSEAD()
-- if HasRadar then
-- self:T( { "Eliminating Unit:", AttackUnit:GetName(), AttackUnit:IsAlive(), AttackUnit:IsGround() } )
-- AttackTasks[#AttackTasks+1] = DefenderGroup:TaskAttackUnit( AttackUnit )
-- AttackTasks[#AttackTasks+1] = DefenderGroup:TaskFunction( "AI_A2G_ENGAGE.EngageRoute", self )
-- end
-- end
-- end
-- local DefenderTask = DefenderGroup:TaskCombo( AttackTasks )
--
-- DefenderGroup:OptionROEOpenFire()
-- DefenderGroup:OptionROTVertical()
-- DefenderGroup:OptionKeepWeaponsOnThreat()
-- DefenderGroup:OptionRTBAmmo( Weapon.flag.AnyASM )
--
-- DefenderGroup:SetTask( DefenderTask, 0 )
-- end
end end
else else
self:E( DefenderGroupName .. ": No targets found -> Going RTB") self:E( DefenderGroupName .. ": No targets found -> Going RTB")

View File

@ -615,7 +615,7 @@ function AI_AIR:onafterRTB( AIGroup, From, Event, To )
EngageRoute[#EngageRoute+1] = ToRTBRoutePoint EngageRoute[#EngageRoute+1] = ToRTBRoutePoint
local Tasks = {} local Tasks = {}
Tasks[#Tasks+1] = AIGroup:TaskFunction( "AI_A2G_ENGAGE.RTBRoute", self ) Tasks[#Tasks+1] = AIGroup:TaskFunction( "AI_AIR.RTBRoute", self )
EngageRoute[#EngageRoute].task = AIGroup:TaskCombo( Tasks ) EngageRoute[#EngageRoute].task = AIGroup:TaskCombo( Tasks )

View File

@ -2033,6 +2033,54 @@ do -- SET_UNIT
return self return self
end end
--- Get the SET of the SET_UNIT **sorted per Threat Level**.
--
-- @param #SET_UNIT self
-- @param #number FromThreatLevel The TreatLevel to start the evaluation **From** (this must be a value between 0 and 10).
-- @param #number ToThreatLevel The TreatLevel to stop the evaluation **To** (this must be a value between 0 and 10).
-- @return #SET_UNIT self
-- @usage
--
--
function SET_UNIT:GetSetPerThreatLevel( FromThreatLevel, ToThreatLevel )
self:F2( arg )
local ThreatLevelSet = {}
if self:Count() ~= 0 then
for UnitName, UnitObject in pairs( self.Set ) do
local Unit = UnitObject -- Wrapper.Unit#UNIT
local ThreatLevel = Unit:GetThreatLevel()
ThreatLevelSet[ThreatLevel] = ThreatLevelSet[ThreatLevel] or {}
ThreatLevelSet[ThreatLevel].Set = ThreatLevelSet[ThreatLevel].Set or {}
ThreatLevelSet[ThreatLevel].Set[UnitName] = UnitObject
self:F( { ThreatLevel = ThreatLevel, ThreatLevelSet = ThreatLevelSet[ThreatLevel].Set } )
end
local OrderedPerThreatLevelSet = {}
local ThreatLevelIncrement = FromThreatLevel <= ToThreatLevel and 1 or -1
for ThreatLevel = FromThreatLevel, ToThreatLevel, ThreatLevelIncrement do
self:F( { ThreatLevel = ThreatLevel } )
local ThreatLevelItem = ThreatLevelSet[ThreatLevel]
if ThreatLevelItem then
for UnitName, UnitObject in pairs( ThreatLevelItem.Set ) do
table.insert( OrderedPerThreatLevelSet, UnitObject )
end
end
end
return OrderedPerThreatLevelSet
end
end
--- Iterate the SET_UNIT **sorted *per Threat Level** and call an interator function for each **alive** UNIT, providing the UNIT and optional parameters. --- Iterate the SET_UNIT **sorted *per Threat Level** and call an interator function for each **alive** UNIT, providing the UNIT and optional parameters.
-- --
-- @param #SET_UNIT self -- @param #SET_UNIT self

View File

@ -400,7 +400,7 @@ function CONTROLLABLE:SetTask( DCSTask, WaitTime )
local Controller = self:_GetController() local Controller = self:_GetController()
--self:I( "Before SetTask" ) --self:I( "Before SetTask" )
Controller:setTask( DCSTask ) Controller:setTask( DCSTask )
self:F( { DCSTask = DCSTask } ) self:I( { ControllableName = self:GetName(), DCSTask = DCSTask } )
else else
BASE:E( { DCSControllableName .. " is not alive anymore.", DCSTask = DCSTask } ) BASE:E( { DCSControllableName .. " is not alive anymore.", DCSTask = DCSTask } )
end end
@ -408,7 +408,7 @@ function CONTROLLABLE:SetTask( DCSTask, WaitTime )
if not WaitTime or WaitTime == 0 then if not WaitTime or WaitTime == 0 then
SetTask( self, DCSTask ) SetTask( self, DCSTask )
self:F( { DCSTask = DCSTask } ) self:I( { ControllableName = self:GetName(), DCSTask = DCSTask } )
else else
self.TaskScheduler:Schedule( self, SetTask, { DCSTask }, WaitTime ) self.TaskScheduler:Schedule( self, SetTask, { DCSTask }, WaitTime )
end end