mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Merge branch 'develop' into FF/Ops
This commit is contained in:
@@ -1586,12 +1586,12 @@ function UTILS.HdgDiff(h1, h2)
|
||||
return math.abs(delta)
|
||||
end
|
||||
|
||||
--- Returns the heading from one vec3 to another vec3.
|
||||
-- @param DCS#Vec3 a From vec3.
|
||||
-- @param DCS#Vec3 b To vec3.
|
||||
--- Returns the heading from one vec2/vec3 to another vec2/vec3.
|
||||
-- @param DCS#Vec3 a From Vec2 or Vec3.
|
||||
-- @param DCS#Vec3 b To Vec2 or Vec3.
|
||||
-- @return #number Heading in degrees.
|
||||
function UTILS.HdgTo(a, b)
|
||||
local dz=b.z-a.z
|
||||
local dz=(b.z or b.y) - (a.z or a.y)
|
||||
local dx=b.x-a.x
|
||||
local heading=math.deg(math.atan2(dz, dx))
|
||||
if heading < 0 then
|
||||
@@ -4981,3 +4981,51 @@ function UTILS.ValidateAndRepositionGroundUnits(Positions, Anchor, MaxRadius, Sp
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- This function uses Disposition and other fallback logic to find better ground positions for statics.
|
||||
--- NOTE: This is not a spawn randomizer.
|
||||
--- It will try to find clear ground locations avoiding trees, water, roads, runways, map scenery, statics and other units in the area and modifies the provided positions table.
|
||||
--- Maintains the original layout and unit positions as close as possible by searching for the next closest valid position to each unit.
|
||||
-- @param #table Positions A table of DCS#Vec2 or DCS#Vec3, can be a units table from the group template.
|
||||
-- @param DCS#Vec2 Position DCS#Vec2 or DCS#Vec3 initial spawn location.
|
||||
-- @param #number MaxRadius (Optional) Max radius to search for valid ground locations in meters. Default is double the max radius of the static.
|
||||
-- @return DCS#Vec2 Initial Position if it's valid, else a valid spawn position. nil if no valid position found.
|
||||
function UTILS.ValidateAndRepositionStatic(Country, Category, Type, Position, ShapeName, MaxRadius)
|
||||
local coord = COORDINATE:NewFromVec2(Position)
|
||||
local st = SPAWNSTATIC:NewFromType(Type, Category, Country)
|
||||
if ShapeName then
|
||||
st:InitShape(ShapeName)
|
||||
end
|
||||
local sName = "s-"..timer.getTime().."-"..math.random(1,10000)
|
||||
local tempStatic = st:SpawnFromCoordinate(coord, 0, sName)
|
||||
if tempStatic then
|
||||
local sRadius = tempStatic:GetBoundingRadius(2) or 3
|
||||
tempStatic:Destroy()
|
||||
sRadius = sRadius * 0.5
|
||||
MaxRadius = MaxRadius or math.max(sRadius * 10, 100)
|
||||
local positions = UTILS.GetSimpleZones(coord:GetVec3(), MaxRadius, sRadius, 20)
|
||||
if positions and #positions > 0 then
|
||||
local closestSpot
|
||||
local closestDist = math.huge
|
||||
for _, spot in pairs(positions) do -- Disposition sometimes returns points on roads, hence this filter.
|
||||
if land.getSurfaceType(spot) == land.SurfaceType.LAND then
|
||||
local dist = UTILS.VecDist2D(Position, spot)
|
||||
if dist < closestDist then
|
||||
closestDist = dist
|
||||
closestSpot = spot
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if closestSpot then
|
||||
if closestDist >= sRadius then
|
||||
return closestSpot
|
||||
else
|
||||
return Position
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user