Merge branch 'master' into funkyfranky

This commit is contained in:
funkyfranky 2017-09-09 18:26:22 +02:00
commit 7a23115cf9
3 changed files with 41 additions and 23 deletions

View File

@ -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 )

View File

@ -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
@ -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

View File

@ -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
BASE:E( DCSControllableName .. " is not alive anymore. Cannot set DCSTask " .. DCSTask )
end
end
if not WaitTime or WaitTime == 0 then