Merge branch 'master' into funkyfranky

This commit is contained in:
funkyfranky 2017-09-03 09:48:16 +02:00
commit 84b4651cd9
4 changed files with 259 additions and 248 deletions

View File

@ -391,9 +391,9 @@ function AI_A2A_CAP:onafterEngage( AIGroup, From, Event, To, AttackSetUnit )
self.AttackSetUnit = AttackSetUnit or self.AttackSetUnit -- Core.Set#SET_UNIT self.AttackSetUnit = AttackSetUnit or self.AttackSetUnit -- Core.Set#SET_UNIT
local FirstAttackUnit = self.AttackSetUnit:GetFirst() local FirstAttackUnit = self.AttackSetUnit:GetFirst() -- Wrapper.Unit#UNIT
if FirstAttackUnit then if FirstAttackUnit and FirstAttackUnit:IsAlive() then -- If there is no attacker anymore, stop the engagement.
if AIGroup:IsAlive() then if AIGroup:IsAlive() then

View File

@ -1369,14 +1369,14 @@ do -- AI_A2A_DISPATCHER
--- ---
-- @param #AI_A2A_DISPATCHER self -- @param #AI_A2A_DISPATCHER self
-- @param Wrapper.Group#GROUP AIGroup -- @param Wrapper.Group#GROUP AIGroup
function AI_A2A_DISPATCHER:SetDefenderTaskTarget( Defender, Target ) function AI_A2A_DISPATCHER:SetDefenderTaskTarget( Defender, AttackerDetection )
local Message = "(" .. self.DefenderTasks[Defender].Type .. ") " local Message = "(" .. self.DefenderTasks[Defender].Type .. ") "
Message = Message .. Defender:GetName() Message = Message .. Defender:GetName()
Message = Message .. ( Target and ( " target " .. Target.Index .. " [" .. Target.Set:Count() .. "]" ) ) or "" Message = Message .. ( AttackerDetection and ( " target " .. AttackerDetection.Index .. " [" .. AttackerDetection.Set:Count() .. "]" ) ) or ""
self:F( { Target = Message } ) self:F( { AttackerDetection = Message } )
if Target then if AttackerDetection then
self.DefenderTasks[Defender].Target = Target self.DefenderTasks[Defender].Target = AttackerDetection
end end
return self return self
end end
@ -2510,20 +2510,20 @@ do -- AI_A2A_DISPATCHER
--- ---
-- @param #AI_A2A_DISPATCHER self -- @param #AI_A2A_DISPATCHER self
function AI_A2A_DISPATCHER:CountDefendersEngaged( Target ) function AI_A2A_DISPATCHER:CountDefendersEngaged( AttackerDetection )
-- First, count the active AIGroups Units, targetting the DetectedSet -- First, count the active AIGroups Units, targetting the DetectedSet
local AIUnitCount = 0 local AIUnitCount = 0
self:E( "Counting Defenders Engaged for Attacker:" ) self:E( "Counting Defenders Engaged for Attacker:" )
local DetectedSet = Target.Set local DetectedSet = AttackerDetection.Set
DetectedSet:Flush() DetectedSet:Flush()
local DefenderTasks = self:GetDefenderTasks() local DefenderTasks = self:GetDefenderTasks()
for AIGroup, DefenderTask in pairs( DefenderTasks ) do for AIGroup, DefenderTask in pairs( DefenderTasks ) do
local AIGroup = AIGroup -- Wrapper.Group#GROUP local AIGroup = AIGroup -- Wrapper.Group#GROUP
local DefenderTask = self:GetDefenderTaskTarget( AIGroup ) local DefenderTask = self:GetDefenderTaskTarget( AIGroup )
if DefenderTask and DefenderTask.Index == Target.Index then if DefenderTask and DefenderTask.Index == AttackerDetection.Index then
AIUnitCount = AIUnitCount + AIGroup:GetSize() AIUnitCount = AIUnitCount + AIGroup:GetSize()
self:E( "Defender Group Name: " .. AIGroup:GetName() .. ", Size: " .. AIGroup:GetSize() ) self:E( "Defender Group Name: " .. AIGroup:GetName() .. ", Size: " .. AIGroup:GetSize() )
end end
@ -2534,18 +2534,18 @@ do -- AI_A2A_DISPATCHER
--- ---
-- @param #AI_A2A_DISPATCHER self -- @param #AI_A2A_DISPATCHER self
function AI_A2A_DISPATCHER:CountDefendersToBeEngaged( DetectedItem, DefenderCount ) function AI_A2A_DISPATCHER:CountDefendersToBeEngaged( AttackerDetection, DefenderCount )
local Friendlies = nil local Friendlies = nil
local DetectedSet = DetectedItem.Set local AttackerSet = AttackerDetection.Set
local DetectedCount = DetectedSet:Count() local AttackerCount = AttackerSet:Count()
local AIFriendlies = self:GetAIFriendliesNearBy( DetectedItem ) local DefenderFriendlies = self:GetAIFriendliesNearBy( AttackerDetection )
for FriendlyDistance, AIFriendly in UTILS.spairs( AIFriendlies or {} ) do for FriendlyDistance, AIFriendly in UTILS.spairs( DefenderFriendlies or {} ) do
-- We only allow to ENGAGE targets as long as the Units on both sides are balanced. -- We only allow to ENGAGE targets as long as the Units on both sides are balanced.
if DetectedCount > DefenderCount then if AttackerCount > DefenderCount then
local Friendly = AIFriendly:GetGroup() -- Wrapper.Group#GROUP local Friendly = AIFriendly:GetGroup() -- Wrapper.Group#GROUP
if Friendly and Friendly:IsAlive() then if Friendly and Friendly:IsAlive() then
-- Ok, so we have a friendly near the potential target. -- Ok, so we have a friendly near the potential target.
@ -2554,7 +2554,7 @@ do -- AI_A2A_DISPATCHER
if DefenderTask then if DefenderTask then
-- The Task should be CAP or GCI -- The Task should be CAP or GCI
if DefenderTask.Type == "CAP" or DefenderTask.Type == "GCI" then if DefenderTask.Type == "CAP" or DefenderTask.Type == "GCI" then
-- If there is no target, then add the AIGroup to the ResultAIGroups for Engagement to the TargetSet -- If there is no target, then add the AIGroup to the ResultAIGroups for Engagement to the AttackerSet
if DefenderTask.Target == nil then if DefenderTask.Target == nil then
if DefenderTask.Fsm:Is( "Returning" ) if DefenderTask.Fsm:Is( "Returning" )
or DefenderTask.Fsm:Is( "Patrolling" ) then or DefenderTask.Fsm:Is( "Patrolling" ) then
@ -2650,16 +2650,16 @@ do -- AI_A2A_DISPATCHER
--- ---
-- @param #AI_A2A_DISPATCHER self -- @param #AI_A2A_DISPATCHER self
function AI_A2A_DISPATCHER:onafterENGAGE( From, Event, To, Target, Defenders ) function AI_A2A_DISPATCHER:onafterENGAGE( From, Event, To, AttackerDetection, Defenders )
if Defenders then if Defenders then
for DefenderID, Defender in pairs( Defenders ) do for DefenderID, Defender in pairs( Defenders ) do
local Fsm = self:GetDefenderTaskFsm( Defender ) local Fsm = self:GetDefenderTaskFsm( Defender )
Fsm:__Engage( 1, Target.Set ) -- Engage on the TargetSetUnit Fsm:__Engage( 1, AttackerDetection.Set ) -- Engage on the TargetSetUnit
self:SetDefenderTaskTarget( Defender, Target ) self:SetDefenderTaskTarget( Defender, AttackerDetection )
end end
end end
@ -2667,32 +2667,35 @@ do -- AI_A2A_DISPATCHER
--- ---
-- @param #AI_A2A_DISPATCHER self -- @param #AI_A2A_DISPATCHER self
function AI_A2A_DISPATCHER:onafterGCI( From, Event, To, DetectedItem, DefendersMissing, Friendlies ) function AI_A2A_DISPATCHER:onafterGCI( From, Event, To, AttackerDetection, DefendersMissing, DefenderFriendlies )
self:F( { From, Event, To, DetectedItem.Index, DefendersMissing, Friendlies } ) self:F( { From, Event, To, AttackerDetection.Index, DefendersMissing, DefenderFriendlies } )
local AttackerSet = DetectedItem.Set local AttackerSet = AttackerDetection.Set
local AttackerUnit = AttackerSet:GetFirst()
if AttackerUnit and AttackerUnit:IsAlive() then
local AttackerCount = AttackerSet:Count() local AttackerCount = AttackerSet:Count()
local DefendersCount = 0 local DefenderCount = 0
for DefenderID, AIGroup in pairs( Friendlies or {} ) do for DefenderID, DefenderGroup in pairs( DefenderFriendlies or {} ) do
local Fsm = self:GetDefenderTaskFsm( AIGroup ) local Fsm = self:GetDefenderTaskFsm( DefenderGroup )
Fsm:__Engage( 1, AttackerSet ) -- Engage on the TargetSetUnit Fsm:__Engage( 1, AttackerSet ) -- Engage on the TargetSetUnit
self:SetDefenderTaskTarget( AIGroup, DetectedItem ) self:SetDefenderTaskTarget( DefenderGroup, AttackerDetection )
DefendersCount = DefendersCount + AIGroup:GetSize() DefenderCount = DefenderCount + DefenderGroup:GetSize()
end end
DefendersCount = DefendersMissing DefenderCount = DefendersMissing
local ClosestDistance = 0 local ClosestDistance = 0
local ClosestDefenderSquadronName = nil local ClosestDefenderSquadronName = nil
local BreakLoop = false local BreakLoop = false
while( DefendersCount > 0 and not BreakLoop ) do while( DefenderCount > 0 and not BreakLoop ) do
self:F( { DefenderSquadrons = self.DefenderSquadrons } ) self:F( { DefenderSquadrons = self.DefenderSquadrons } )
for SquadronName, DefenderSquadron in pairs( self.DefenderSquadrons or {} ) do for SquadronName, DefenderSquadron in pairs( self.DefenderSquadrons or {} ) do
self:F( { GCI = DefenderSquadron.Gci } ) self:F( { GCI = DefenderSquadron.Gci } )
@ -2700,18 +2703,19 @@ do -- AI_A2A_DISPATCHER
self:F( { DefenderSquadron } ) self:F( { DefenderSquadron } )
local SpawnCoord = DefenderSquadron.Airbase:GetCoordinate() -- Core.Point#COORDINATE local SpawnCoord = DefenderSquadron.Airbase:GetCoordinate() -- Core.Point#COORDINATE
--local TargetCoord = AttackerSet:GetFirst():GetCoordinate() local AttackerCoord = AttackerUnit:GetCoordinate()
local InterceptCoord = DetectedItem.InterceptCoord local InterceptCoord = AttackerDetection.InterceptCoord
self:F({InterceptCoord = InterceptCoord}) self:F({InterceptCoord = InterceptCoord})
if InterceptCoord then if InterceptCoord then
local Distance = SpawnCoord:Get2DDistance( InterceptCoord ) local InterceptDistance = SpawnCoord:Get2DDistance( InterceptCoord )
self:F( { Distance = Distance, InterceptCoord = InterceptCoord } ) local AirbaseDistance = SpawnCoord:Get2DDistance( AttackerCoord )
self:F( { InterceptDistance = InterceptDistance, AirbaseDistance = AirbaseDistance, InterceptCoord = InterceptCoord } )
if ClosestDistance == 0 or Distance < ClosestDistance then if ClosestDistance == 0 or InterceptDistance < ClosestDistance then
-- Only intercept if the distance to target is smaller or equal to the GciRadius limit. -- Only intercept if the distance to target is smaller or equal to the GciRadius limit.
if Distance <= self.GciRadius then if AirbaseDistance <= self.GciRadius then
ClosestDistance = Distance ClosestDistance = InterceptDistance
ClosestDefenderSquadronName = SquadronName ClosestDefenderSquadronName = SquadronName
end end
end end
@ -2731,11 +2735,11 @@ do -- AI_A2A_DISPATCHER
local DefenderOverhead = DefenderSquadron.Overhead or self.DefenderDefault.Overhead local DefenderOverhead = DefenderSquadron.Overhead or self.DefenderDefault.Overhead
local DefenderGrouping = DefenderSquadron.Grouping or self.DefenderDefault.Grouping local DefenderGrouping = DefenderSquadron.Grouping or self.DefenderDefault.Grouping
local DefendersNeeded = math.ceil( DefendersCount * DefenderOverhead ) local DefendersNeeded = math.ceil( DefenderCount * DefenderOverhead )
self:F( { DefaultOverhead = self.DefenderDefault.Overhead, Overhead = DefenderOverhead } ) self:F( { DefaultOverhead = self.DefenderDefault.Overhead, Overhead = DefenderOverhead } )
self:F( { DefaultGrouping = self.DefenderDefault.Grouping, Grouping = DefenderGrouping } ) self:F( { DefaultGrouping = self.DefenderDefault.Grouping, Grouping = DefenderGrouping } )
self:F( { DefendersCount = DefendersCount, DefendersNeeded = DefendersNeeded } ) self:F( { DefendersCount = DefenderCount, DefendersNeeded = DefendersNeeded } )
while ( DefendersNeeded > 0 ) do while ( DefendersNeeded > 0 ) do
@ -2757,7 +2761,7 @@ do -- AI_A2A_DISPATCHER
if DefenderGCI then if DefenderGCI then
DefendersCount = DefendersCount - DefenderGrouping DefenderCount = DefenderCount - DefenderGrouping
local Fsm = AI_A2A_GCI:New( DefenderGCI, Gci.EngageMinSpeed, Gci.EngageMaxSpeed ) local Fsm = AI_A2A_GCI:New( DefenderGCI, Gci.EngageMinSpeed, Gci.EngageMaxSpeed )
Fsm:SetDispatcher( self ) Fsm:SetDispatcher( self )
@ -2766,10 +2770,10 @@ do -- AI_A2A_DISPATCHER
Fsm:SetDamageThreshold( self.DefenderDefault.DamageThreshold ) Fsm:SetDamageThreshold( self.DefenderDefault.DamageThreshold )
Fsm:SetDisengageRadius( self.DisengageRadius ) Fsm:SetDisengageRadius( self.DisengageRadius )
Fsm:Start() Fsm:Start()
Fsm:__Engage( 2, DetectedItem.Set ) -- Engage on the TargetSetUnit Fsm:__Engage( 2, AttackerDetection.Set ) -- Engage on the TargetSetUnit
self:SetDefenderTask( ClosestDefenderSquadronName, DefenderGCI, "GCI", Fsm, DetectedItem ) self:SetDefenderTask( ClosestDefenderSquadronName, DefenderGCI, "GCI", Fsm, AttackerDetection )
function Fsm:onafterRTB( Defender, From, Event, To ) function Fsm:onafterRTB( Defender, From, Event, To )
@ -2825,6 +2829,7 @@ do -- AI_A2A_DISPATCHER
break break
end end
end -- if DefenderSquadron then end -- if DefenderSquadron then
end -- if AttackerUnit
end end

