This commit is contained in:
Applevangelist 2023-12-09 13:01:32 +01:00
parent 99a55a3c8a
commit 6fbe981ce1
2 changed files with 42 additions and 49 deletions

View File

@ -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. -- @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() function SET_UNIT:GetCoordinate()
local Coordinate = nil local function GetSetVec3(units)
local unit = self:GetFirst() -- Init.
if self:Count() == 1 and unit then local x=0
return unit:GetCoordinate() local y=0
end local z=0
if unit then local n=0
Coordinate = unit:GetCoordinate() -- Loop over all units.
self:T2(UTILS.PrintTableToLog(Coordinate:GetVec3())) for _,unit in pairs(units) do
local vec3=nil --DCS#Vec3
local x1 = Coordinate.x if unit and unit:IsAlive() then
local x2 = Coordinate.x vec3 = unit:GetVec3()
local y1 = Coordinate.y end
local y2 = Coordinate.y if vec3 then
local z1 = Coordinate.z -- Sum up posits.
local z2 = Coordinate.z x=x+vec3.x
local MaxVelocity = 0 y=y+vec3.y
local AvgHeading = nil z=z+vec3.z
local MovingCount = 0 -- Increase counter.
n=n+1
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
end end
end end
if n>0 then
AvgHeading = AvgHeading and (AvgHeading / MovingCount) -- Average.
local Vec3={x=x/n, y=y/n, z=z/n} --DCS#Vec3
Coordinate.x = (x2 - x1) / 2 + x1 return Vec3
Coordinate.y = (y2 - y1) / 2 + y1 end
Coordinate.z = (z2 - z1) / 2 + z1 return nil
Coordinate:SetHeading( AvgHeading )
Coordinate:SetVelocity( MaxVelocity )
self:T2(UTILS.PrintTableToLog(Coordinate:GetVec3()))
end end
return Coordinate
local Coordinate = nil
local Vec3 = GetSetVec3(self.Set)
if Vec3 then
Coordinate = COORDINATE:NewFromVec3(Vec3)
end
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 end
--- Get the maximum velocity of the SET_UNIT. --- Get the maximum velocity of the SET_UNIT.

View File

@ -2436,6 +2436,7 @@ end
do -- DETECTION_AREAS do -- DETECTION_AREAS
---
-- @type DETECTION_AREAS -- @type DETECTION_AREAS
-- @field DCS#Distance DetectionZoneRange The range till which targets are grouped upon the first detected target. -- @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. -- @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.