Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions LuaUI/Widgets/gui_attack_aoe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,41 @@ local function DrawAoE(tx, ty, tz, aoe, ee, alphaMult, offset, circleMode)
glLineWidth(1)
end

--------------------------------------------------------------------------------
-- Shared blast-radius preview, exposed via WG so other widgets (e.g. the missile
-- silo launch UI) draw their AoE footprint with THIS falloff code instead of
-- duplicating it. Nested rings at (tx,ty,tz) whose alpha decays toward the edge by
-- edgeEffectiveness `ee`. `color` (optional {r,g,b[,a]}) overrides the ring colour;
-- `alphaMult` (optional) scales overall opacity. Line width is derived from the
-- camera distance to the point, so callers need no per-frame setup of their own.
--------------------------------------------------------------------------------
local function DrawAoEPreview(tx, ty, tz, aoe, ee, color, alphaMult)
if not aoe or aoe <= 0 then
return
end
ee = ee or 1
local cx, cy, cz = GetCameraPosition()
local dx, dy, dz = cx - tx, cy - ty, cz - tz
local camDist = sqrt(dx*dx + dy*dy + dz*dz)
if camDist < 1 then
camDist = 1
end
local r = (color and color[1]) or aoeColor[1]
local g = (color and color[2]) or aoeColor[2]
local b = (color and color[3]) or aoeColor[3]
local baseAlpha = ((color and color[4]) or aoeColor[4]) * (alphaMult or 1)

glLineWidth(math.max(0.05, aoeLineWidthMult * aoe / camDist))
for i = 1, numAoECircles do
local proportion = i / (numAoECircles + 1)
local alpha = baseAlpha * (1 - proportion) / (1 - proportion * ee)
glColor(r, g, b, alpha)
DrawCircle(tx, ty, tz, aoe * proportion)
end
glColor(1, 1, 1, 1)
glLineWidth(1)
end

--------------------------------------------------------------------------------
--dgun/noexplode
--------------------------------------------------------------------------------
Expand Down Expand Up @@ -939,6 +974,39 @@ local function CalculateVlaunchImpact(info, fx, fy, fz, tx, ty, tz)
return false
end

--------------------------------------------------------------------------------
-- Shared terrain-impact test, exposed via WG for the missile silo launch UI. Given a
-- firing unit (a vlaunch missile sitting on its pad) and a target point, returns the
-- terrain impact point (hx, hy, hz) if that unit's vlaunch trajectory is projected to
-- strike the ground before reaching the target (a hill in the way), or nil if it
-- reaches the target -- or has no vlaunch data, so the caller simply doesn't filter.
-- Uses exactly the same CalculateVlaunchImpact path this widget draws (the depth line
-- shown when force-firing), so the silo UI's "which silo can actually hit here" filter
-- matches what a player sees.
--------------------------------------------------------------------------------
local function GetVlaunchTerrainImpact(unitID, tx, ty, tz)
local unitDefID = spGetUnitDefID(unitID)
local info = unitDefID and aoeDefInfo[unitDefID]
if not (info and info.vlaunch) or info.circleMode == "cloaker" then
return nil
end
local _,_,_,fx, fy, fz = GetUnitPosition(unitID, true)
if not fx then
return nil
end
if not info.mobile then
fy = fy + GetUnitRadius(unitID)
end
if not info.waterWeapon then
ty = max(0, ty)
end
local hx, hy, hz = CalculateVlaunchImpact(info, fx, fy, fz, tx, ty, tz)
if hx then
return hx, hy, hz
end
return nil
end

--------------------------------------------------------------------------------
--Main draw
--------------------------------------------------------------------------------
Expand Down Expand Up @@ -1027,10 +1095,14 @@ function widget:Initialize()
aoeDefInfo[unitDefID], dgunInfo[unitDefID], extraDrawRangeDefInfo[unitDefID] = SetupUnit(unitDef)
end
SetupDisplayLists()
WG.DrawAoEPreview = DrawAoEPreview
WG.GetVlaunchTerrainImpact = GetVlaunchTerrainImpact
end

function widget:Shutdown()
DeleteDisplayLists()
WG.DrawAoEPreview = nil
WG.GetVlaunchTerrainImpact = nil
end

function widget:DrawWorld()
Expand Down
Loading