From 6fbe981ce147c73ac4412c8615016616976b32df Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Sat, 9 Dec 2023 13:01:32 +0100 Subject: [PATCH] xxx --- Moose Development/Moose/Core/Set.lua | 88 +++++++++---------- .../Moose/Functional/Detection.lua | 3 +- 2 files changed, 42 insertions(+), 49 deletions(-) diff --git a/Moose Development/Moose/Core/Set.lua b/Moose Development/Moose/Core/Set.lua index c9cbc9f3a..43fbd8fce 100644 --- a/Moose Development/Moose/Core/Set.lua +++ b/Moose Development/Moose/Core/Set.lua @@ -2854,58 +2854,50 @@ do -- SET_UNIT -- @return Core.Point#COORDINATE The center coordinate of all the units in the set, including heading in degrees and speed in mps in case of moving units. function SET_UNIT:GetCoordinate() - local Coordinate = nil - local unit = self:GetFirst() - if self:Count() == 1 and unit then - return unit:GetCoordinate() - end - if unit then - Coordinate = unit:GetCoordinate() - self:T2(UTILS.PrintTableToLog(Coordinate:GetVec3())) - - local x1 = Coordinate.x - local x2 = Coordinate.x - local y1 = Coordinate.y - local y2 = Coordinate.y - local z1 = Coordinate.z - local z2 = Coordinate.z - local MaxVelocity = 0 - local AvgHeading = nil - local MovingCount = 0 - - for UnitName, UnitData in pairs( self.Set) do - - local Unit = UnitData -- Wrapper.Unit#UNIT - local Coord = Unit:GetCoordinate() - - x1 = (Coord.x < x1) and Coord.x or x1 - x2 = (Coord.x > x2) and Coord.x or x2 - y1 = (Coord.y < y1) and Coord.y or y1 - y2 = (Coord.y > y2) and Coord.y or y2 - z1 = (Coord.y < z1) and Coord.z or z1 - z2 = (Coord.y > z2) and Coord.z or z2 - - local Velocity = Coord:GetVelocity() - if Velocity ~= 0 then - MaxVelocity = (MaxVelocity < Velocity) and Velocity or MaxVelocity - local Heading = Coordinate:GetHeading() - AvgHeading = AvgHeading and (AvgHeading + Heading) or Heading - MovingCount = MovingCount + 1 + local function GetSetVec3(units) + -- Init. + local x=0 + local y=0 + local z=0 + local n=0 + -- Loop over all units. + for _,unit in pairs(units) do + local vec3=nil --DCS#Vec3 + if unit and unit:IsAlive() then + vec3 = unit:GetVec3() + end + if vec3 then + -- Sum up posits. + x=x+vec3.x + y=y+vec3.y + z=z+vec3.z + -- Increase counter. + n=n+1 end end - - AvgHeading = AvgHeading and (AvgHeading / MovingCount) - - Coordinate.x = (x2 - x1) / 2 + x1 - Coordinate.y = (y2 - y1) / 2 + y1 - Coordinate.z = (z2 - z1) / 2 + z1 - Coordinate:SetHeading( AvgHeading ) - Coordinate:SetVelocity( MaxVelocity ) - - self:T2(UTILS.PrintTableToLog(Coordinate:GetVec3())) + if n>0 then + -- Average. + local Vec3={x=x/n, y=y/n, z=z/n} --DCS#Vec3 + return Vec3 + end + return nil + end + + local Coordinate = nil + local Vec3 = GetSetVec3(self.Set) + if Vec3 then + Coordinate = COORDINATE:NewFromVec3(Vec3) end - return Coordinate + if Coordinate then + local heading = self:GetHeading() or 0 + local velocity = self:GetVelocity() or 0 + Coordinate:SetHeading( heading ) + Coordinate:SetVelocity( velocity ) + self:I(UTILS.PrintTableToLog(Coordinate)) + end + + return Coordinate end --- Get the maximum velocity of the SET_UNIT. diff --git a/Moose Development/Moose/Functional/Detection.lua b/Moose Development/Moose/Functional/Detection.lua index 1d44ca079..3922cd36b 100644 --- a/Moose Development/Moose/Functional/Detection.lua +++ b/Moose Development/Moose/Functional/Detection.lua @@ -2435,7 +2435,8 @@ do -- DETECTION_TYPES end do -- DETECTION_AREAS - + + --- -- @type DETECTION_AREAS -- @field DCS#Distance DetectionZoneRange The range till which targets are grouped upon the first detected target. -- @field #DETECTION_BASE.DetectedItems DetectedItems A list of areas containing the set of @{Wrapper.Unit}s, @{Core.Zone}s, the center @{Wrapper.Unit} within the zone, and ID of each area that was detected within a DetectionZoneRange.