@@ -115,26 +115,17 @@ local spTraceScreenRay = Spring.TraceScreenRay
115115local spGetGroundHeight = Spring .GetGroundHeight
116116local spGetUnitAllyTeam = Spring .GetUnitAllyTeam
117117local spGetMyAllyTeamID = Spring .GetMyAllyTeamID
118- local spGetCameraPosition = Spring .GetCameraPosition
119118
120119local glColor = gl .Color
121120local glLineWidth = gl .LineWidth
122121local glLineStipple = gl .LineStipple
123122local glDrawGroundCircle = gl .DrawGroundCircle
124123local glDepthTest = gl .DepthTest
125124
126- -- AoE-preview look, mirrored from the stock "Attack AoE" widget (gui_attack_aoe.lua):
127- -- concentric rings whose alpha decays toward the edge by edgeEffectiveness, so the
128- -- preview conveys how the blast's strength falls off with distance from the epicentre.
129- local NUM_AOE_CIRCLES = 9
130- local AOE_LINE_WIDTH_MULT = 64 -- ring width scales with aoe/cameraDistance (screen-space)
131-
132125local CMD_ATTACK = CMD .ATTACK
133126local CMD_OPT_RIGHT = CMD .OPT_RIGHT
134127
135128local floor = math.floor
136- local sqrt = math.sqrt
137- local max = math.max
138129local schar = string.char
139130
140131-- Chili colour escape for a caption ("\255rgb").
275266-- Targeting helpers
276267---- ----------------------------------------------------------------------------
277268
278- local function Dist2 (ax , az , bx , bz )
279- local dx , dz = ax - bx , az - bz
280- return dx * dx + dz * dz
281- end
269+ -- Squared XZ distance -- shared engine utility (Spring.Utilities.Vector), not hand-rolled.
270+ local Dist2 = Spring .Utilities .Vector .DistSq
282271
283272-- Fire one ready missile of `t` from the nearest in-range silo to (tx,tz).
284273local function FireType (t , tx , tz , targetUnitID )
528517-- World-space range/AoE preview (immediate-mode; Chili can't draw on the map)
529518---- ----------------------------------------------------------------------------
530519
531- -- Draw the blast footprint at (cx,cz) as nested rings whose alpha falls off toward
532- -- the edge, exactly like the stock force-fire AoE indicator (gui_attack_aoe.lua):
533- -- alpha(r) = baseAlpha * (1 - p) / (1 - p*ee), p = ring proportion of the radius.
534- -- ee == 1 (e.g. EMP) => flat alpha (uniform damage to the edge); ee < 1 => brighter
535- -- centre fading out, conveying reduced damage with distance from the epicentre.
536- local function DrawAoEFalloff (cx , cz , t )
537- local aoe = t .aoe
538- if not aoe or aoe <= 0 then return end
539- local ee = t .ee or 1
540-
541- -- Match native screen-space ring thickness: scale by aoe / cameraDistance.
542- local camx , camy , camz = spGetCameraPosition ()
543- local cy = spGetGroundHeight (cx , cz ) or 0
544- local dx , dy , dz = camx - cx , camy - cy , camz - cz
545- local camDist = sqrt (dx * dx + dy * dy + dz * dz )
546- if camDist < 1 then camDist = 1 end
547- glLineWidth (max (0.5 , AOE_LINE_WIDTH_MULT * aoe / camDist ))
548-
549- local r , g , b = t .color [1 ], t .color [2 ], t .color [3 ]
550- for i = 1 , NUM_AOE_CIRCLES do
551- local p = i / (NUM_AOE_CIRCLES + 1 )
552- local alpha = 0.9 * (1 - p ) / (1 - p * ee )
553- glColor (r , g , b , alpha )
554- glDrawGroundCircle (cx , 0 , cz , aoe * p , 48 )
555- end
556- end
557-
558520function widget :DrawWorld ()
559521 if not haveSilos or not uiBuilt then return end
560522
@@ -593,11 +555,13 @@ function widget:DrawWorld()
593555 -- AoE preview at the cursor while armed. Zeno is homing but still lays down a slow
594556 -- FIELD, so it has a real AoE too -- show it exactly like force-firing via selection
595557 -- (gui_attack_aoe draws Zeno's gui_aoe at the target). Gated only on aoe > 0.
596- if activeT == t and t .aoe and t .aoe > 0 then
558+ -- Reuse the stock Attack AoE falloff renderer (exposed via WG) rather than
559+ -- duplicating it; the missile's colour makes the preview read as its type.
560+ if activeT == t and t .aoe and t .aoe > 0 and WG .DrawAoEPreview then
597561 local mx , my = spGetMouseState ()
598562 local _ , coords = spTraceScreenRay (mx , my , true )
599563 if coords then
600- DrawAoEFalloff (coords [1 ], coords [3 ], t )
564+ WG . DrawAoEPreview (coords [1 ], coords [2 ], coords [ 3 ], t . aoe , t . ee , t . color )
601565 end
602566 end
603567
0 commit comments