Page 1 of 1

Spitters attacking trees

Posted: Fri Jan 11, 2019 6:04 pm
by TheSAguy
Hi,

In my mod, I've added some spitters that shoot mines.
I've noticed that sometimes they attack trees, probably if they are stuck or something. As a result you have a lot of mines just piling up.
I actually have a check to remove old mines, but was wondering what I could do about this issue?

Would a check if a mine is created to kill all trees in a small radius around it be too CPU intense?

Thanks.

Re: Spitters attacking trees

Posted: Mon Jan 14, 2019 5:57 pm
by TheSAguy
Okay, so I've implemented the below check, when Mine Layers place mines or Unit Launchers launch units, to look for trees in the immediate area and remove them if there. Hoping this will not be too CPU intense and solve the issue of them getting stuck and keeping attaching trees.

Code: Select all

--- Remove Trees
function Remove_Trees(entity)
		--- Where "entity" is or newly created units form the launcher or Mines being layed.
		local surface = entity.surface
		local radius = 1.5
		local pos = entity.position
		local area = {{pos.x - radius, pos.y - radius}, {pos.x + radius, pos.y + radius}}	
		-- find nearby trees
		local trees = {}
		local trees = surface.find_entities_filtered{area=area, type="tree"}
		-- Remove Trees
		if #trees > 0 then
		writeDebug("Tree Found")
			for i,tree in pairs(trees) do
				if tree and tree.valid then
					tree.die()
				end
			end
		end
end