@@ -18,13 +18,10 @@ local rangeLineWidth = 4.5 -- (note: will end up larger for larger vertical scre
18
18
19
19
local circleSegments = 64
20
20
local rangecorrectionelmos = 16 -- how much smaller they are drawn than truth due to LOS mipping
21
-
22
- local debugmode = false
23
21
---- ----- End configurables ------
24
22
25
23
local minSightDistance = 100
26
24
local gaiaTeamID = Spring .GetGaiaTeamID ()
27
- local olduseteamcolors = false -- needs re-init when teamcolor prefs are changed
28
25
29
26
---- --- GL4 NOTES -----
30
27
-- 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
40
37
-- X remove debug code
41
38
-- X validate options!
42
39
-- X The only actual param needed per unit is its los range :D
43
- -- X refactor the opacity
40
+ -- X refactor the opacity
44
41
45
42
local luaShaderDir = " LuaUI/Widgets/Include/"
46
43
local LuaShader = VFS .Include (luaShaderDir .. " LuaShader.lua" )
98
95
99
96
-- Functions shortcuts
100
97
local spGetSpectatingState = Spring .GetSpectatingState
101
- local spGetUnitDefID = Spring .GetUnitDefID
102
- local spGetUnitPosition = Spring .GetUnitPosition
103
- local spGetUnitSensorRadius = Spring .GetUnitSensorRadius
104
98
local spIsUnitAllied = Spring .IsUnitAllied
105
99
local spGetUnitTeam = Spring .GetUnitTeam
106
- local glColor = gl .Color
107
100
local glColorMask = gl .ColorMask
108
101
local glDepthTest = gl .DepthTest
109
102
local glLineWidth = gl .LineWidth
@@ -119,7 +112,6 @@ local GL_REPLACE = GL.REPLACE
119
112
local GL_TRIANGLE_FAN = GL .TRIANGLE_FAN
120
113
121
114
-- Globals
122
- local vsx , vsy = Spring .GetViewGeometry ()
123
115
local lineScale = 1
124
116
local spec , fullview = spGetSpectatingState ()
125
117
local allyTeamID = Spring .GetMyAllyTeamID ()
@@ -135,7 +127,7 @@ for unitDefID, unitDef in pairs(UnitDefs) do
135
127
end
136
128
137
129
function widget :ViewResize (newX , newY )
138
- vsx , vsy = Spring .GetViewGeometry ()
130
+ local vsx , vsy = Spring .GetViewGeometry ()
139
131
lineScale = (vsy + 500 )/ 1300
140
132
end
141
133
@@ -171,35 +163,35 @@ local function CalculateOverlapping()
171
163
local totaloverlapping = 0
172
164
local inviewcircles = 0
173
165
local inviewoverlapping = 0
174
-
175
- for index , unitID in ipairs (allcircles ) do
166
+
167
+ for index , unitID in ipairs (allcircles ) do
176
168
local px ,py ,pz = Spring .GetUnitPosition (unitID )
177
169
-- Spring.Echo(px,py,pz)
178
- if px then
170
+ if px then
179
171
local unitDefID = Spring .GetUnitDefID (unitID )
180
172
local losrange = unitRange [unitDefID ]
181
173
totalcircles = totalcircles + 1
182
174
-- check for overlap
183
175
local overlaps = False
184
- for index2 , unitID2 in ipairs (allcircles ) do
176
+ for index2 , unitID2 in ipairs (allcircles ) do
185
177
local unitDefID2 = Spring .GetUnitDefID (unitID2 )
186
178
local losrange2 = unitRange [unitDefID2 ]
187
179
-- Spring.Echo(losrange2, losrange)
188
- if losrange2 > losrange then
180
+ if losrange2 > losrange then
189
181
local px2 , py2 , pz2 = Spring .GetUnitPosition (unitID2 )
190
182
-- Spring.Echo(px-px2, pz-pz2, losrange2, losrange)
191
183
if px2 and (math .diag (px - px2 , pz - pz2 ) < losrange2 - losrange ) then
192
184
overlaps = true
193
185
end
194
186
end
195
187
end
196
-
197
-
198
-
188
+
189
+
190
+
199
191
if Spring .IsSphereInView (px ,py ,pz ,losrange ) then
200
192
inviewcircles = inviewcircles + 1
201
193
if overlaps then inviewoverlapping = inviewoverlapping + 1 end
202
- end
194
+ end
203
195
if overlaps then totaloverlapping = totaloverlapping + 1 end
204
196
end
205
197
end
208
200
209
201
function widget :TextCommand (command )
210
202
if string.find (command , " loscircleoverlap" , nil , true ) then
211
- Spring .Echo (" CalculateOverlapping" , CalculateOverlapping ())
203
+ Spring .Echo (" CalculateOverlapping" , CalculateOverlapping ())
212
204
end
213
205
end
214
206
@@ -217,6 +209,10 @@ function widget:Initialize()
217
209
widgetHandler :RemoveWidget ()
218
210
return
219
211
end
212
+ if Spring .GetModOptions ().disable_fogofwar then
213
+ widgetHandler :RemoveWidget ()
214
+ return
215
+ end
220
216
WG .losrange = {}
221
217
WG .losrange .getOpacity = function ()
222
218
return opacity
@@ -244,14 +240,14 @@ function widget:VisibleUnitAdded(unitID, unitDefID, unitTeam, noupload)
244
240
unitTeam = unitTeam or spGetUnitTeam (unitID )
245
241
noupload = noupload == true
246
242
if unitRange [unitDefID ] == nil or unitTeam == gaiaTeamID then return end
247
-
243
+
248
244
if (not (spec and fullview )) and (not spIsUnitAllied (unitID )) then -- given units are still considered allies :/
249
245
return
250
246
end -- display mode for specs
251
247
252
248
if Spring .GetUnitIsBeingBuilt (unitID ) then return end
253
249
254
- instanceCache [1 ] = unitRange [unitDefID ]
250
+ instanceCache [1 ] = unitRange [unitDefID ]
255
251
pushElementInstance (circleInstanceVBO ,
256
252
instanceCache ,
257
253
unitID , -- key
274
270
275
271
function widget :DrawWorld ()
276
272
-- if spec and fullview then return end
277
-
273
+
278
274
if Spring .IsGUIHidden () or (WG [' topbar' ] and WG [' topbar' ].showingQuit ()) then return end
279
275
if circleInstanceVBO .usedElements == 0 then return end
280
276
if opacity < 0.01 then return end
@@ -285,7 +281,7 @@ function widget:DrawWorld()
285
281
glDepthTest (false ) -- Dont do depth tests, as we are still pre-unit
286
282
287
283
gl .Texture (0 , " $heightmap" ) -- Bind the heightmap texture
288
- circleShader :Activate ()
284
+ circleShader :Activate ()
289
285
circleShader :SetUniform (" rangeColor" , rangeColor [1 ], rangeColor [2 ], rangeColor [3 ], opacity * (useteamcolors and 2 or 1 ))
290
286
circleShader :SetUniform (" teamColorMix" , useteamcolors and 1 or 0 )
291
287
0 commit comments