function gadget:GetInfo()
	return {
		name = "DPS Gadget",
		desc = "Displays damage dealt",
		author = "Argh",
		date = "October 29, 2009",
		license = "GPL, v. 2 or later, 2009",
		layer = -255,
		enabled = true,
	}
end
if (gadgetHandler:IsSyncedCode()) then

function gadget:UnitDamaged(unitID, unitDefID, unitTeam, damage, paralyzer, weaponID, attackerID, attackerDefID, attackerTeam)
	if damage ~= nil and damage > 1 then
		SendToUnsynced("dps_display",unitTeam,attackerTeam,unitID,math.floor(damage),paralyzer)
	end
end

function gadget:RecvLuaMsg(msg, playerID)
	--Spring.Echo("message received, "..msg)
	if string.find(msg,"dpsGadgetStart") then
		msg = msg:gsub("dpsGadgetStart","")
		team = tonumber(msg)
		SendToUnsynced("dps_on",team)
	end
	if string.find(msg,"dpsGadgetStop") then
		msg = msg:gsub("dpsGadgetStop","")
		team = tonumber(msg)
		SendToUnsynced("dps_off",team)
	end
end

else

local myTeam = Spring.GetLocalTeamID()
local gaiaTeam = Spring.GetGaiaTeamID()
local damagedTable = {}
local removeList = {}
local displayTable = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
local a,b = 0,0
local x,y = gl.GetViewSizes()
local fontScale = 25 * x /1600

local dt,diffTime,oldTime = 0,0,0

local function updateDPS(diffTime)
	for i,k in pairs(damagedTable) do
		if k.alpha == nil or k.alpha - 0.05 <= 0 then
			table.insert(removeList,i)
		else
			k.alpha = k.alpha - 0.05
			k.yLoc = k.yLoc + 2
		end
	end
	for i,k in ipairs(removeList) do
		damagedTable[k] = nil
	end
	removeList = {}
end


function gadget:DrawScreen()
	dt = Spring.GetLastUpdateSeconds()
	diffTime = oldTime + dt
	oldTime = diffTime
	local glColor = gl.Color
	local glText = gl.Text
	local WorldToScreenCoords = Spring.WorldToScreenCoords

	if diffTime % 0.1 < 0.05 then
		updateDPS(diffTime)
	end
	if displayTable[myTeam + 1] == 1 then
		for i,k in pairs(damagedTable) do
			if k.attackerTeam == myTeam then
				a,b = WorldToScreenCoords(k.xLoc,k.yLoc,k.zLoc)
				glColor(1.0,1.0,1.0,k.alpha)
				glText(k.damage,a,b + 32,fontScale)
			elseif k.unitTeam == myTeam then
				a,b = WorldToScreenCoords(k.xLoc,k.yLoc,k.zLoc)
				glColor(1.0,0.5,0.0,k.alpha)
				glText(k.damage,a,b + 32,fontScale)
			end
		end
	end
end



local function dpsDisplay(_,unitTeam,attackerTeam,unitID,damage,paralyzer)
	if unitID ~= nil then
	xLoc,yLoc,zLoc = Spring.GetUnitPosition(unitID)
	if xLoc ~= nil  then
		table.insert(damagedTable,unitID,{alpha = 1.0,unitTeam = unitTeam,attackerTeam = attackerTeam,unitID = unitID, damage = damage, paralyzer = paralyzer,xLoc = xLoc, yLoc = yLoc, zLoc = zLoc})

	end
	end
end

local function dpsOn(_,team)
	--Spring.Echo("on triggered")	
	if team == myTeam then
		displayTable[myTeam + 1] = 1
	end

end

local function dpsOff(_,team)
	--Spring.Echo("off triggered")
	if team == myTeam then
		displayTable[myTeam + 1] = 0
	end

end

function gadget:Initialize()
	gadgetHandler:AddSyncAction("dps_on", dpsOn)
	gadgetHandler:AddSyncAction("dps_off", dpsOff)
	gadgetHandler:AddSyncAction("dps_display", dpsDisplay)
end

end
