Algorithm for finding nearest entity

Place to get help with not working mods / modding interface.
Simcra
Long Handed Inserter
Long Handed Inserter
Posts: 76
Joined: Wed Apr 06, 2016 6:05 am
Contact:

Algorithm for finding nearest entity

Post by Simcra »

Hi all,

I have been struggling to achieve an efficient algorithm for finding the nearest entity of a certain type to an entity or player in the same surface. I am aware that a function already exists for finding the nearest enemy to a player in the game and that it is quite optimized, I need something equivalent to this. Does anyone have a working algorithm that fits this criteria or could perhaps point me in the right direction? Again, my appologies if this is in the wrong forum.

Kind Regards,
Simcra
Rseding91
Factorio Staff
Factorio Staff
Posts: 15938
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Algorithm for finding nearest entity

Post by Rseding91 »

The internal data structures for entities aren't setup for a "find nearest of type" - you'd just have to find all and iterate checking distance - which is inefficient at best and horribly slow at worse due to all the extra memory allocations of finding entities and pushing references into the lua state.
If you want to get ahold of me I'm almost always on Discord.
Simcra
Long Handed Inserter
Long Handed Inserter
Posts: 76
Joined: Wed Apr 06, 2016 6:05 am
Contact:

Re: Algorithm for finding nearest entity

Post by Simcra »

That's sad, I'm guessing it's not worth feature requesting this?
Post Reply

Return to “Modding help”