From f92e8a285a0fff0a43a8517238a438184f30c073 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 25 Mar 2022 10:27:32 +0100 Subject: [PATCH] OPS - Added nil check on vec3 for _UndateEngageTarget in ARMYGROUP and NAVYGROUP --- Moose Development/Moose/Ops/ArmyGroup.lua | 53 +++++++++++++---------- Moose Development/Moose/Ops/NavyGroup.lua | 53 +++++++++++++---------- 2 files changed, 62 insertions(+), 44 deletions(-) diff --git a/Moose Development/Moose/Ops/ArmyGroup.lua b/Moose Development/Moose/Ops/ArmyGroup.lua index f4a881f55..98d372ade 100644 --- a/Moose Development/Moose/Ops/ArmyGroup.lua +++ b/Moose Development/Moose/Ops/ArmyGroup.lua @@ -1475,37 +1475,46 @@ function ARMYGROUP:_UpdateEngageTarget() -- Get current position vector. local vec3=self.engage.Target:GetVec3() + + if vec3 then - -- Distance to last known position of target. - local dist=UTILS.VecDist3D(vec3, self.engage.Coordinate:GetVec3()) - - -- Check if target moved more than 100 meters. - if dist>100 then - - --env.info("FF Update Engage Target Moved "..self.engage.Target:GetName()) - - -- Update new position. - self.engage.Coordinate:UpdateFromVec3(vec3) - - -- ID of current waypoint. - local uid=self:GetWaypointCurrent().uid - - -- Remove current waypoint - self:RemoveWaypointByID(self.engage.Waypoint.uid) + -- Distance to last known position of target. + local dist=UTILS.VecDist3D(vec3, self.engage.Coordinate:GetVec3()) - local intercoord=self:GetCoordinate():GetIntermediateCoordinate(self.engage.Coordinate, 0.9) + -- Check if target moved more than 100 meters. + if dist>100 then + + --env.info("FF Update Engage Target Moved "..self.engage.Target:GetName()) + + -- Update new position. + self.engage.Coordinate:UpdateFromVec3(vec3) - -- Add waypoint after current. - self.engage.Waypoint=self:AddWaypoint(intercoord, nil, uid, Formation, true) + -- ID of current waypoint. + local uid=self:GetWaypointCurrent().uid + + -- Remove current waypoint + self:RemoveWaypointByID(self.engage.Waypoint.uid) + + local intercoord=self:GetCoordinate():GetIntermediateCoordinate(self.engage.Coordinate, 0.9) - -- Set if we want to resume route after reaching the detour waypoint. - self.engage.Waypoint.detour=0 + -- Add waypoint after current. + 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 else - -- Target not alive any more == Disengage. + -- Target not alive any more ==> Disengage. self:Disengage() end diff --git a/Moose Development/Moose/Ops/NavyGroup.lua b/Moose Development/Moose/Ops/NavyGroup.lua index 595deb24a..b3226c04e 100644 --- a/Moose Development/Moose/Ops/NavyGroup.lua +++ b/Moose Development/Moose/Ops/NavyGroup.lua @@ -1439,37 +1439,46 @@ function NAVYGROUP:_UpdateEngageTarget() -- Get current position vector. local vec3=self.engage.Target:GetVec3() + + if vec3 then - -- Distance to last known position of target. - local dist=UTILS.VecDist3D(vec3, self.engage.Coordinate:GetVec3()) - - -- Check if target moved more than 100 meters. - if dist>100 then - - --env.info("FF Update Engage Target Moved "..self.engage.Target:GetName()) - - -- Update new position. - self.engage.Coordinate:UpdateFromVec3(vec3) - - -- ID of current waypoint. - local uid=self:GetWaypointCurrent().uid - - -- Remove current waypoint - self:RemoveWaypointByID(self.engage.Waypoint.uid) + -- Distance to last known position of target. + local dist=UTILS.VecDist3D(vec3, self.engage.Coordinate:GetVec3()) - local intercoord=self:GetCoordinate():GetIntermediateCoordinate(self.engage.Coordinate, 0.9) + -- Check if target moved more than 100 meters. + if dist>100 then + + --env.info("FF Update Engage Target Moved "..self.engage.Target:GetName()) + + -- Update new position. + self.engage.Coordinate:UpdateFromVec3(vec3) - -- Add waypoint after current. - self.engage.Waypoint=self:AddWaypoint(intercoord, nil, uid, Formation, true) + -- ID of current waypoint. + local uid=self:GetWaypointCurrent().uid + + -- Remove current waypoint + self:RemoveWaypointByID(self.engage.Waypoint.uid) + + local intercoord=self:GetCoordinate():GetIntermediateCoordinate(self.engage.Coordinate, 0.9) - -- Set if we want to resume route after reaching the detour waypoint. - self.engage.Waypoint.detour=0 + -- Add waypoint after current. + 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 else - -- Target not alive any more == Disengage. + -- Target not alive any more ==> Disengage. self:Disengage() end