This is the very last time I will help you, though, I don't help people who don't want to learn, and your attitude sucks.
Code: Select all
function widget:GetInfo()
return {
name = "Enemy Spotter",
desc = "Shows a team-colored circle where bad guys' units are",
author = "Argh",
date = "December 16th, 2009",
license = "(C) Wolfe Games, released under GPL v. 2",
layer = 0,
enabled = true -- loaded by default?
}
end
------------------------------------------------------------------------------LOCAL STUFF
local myUnitID, myDefID, myTeamID
local frame, oldframe = 1,0
local texture = "bitmaps/StaticCircle.tga"
local LocalTeam = Spring.GetLocalTeamID()
local teamColorTable = {}
local visibleTable = {}
local radiusTable = {}
------------------------------------------------------------------------------OPENGL LOCALS
local glColor = gl.Color
local glTexture = gl.Texture
local glDrawListAtUnit = gl.DrawListAtUnit
local glDeleteList = gl.DeleteList
local glBlending = gl.Blending
local glDepthMask = gl.DepthMask
local glTexCoord = gl.TexCoord
local glVertex = gl.Vertex
local glCreateList = gl.CreateList
local glBeginEnd = gl.BeginEnd
local GL_QUADS = GL.QUADS
local glDepthTest = gl.DepthTest
local GL_SRC_ALPHA = GL.SRC_ALPHA
local GL_ONE = GL.ONE
------------------------------------------------------------------------------SPRING LOCALS
local GetVisibleUnits = Spring.GetVisibleUnits
local GetUnitTeam = Spring.GetUnitTeam
local GetUnitDefID = Spring.GetUnitDefID
local GetTeamColor = Spring.GetTeamColor
local IsUnitVisible = Spring.IsUnitVisible
local GetDrawFrame = Spring.GetDrawFrame
local GetVisibleUnits = Spring.GetVisibleUnits
local ALL_UNITS = Spring.ALL_UNITS
function widget:Initialize()
--A simple quad
SimpleCircle = glCreateList(function()
glBeginEnd(GL_QUADS, function()
glTexCoord(0.04,0.04)
glVertex(-1,10,-1)
glTexCoord(0.96,0.04)
glVertex(1,10,-1)
glTexCoord(0.96,0.96)
glVertex(1,10,1)
glTexCoord(0.04,0.96)
glVertex(-1,10,1)
end)
end)
--Little speedup, so we don't have to constantly look that up from Spring
for i = 0,64 do
r,g,b = GetTeamColor(i)
if i ~= nil then
table.insert(teamColorTable,i,{r = r,g = g,b =b})
end
end
for i,k in ipairs (UnitDefs) do
table.insert(radiusTable,{radius = k.xsize * 6})
end
end
function widget:Shutdown()
glDeleteList(SimpleCircle)
end
-- Drawing:
function widget:DrawWorldPreUnit()
--Speedup of GetVisibleUnits
frame = GetDrawFrame()
if frame > oldframe then
visibleTable = GetVisibleUnits(ALL_UNITS,LocalTeam,false)
oldframe = frame + 5
end
--Main drawing setup
glBlending(GL_SRC_ALPHA, GL_ONE)
glDepthTest(true)
glDepthMask(false)
for i=1,#visibleTable do
myUnitID = visibleTable[i]
myDefID = GetUnitDefID(myUnitID)
myTeamID = GetUnitTeam(myUnitID)
if (myTeamID) and myTeamID ~= LocalTeam then
radius = radiusTable[myDefID].radius
glColor(teamColorTable[myTeamID].r,teamColorTable[myTeamID].g,teamColorTable[myTeamID].b,1.0)
glTexture(texture)
glDrawListAtUnit(myUnitID, SimpleCircle, false, radius, 1.0, radius, 0, 0, 0, 0)
end
end
end
For advanced folks, there is at least one speedup left (and, ofc, if you don't like the circles clipping the ground, feel free to change that glDepthTest to false, it's that way because of other things in P.U.R.E.).