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!
Access to function that returns a pollution cloud's origin
Re: Access to function that returns a pollution cloud's origin
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.
-
- Filter Inserter
- Posts: 329
- Joined: Sat Oct 07, 2023 6:44 am
- Contact:
Re: Access to function that returns a pollution cloud's origin
Do biters just follow the pollution gradient until they encounter a hostile military target or pollution source?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.
Re: Access to function that returns a pollution cloud's origin
Yes, and they search inside those chunks to find things to attack using the “find nearest enemy”.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?
If you want to get ahold of me I'm almost always on Discord.
-
- Filter Inserter
- Posts: 329
- Joined: Sat Oct 07, 2023 6:44 am
- Contact:
Re: Access to function that returns a pollution cloud's origin
I wonder if you could somehow exploit this to produce a biter sinkhole where the densest pollution is in a chunk with no targets.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”.
Re: Access to function that returns a pollution cloud's origin
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.Rseding91 wrote: Sun Feb 23, 2025 5:52 pmYes, and they search inside those chunks to find things to attack using the “find nearest enemy”.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?
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!