From 6959f50777c55c4bd02c195255935af157a85763 Mon Sep 17 00:00:00 2001 From: FlightControl_Master Date: Fri, 8 Sep 2017 10:19:48 +0200 Subject: [PATCH 1/4] First fixes --- Moose Development/Moose/Functional/Detection.lua | 10 +++++----- Moose Development/Moose/Wrapper/Controllable.lua | 9 +++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Moose Development/Moose/Functional/Detection.lua b/Moose Development/Moose/Functional/Detection.lua index 2b67e54dd..93456ffc2 100644 --- a/Moose Development/Moose/Functional/Detection.lua +++ b/Moose Development/Moose/Functional/Detection.lua @@ -1239,9 +1239,11 @@ do -- DETECTION_BASE DetectedItem.FriendliesNearBy = nil - if DetectedUnit then + -- We need to ensure that the DetectedUnit is alive! + if DetectedUnit and DetectedUnit:IsAlive() then - local InterceptCoord = ReportGroupData.InterceptCoord or DetectedUnit:GetCoordinate() + local DetectedUnitCoord = DetectedUnit:GetCoordinate() + local InterceptCoord = ReportGroupData.InterceptCoord or DetectedUnitCoord local SphereSearch = { id = world.VolumeType.SPHERE, @@ -1336,9 +1338,7 @@ do -- DETECTION_BASE DetectedItem.FriendliesNearBy = DetectedItem.FriendliesNearBy or {} DetectedItem.FriendliesNearBy[PlayerUnitName] = PlayerUnit - local CenterCoord = DetectedUnit:GetCoordinate() - - local Distance = CenterCoord:Get2DDistance( PlayerUnit:GetCoordinate() ) + local Distance = DetectedUnitCoord:Get2DDistance( PlayerUnit:GetCoordinate() ) DetectedItem.FriendliesDistance = DetectedItem.FriendliesDistance or {} DetectedItem.FriendliesDistance[Distance] = PlayerUnit diff --git a/Moose Development/Moose/Wrapper/Controllable.lua b/Moose Development/Moose/Wrapper/Controllable.lua index 8d3a037a1..b6de2d519 100644 --- a/Moose Development/Moose/Wrapper/Controllable.lua +++ b/Moose Development/Moose/Wrapper/Controllable.lua @@ -368,14 +368,19 @@ function CONTROLLABLE:SetTask( DCSTask, WaitTime ) if DCSControllable then + local DCSControllableName = self:GetName() -- When a controllable SPAWNs, it takes about a second to get the controllable in the simulator. Setting tasks to unspawned controllables provides unexpected results. -- Therefore we schedule the functions to set the mission and options for the Controllable. -- Controller.setTask( Controller, DCSTask ) local function SetTask( Controller, DCSTask ) - local Controller = self:_GetController() - Controller:setTask( DCSTask ) + if self and self:IsAlive() then + local Controller = self:_GetController() + Controller:setTask( DCSTask ) + else + error( DCSControllableName .. " is not alive anymore. Cannot set DCSTask " .. DCSTask ) + end end if not WaitTime or WaitTime == 0 then From f628e720a98342aaf8b6ec967c60b714db611075 Mon Sep 17 00:00:00 2001 From: FlightControl_Master Date: Fri, 8 Sep 2017 10:27:31 +0200 Subject: [PATCH 2/4] Check if RecceGroup is alive before iterating... --- Moose Development/Moose/Functional/Detection.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Moose Development/Moose/Functional/Detection.lua b/Moose Development/Moose/Functional/Detection.lua index 93456ffc2..916b10f85 100644 --- a/Moose Development/Moose/Functional/Detection.lua +++ b/Moose Development/Moose/Functional/Detection.lua @@ -2453,13 +2453,15 @@ do -- DETECTION_AREAS local DistanceRecce = 1000000000 -- Units are not further than 1000000 km away from an area :-) for RecceGroupName, RecceGroup in pairs( self.DetectionSetGroup:GetSet() ) do - for RecceUnit, RecceUnit in pairs( RecceGroup:GetUnits() ) do - if RecceUnit:IsActive() then - local RecceUnitCoord = RecceUnit:GetCoordinate() - local Distance = RecceUnitCoord:Get2DDistance( self:GetDetectedItemCoordinate( DetectedItem.Index ) ) - if Distance < DistanceRecce then - DistanceRecce = Distance - NearestRecce = RecceUnit + if RecceGroup and RecceGroup:IsAlive() then + for RecceUnit, RecceUnit in pairs( RecceGroup:GetUnits() ) do + if RecceUnit:IsActive() then + local RecceUnitCoord = RecceUnit:GetCoordinate() + local Distance = RecceUnitCoord:Get2DDistance( self:GetDetectedItemCoordinate( DetectedItem.Index ) ) + if Distance < DistanceRecce then + DistanceRecce = Distance + NearestRecce = RecceUnit + end end end end From fcce06c3f1a8d00a8c66b59917595b771eb30645 Mon Sep 17 00:00:00 2001 From: FlightControl_Master Date: Fri, 8 Sep 2017 10:30:52 +0200 Subject: [PATCH 3/4] Error handling --- Moose Development/Moose/Wrapper/Controllable.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Moose Development/Moose/Wrapper/Controllable.lua b/Moose Development/Moose/Wrapper/Controllable.lua index b6de2d519..bc15ea795 100644 --- a/Moose Development/Moose/Wrapper/Controllable.lua +++ b/Moose Development/Moose/Wrapper/Controllable.lua @@ -379,7 +379,7 @@ function CONTROLLABLE:SetTask( DCSTask, WaitTime ) local Controller = self:_GetController() Controller:setTask( DCSTask ) else - error( DCSControllableName .. " is not alive anymore. Cannot set DCSTask " .. DCSTask ) + BASE:E( DCSControllableName .. " is not alive anymore. Cannot set DCSTask " .. DCSTask ) end end From 1fee3eb7a820c8a8d37696c2d6c4080df8a10f33 Mon Sep 17 00:00:00 2001 From: FlightControl_Master Date: Fri, 8 Sep 2017 14:04:33 +0200 Subject: [PATCH 4/4] Fixed overhead problems --- .../Moose/AI/AI_A2A_Dispatcher.lua | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/Moose Development/Moose/AI/AI_A2A_Dispatcher.lua b/Moose Development/Moose/AI/AI_A2A_Dispatcher.lua index f479a2170..4b5c1496e 100644 --- a/Moose Development/Moose/AI/AI_A2A_Dispatcher.lua +++ b/Moose Development/Moose/AI/AI_A2A_Dispatcher.lua @@ -1304,6 +1304,12 @@ do -- AI_A2A_DISPATCHER function AI_A2A_DISPATCHER:GetDefenderTaskTarget( Defender ) return self:GetDefenderTask( Defender ).Target end + + --- + -- @param #AI_A2A_DISPATCHER self + function AI_A2A_DISPATCHER:GetDefenderTaskSquadronName( Defender ) + return self:GetDefenderTask( Defender ).SquadronName + end --- -- @param #AI_A2A_DISPATCHER self @@ -2513,23 +2519,28 @@ do -- AI_A2A_DISPATCHER function AI_A2A_DISPATCHER:CountDefendersEngaged( AttackerDetection ) -- First, count the active AIGroups Units, targetting the DetectedSet - local AIUnitCount = 0 + local DefenderCount = 0 self:E( "Counting Defenders Engaged for Attacker:" ) local DetectedSet = AttackerDetection.Set DetectedSet:Flush() local DefenderTasks = self:GetDefenderTasks() - for AIGroup, DefenderTask in pairs( DefenderTasks ) do - local AIGroup = AIGroup -- Wrapper.Group#GROUP - local DefenderTask = self:GetDefenderTaskTarget( AIGroup ) - if DefenderTask and DefenderTask.Index == AttackerDetection.Index then - AIUnitCount = AIUnitCount + AIGroup:GetSize() - self:E( "Defender Group Name: " .. AIGroup:GetName() .. ", Size: " .. AIGroup:GetSize() ) + for Defender, DefenderTask in pairs( DefenderTasks ) do + local Defender = Defender -- Wrapper.Group#GROUP + local DefenderTaskTarget = DefenderTask.Target + local DefenderSquadronName = DefenderTask.SquadronName + if DefenderTaskTarget and DefenderTaskTarget.Index == AttackerDetection.Index then + local Squadron = self:GetSquadron( DefenderSquadronName ) + local SquadronOverhead = Squadron.Overhead or self.DefenderDefault.Overhead + DefenderCount = DefenderCount + Defender:GetSize() / SquadronOverhead + self:E( "Defender Group Name: " .. Defender:GetName() .. ", Size: " .. Defender:GetSize() ) end end - return AIUnitCount + self:F( { DefenderCount = DefenderCount } ) + + return DefenderCount end --- @@ -2766,7 +2777,7 @@ do -- AI_A2A_DISPATCHER if DefenderGCI then - DefenderCount = DefenderCount - DefenderGrouping + DefenderCount = DefenderCount - DefenderGrouping / DefenderOverhead local Fsm = AI_A2A_GCI:New( DefenderGCI, Gci.EngageMinSpeed, Gci.EngageMaxSpeed ) Fsm:SetDispatcher( self )