function gadget:GetInfo() return { name = "mining blabla2", desc = "some broken stuff", author = "knorke", date = "4 Okt 2010", license = "rcdraco's draco license", layer = 0, enabled = true -- loaded by default } end if (gadgetHandler:IsSyncedCode()) then local miners = {} -- [unitID] alive: true oder false cargo: wieviel er trägt status: was er gerade macht: "loading" "unloading" "mining" "to_res" "to_hq" local miner_name = "armflash"; function gadget:UnitFinished(unitID, unitDefID, teamID) if (is_miner_type (unitDefID) == true) then add_miner (unitID) end end function gadget:GameFrame(frameNum) _G.miners = miners; end function gadget:Initialize() make_miner_table() _G.miners = miners; end function marker_on_unit (_uID, _text) if (markers == false) then return end if (_uID == nil) then return end if (_text == nil) then return end local x,y,z=Spring.GetUnitPosition (_uID) if (x == nil or y == nil or z == nil) then return end Spring.MarkerAddPoint (x,y,z, _text .. "id:" .. _uID) end function make_miner_table() miners = {} local all_units = Spring.GetAllUnits () for i in pairs(all_units) do local unitDefID = Spring.GetUnitDefID(all_units[i]) if (is_miner_type (unitDefID)==true) then add_miner (all_units[i]) end end end function is_miner_type (unitDefID) if (unitDefID == nil) then return false end local unitDef = UnitDefs[unitDefID] if (unitDef == nil) then return false end if (unitDef.name == miner_name) then return true end return false end function add_miner (unitID) miners [unitID] = {} miners [unitID].alive = true miners [unitID].cargo = 0 marker_on_unit (unitID, "added") end -------------------------------------------------------- --Border between SYNC and UNSYNC --when i wear my frilly dress im a real touhou end if (not gadgetHandler:IsSyncedCode()) then -------------------------------------------------------- --Length of table, for synced (using spairs) function sxlen(tbl) local qq = 0; for v in spairs(tbl) do qq = qq + 1; end return qq; end function gadget:DrawScreen() gl.Color(0.5, 0.5, 0.5, 1) local ty = 0 for i in spairs(SYNCED.miners) do ty = ty + 1 gl.Text (ty .."| [" .. i .. "]".. "cargo:" .. SYNCED.miners[i].cargo, 100,300-ty*25 , 25, 'o') end gl.Text ("miners counted="..ty .. "#miners:" .. sxlen(SYNCED.miners), 100,300 , 25, 'o') end function gadget:DrawWorldPreUnit() gl.LineWidth(5.0) for i in spairs(SYNCED.miners) do if (SYNCED.miners[i].alive == true and i ~= nil and SYNCED.miners[i] ~=nil) then local x,y,z=Spring.GetUnitPosition (i) if (x ~= nil and y ~= nil and z ~= nil) then gl.Color(0, 1, 0, 1) gl.DrawGroundCircle (x,y,z, 50, 4) --all miners marked with a diamond shape --cargo status gl.Color(1, 0, 0, 1) gl.DrawGroundCircle (x+60,y,z, 90, 3) gl.Color(1, 1, 0, 1) gl.DrawGroundCircle (x+60,y,z, SYNCED.miners[i].cargo, 3) --growing triangle shows cargo status end end end end end