- Added nil check on vec3 for _UndateEngageTarget in ARMYGROUP and NAVYGROUP
This commit is contained in:
Frank 2022-03-25 10:27:32 +01:00
parent 0411120551
commit f92e8a285a
2 changed files with 62 additions and 44 deletions

View File

@ -1476,36 +1476,45 @@ function ARMYGROUP:_UpdateEngageTarget()
-- Get current position vector. -- Get current position vector.
local vec3=self.engage.Target:GetVec3() local vec3=self.engage.Target:GetVec3()
-- Distance to last known position of target. if vec3 then
local dist=UTILS.VecDist3D(vec3, self.engage.Coordinate:GetVec3())
-- Check if target moved more than 100 meters. -- Distance to last known position of target.
if dist>100 then local dist=UTILS.VecDist3D(vec3, self.engage.Coordinate:GetVec3())
--env.info("FF Update Engage Target Moved "..self.engage.Target:GetName()) -- Check if target moved more than 100 meters.
if dist>100 then
-- Update new position. --env.info("FF Update Engage Target Moved "..self.engage.Target:GetName())
self.engage.Coordinate:UpdateFromVec3(vec3)
-- ID of current waypoint. -- Update new position.
local uid=self:GetWaypointCurrent().uid self.engage.Coordinate:UpdateFromVec3(vec3)
-- Remove current waypoint -- ID of current waypoint.
self:RemoveWaypointByID(self.engage.Waypoint.uid) local uid=self:GetWaypointCurrent().uid
local intercoord=self:GetCoordinate():GetIntermediateCoordinate(self.engage.Coordinate, 0.9) -- Remove current waypoint
self:RemoveWaypointByID(self.engage.Waypoint.uid)
-- Add waypoint after current. local intercoord=self:GetCoordinate():GetIntermediateCoordinate(self.engage.Coordinate, 0.9)
self.engage.Waypoint=self:AddWaypoint(intercoord, nil, uid, Formation, true)
-- Set if we want to resume route after reaching the detour waypoint. -- Add waypoint after current.
self.engage.Waypoint.detour=0 self.engage.Waypoint=self:AddWaypoint(intercoord, nil, uid, Formation, true)
-- Set if we want to resume route after reaching the detour waypoint.
self.engage.Waypoint.detour=0
end
else
-- Could not get position of target (not alive any more?) ==> Disengage.
self:Disengage()
end end
else else
-- Target not alive any more == Disengage. -- Target not alive any more ==> Disengage.
self:Disengage() self:Disengage()
end end

View File

@ -1440,36 +1440,45 @@ function NAVYGROUP:_UpdateEngageTarget()
-- Get current position vector. -- Get current position vector.
local vec3=self.engage.Target:GetVec3() local vec3=self.engage.Target:GetVec3()
-- Distance to last known position of target. if vec3 then
local dist=UTILS.VecDist3D(vec3, self.engage.Coordinate:GetVec3())
-- Check if target moved more than 100 meters. -- Distance to last known position of target.
if dist>100 then local dist=UTILS.VecDist3D(vec3, self.engage.Coordinate:GetVec3())
--env.info("FF Update Engage Target Moved "..self.engage.Target:GetName()) -- Check if target moved more than 100 meters.
if dist>100 then
-- Update new position. --env.info("FF Update Engage Target Moved "..self.engage.Target:GetName())
self.engage.Coordinate:UpdateFromVec3(vec3)
-- ID of current waypoint. -- Update new position.
local uid=self:GetWaypointCurrent().uid self.engage.Coordinate:UpdateFromVec3(vec3)
-- Remove current waypoint -- ID of current waypoint.
self:RemoveWaypointByID(self.engage.Waypoint.uid) local uid=self:GetWaypointCurrent().uid
local intercoord=self:GetCoordinate():GetIntermediateCoordinate(self.engage.Coordinate, 0.9) -- Remove current waypoint
self:RemoveWaypointByID(self.engage.Waypoint.uid)
-- Add waypoint after current. local intercoord=self:GetCoordinate():GetIntermediateCoordinate(self.engage.Coordinate, 0.9)
self.engage.Waypoint=self:AddWaypoint(intercoord, nil, uid, Formation, true)
-- Set if we want to resume route after reaching the detour waypoint. -- Add waypoint after current.
self.engage.Waypoint.detour=0 self.engage.Waypoint=self:AddWaypoint(intercoord, nil, uid, Formation, true)
-- Set if we want to resume route after reaching the detour waypoint.
self.engage.Waypoint.detour=0
end
else
-- Could not get position of target (not alive any more?) ==> Disengage.
self:Disengage()
end end
else else
-- Target not alive any more == Disengage. -- Target not alive any more ==> Disengage.
self:Disengage() self:Disengage()
end end