- Introduced pcall to getName() of detected objects. Found a problem with an object of ID 5,000,031
This commit is contained in:
Frank 2021-10-06 22:03:02 +02:00
parent 653dfe82fa
commit f6dce02203
5 changed files with 40 additions and 57 deletions

View File

@ -1396,7 +1396,7 @@ function CHIEF:CheckTargetQueue()
else
text=text..string.format(", NO mission yet")
end
self:I(self.lid..text)
self:T2(self.lid..text)
-- Check that target is alive and not already a mission has been assigned.
if isAlive and isThreat and isImportant and not target.mission then
@ -1485,14 +1485,14 @@ function CHIEF:CheckTargetQueue()
local mp=_mp --#CHIEF.MissionPerformance
-- Debug info.
self:I(self.lid..string.format("Recruiting assets for mission type %s [performance=%d] of target %s", mp.MissionType, mp.Performance, target:GetName()))
self:T2(self.lid..string.format("Recruiting assets for mission type %s [performance=%d] of target %s", mp.MissionType, mp.Performance, target:GetName()))
-- Recruit assets.
local recruited, assets, legions=self:RecruitAssetsForTarget(target, mp.MissionType, NassetsMin, NassetsMax)
if recruited then
self:I(self.lid..string.format("Recruited %d assets for mission type %s [performance=%d] of target %s", #assets, mp.MissionType, mp.Performance, target:GetName()))
self:T(self.lid..string.format("Recruited %d assets for mission type %s [performance=%d] of target %s", #assets, mp.MissionType, mp.Performance, target:GetName()))
-- Create a mission.
mission=AUFTRAG:NewFromTarget(target, mp.MissionType)
@ -1509,7 +1509,7 @@ function CHIEF:CheckTargetQueue()
break
end
else
self:I(self.lid..string.format("Could NOT recruit assets for mission type %s [performance=%d] of target %s", mp.MissionType, mp.Performance, target:GetName()))
self:T(self.lid..string.format("Could NOT recruit assets for mission type %s [performance=%d] of target %s", mp.MissionType, mp.Performance, target:GetName()))
end
end
end

View File

@ -132,7 +132,7 @@ function COHORT:New(TemplateGroupName, Ngroups, CohortName)
-- Mission range depends on
if self.category==Group.Category.AIRPLANE then
self:SetMissionRange(150)
self:SetMissionRange(200)
elseif self.category==Group.Category.HELICOPTER then
self:SetMissionRange(150)
elseif self.category==Group.Category.GROUND then

View File

@ -2172,7 +2172,7 @@ function FLIGHTGROUP:_CheckGroupDone(delay, waittime)
elseif destbase then
if self.currbase and self.currbase.AirbaseName==destbase.AirbaseName and self:IsParking() then
self:T(self.lid.."Passed Final WP and No current and/or future missions/tasks/transports AND parking at destination airbase ==> Arrived!")
self:__Arrived(0.1)
self:Arrived()
else
self:T(self.lid.."Passed Final WP and No current and/or future missions/tasks/transports ==> RTB!")
self:__RTB(-0.1, destbase)
@ -2818,6 +2818,7 @@ end
-- @param #string To To state.
function FLIGHTGROUP:onafterFuelLow(From, Event, To)
-- Current min fuel.
local fuel=self:GetFuelMin() or 0
-- Debug message.
@ -2830,52 +2831,27 @@ function FLIGHTGROUP:onafterFuelLow(From, Event, To)
-- Back to destination or home.
local airbase=self.destbase or self.homebase
local airwing=self:GetAirWing()
if airwing then
-- Get closest tanker from airwing that can refuel this flight.
local tanker=airwing:GetTankerForFlight(self)
if tanker and self.fuellowrefuel then
-- Debug message.
self:I(self.lid..string.format("Send to refuel at tanker %s", tanker.flightgroup:GetName()))
-- Get a coordinate towards the tanker.
local coordinate=self:GetCoordinate():GetIntermediateCoordinate(tanker.flightgroup:GetCoordinate(), 0.75)
-- Send flight to tanker with refueling task.
self:Refuel(coordinate)
else
if airbase and self.fuellowrtb then
self:RTB(airbase)
--TODO: RTZ
end
end
else
if self.fuellowrefuel and self.refueltype then
-- Find nearest tanker within 50 NM.
local tanker=self:FindNearestTanker(50)
if tanker then
-- Debug message.
self:I(self.lid..string.format("Send to refuel at tanker %s", tanker:GetName()))
-- Get a coordinate towards the tanker.
local coordinate=self:GetCoordinate():GetIntermediateCoordinate(tanker:GetCoordinate(), 0.75)
-- Trigger refuel even.
self:Refuel(coordinate)
return
end
end
-- Send back to airbase.
if airbase and self.fuellowrtb then
self:RTB(airbase)
--TODO: RTZ
@ -2883,8 +2859,6 @@ function FLIGHTGROUP:onafterFuelLow(From, Event, To)
end
end
--- On after "FuelCritical" event.
-- @param #FLIGHTGROUP self
-- @param #string From From state.

View File

@ -804,17 +804,29 @@ function INTEL:GetDetectedUnits(Unit, DetectedUnits, RecceDetecting, DetectVisua
for DetectionObjectID, Detection in pairs(detectedtargets or {}) do
local DetectedObject=Detection.object -- DCS#Object
-- NOTE: Got an object that exists but when trying UNIT:Find() the DCS getName() function failed. ID of the object was 5,000,031
if DetectedObject and DetectedObject:isExist() and DetectedObject.id_<50000000 then
local unit=UNIT:Find(DetectedObject)
-- Protected call to get the name of the object.
local status,name = pcall(
function()
local name=DetectedObject:getName()
return name
end)
if status then
local unit=UNIT:FindByName(name)
if unit and unit:IsAlive() then
DetectedUnits[name]=unit
RecceDetecting[name]=reccename
self:T(string.format("Unit %s detect by %s", name, reccename))
end
local unitname=unit:GetName()
DetectedUnits[unitname]=unit
RecceDetecting[unitname]=reccename
self:T(string.format("Unit %s detect by %s", unitname, reccename))
else
-- Warning!
self:T(self.lid..string.format("WARNING: Could not get name of detected object ID=%s! Detected by %s", DetectedObject.id_, reccename))
end
end
end

View File

@ -6008,10 +6008,7 @@ function OPSGROUP:onafterDead(From, Event, To)
self.cohort:DelGroup(self.groupname)
end
else
if self.airwing then
-- Not all assets were destroyed (despawn) ==> Add asset back to airwing.
--self.airwing:AddAsset(self.group, 1)
end
-- Not all assets were destroyed (despawn) ==> Add asset back to legion?
end
-- Stop in a sec.