- 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 else
text=text..string.format(", NO mission yet") text=text..string.format(", NO mission yet")
end end
self:I(self.lid..text) self:T2(self.lid..text)
-- Check that target is alive and not already a mission has been assigned. -- Check that target is alive and not already a mission has been assigned.
if isAlive and isThreat and isImportant and not target.mission then if isAlive and isThreat and isImportant and not target.mission then
@ -1485,14 +1485,14 @@ function CHIEF:CheckTargetQueue()
local mp=_mp --#CHIEF.MissionPerformance local mp=_mp --#CHIEF.MissionPerformance
-- Debug info. -- 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. -- Recruit assets.
local recruited, assets, legions=self:RecruitAssetsForTarget(target, mp.MissionType, NassetsMin, NassetsMax) local recruited, assets, legions=self:RecruitAssetsForTarget(target, mp.MissionType, NassetsMin, NassetsMax)
if recruited then 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. -- Create a mission.
mission=AUFTRAG:NewFromTarget(target, mp.MissionType) mission=AUFTRAG:NewFromTarget(target, mp.MissionType)
@ -1509,7 +1509,7 @@ function CHIEF:CheckTargetQueue()
break break
end end
else 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 end
end end

View File

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

View File

@ -2172,7 +2172,7 @@ function FLIGHTGROUP:_CheckGroupDone(delay, waittime)
elseif destbase then elseif destbase then
if self.currbase and self.currbase.AirbaseName==destbase.AirbaseName and self:IsParking() 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: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 else
self:T(self.lid.."Passed Final WP and No current and/or future missions/tasks/transports ==> RTB!") self:T(self.lid.."Passed Final WP and No current and/or future missions/tasks/transports ==> RTB!")
self:__RTB(-0.1, destbase) self:__RTB(-0.1, destbase)
@ -2818,6 +2818,7 @@ end
-- @param #string To To state. -- @param #string To To state.
function FLIGHTGROUP:onafterFuelLow(From, Event, To) function FLIGHTGROUP:onafterFuelLow(From, Event, To)
-- Current min fuel.
local fuel=self:GetFuelMin() or 0 local fuel=self:GetFuelMin() or 0
-- Debug message. -- Debug message.
@ -2830,59 +2831,32 @@ function FLIGHTGROUP:onafterFuelLow(From, Event, To)
-- Back to destination or home. -- Back to destination or home.
local airbase=self.destbase or self.homebase 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 if self.fuellowrefuel and self.refueltype then
-- Find nearest tanker within 50 NM.
local tanker=self:FindNearestTanker(50) local tanker=self:FindNearestTanker(50)
if tanker then if tanker then
-- Debug message.
self:I(self.lid..string.format("Send to refuel at tanker %s", tanker:GetName())) self:I(self.lid..string.format("Send to refuel at tanker %s", tanker:GetName()))
-- Get a coordinate towards the tanker. -- Get a coordinate towards the tanker.
local coordinate=self:GetCoordinate():GetIntermediateCoordinate(tanker:GetCoordinate(), 0.75) local coordinate=self:GetCoordinate():GetIntermediateCoordinate(tanker:GetCoordinate(), 0.75)
-- Trigger refuel even.
self:Refuel(coordinate) self:Refuel(coordinate)
return return
end end
end end
-- Send back to airbase.
if airbase and self.fuellowrtb then if airbase and self.fuellowrtb then
self:RTB(airbase) self:RTB(airbase)
--TODO: RTZ --TODO: RTZ
end end
end
end end
--- On after "FuelCritical" event. --- On after "FuelCritical" event.

View File

@ -804,17 +804,29 @@ function INTEL:GetDetectedUnits(Unit, DetectedUnits, RecceDetecting, DetectVisua
for DetectionObjectID, Detection in pairs(detectedtargets or {}) do for DetectionObjectID, Detection in pairs(detectedtargets or {}) do
local DetectedObject=Detection.object -- DCS#Object 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 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 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() else
-- Warning!
DetectedUnits[unitname]=unit self:T(self.lid..string.format("WARNING: Could not get name of detected object ID=%s! Detected by %s", DetectedObject.id_, reccename))
RecceDetecting[unitname]=reccename
self:T(string.format("Unit %s detect by %s", unitname, reccename))
end end
end end
end end

View File

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