Binary file not shown.
+40
-22
@@ -382,37 +382,37 @@ end
|
|||||||
---@param origin Vec2
|
---@param origin Vec2
|
||||||
---@return Array<Vec2>
|
---@return Array<Vec2>
|
||||||
function UTIL.GetTangentHullPointsFromOrigin(hull, origin)
|
function UTIL.GetTangentHullPointsFromOrigin(hull, origin)
|
||||||
local function cross(o, a, b)
|
|
||||||
return (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x)
|
local function orientation(a, b, c)
|
||||||
|
-- Returns >0 if c is to the left of ab, <0 if to the right, 0 if colinear
|
||||||
|
return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)
|
||||||
end
|
end
|
||||||
|
|
||||||
local n = #hull
|
local n = #hull
|
||||||
if n == 0 then return {} end
|
if n == 0 then return {} end
|
||||||
if n == 1 then return { hull[1] } end
|
if n == 1 then return { hull[1] } end
|
||||||
|
|
||||||
local left, right = nil, nil
|
-- Find left tangent: the hull point where all other points are to the right of the line from origin to that point
|
||||||
for i = 1, n do
|
local function findTangent(isLeft)
|
||||||
local prev = hull[(i - 2 + n) % n + 1]
|
local best = 1
|
||||||
local curr = hull[i]
|
for i = 2, n do
|
||||||
local next = hull[(i % n) + 1]
|
local o = orientation(origin, hull[best], hull[i])
|
||||||
|
if (isLeft and o < 0) or (not isLeft and o > 0) then
|
||||||
local cp1 = cross(origin, curr, prev)
|
best = i
|
||||||
local cp2 = cross(origin, curr, next)
|
|
||||||
|
|
||||||
-- Tangent if the cross products have different signs or one is zero
|
|
||||||
if cp1 * cp2 <= 0 then
|
|
||||||
if not left then
|
|
||||||
left = curr
|
|
||||||
else
|
|
||||||
right = curr
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return hull[best]
|
||||||
end
|
end
|
||||||
|
|
||||||
local result = {}
|
local leftTangent = findTangent(true)
|
||||||
if left then table.insert(result, left) end
|
local rightTangent = findTangent(false)
|
||||||
if right and right ~= left then table.insert(result, right) end
|
|
||||||
return result
|
-- If tangents are the same (can happen if origin is colinear), only return one
|
||||||
|
if leftTangent.x == rightTangent.x and leftTangent.y == rightTangent.y then
|
||||||
|
return { leftTangent }
|
||||||
|
else
|
||||||
|
return { leftTangent, rightTangent }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -1089,7 +1089,6 @@ do -- INIT DCS_UTIL
|
|||||||
end
|
end
|
||||||
functionString = functionString .. "{0,1,0,1}, {0,1,0,1}, " .. lineStyle .. ")"
|
functionString = functionString .. "{0,1,0,1}, {0,1,0,1}, " .. lineStyle .. ")"
|
||||||
|
|
||||||
env.info(functionString)
|
|
||||||
---@diagnostic disable-next-line: deprecated
|
---@diagnostic disable-next-line: deprecated
|
||||||
local f, err = loadstring(functionString)
|
local f, err = loadstring(functionString)
|
||||||
if f then
|
if f then
|
||||||
@@ -1118,6 +1117,25 @@ do -- INIT DCS_UTIL
|
|||||||
return drawID
|
return drawID
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param start Vec3
|
||||||
|
---@param finish Vec3
|
||||||
|
---@param lineColor DrawColor
|
||||||
|
---@param lineStyle LineType
|
||||||
|
function DCS_UTIL.DrawLine(start, finish, lineColor, lineStyle)
|
||||||
|
if lineStyle == nil then lineStyle = 4 end
|
||||||
|
drawID = drawID + 1
|
||||||
|
|
||||||
|
local lineColorMapped = {
|
||||||
|
lineColor.r or 0,
|
||||||
|
lineColor.g or 0,
|
||||||
|
lineColor.b or 0,
|
||||||
|
lineColor.a or 1
|
||||||
|
}
|
||||||
|
|
||||||
|
trigger.action.lineToAll(-1, drawID, start, finish, lineColorMapped, lineStyle)
|
||||||
|
return drawID
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local _markID = 200
|
local _markID = 200
|
||||||
|
|
||||||
|
|||||||
@@ -92,6 +92,8 @@ function BattleManager:Update()
|
|||||||
return math.random(4, 10) -- Return a random interval between 5 and 10 seconds for the next update
|
return math.random(4, 10) -- Return a random interval between 5 and 10 seconds for the next update
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local drawID = 8633
|
||||||
---@private
|
---@private
|
||||||
---@param groups Array<SpearheadGroup>
|
---@param groups Array<SpearheadGroup>
|
||||||
---@param targetGroups Array<SpearheadGroup>
|
---@param targetGroups Array<SpearheadGroup>
|
||||||
@@ -124,11 +126,22 @@ function BattleManager:LetUnitsShoot(groups, targetGroups)
|
|||||||
radius = 1,
|
radius = 1,
|
||||||
expendQty = qty,
|
expendQty = qty,
|
||||||
weaponType = ammo,
|
weaponType = ammo,
|
||||||
expendQtyEnabled = true,
|
expendQtyEnabled = true
|
||||||
counterbattaryRadius = math.random(5, 10)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
---- DEBUG ONLY!!
|
||||||
|
--- DRAWS THE SHOOTING LINE
|
||||||
|
-- do
|
||||||
|
-- local color = {r = 1, g = 0, b = 0, a = 1}
|
||||||
|
-- if unit:getCoalition() == 2 then
|
||||||
|
-- color = {r = 0, g = 0, b = 1, a = 1}
|
||||||
|
-- end
|
||||||
|
|
||||||
|
-- Spearhead.DcsUtil.DrawLine(unitPos, {x = point.x, y = 0, z = point.y}, color, 1)
|
||||||
|
-- end
|
||||||
|
|
||||||
|
|
||||||
self._logger:debug("Red unit " .. unit:getName() .. " will shoot " .. qty .. " rounds at point: " .. tostring(point))
|
self._logger:debug("Red unit " .. unit:getName() .. " will shoot " .. qty .. " rounds at point: " .. tostring(point))
|
||||||
|
|
||||||
local controller = unit:getController()
|
local controller = unit:getController()
|
||||||
@@ -211,7 +224,35 @@ function BattleManager:GetRandomPoint(origin, groups)
|
|||||||
local hull = Spearhead.Util.randomFromList(hulls) --[[@as Array<Vec2>]]
|
local hull = Spearhead.Util.randomFromList(hulls) --[[@as Array<Vec2>]]
|
||||||
local enlargedHull = Spearhead.Util.enlargeConvexHull(hull, 25)
|
local enlargedHull = Spearhead.Util.enlargeConvexHull(hull, 25)
|
||||||
local shootPoints = Spearhead.Util.GetTangentHullPointsFromOrigin(enlargedHull, origin)
|
local shootPoints = Spearhead.Util.GetTangentHullPointsFromOrigin(enlargedHull, origin)
|
||||||
|
|
||||||
|
---- DEBUG ONLY!!
|
||||||
|
---- DRAWS the hulls of the units
|
||||||
|
-- for _, drawHull in pairs(hulls) do
|
||||||
|
|
||||||
|
-- ---@type SpearheadTriggerZone
|
||||||
|
-- local zone = {
|
||||||
|
-- name = "temp",
|
||||||
|
-- zone_type = "Polygon",
|
||||||
|
-- radius = 0,
|
||||||
|
-- verts = drawHull,
|
||||||
|
-- location = { x=drawHull[1].x, y=drawHull[1].y },
|
||||||
|
-- }
|
||||||
|
|
||||||
|
-- Spearhead.DcsUtil.DrawZone(zone, {r =0, g= 1, b =0, a = 0.5} ,{r =0, g= 1, b =0, a = 0}, 1)
|
||||||
|
|
||||||
|
-- local enlarged = Spearhead.Util.enlargeConvexHull(drawHull, 25)
|
||||||
|
-- local enlargedZone = {
|
||||||
|
-- name = "temp_enlarged",
|
||||||
|
-- zone_type = "Polygon",
|
||||||
|
-- radius = 0,
|
||||||
|
-- verts = enlarged,
|
||||||
|
-- location = { x=enlarged[1].x, y=enlarged[1].y },
|
||||||
|
-- }
|
||||||
|
-- Spearhead.DcsUtil.DrawZone(enlargedZone, {r =0, g= 0, b =1, a = 0.5} ,{r =0, g= 1, b =0, a = 0}, 1)
|
||||||
|
|
||||||
|
-- end
|
||||||
|
|
||||||
|
|
||||||
return Spearhead.Util.randomFromList(shootPoints) --[[@as Vec2]]
|
return Spearhead.Util.randomFromList(shootPoints) --[[@as Vec2]]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user