mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
xxx
This commit is contained in:
parent
99a55a3c8a
commit
6fbe981ce1
@ -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 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 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
|
||||
end
|
||||
local Vec3 = GetSetVec3(self.Set)
|
||||
if Vec3 then
|
||||
Coordinate = COORDINATE:NewFromVec3(Vec3)
|
||||
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 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.
|
||||
|
||||
@ -2436,6 +2436,7 @@ 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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user