Page 1 of 1

[Solved] Finding entities

Posted: Mon Jul 01, 2019 7:09 pm
by FuryoftheStars
EDIT: I'm having a hard time finding any info on surface.find_entities_filtered. Anyone got a link to it on the wiki?

Hi,

So I'm working on updating a mod created by someone else (Diesel Locomotive) where the mod checks for the existence of pumps adjacent to the locomotive by using the find_entities_filtered method. The problem I'm finding with this is that the locomotive can sit "off grid", and with the pumps collision box not encompassing the entire tile it sits on, it's possible for this method to check a point on the tile that is outside of the pump's collision box and thus misses seeing it.

My question is, is there another method of detecting entities that would be better/can check the entire tile of a given position?

EDIT: Ok, as I'm digging more into this, it seems like there are several different ways that it can do searches. This is the current variation of it that's being used in this mod:

Code: Select all

local found_pumps = loco.surface.find_entities_filtered{
	name = "pump",
	position = moveposition(
		loco.position,
		ori_to_dir(loco.orientation),
		{x = connection_array[j][1], y = connection_array[j][2]}
	)
}
Where connection_array is a table of {x,y} coordinates that we care about finding a pump at relative to the locomotive's current position.

Re: Finding entities

Posted: Mon Jul 01, 2019 9:36 pm
by darkfrei

Re: Finding entities

Posted: Mon Jul 01, 2019 11:51 pm
by FuryoftheStars
darkfrei wrote: Mon Jul 01, 2019 9:36 pm LuaSurface.find_entities_filtered
Ah, thank you! I'll look this over and see if it helps me understand it better. :)

Re: Finding entities

Posted: Tue Jul 02, 2019 2:03 am
by FuryoftheStars
Thanks for the link. As I was considering on using the radius argument to allow it to span the gaps, it occurred to me that if I also rounded the locomotive's position values that were being fed in, it would help make sure that the function was always scanning the middle of the tiles.

Anyways, this issue seems to be solved. Time to tackle the next one.... :)