From acfe1a856ec76d354b4e66608b98b07142b3e110 Mon Sep 17 00:00:00 2001 From: Frank Date: Sat, 11 Jan 2025 23:38:15 +0100 Subject: [PATCH] Update OpsGroup.lua - Added surface type check for ARTY mission - Improved search for coordinate in range - Added option to specify distance conversion for weapon ranges --- Moose Development/Moose/Ops/OpsGroup.lua | 81 ++++++++++++++++-------- 1 file changed, 55 insertions(+), 26 deletions(-) diff --git a/Moose Development/Moose/Ops/OpsGroup.lua b/Moose Development/Moose/Ops/OpsGroup.lua index 9f7a76c0b..c9a59be3c 100644 --- a/Moose Development/Moose/Ops/OpsGroup.lua +++ b/Moose Development/Moose/Ops/OpsGroup.lua @@ -512,7 +512,7 @@ OPSGROUP.CargoStatus={ --- OpsGroup version. -- @field #string version -OPSGROUP.version="1.0.3" +OPSGROUP.version="1.0.4" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- TODO list @@ -1333,8 +1333,9 @@ end -- @param Core.Point#COORDINATE TargetCoord Coordinate of the target. -- @param #number WeaponBitType Weapon type. -- @param Core.Point#COORDINATE RefCoord Reference coordinate. +-- @param #table SurfaceTypes Valid surfaces types of the coordinate. Default any (nil). -- @return Core.Point#COORDINATE Coordinate in weapon range -function OPSGROUP:GetCoordinateInRange(TargetCoord, WeaponBitType, RefCoord) +function OPSGROUP:GetCoordinateInRange(TargetCoord, WeaponBitType, RefCoord, SurfaceTypes) local coordInRange=nil --Core.Point#COORDINATE @@ -1343,35 +1344,58 @@ function OPSGROUP:GetCoordinateInRange(TargetCoord, WeaponBitType, RefCoord) -- Get weapon range. local weapondata=self:GetWeaponData(WeaponBitType) + -- Heading intervals to search for a possible new coordinate in range. + local dh={0, -5, 5, -10, 10, -15, 15, -20, 20, -25, 25, -30, 30} + + -- Function that checks if the given surface type is valid.ss + local function _checkSurface(point) + if SurfaceTypes then + local stype=land.getSurfaceType(point) + for _,sf in pairs(SurfaceTypes) do + if sf==stype then + return true + end + end + return false + else + return true + end + end + if weapondata then -- Heading to target. - local heading=RefCoord:HeadingTo(TargetCoord) + local heading=TargetCoord:HeadingTo(RefCoord) -- Distance to target. local dist=RefCoord:Get2DDistance(TargetCoord) + + local range=nil + if dist>weapondata.RangeMax then + range=weapondata.RangeMax + self:T(self.lid..string.format("Out of max range = %.1f km by %.1f km for weapon %s", weapondata.RangeMax/1000, (weapondata.RangeMax-dist)/1000, tostring(WeaponBitType))) + elseif distweapondata.RangeMax then - - local d=(dist-weapondata.RangeMax)*1.05 - - -- New waypoint coord. - coordInRange=RefCoord:Translate(d, heading) - - -- Debug info. - self:T(self.lid..string.format("Out of max range = %.1f km for weapon %s", weapondata.RangeMax/1000, tostring(WeaponBitType))) - elseif dist