Skip to content

Commit bac0433

Browse files
authored
los sensor ranges: disable when fog of war remover is active (#4231)
1 parent 9c7469e commit bac0433

File tree

2 files changed

+20
-26
lines changed

2 files changed

+20
-26
lines changed

luarules/gadgets/game_fogofwar_remover.lua

-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ function gadget:GetInfo()
1919
}
2020
end
2121

22-
local spGetTeamList = Spring.GetTeamList
2322
local spGetAllyTeamList= Spring.GetAllyTeamList
2423

2524
function gadget:GameFrame(n)
2625
if n%1800 == 10 then
27-
local teams = spGetTeamList()
2826
local allyteams = spGetAllyTeamList()
2927
for i = 1,#allyteams do
3028
local allyTeamID = allyteams[i]

luaui/Widgets/gui_sensor_ranges_los.lua

+20-24
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,10 @@ local rangeLineWidth = 4.5 -- (note: will end up larger for larger vertical scre
1818

1919
local circleSegments = 64
2020
local rangecorrectionelmos = 16 -- how much smaller they are drawn than truth due to LOS mipping
21-
22-
local debugmode = false
2321
--------- End configurables ------
2422

2523
local minSightDistance = 100
2624
local gaiaTeamID = Spring.GetGaiaTeamID()
27-
local olduseteamcolors = false -- needs re-init when teamcolor prefs are changed
2825

2926
------- GL4 NOTES -----
3027
--only update every 15th frame, and interpolate pos in shader!
@@ -40,7 +37,7 @@ local olduseteamcolors = false -- needs re-init when teamcolor prefs are changed
4037
-- X remove debug code
4138
-- X validate options!
4239
-- X The only actual param needed per unit is its los range :D
43-
-- X refactor the opacity
40+
-- X refactor the opacity
4441

4542
local luaShaderDir = "LuaUI/Widgets/Include/"
4643
local LuaShader = VFS.Include(luaShaderDir .. "LuaShader.lua")
@@ -98,12 +95,8 @@ end
9895

9996
-- Functions shortcuts
10097
local spGetSpectatingState = Spring.GetSpectatingState
101-
local spGetUnitDefID = Spring.GetUnitDefID
102-
local spGetUnitPosition = Spring.GetUnitPosition
103-
local spGetUnitSensorRadius = Spring.GetUnitSensorRadius
10498
local spIsUnitAllied = Spring.IsUnitAllied
10599
local spGetUnitTeam = Spring.GetUnitTeam
106-
local glColor = gl.Color
107100
local glColorMask = gl.ColorMask
108101
local glDepthTest = gl.DepthTest
109102
local glLineWidth = gl.LineWidth
@@ -119,7 +112,6 @@ local GL_REPLACE = GL.REPLACE
119112
local GL_TRIANGLE_FAN = GL.TRIANGLE_FAN
120113

121114
-- Globals
122-
local vsx, vsy = Spring.GetViewGeometry()
123115
local lineScale = 1
124116
local spec, fullview = spGetSpectatingState()
125117
local allyTeamID = Spring.GetMyAllyTeamID()
@@ -135,7 +127,7 @@ for unitDefID, unitDef in pairs(UnitDefs) do
135127
end
136128

137129
function widget:ViewResize(newX, newY)
138-
vsx, vsy = Spring.GetViewGeometry()
130+
local vsx, vsy = Spring.GetViewGeometry()
139131
lineScale = (vsy + 500)/ 1300
140132
end
141133

@@ -171,35 +163,35 @@ local function CalculateOverlapping()
171163
local totaloverlapping = 0
172164
local inviewcircles = 0
173165
local inviewoverlapping = 0
174-
175-
for index, unitID in ipairs(allcircles) do
166+
167+
for index, unitID in ipairs(allcircles) do
176168
local px,py,pz = Spring.GetUnitPosition(unitID)
177169
--Spring.Echo(px,py,pz)
178-
if px then
170+
if px then
179171
local unitDefID = Spring.GetUnitDefID(unitID)
180172
local losrange = unitRange[unitDefID]
181173
totalcircles = totalcircles + 1
182174
-- check for overlap
183175
local overlaps = False
184-
for index2, unitID2 in ipairs(allcircles) do
176+
for index2, unitID2 in ipairs(allcircles) do
185177
local unitDefID2 = Spring.GetUnitDefID(unitID2)
186178
local losrange2 = unitRange[unitDefID2]
187179
--Spring.Echo(losrange2, losrange)
188-
if losrange2 > losrange then
180+
if losrange2 > losrange then
189181
local px2, py2, pz2 = Spring.GetUnitPosition(unitID2)
190182
--Spring.Echo(px-px2, pz-pz2, losrange2, losrange)
191183
if px2 and (math.diag(px-px2, pz-pz2) < losrange2 - losrange) then
192184
overlaps = true
193185
end
194186
end
195187
end
196-
197-
198-
188+
189+
190+
199191
if Spring.IsSphereInView(px,py,pz,losrange) then
200192
inviewcircles =inviewcircles + 1
201193
if overlaps then inviewoverlapping = inviewoverlapping + 1 end
202-
end
194+
end
203195
if overlaps then totaloverlapping = totaloverlapping + 1 end
204196
end
205197
end
@@ -208,7 +200,7 @@ end
208200

209201
function widget:TextCommand(command)
210202
if string.find(command, "loscircleoverlap", nil, true) then
211-
Spring.Echo("CalculateOverlapping", CalculateOverlapping())
203+
Spring.Echo("CalculateOverlapping", CalculateOverlapping())
212204
end
213205
end
214206

@@ -217,6 +209,10 @@ function widget:Initialize()
217209
widgetHandler:RemoveWidget()
218210
return
219211
end
212+
if Spring.GetModOptions().disable_fogofwar then
213+
widgetHandler:RemoveWidget()
214+
return
215+
end
220216
WG.losrange = {}
221217
WG.losrange.getOpacity = function()
222218
return opacity
@@ -244,14 +240,14 @@ function widget:VisibleUnitAdded(unitID, unitDefID, unitTeam, noupload)
244240
unitTeam = unitTeam or spGetUnitTeam(unitID)
245241
noupload = noupload == true
246242
if unitRange[unitDefID] == nil or unitTeam == gaiaTeamID then return end
247-
243+
248244
if (not (spec and fullview)) and (not spIsUnitAllied(unitID)) then -- given units are still considered allies :/
249245
return
250246
end -- display mode for specs
251247

252248
if Spring.GetUnitIsBeingBuilt(unitID) then return end
253249

254-
instanceCache[1] = unitRange[unitDefID]
250+
instanceCache[1] = unitRange[unitDefID]
255251
pushElementInstance(circleInstanceVBO,
256252
instanceCache,
257253
unitID, --key
@@ -274,7 +270,7 @@ end
274270

275271
function widget:DrawWorld()
276272
--if spec and fullview then return end
277-
273+
278274
if Spring.IsGUIHidden() or (WG['topbar'] and WG['topbar'].showingQuit()) then return end
279275
if circleInstanceVBO.usedElements == 0 then return end
280276
if opacity < 0.01 then return end
@@ -285,7 +281,7 @@ function widget:DrawWorld()
285281
glDepthTest(false) -- Dont do depth tests, as we are still pre-unit
286282

287283
gl.Texture(0, "$heightmap") -- Bind the heightmap texture
288-
circleShader:Activate()
284+
circleShader:Activate()
289285
circleShader:SetUniform("rangeColor", rangeColor[1], rangeColor[2], rangeColor[3], opacity * (useteamcolors and 2 or 1 ))
290286
circleShader:SetUniform("teamColorMix", useteamcolors and 1 or 0)
291287

0 commit comments

Comments
 (0)