Page 1 of 1

Make count_tiles and find_tiles filtered

Posted: Thu Nov 30, 2017 9:27 pm
by darkfrei
Hi all!

It would be good to search tiles with some fast function. For example we have

Code: Select all

surface.count_entities_filtered{area=…, position=…, name=…, type=…, force=…, limit=…}
with parameters

Code: Select all

surface.count_entities_filtered{area=area, force=player_force, limit=1}
, it works much better then code like

Code: Select all

function find_first_good_tile_in_chunk(chunk, surface, good_tiles_list)
	for y = (chunk.y*32), (chunk.y*32+31) do
		for x = (chunk.x*32), (chunk.x*32+31) do
			local tile = surface.get_tile(x, y)
			for i, tile_name in pairs (good_tiles_list) do
				if tile and (tile.name == tile_name) then
					return true
				end
			end
		end
	end
	return false
end
Reference mod: https://mods.factorio.com/mods/darkfrei ... mptyChunks
Performance was got from https://mods.factorio.com/mods/darkfrei ... sion/21503 - first tile searching needs twice (in this case) more time then first entity searching with force in higher quantity of chunks.

Re: Make count_tiles and find_tiles filtered

Posted: Thu Nov 30, 2017 9:29 pm
by darkfrei
Or it will be good to have tile.force by all player placed tiles, if it possible.

Re: Make count_tiles and find_tiles filtered

Posted: Fri Dec 01, 2017 10:23 am
by Rseding91
darkfrei wrote:Or it will be good to have tile.force by all player placed tiles, if it possible.
There exists no such property that the game could expose. All tiles are forceless and owned by no one.

Re: Make count_tiles and find_tiles filtered

Posted: Fri Dec 01, 2017 11:20 am
by darkfrei
Rseding91 wrote:There exists no such property that the game could expose. All tiles are forceless and owned by no one.
There must be one parameter - can this tile be removed by the player or not. Or was this tile place by player or was generated. I can remove concrete, but I can't remove landfill. Why?