Access to function that returns a pollution cloud's origin

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
DataCpt
Burner Inserter
Burner Inserter
Posts: 14
Joined: Mon Jan 20, 2025 11:16 pm
Contact:

Access to function that returns a pollution cloud's origin

Post by DataCpt »

There is clearly an efficient enough way for biters to pick an attack area or target based on pollution clouds.

To reimplement that behaviour for new entities or ones that don't have it built in, I'm using distance checks + surface.find_nearest_enemy_entity_with_owner followed by surface.find_entities_filtered (for polluting entities) alongside caching and load spreading to dodge performance issues.

I've considered creating and traversing a grid of all neighbouring polluted tiles and implementation A* to get the "center" but at this point it might be simpler to make whatever is used internally available.

I do not mind whether it returns a small area, an entity, a position or even something else. This is the most performance unfriendly hurdle I've run into when adding new enemies or adding behaviour to existing ones and I'd love a better solution!

If I've missed something in the API or if there's anything else I'm not thinking of, I'd love to hear it!
Rseding91
Factorio Staff
Factorio Staff
Posts: 15527
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Access to function that returns a pollution cloud's origin

Post by Rseding91 »

This information simply doesn’t exist. The game has no idea where pollution came from after it has been created.
If you want to get ahold of me I'm almost always on Discord.
computeraddict
Filter Inserter
Filter Inserter
Posts: 329
Joined: Sat Oct 07, 2023 6:44 am
Contact:

Re: Access to function that returns a pollution cloud's origin

Post by computeraddict »

Rseding91 wrote: Sun Feb 23, 2025 4:00 pm This information simply doesn’t exist. The game has no idea where pollution came from after it has been created.
Do biters just follow the pollution gradient until they encounter a hostile military target or pollution source?
Rseding91
Factorio Staff
Factorio Staff
Posts: 15527
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Access to function that returns a pollution cloud's origin

Post by Rseding91 »

computeraddict wrote: Sun Feb 23, 2025 5:08 pm Do biters just follow the pollution gradient until they encounter a hostile military target or pollution source?
Yes, and they search inside those chunks to find things to attack using the “find nearest enemy”.
If you want to get ahold of me I'm almost always on Discord.
computeraddict
Filter Inserter
Filter Inserter
Posts: 329
Joined: Sat Oct 07, 2023 6:44 am
Contact:

Re: Access to function that returns a pollution cloud's origin

Post by computeraddict »

Rseding91 wrote: Sun Feb 23, 2025 5:52 pm Yes, and they search inside those chunks to find things to attack using the “find nearest enemy”.
I wonder if you could somehow exploit this to produce a biter sinkhole where the densest pollution is in a chunk with no targets. 🤔
DataCpt
Burner Inserter
Burner Inserter
Posts: 14
Joined: Mon Jan 20, 2025 11:16 pm
Contact:

Re: Access to function that returns a pollution cloud's origin

Post by DataCpt »

Rseding91 wrote: Sun Feb 23, 2025 5:52 pm
computeraddict wrote: Sun Feb 23, 2025 5:08 pm Do biters just follow the pollution gradient until they encounter a hostile military target or pollution source?
Yes, and they search inside those chunks to find things to attack using the “find nearest enemy”.
That's interesting because find nearest enemy says it only finds military targets but the behaviour I remember seeing has them path towards mining drills and steam engines (pollution centre). I don't recall them ever doing a 90 degree turn to go attack a gun turret that's outside of their aggro range but inside the pollution cloud instead of going for a non-military target that's at the centre of the cloud.

I'm familiar with the controllable distraction command field so maybe this is just emergent behaviour from those basic rules. Or I'm misunderstanding the order of operations here. If it's travel to centre, then look for military while attacking anything, then look for military, that would fit my experience better.

Either way I should be able to optimise things a little by simply getting the closest entity at the pollution centre rather than filtering for drills without affecting behaviour much! Thank you for the response!
Post Reply

Return to “Modding interface requests”