energy-consumption-multiplier for a recipe
energy-consumption-multiplier for a recipe
Hey,
is there a way to let a recipe increase the energy consumption of the corresponding assembling machine, similar to the 'emissions_multiplier' field?
If I increase the field 'energy_required' the assembling machine won't consume more energy, but will take longer to complete the recipe - which isn't really what I want.
is there a way to let a recipe increase the energy consumption of the corresponding assembling machine, similar to the 'emissions_multiplier' field?
If I increase the field 'energy_required' the assembling machine won't consume more energy, but will take longer to complete the recipe - which isn't really what I want.
- Deadlock989
- Smart Inserter
- Posts: 2528
- Joined: Fri Nov 06, 2015 7:41 pm
Re: energy-consumption-multiplier for a recipe
Short answer - no.koun wrote: ↑Mon Jul 01, 2019 3:19 pmHey,
is there a way to let a recipe increase the energy consumption of the corresponding assembling machine, similar to the 'emissions_multiplier' field?
If I increase the field 'energy_required' the assembling machine won't consume more energy, but will take longer to complete the recipe - which isn't really what I want.
Longer answer - well, it does consume more energy if the recipe takes longer. Because the machine runs longer per cycle. But you want different recipes to consume energy at a different rates. No such property for recipes currently exists. You're stuck with (a) asking for it in the modding interface forum, (b) using a different crafting machine for that class of recipes, with a different energy consumption rate.
Re: energy-consumption-multiplier for a recipe
Hm, maybe a hacky (and imho dirty) way to implement this behaviour could work like minno's mod More Mining Productivity, that creates invisible beacons with invisible modules with the desired effect.
So... I will kindly ask prague. :x
So... I will kindly ask prague. :x
Re: energy-consumption-multiplier for a recipe
The property "energy_usage" determines how much energy needed to operate the machine and is the property that needs to be focused on. That can be set at the time the entity is defined.
Another way to look at this challenge might be to create a second set of assembly machines for your module. The base set is what the the low energy usage. The second set is is the high energy usage. Then if the recipe is the expensive energy recipe programmatically change the machine to the right type of machine.
This check might have to be triggered off some sort of on recipe change in machine event.
A second way to accomplish this might be to do a binary edit of the table once it has been built.
Another way to look at this challenge might be to create a second set of assembly machines for your module. The base set is what the the low energy usage. The second set is is the high energy usage. Then if the recipe is the expensive energy recipe programmatically change the machine to the right type of machine.
This check might have to be triggered off some sort of on recipe change in machine event.
A second way to accomplish this might be to do a binary edit of the table once it has been built.
Re: energy-consumption-multiplier for a recipe
New assembling machine with new recipe category. For example the chemical plant and centrifuge are also assembling machines, but with special recipe categories.
Re: energy-consumption-multiplier for a recipe
That's not what I meant.
I need to have a script executed when the recipe in a machine is changed or set. So that I can make changes according to the active recipe.
Something like this:
Except that there is no 'on_recipe_change' event and I need to use another one. So on what kind of event from the api could I use to have such a functionality?
(Sorry, somehow my brain has issues with the words today.)
I need to have a script executed when the recipe in a machine is changed or set. So that I can make changes according to the active recipe.
Something like this:
Code: Select all
function on_recipe_change(event)
if event.entity.name == "foo" and event.entity.get_recipe().name == "bar" then
--black lua magic
end
end
script.on_event(defines.events.on_recipe_change, on_recipe_change)
(Sorry, somehow my brain has issues with the words today.)
Re: energy-consumption-multiplier for a recipe
Code: Select all
function on_tick()
for i, assembly_machine in pairs (global.assembly_machines) do
local entity = assembly_machine.entity
if not entity.valid then
global.assembly_machines[i] = nil
return
end
local last_recipe = assembly_machine.recipe
local recipe = entity.get_recipe() or "" --https://lua-api.factorio.com/latest/LuaEntity.html#LuaEntity.get_recipe
if not (last_recipe == recipe) then
assembly_machine.recipe = recipe
on_recipe_change({entity=entity, recipe=recipe, last_recipe=last_recipe})
end
end
end
Re: energy-consumption-multiplier for a recipe
Oh nice, that would allow me to create my own events. Thanks a lot. :)
How serious are the performance implications of such a solution?
And would it make sense to let such a script run only every.. 6 or 10 ticks via script.on_nth_tick?
How serious are the performance implications of such a solution?
And would it make sense to let such a script run only every.. 6 or 10 ticks via script.on_nth_tick?
- Deadlock989
- Smart Inserter
- Posts: 2528
- Joined: Fri Nov 06, 2015 7:41 pm
Re: energy-consumption-multiplier for a recipe
Potentially very serious. IMO onTick is an absolutely terrible event to simulate game mechanics with. And scanning every assembler in the world, every single tick, just to see if any of them has just changed a recipe, is completely ludicrous. I wouldn't touch this with a bargepole. If you don't do it every tick but every Nth tick, then you're going to have all kinds of unwanted crap like lost ingredients etc.
Much better to go with what DaveMcW suggests, although there are other problems to solve. Or ask for a dedicated onRecipeChanged event. Or accept that both the game engine and the Lua interface to it have limitations.
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: energy-consumption-multiplier for a recipe
Of asking every single fucking assembling machine on the planet if it has a recipe every tick? What's the most serious word you know for "serious"? Because that's your answer. Unless you want it only for a really small subset of custom assembling machines.
General rule of thumb:
If you want performance -> Hook into all events that might change it.
If you don't care about performance -> Iterate the stuff in on_tick.
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.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: energy-consumption-multiplier for a recipe
Has already been denied: viewtopic.php?f=28&t=61339
Or just accept that you'll have to use a different machine for "fast bust energy expensive recipes".
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.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: energy-consumption-multiplier for a recipe
The most serious word for 'serious' I know is probably 'todernst' or 'gravallvarlig'.eradicator wrote: ↑Wed Jul 10, 2019 12:44 pmOf asking every single fucking assembling machine on the planet if it has a recipe every tick? What's the most serious word you know for "serious"? Because that's your answer. Unless you want it only for a really small subset of custom assembling machines.
Well, I want it for a small subset of custom assembling machines (fawogae-plantations in pyanodons mods), but it's hard to estimate how much of them a player is likely to place. Maybe in the range 100 to 500 for a really big factory.
This shouldn't be a problem if I'm not mistaken. I want to manipulate the module effects that affect the assembling machine. So I guess a delayed update would only make the player loose 1/6 seconds worth of speed/productivity/consumption.Deadlock989 wrote: ↑Wed Jul 10, 2019 12:40 pmIf you don't do it every tick but every Nth tick, then you're going to have all kinds of unwanted crap like lost ingredients etc.
- Deadlock989
- Smart Inserter
- Posts: 2528
- Joined: Fri Nov 06, 2015 7:41 pm
Re: energy-consumption-multiplier for a recipe
No, because unless I've lost the plot on this strange thread (which is likely/possible), you're proposing replacing an assembler entity with another (more energy-hungry) assembler entity, for certain recipes only. If that isn't done immediately on switching to one of the target recipes, and the old assembler is allowed to start processing ingredients, those ingredients will be lost when the entity is fast-replaced with the new entity, the same as if you'd cancelled the crafting. "In progress" ingredients are always lost, see any of the gnashing-of-teeth centrifuge threads for evidence. And you can't disallow the old entities from using the recipes and beginning the processing, because then you'd never be able to select the recipe in the first place.
This plan has more holes in it than a lace doily that has been attacked by incontinent moths in fishnet stockings.
Re: energy-consumption-multiplier for a recipe
You can disable that behaviour on the assemblers: https://wiki.factorio.com/Prototype/Cra ... _on_change. This is the same property that https://mods.factorio.com/mod/Dont_lose ... ngredients uses.Deadlock989 wrote: ↑Wed Jul 10, 2019 1:18 pm... those ingredients will be lost when the entity is fast-replaced with the new entity, the same as if you'd cancelled the crafting. "In progress" ingredients are always lost, see any of the gnashing-of-teeth centrifuge threads for evidence. And you can't disallow the old entities from using the recipes and beginning the processing, because then you'd never be able to select the recipe in the first place.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Re: energy-consumption-multiplier for a recipe
Oh, actually it's not about that idea anymore. I just posted here because here is where Hiladdar spoke about some sort of on recipe change... and I was afraid to spam the forum.eradicator wrote: ↑Wed Jul 10, 2019 12:50 pmOr just accept that you'll have to use a different machine for "fast bust energy expensive recipes".
Re: energy-consumption-multiplier for a recipe
Yes, sorry, I really should have created a new thread.Deadlock989 wrote: ↑Wed Jul 10, 2019 1:18 pmNo, because unless I've lost the plot on this strange thread (which is likely/possible), you're proposing replacing an assembler entity with another (more energy-hungry) assembler entity, for certain recipes only. If that isn't done immediately on switching to one of the target recipes, and the old assembler is allowed to start processing ingredients, those ingredients will be lost when the entity is fast-replaced with the new entity, the same as if you'd cancelled the crafting. "In progress" ingredients are always lost, see any of the gnashing-of-teeth centrifuge threads for evidence. And you can't disallow the old entities from using the recipes and beginning the processing, because then you'd never be able to select the recipe in the first place.
This plan has more holes in it than a lace doily that has been attacked by incontinent moths in fishnet stockings.
I'm following the idea of creating invisible beacons with invisible modules with the desired effects (as I remarked in my second post, here is the code if you want to see it), rather than replacing the entity. So far it's working when I don't care about the recipe.
(I like your comparisons, very poetic)
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: energy-consumption-multiplier for a recipe
Well, if it's only for a subset of machines, and you don't care about the player losing (or gaining) a bit of energy/stuff, then updating beacons in a fixed-time manner should be ok. Fixed-time means that you process only i.e. 50 beacons once per second. That way the scale of the factory only influences the update delay, and not the processing cost, keeping your mod viable for large factories. This is what for example mods like "Bottleneck" do.
Edit: If you hook into some events like gui_closed to detect the recipe change and only use the on_tick as a backup in case you missed some recipe change (because perfect detection would be difficult), then you could use a much larger delay in on_tick.
Edit: If you hook into some events like gui_closed to detect the recipe change and only use the on_tick as a backup in case you missed some recipe change (because perfect detection would be difficult), then you could use a much larger delay in on_tick.
Last edited by eradicator on Wed Jul 10, 2019 2:21 pm, edited 2 times in total.
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.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: energy-consumption-multiplier for a recipe
Yes, the principle "do stuff for only one entity per tick" is very fast for all factory sizes.