function gadget:GetInfo() return { name = "Hacky unreached Command workaround", desc = "Set smaller move goal for builder commands", author = "Pako", date = "15 March 2012", license = "GNU GPL, v2 or later", layer = 0, enabled = true } end -- pako IS AWESOME: -- SEND DOUBLE WAIT command to ALL cons that dont have an empty queu ------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------- if (not gadgetHandler:IsSyncedCode()) then return end ------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------- local CMD_RECLAIM = CMD.RECLAIM local CMD_RESURRECT = CMD.RESURRECT local CMD_REPAIR = CMD.REPAIR local CMD_WAIT = CMD.WAIT local builders = {} local numbuilders=0 function gadget:UnitCreated(unitID, unitDefID, unitTeam, builderID) if unitDefID and tonumber(UnitDefs[unitDefID].buildSpeed) and UnitDefs[unitDefID].buildSpeed > 0 and tonumber(UnitDefs[unitDefID].speed) and UnitDefs[unitDefID].speed>0 then --Spring.Echo(UnitDefs[unitDefID].name .. " added to table id:" .. tostring(unitID)) table.insert(builders, 1, unitID) --builders[unitID] = true numbuilders = numbuilders+1 else builders[unitID] = nil --Spring.Echo(UnitDefs[unitDefID].name .. " is not a builder") end end function gadget:UnitDestroyed(unitID, unitDefID, unitTeam) if unitDefID and tonumber(UnitDefs[unitDefID].buildSpeed) and UnitDefs[unitDefID].buildSpeed > 0 and tonumber(UnitDefs[unitDefID].speed) and UnitDefs[unitDefID].speed>0 then table.remove(builders, unitID) numbuilders = numbuilders-1 --Spring.Echo(UnitDefs[unitDefID].name .. " removed from table") end end --buildDistance function gadget:GameFrame(f) local framemod=f%37 for b,unitID in ipairs(builders) do if unitID%37 == framemod then -- only wait wait each unit every 37 frames, only if they actually have commands, this also staggers the command sending so it doesnt all happen in 1 frame if Spring.ValidUnitID(unitID) and Spring.GetUnitCommands(unitID) and #Spring.GetUnitCommands(unitID) >0 then Spring.GiveOrderToUnit(unitID,CMD_WAIT,{},{}) Spring.GiveOrderToUnit(unitID,CMD_WAIT,{},{}) end end end end