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 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
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 Coordinate = nil
local unit = self:GetFirst() local Vec3 = GetSetVec3(self.Set)
if self:Count() == 1 and unit then if Vec3 then
return unit:GetCoordinate() Coordinate = COORDINATE:NewFromVec3(Vec3)
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
end
end end
AvgHeading = AvgHeading and (AvgHeading / MovingCount) if Coordinate then
local heading = self:GetHeading() or 0
Coordinate.x = (x2 - x1) / 2 + x1 local velocity = self:GetVelocity() or 0
Coordinate.y = (y2 - y1) / 2 + y1 Coordinate:SetHeading( heading )
Coordinate.z = (z2 - z1) / 2 + z1 Coordinate:SetVelocity( velocity )
Coordinate:SetHeading( AvgHeading ) self:I(UTILS.PrintTableToLog(Coordinate))
Coordinate:SetVelocity( MaxVelocity )
self:T2(UTILS.PrintTableToLog(Coordinate:GetVec3()))
end end
return Coordinate 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.