Spitters attacking trees

Place to get help with not working mods / modding interface.
Post Reply
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Spitters attacking trees

Post 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.

TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: Spitters attacking trees

Post 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

Post Reply

Return to “Modding help”