View File

@ -360,7 +360,7 @@ function AI_A2A_GCI:onafterEngage( AIGroup, From, Event, To, AttackSetUnit )
local FirstAttackUnit = self.AttackSetUnit:GetFirst() local FirstAttackUnit = self.AttackSetUnit:GetFirst()
if FirstAttackUnit then if FirstAttackUnit and FirstAttackUnit:IsAlive() then
if AIGroup:IsAlive() then if AIGroup:IsAlive() then
@ -368,7 +368,6 @@ function AI_A2A_GCI:onafterEngage( AIGroup, From, Event, To, AttackSetUnit )
local CurrentCoord = AIGroup:GetCoordinate() local CurrentCoord = AIGroup:GetCoordinate()
--- Calculate the target route point. --- Calculate the target route point.
local CurrentCoord = AIGroup:GetCoordinate() local CurrentCoord = AIGroup:GetCoordinate()

View File

@ -990,6 +990,8 @@ do -- DESIGNATE
function DESIGNATE:onafterLaseOn( From, Event, To, Index, Duration, LaserCode ) function DESIGNATE:onafterLaseOn( From, Event, To, Index, Duration, LaserCode )
self.Designating[Index] = "Laser" self.Designating[Index] = "Laser"
self.LaseStart = timer.getTime()
self.LaseDuration = Duration
self:__Lasing( -1, Index, Duration, LaserCode ) self:__Lasing( -1, Index, Duration, LaserCode )
end end
@ -1038,6 +1040,7 @@ do -- DESIGNATE
end end
end end
if self.AutoLase or ( not self.AutoLase and ( self.LaseStart + Duration >= timer.getTime() ) ) then
TargetSetUnit:ForEachUnitPerThreatLevel( 10, 0, TargetSetUnit:ForEachUnitPerThreatLevel( 10, 0,
--- @param Wrapper.Unit#UNIT SmokeUnit --- @param Wrapper.Unit#UNIT SmokeUnit
@ -1147,10 +1150,14 @@ do -- DESIGNATE
self.CC:GetPositionable():MessageToSetGroup( "Marking " .. MarkingCount .. " x " .. MarkedTypesText .. " with lasers " .. MarkedLaserCodesText .. ".", 5, self.AttackSet, self.DesignateName ) self.CC:GetPositionable():MessageToSetGroup( "Marking " .. MarkingCount .. " x " .. MarkedTypesText .. " with lasers " .. MarkedLaserCodesText .. ".", 5, self.AttackSet, self.DesignateName )
end end
self:__Lasing( -30, Index, Duration ) self:__Lasing( -30, Index, Duration, LaserCodeRequested )
self:SetDesignateMenu() self:SetDesignateMenu()
else
self:__LaseOff( 1 )
end
end end
--- ---