Mined Area Widget
Posted: 19 Dec 2008, 08:59
This is a super-simple Widget, for a super-simple purpose. For whatever reason, Spring 0.77b5 doesn't render the metalmap's "mined" status very clearly on my hardware (devs, yes, it renders, but it's so faint I can hardly see it, it's probably a layer issue).
I wrote this to fix it, because P.U.R.E.'s relationship between metal and the maps has changed, and I needed to very clearly tell players where they were already mining, and this does it.
To make use of this, Units need to have a customParam, "miner", with a value of "yes" (or change this to however you want, obviously- I tend to avoid using UnitDef values for most things).
At any rate, it was a 20-minute little thing, so if anybody likes it, great, if not, no biggie.
I wrote this to fix it, because P.U.R.E.'s relationship between metal and the maps has changed, and I needed to very clearly tell players where they were already mining, and this does it.
To make use of this, Units need to have a customParam, "miner", with a value of "yes" (or change this to however you want, obviously- I tend to avoid using UnitDef values for most things).
At any rate, it was a 20-minute little thing, so if anybody likes it, great, if not, no biggie.
Code: Select all
function widget:GetInfo()
return {
name = "Mine Widget",
desc = "Shows mined areas clearly.",
author = "Argh",
date = "December 19, 2008",
license = "Public Domain, or the least-restrictive rights of your country of residence",
layer = 0,
enabled = true -- loaded by default?
}
end
local radius = Game.extractorRadius
local radius2 = Game.extractorRadius - 32
local radius3 = Game.extractorRadius - 64
local mode
local MinerList = {}
local unitIDList
local id
local unitID
local GetMapDrawMode = Spring.GetMapDrawMode
local GetVisibleUnits = Spring.GetVisibleUnits
local IsUnitVisible = Spring.IsUnitVisible
local GetUnitDefID = Spring.GetUnitDefID
local GetUnitPosition = Spring.GetUnitPosition
local glColor = gl.Color
local glDrawGroundCircle = gl.DrawGroundCircle
local glLineWidth = gl.LineWidth
function widget:Initialize()
for ud,_ in pairs(UnitDefs) do
if UnitDefs[ud].customParams.miner == 'yes' then
table.insert(MinerList,ud,1)
end
end
end
function widget:DrawWorldPreUnit()
mode = GetMapDrawMode()
if mode == "metal" then
unitIDList = GetVisibleUnits(-1,3000,false)
if unitIDList[1] ~= nil then
for _,unitID in ipairs(unitIDList) do
if (IsUnitVisible(unitID)) then
id = GetUnitDefID(unitID)
if MinerList[id] then
x,y,z = GetUnitPosition(unitID)
glLineWidth(10)
glColor(1,0,0,1.0)
glDrawGroundCircle(x,y,z,radius,123)
glColor(1,0,0,0.75)
glDrawGroundCircle(x,y,z,radius2,123)
glColor(1,0,0,0.5)
glDrawGroundCircle(x,y,z,radius3,123)
end
end
end
end
end
end