All pastes #1954880 Raw Edit

Unnamed

public lua v1 · immutable
#1954880 ·published 2010-10-05 14:54 UTC
rendered paste body
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	  }endif (gadgetHandler:IsSyncedCode()) thenlocal 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) endendfunction gadget:GameFrame(frameNum) 	_G.miners = miners;endfunction gadget:Initialize()	make_miner_table()	_G.miners = miners;endfunction 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)endfunction 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	endendfunction 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 falseendfunction 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 touhouendif (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;endfunction 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')endfunction 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	endendend