Currently, to get the total amount of pollution on a surface, you have to iterate over every chunk, and call get_pollution on them all. As surfaces can easily have hundreds if not thousands of chunks, it quickly gets slow.
Bilka said on discord that the game tracks polluted chunks, and thus will be able to do it more efficiently. Also less API calls is always better.
surface.total_pollution read
Re: surface.total_pollution read
What's the use-case? I could add it, but it's still an O(N) cost where N is all of the polluted chunks.
If you want to get ahold of me I'm almost always on Discord.
Re: surface.total_pollution read
How it was checked in evolution calculation?Rseding91 wrote: Thu Jan 03, 2019 8:48 am What's the use-case? I could add it, but it's still an O(N) cost where N is all of the polluted chunks.
Re: surface.total_pollution read
I would guess that that one only sums up the pollution absorbed by the spawnersHow it was checked in evolution calculation?
Re: surface.total_pollution read
Evolution only adds up pollution, it doesn't subtract when it is absorbed by tiles.
Re: surface.total_pollution read
Evolution is modified as pollution is created.
If you want to get ahold of me I'm almost always on Discord.
Re: surface.total_pollution read
It's pretty simple to do in lua:
Code: Select all
function getPollution()
-- Iterate over all chunks and sum pollution.
local pollution = 0
-- local surface = game.surfaces[1]
for chunk in game.surfaces[1].get_chunks() do
pollution = pollution + game.surfaces[1].get_pollution({chunk.x*32, chunk.y*32})
end
return pollution
end
Re: surface.total_pollution read
A simple use case would be just a GUI that monitors the total amount of pollution your factory is producing.Rseding91 wrote: Thu Jan 03, 2019 8:48 am What's the use-case? I could add it, but it's still an O(N) cost where N is all of the polluted chunks.
My use case is: a mod which makes pollution affect whether the surface is habitable, or if you need a special suit to breathe, and also causes global warming which can melt ice (alien biomes), and start forest fires.
As an alternative to the O(N), you could keep a running total for each surface that updates when pollution is created/absorbed. It would affect performance of the base game, but perhaps it could be used in a graph. It would be nice to be able to see how much less pollution you're producing by installing efficiency modules, for example.
Read the OP
Re: surface.total_pollution read
Ayy I implemented this myself for 0.17 (I got access to the game's source code).
LuaSurface.get_total_pollution()
LuaSurface.get_total_pollution()