It uses CustomParams, so you can use different colors for different Units, or multiple weapons on a Unit, to show people what's what really clearly.
Will not show enemy ranges, ever, since that would be a cheat.
Can currently be set up for up to three weapons, adding more is trivial.
Code: Select all
function widget:GetInfo()
return {
name = "Range Widget",
desc = "Shows your units' weapon ranges, when selected.",
author = "Argh",
date = "January 21, 2009",
license = "Public Domain, or the least-restrictive rights of your country of residence",
layer = 0,
enabled = true -- loaded by default?
}
end
local RangeList = {}
local unitIDList
local id
local unitID
local Team = Spring.GetLocalTeamID()
local GetUnitDefID = Spring.GetUnitDefID
local glColor = gl.Color
local glDrawGroundCircle = gl.DrawGroundCircle
local glLineWidth = gl.LineWidth
local GetUnitPosition = Spring.GetUnitPosition
local GetUnitTeam = Spring.GetUnitTeam
local GetSelectedUnits = Spring.GetSelectedUnits
function widget:Initialize()
for ud,_ in pairs(UnitDefs) do
if UnitDefs[ud].customParams.show_range_one == 'yes' then
table.insert(RangeList,ud,{range_one = tonumber(UnitDefs[ud].customParams.weapon_range_one), colorR_one = tonumber(UnitDefs[ud].customParams.color_r_one),
colorG_one = tonumber(UnitDefs[ud].customParams.color_g_one), colorB_one = tonumber(UnitDefs[ud].customParams.color_b_one)})
end
if UnitDefs[ud].customParams.show_range_two == 'yes' then
table.insert(RangeList,ud,{range_two = tonumber(UnitDefs[ud].customParams.weapon_range_two), colorR_two = tonumber(UnitDefs[ud].customParams.color_r_two),
colorG_two = tonumber(UnitDefs[ud].customParams.color_g_two), colorB_two = tonumber(UnitDefs[ud].customParams.color_b_two)})
end
if UnitDefs[ud].customParams.show_range_three == 'yes' then
table.insert(RangeList,ud,{range_three = tonumber(UnitDefs[ud].customParams.weapon_range_three), colorR_three = tonumber(UnitDefs[ud].customParams.color_r_three),
colorG_three = tonumber(UnitDefs[ud].customParams.color_g_three), colorB_three = tonumber(UnitDefs[ud].customParams.color_b_three)})
end
end
end
function widget:DrawWorldPreUnit()
unitIDList = GetSelectedUnits()
if unitIDList[1] ~= nil then
for _,unitID in ipairs(unitIDList) do
if Team == GetUnitTeam(unitID) then
id = GetUnitDefID(unitID)
if RangeList[id] then
x,y,z = GetUnitPosition(unitID)
glLineWidth(2.5)
if RangeList[id].range_one ~= nil then
glColor(RangeList[id].colorR_one,RangeList[id].colorG_one,RangeList[id].colorB_one,0.35)
glDrawGroundCircle(x,y,z,RangeList[id].range_one,128)
end
if RangeList[id].range_two ~= nil then
glColor(RangeList[id].colorR_two,RangeList[id].colorG_two,RangeList[id].colorB_two,0.35)
glDrawGroundCircle(x,y,z,RangeList[id].range_two,128)
end
if RangeList[id].range_three ~= nil then
glColor(RangeList[id].colorR_three,RangeList[id].colorG_three,RangeList[id].colorB_three,0.35)
glDrawGroundCircle(x,y,z,RangeList[id].range_three,128)
end
end
end
end
end
end