Emissions in control stage?

Place to get help with not working mods / modding interface.
User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2529
Joined: Fri Nov 06, 2015 7:41 pm

Emissions in control stage?

Post by Deadlock989 »

Bit confused about detecting the pollution emissions produced by an entity in control.lua - not the current emissions at that moment, but what was set for the machine in the energy source at the data stage.

The 0.18.0 changelog said:
Removed EntityPrototype::emissions_per_tick, it is replaced by emissions_per_second.
Removed EnergySourcePrototype::emissions_per_second_per_watt and emissions, they are replaced by emissions_per_minute.
But entity.prototype.emissions_per_second always seems to return 0 no matter what. At the energy source prototype level, the API docs for ElectricEnergySourcePrototype and BurnerPrototype don't have any entries for emissions_per_minute, it's still emissions. Quickly testing in game, I get illegal index for entity.prototype.electric_energy_source.emissions_per_minute. Plain ol' emissions still works, but it returns some tiny number that's too small even to be emissions per tick, so it must be emissions per watt per tick or something.

Fortunately all I want is to detect an entity with negative emissions, so this currently works for that in 0.18.3:

Code: Select all

local function get_emissions(entity)
	local p = entity.prototype
	if p.electric_energy_source_prototype then
		return p.electric_energy_source_prototype.emissions
	elseif p.burner_prototype then
		return p.burner_prototype.emissions
	end
	return 0
end
So what is going here?
Last edited by Deadlock989 on Fri Jan 31, 2020 4:56 am, edited 2 times in total.
User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2529
Joined: Fri Nov 06, 2015 7:41 pm

Re: Emissions in control stage?

Post by Deadlock989 »

Also - how do you get the emissions of a void energy machine?
Honktown
Smart Inserter
Smart Inserter
Posts: 1058
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Emissions in control stage?

Post by Honktown »

emissions_per_second just isn't what you think it is. All entities except trees and flames have emissions_per_second as 0 (I ran a command over the table). It's not that the values are inaccurate/wrong, it's that the description is vague: emissions_per_second applies to the entity existing, outside of the context of anything else. In data.raw these entities do have emissions_per_second defined at the prototype root (trees are negative, flames are positive).

Your command works fine in my game. I modified it to:

Code: Select all

/c

local ent = game.player.selected

if ent == nil then return end

local function get_emissions(entity)
	local p = entity.prototype
	if p.electric_energy_source_prototype then
		return p.electric_energy_source_prototype.emissions
	elseif p.burner_prototype then
		return p.burner_prototype.emissions
	end
	return 0
end

game.print(ent.name .. " " .. get_emissions(ent))
which shows me the emissions of anything under my cursor.

For an assembling-machine 2: 3.33333333 e-7. I first multiplied by 60, assuming per-tick, which gives 2e-5. I then multiplied by power on the tooltip: 155kW. This gives 3.1. I checked the data.raw prototype: 3 emissions_per_minute, with 150kW energy_usage. Fix the calculation: 3.3333333e-7 * 150kW = .05. That * 60 = 3. Therefore 3 / (60 * 150k) = 3.33333e-7. This makes the prototype emissions in units of pollution / W-s.


For a boiler: 2.7777e-7. In this case, 2.777777e-7 (pollution/W-s)? * 60s * 1.8MW = 30. Boilers produce 30 pollution per minute. Consistent with the calculation for an assembling-machine-2.

Doing:

Code: Select all

/c

local ent = game.player.selected
local prot = nil
local str = ""
if ent == nil then return end

str = str .. ent.name

prot = ent.prototype

if prot.energy_usage then
  str = str .. " energy usage: " .. prot.energy_usage
end

if prot.max_energy_usage then
  str = str .. " max usage: " .. prot.max_energy_usage
end

game.print(str)

On an assembling-machine-2 gives me:
assembling-machine-2 energy usage: 2500 max usage: 2500

Using it on a boiler gives me:
boiler max usage 30000

Using it on a steel-furnace gives me:
steel-furnace energy usage: 1500 max usage:1500

burner-inserter max usage: 1570

steam-turbine max usage: 0

All of these * 60 give me the chemical or electrical energy of the entity consumed per second, without drain (ironically, even though it does contribute to the maximum, obviously).

Edit: a void machine has no emissions. The energy is free. Completely, apparently.

