Page 1 of 1

How do I calculate energy consumption via script

Posted: Sat Jun 06, 2020 3:14 pm
by Theanderblast
I'm the author of the Max Rate Calculator mod. One of the more frequent requests is for it to calculate the energy usage of the tool's selection area.

I've been using the new ctrl-shift-e tool to look at entity prototypes to see how I might do this, but it's not obvious to me.

For example, the Assembler 1 has an energy_usage value of 1250, it's tooltip shows Min Energy Consumption of 2.5 kW and max of 77.5 kW.

Now I observe that 1250 x 2 = 2.5k,, and that 2.5k x 31 = 77.5k. Are these two constants, 2, and 31 surfaced in the entity prototype? I'm not seeing them.
The same constants work for the other two kinds of assemblers, also the electric furnace, the oil refinery and the chemical plant.

An electric mining drill has energy_usage of 1500, and the tooltip shows max usage of 90. So here 1500 / 90 = 6. Where does this '6' come from.

Inserters are even odder. There's no obvious ratio between min and max as shown on the tooltip among the types of inserters, and the entity prototype values don't have an energy_usage value (though there are a couple of values for energy used by rotation and extension ).


Are the various constants associated with energy consuming entities available that I can use in my mod to calculate energy usage?
Does the recipe/resource ever affect the energy usage?

Thanks in advance...

Re: How do I calculate energy consumption via script

Posted: Sun Jun 07, 2020 2:50 pm
by mrudat
I believe that minimum usage comes from energy_source_prototype.drain, which is by default, a fixed fraction of energy_usage.

energy_usage and drain, I believe are expressed in terms of J/tick.

So, an AM1, which has an energy_usage of 1250J/tick can consume 75kW of energy performing useful work, but will also consume 41 2/3 J/tick (2.5kW) just sitting there, or in total, presuming that it is busy every tick, it will consume a total of 77.5kW.

It looks like inserters use energy_per_movement and energy_per_rotation. I believe that the maximum consumption is based on the assumption that the inserter in question spends every tick in motion. I have no idea what the formula would look like if energy_per_movement != energy_per_rotation.

Re: How do I calculate energy consumption via script

Posted: Sun Jun 07, 2020 9:03 pm
by Theanderblast
Thanks, that makes sense. Will have to puzzle a bit more on the inserter calcuations.

Re: How do I calculate energy consumption via script

Posted: Sun Jun 21, 2020 4:41 pm
by Theanderblast
I'm having trouble getting the energy_per_rotation and energy_per_movement values:

/c game.print(game.entity_prototypes["inserter"].inserter_rotation_speed)
gives:
0.014

but
/c game.print(game.entity_prototypes["inserter"].energy_per_rotation)
/c game.print(game.entity_prototypes["inserter"].inserter_energy_per_rotation)

yields "Error: LuaEntityPrototype doesn't contain key inserter_energy_per_rotation

https://wiki.factorio.com/Prototype/Inserter seems to indicate these are fields in the PrototypeEntity and the prototype gui (ctrl-shift-E) displays energy_per_rotation as 5000.000000 (it seems like what that tool and the wiki show must be the C++ versions of the class, not the LUA-accessible version, especially since "inserter_rotation_speed" works, not "rotation_speed: as the prototype gui indicates, although it's unclear: =
/c game.print(game.entity_prototypes["inserter"].stack) works, not .inserter_stack.


https://lua-api.factorio.com/latest/Lua ... otype.html for LuaEntityPrototype doesn't seem to show any energy values for inserter rotation or movement, so maybe Wube hasn't surfaced these numbers for mod creators.

Re: How do I calculate energy consumption via script

Posted: Tue Jun 30, 2020 8:27 am
by Helfima
hello
that return max and min consumption

Code: Select all

/c game.print(
(function() 
	local lua_prototype=game.entity_prototypes["inserter"]
	local max_energy_usage=lua_prototype.max_energy_usage
	local drain=lua_prototype.electric_energy_source_prototype.drain
	local max_consumption=math.ceil((max_energy_usage+drain)*60/100)/10
	local min_consumption=drain*60
	return string.format("Max consumption=%skW\nMin consumption=%sW",max_consumption,min_consumption)
end)()
)
if you want see my code for consumption https://github.com/Helfima/helmod/blob/ ... e.lua#L145 to L152 for Electrical energy
me I use only max_energy_usage because energy_usage attribut is not reliable

Re: How do I calculate energy consumption via script

Posted: Tue Jun 30, 2020 12:56 pm
by Theanderblast
Thanks!