Merge pull request #678 from FlightControl-Master/Fixes-for-AI_A2A_DISPATCHER

Fixes for ai a2a dispatcher
This commit is contained in:
Sven Van de Velde 2017-09-08 10:35:57 +02:00 committed by GitHub
commit 8b26f7d975
2 changed files with 21 additions and 14 deletions

View File

@ -1239,9 +1239,11 @@ do -- DETECTION_BASE
DetectedItem.FriendliesNearBy = nil 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 = { local SphereSearch = {
id = world.VolumeType.SPHERE, id = world.VolumeType.SPHERE,
@ -1336,9 +1338,7 @@ do -- DETECTION_BASE
DetectedItem.FriendliesNearBy = DetectedItem.FriendliesNearBy or {} DetectedItem.FriendliesNearBy = DetectedItem.FriendliesNearBy or {}
DetectedItem.FriendliesNearBy[PlayerUnitName] = PlayerUnit DetectedItem.FriendliesNearBy[PlayerUnitName] = PlayerUnit
local CenterCoord = DetectedUnit:GetCoordinate() local Distance = DetectedUnitCoord:Get2DDistance( PlayerUnit:GetCoordinate() )
local Distance = CenterCoord:Get2DDistance( PlayerUnit:GetCoordinate() )
DetectedItem.FriendliesDistance = DetectedItem.FriendliesDistance or {} DetectedItem.FriendliesDistance = DetectedItem.FriendliesDistance or {}
DetectedItem.FriendliesDistance[Distance] = PlayerUnit 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 :-) local DistanceRecce = 1000000000 -- Units are not further than 1000000 km away from an area :-)
for RecceGroupName, RecceGroup in pairs( self.DetectionSetGroup:GetSet() ) do for RecceGroupName, RecceGroup in pairs( self.DetectionSetGroup:GetSet() ) do
for RecceUnit, RecceUnit in pairs( RecceGroup:GetUnits() ) do if RecceGroup and RecceGroup:IsAlive() then
if RecceUnit:IsActive() then for RecceUnit, RecceUnit in pairs( RecceGroup:GetUnits() ) do
local RecceUnitCoord = RecceUnit:GetCoordinate() if RecceUnit:IsActive() then
local Distance = RecceUnitCoord:Get2DDistance( self:GetDetectedItemCoordinate( DetectedItem.Index ) ) local RecceUnitCoord = RecceUnit:GetCoordinate()
if Distance < DistanceRecce then local Distance = RecceUnitCoord:Get2DDistance( self:GetDetectedItemCoordinate( DetectedItem.Index ) )
DistanceRecce = Distance if Distance < DistanceRecce then
NearestRecce = RecceUnit DistanceRecce = Distance
NearestRecce = RecceUnit
end
end end
end end
end end

View File

@ -368,14 +368,19 @@ function CONTROLLABLE:SetTask( DCSTask, WaitTime )
if DCSControllable then 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. -- 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. -- Therefore we schedule the functions to set the mission and options for the Controllable.
-- Controller.setTask( Controller, DCSTask ) -- Controller.setTask( Controller, DCSTask )
local function SetTask( Controller, DCSTask ) local function SetTask( Controller, DCSTask )
local Controller = self:_GetController() if self and self:IsAlive() then
Controller:setTask( DCSTask ) local Controller = self:_GetController()
Controller:setTask( DCSTask )
else
BASE:E( DCSControllableName .. " is not alive anymore. Cannot set DCSTask " .. DCSTask )
end
end end
if not WaitTime or WaitTime == 0 then if not WaitTime or WaitTime == 0 then