Also, I needed to mention, a number of mods do pollution reduction via control effects. One mod I play with has a negative emissions per second. Better Air Filtering on the other hand uses control events to pull pollution in from chunks, and feed it into the machine as an ingredient. It has no emissions.
I have mods! I guess!
Link
User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2529
Joined: Fri Nov 06, 2015 7:41 pm

Re: Emissions in control stage?

Post by Deadlock989 »

Honktown wrote: Fri Jan 31, 2020 8:28 am emissions_per_second just isn't what you think it is.
It is exactly what I thought it was.
Edit: a void machine has no emissions. The energy is free. Completely, apparently.
What's this, then - scotch mist?

Code: Select all

	energy_source = {
		effectivity = 1,
		emissions_per_minute = 50,
		type = "void",
	}
void pollution.jpg
void pollution.jpg (40.7 KiB) Viewed 1440 times
Honktown
Smart Inserter
Smart Inserter
Posts: 1058
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Emissions in control stage?

Post by Honktown »

Deadlock989 wrote: Fri Jan 31, 2020 12:45 pm It is exactly what I thought it was.
You never said what you thought it was, dingus. You lumped it in with "But entity.prototype.emissions_per_second always seems to return 0 no matter what." Which is incorrect.
What's this, then - scotch mist?
You're right. I misread the wiki page :shrug: . There's no "luaVoid" prototype for a void energy source table in the api.

Ohhhh boy here we go, we get to go with my original terrible idea!

1) Find all entities of that type on all surfaces (if you can even tell if something uses void in the prototype? It would have a max energy usage and no burner or electric table, dunno). if producing power, record power produced for each entity found
2) check the pollution statistics, total is easiest: game.pollution_statistics.input_counts["entity_name"]
3) next tick, take the difference of pollution from current tick and tick-1. You know the energy produced last tick, and number of entities. Emissions per tick-power = difference in total / (power produced). If there was no power produced, then all the emissions had to be emissions_per_second, which can be found anyway. Have to take the difference of n*emissions_per_second and total, and then divide if power produced > 0 (or technically, if no power was being produced, and no pollution was made from activity, then all of it must have been from static values).

Absolutely terrible but it'd work, even if you didn't know the energy source.

Edit: dang, have to scale any entities found by pollution modules if they have any. 1 machine could be "5" if it had a bunch of garbage modules.
Last edited by Honktown on Fri Jan 31, 2020 1:11 pm, edited 1 time in total.
I have mods! I guess!
Link
User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2529
Joined: Fri Nov 06, 2015 7:41 pm

Re: Emissions in control stage?

Post by Deadlock989 »

Honktown wrote: Fri Jan 31, 2020 1:09 pm You never said what you thought it was, dingus.
Congratulations - you lasted an entire half hour off my ignore list.

If there's anyone who has a clue what they're talking about who would like to chip in instead, feel free, but I've worked around this for the time being so it's not necessary.
Bilka
Factorio Staff
Factorio Staff
Posts: 3464
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Emissions in control stage?

Post by Bilka »

Deadlock989 wrote: Fri Jan 31, 2020 1:11 pm If there's anyone who has a clue what they're talking about who would like to chip in instead, feel free, but I've worked around this for the time being so it's not necessary.
Honktown basically answered it already, the emissions are on the energy source, their unit is per tick per watt (or kW, not sure), so multiplying by 60 and then by energy consumption gives you the value the tooltips show.

The changelog lines you quote are for the data phase, not control.

Re: void: Currently can't be read in control. Same for heat and fluid energy source emissions. There are some requests to expose the latter two, none for void. Maybe add it there so whoever ends up adding heat and fluid doesn't forget void.

As an aside: Ask your partner what "Honk" means in their first language for a good laugh.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2529
Joined: Fri Nov 06, 2015 7:41 pm

Re: Emissions in control stage?

Post by Deadlock989 »

Bilka wrote: Fri Jan 31, 2020 1:53 pm Re: void: Currently can't be read in control. Same for heat and fluid energy source emissions. There are some requests to expose the latter two, none for void. Maybe add it there so whoever ends up adding heat and fluid doesn't forget void.
Thanks.
As an aside: Ask your partner what "Honk" means in their first language for a good laugh.
That's interesting. He thinks it's a regional thing but online sources disagree with him.

Merely in passing I would note that in British English the most accessible meaning is the brash, discordant, repetitive sound a horn or a goose makes, but in vernacular adjectival form it can also mean "stinking" (example: this cheese is honking) and there is a regional verb form which means "to vomit" (example: he honked all over the table).
Post Reply

Return to “Modding help”