on_chunk_generated_by_pollution event

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
lyvgbfh
Burner Inserter
Burner Inserter
Posts: 9
Joined: Fri Jul 10, 2020 6:48 pm
Contact:

on_chunk_generated_by_pollution event

Post by lyvgbfh »

Hello,

I would like the ability to prevent chunk generation by pollution in certain situations. An event with the chunk position passed where I can return false if necessary would be more than enough.

The current use is to prevent pollution spreading too far from the player base and waking up/generating more chunks than some PCs can handle.

edit to clarify: There currently is an on_chunk_generated event, but it doesn't know the cause and cannot prevent the generation. Thus the necessity of a different event, or additional arguments to the existing event. Perhaps this suggestion should use the "pre" keyword?

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3427
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: on_chunk_generated_by_pollution event

Post by DaveMcW »

Won't the chunk instantly respawn if the chunk next it remains polluted?

PFQNiet
Fast Inserter
Fast Inserter
Posts: 203
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: on_chunk_generated_by_pollution event

Post by PFQNiet »

Aside from the fact that it would fire constantly, events cannot prevent things from happening. When you get the event, the chunk has already been generated and the best you can do is immediately destroy it again, but as Dave pointed out it'll just regenerate over and over.

lyvgbfh
Burner Inserter
Burner Inserter
Posts: 9
Joined: Fri Jul 10, 2020 6:48 pm
Contact:

Re: on_chunk_generated_by_pollution event

Post by lyvgbfh »

PFQNiet wrote:
Wed Jul 21, 2021 9:16 am
Aside from the fact that it would fire constantly, events cannot prevent things from happening. When you get the event, the chunk has already been generated and the best you can do is immediately destroy it again, but as Dave pointed out it'll just regenerate over and over.
Those are both good points. I guess my issue is, there's no way to prevent pollution from constantly generating more terrain. One could up dissipation rate, but the effect I'm looking for would be closer to truncating how far it can spread instead of just making it dissipate faster.

User avatar
Silari
Fast Inserter
Fast Inserter
Posts: 175
Joined: Sat Jan 27, 2018 10:04 pm
Contact:

Re: on_chunk_generated_by_pollution event

Post by Silari »

Only thing I can think of like that would maybe be to limit the map size via MapGenSettings (width/height) via script and expand it as the player explores/builds out further from the spawn point (up to whatever original limit they set in new game settings). Don't know how well it'd work in practice. Pollution can't cause map gen outside the maps boundaries, but I don't know how well upping the size mid game works - if it'd immediately start generating the chunks needed or what.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5074
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: on_chunk_generated_by_pollution event

Post by eradicator »

[Edit: Oops, interface request not modding help. Welp, having a "reason" in on_chunk_generated wouldn't hurt I guess.]

____
Silari wrote:
Wed Jul 21, 2021 5:54 pm
Only thing I can think of like that would maybe be to limit the map size via MapGenSettings (width/height)
Very vague memories say that map size just generates out-of-map tiles instead of land, but doesn't actually stop generating chunks, or pollution spreading. Albeit the generated chunks would be smaller on disk due to not having any actual content. Did that change over the years?
lyvgbfh wrote:
Wed Jul 21, 2021 11:42 am
good points. I guess my issue is, there's no way to prevent pollution from constantly generating more terrain. One could up dissipation rate, but the effect I'm looking for would be closer to truncating how far it can spread instead of just making it dissipate faster.
Make an invisible entity that absorbs 10 trillion pollution per tick. Spawn a "ring" of those around the player base, use on_chunk_charted to expand the ring. That would prevent pollution from generating more chunks. But in my experience oversized radars are much worse at generating useless chunks.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
Silari
Fast Inserter
Fast Inserter
Posts: 175
Joined: Sat Jan 27, 2018 10:04 pm
Contact:

Re: on_chunk_generated_by_pollution event

Post by Silari »

Very vague memories say that map size just generates out-of-map tiles instead of land, but doesn't actually stop generating chunks, or pollution spreading. Albeit the generated chunks would be smaller on disk due to not having any actual content. Did that change over the years?
I would not have expected that behavior, but from testing it looks like there is a single chunk thick ring around the map (presumably filled with the 'out-of-map'tiles), but beyond which chunks aren't generated and thus pollution can not travel, so it could still work for OPs purpose. You'd just have to make sure to delete the 'void' chunks when expanding the map, and you'd probably want to remove the pollution absorption from the out-of-map prototype - seems to be set to 10, double that of water.

Still pretty hacky, but doable. And pollution would still exist and have to be dealt with eventually - no disappearing from the edges of the map.
Attachments
Pollution only spreads 1 chunk beyond generated land
Pollution only spreads 1 chunk beyond generated land
pollution.png (4.74 KiB) Viewed 97 times

Qon
Smart Inserter
Smart Inserter
Posts: 1628
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: on_chunk_generated_by_pollution event

Post by Qon »

Silari wrote:
Thu Jul 22, 2021 1:03 am
I would not have expected that behavior, but from testing it looks like there is a single chunk thick ring around the map (presumably filled with the 'out-of-map'tiles), but beyond which chunks aren't generated and thus pollution can not travel, so it could still work for OPs purpose.
Your image lacks debug pollution values so you can't conclude anything from that screenshot. There could be unrendered pollution spreading further...

lyvgbfh
Burner Inserter
Burner Inserter
Posts: 9
Joined: Fri Jul 10, 2020 6:48 pm
Contact:

Re: on_chunk_generated_by_pollution event

Post by lyvgbfh »

On giving it some thought, the map size solution isn't ideal -- it would require special care so radars could still reveal sectors. Same with say, blind firing artillery.

User avatar
Silari
Fast Inserter
Fast Inserter
Posts: 175
Joined: Sat Jan 27, 2018 10:04 pm
Contact:

Re: on_chunk_generated_by_pollution event

Post by Silari »

Qon wrote:
Thu Jul 22, 2021 12:40 pm
Silari wrote:
Thu Jul 22, 2021 1:03 am
I would not have expected that behavior, but from testing it looks like there is a single chunk thick ring around the map (presumably filled with the 'out-of-map'tiles), but beyond which chunks aren't generated and thus pollution can not travel, so it could still work for OPs purpose.
Your image lacks debug pollution values so you can't conclude anything from that screenshot. There could be unrendered pollution spreading further...
Wasn't aware of any situation where pollution wouldn't be rendered on the map if the option was on - I would expect it to show all chunks with pollution. Pollution values don't go off the edge of the map when enabled either. Show Polluted Chunks DOES. Really doesn't make sense since those chunks aren't generated at all per is_chunk_generated, but perhaps the API just lies about chunks beyond the map border.

Which just leaves deleting pollution from the edges of the map (via script or entity) or lowering/turning off pollution diffusion as possible fixes, both of which means you're getting much fewer biter attacks than you should.

Post Reply

Return to “Modding interface requests”