Page 1 of 1

Mined Area Widget

Posted: 19 Dec 2008, 08:59
by Argh
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.

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

Re: Mined Area Widget

Posted: 19 Dec 2008, 12:28
by lurker
What is your extractsMetal value?

Re: Mined Area Widget

Posted: 19 Dec 2008, 22:24
by Argh
0.0001...

:roll: If that means it's not taking real metal into account, but is just using that value... then I'll leave it that way, then you can't see enemy metal use very well.

Re: Mined Area Widget

Posted: 19 Dec 2008, 22:30
by lurker
Did you say you set the extraction depth in a gadget? But yeah, that's only 1/10 the normal value; I have no idea why it affects the rendering, but it does.

Re: Mined Area Widget

Posted: 19 Dec 2008, 22:47
by Argh
Did you say you set the extraction depth in a gadget? But yeah, that's only 1/10 the normal value; I have no idea why it affects the rendering, but it does.
No, that's hardcoded right now.

I'm guessing it's affecting the rendering because it's blending based on OTA values, and it's blending it out at the edges to reflect that formula it uses. Sorry, I don't have time atm to dig it up, and if that's the case, it's not a big deal, I would prefer that players not see other players' mines on the metalmap anyhow.

Re: Mined Area Widget

Posted: 19 Dec 2008, 23:03
by lurker
Then cut it by 10 once again! muahaha

Re: Mined Area Widget

Posted: 19 Dec 2008, 23:07
by Argh
Yes :twisted:

Of course, if they turn Widgets off, they're screwed, but with my game, that's pretty much the case anyhow.