I fixed he pathing bug, where it would zig zag around the system wasting lots of time flying back and forth. It now implements nearest neighbor solution to the travelling salesman problem, it's much more efficient. Which is fancy talk for it now targets the asteroid nearest to the one it just finished, rather than to the ship. When it starts it will of course target the one closest to the ship first (Usually, I have seen it target a different nearby one ONCE). Tested in single player, but should work in multiplayer as well as the old way.
Also, I am working off a copy that says it is version 0.9 so if there is a newer version, please post a direct link, as neither the other thread nor this one seems to have the actual link to the mod.
-- check the sector for an asteroid that can be mined.
-- if there is one, assign minableAsteroid
function mineCommand.findMinableAsteroid()
local ship = Entity()
local sector = Sector()
local oldAstroNum
local sourceXYZ
if valid(mineCommand.minableAsteroid) then -- because even after the "asteroiddestroyed" event fired it still is part of sector:getEntitiesByType(EntityType.Asteroid) >,<
oldAstroNum = mineCommand.minableAsteroid.index.number
sourceXYZ = mineCommand.minableAsteroid.translationf
mineCommand.unregisterTarget()
else
sourceXYZ = ship.translationf
end
mineCommand.minableAsteroid = nil
local asteroids = {sector:getEntitiesByType(EntityType.Asteroid)}
local nearest = math.huge
--Go after closest asteroids first
for _, a in pairs(asteroids) do
local resources = a:getMineableResources()
if ((resources ~= nil and resources > 0) or cc.settings["mineAllSetting"]) and a.index.number ~= oldAstroNum then
-- local dist = distance2(a.translationf, ship.translationf)
local dist = distance2(a.translationf, sourceXYZ)
if dist < nearest then
nearest = dist
mineCommand.minableAsteroid = a
end
end
end
if valid(mineCommand.minableAsteroid) then
mineCommand.registerTarget()
return true
else
return false
end
end