The code I'm currently using to find ores in a specific radius around a specific position is this:
Code: Select all
local results = game.findentitiesfiltered{type = "resource", area = GetBoundingBox(position, radius)}
local ores = {}
for i = #results, 1, -1 do
local ore = results[i]
-- No fluids.
if game.entityprototypes[ore.name].resourcecategory == "basic-fluid"
-- No lava.
or game.entityprototypes[ore.name].resourcecategory == "lava-magma"
-- No depleted resources that aren't infinite.
or (ore.amount <= 0 and not game.entityprototypes[ore.name].infiniteresource)
-- No trees.
or string.find(ore.name, "tree") then
--table.remove(results, i)
else
table.insert(ores, results[i])
end
end
--return results
return ores
Code: Select all
local results = game.findentitiesfiltered{type = "resource", area = GetBoundingBox(self.vehicle.position, radius)}
return results
The new list was slightly faster, but only 2-4 ms (on the 15-25).
Situation: There are (currently 21) entities searching for ores in a certain radius, driving there, mining, searching anew, etc..
My question is: Does anyone have suggestions on optimizing this?