Hi there.
I was recently trying to add some new functionality to the RealisticReactors mod and have noticed that they use a rather ugly hack to dynamically set the reactor efficiency and the power: they create 250 reactor prototypes with power output from 1 to 250 MW and then replace the reactor every time its power output has to change. For efficiency it is even worse: a fake fuel cell with some enormous energy content is used and the remaining fuel is added or removed to the actual fuel cell depending on whether the reactor is running above or below 100% efficiency.
I think it would be more elegant, not to say more efficient, if factorio supported power and efficiency tweaking natively.
The settings that control the Nuclear Reactor specifically are Prototype/Reactor/consumption and Prototype/Reactor/energy_source/effectivity. Neither of these values are accessible from the LUA. For a flexibility sake it might be better to grant access not at the reactor level, but, say, at the burner level.
It would, of course, be slightly easier with Factorio2 because we'll be able to dynamically create a prototype with required efficiency and power settings, but it will still be ugly because the reactor entity will have to be replaced every few ticks.
[LUA REQUEST] Dynamically adjustable reactor/burner
Re: [LUA REQUEST] Dynamically adjustable reactor/burner
In case this approach would be easier: could you please allow inserting modules into reactors? With modules the reactor immediately gains some intuitive traits: low power/high power/breeder. A quality module would then affect the produced used fuel cell. Obviously, this should not be a feature of the base game, but it would be nice if mods could use it.
I tried allowing modules for the reactor, but it probably is disallowed in the game engine itself because this setting had no noticeable effect.
I tried allowing modules for the reactor, but it probably is disallowed in the game engine itself because this setting had no noticeable effect.
Re: [LUA REQUEST] Dynamically adjustable reactor/burner
You are suggesting quality affects a fuel's burnt result. Is that already the case with crafting machines?snakeru wrote: Mon Nov 11, 2024 9:48 pm A quality module would then affect the produced used fuel cell.
Re: [LUA REQUEST] Dynamically adjustable reactor/burner
Yes, that's how quality works, isn't it? You feed in items of quality X and you get the result of mostly quality X, but sometimes Y and sometimes even Z.
Thinking more of it, that's how the modules would then affect the performance of a nuclear reactor:
1. Neighbor bonuses.
Since I touch the same mechanic here, the neighbor bonuses will have to be either disabled completely or dramatically nerfed.
2. Speed changes:
The reactor "speed" is the speed at which it "pumps" the energy from a fuel cell into the thermal energy. The speed bonus will, therefore, affect both the reactor power and the fuel cell consumption rate. This could also be compared to the vanilla neighbor bonuses. The vanilla allows for +300% practical setups. A reactor with 4 module slots filled with level 3 speed modules will get the +200% bonus, undershooting the vanilla. If quality is enabled, it would be possible to achieve +500% which is probably also fine.
3. Energy consumption:
The reactor consumes the energy from the cell (and produces thermal energy). Therefore this will affect the reactor efficiency - in exactly the same way as vanilla neighbor bonuses work. Vanilla allows setups with +300% and +400% (impractical) neighbor bonus. This translates to -75% and -80% energy consumption - which aligns nicely with built-in -80% cap for energy consumption.
4. Productivity:
From the point of view of the most basic mechanic of the game, a reactor is just a very slow machine that converts uranium fuel cells into spent uranium fuel cells. The productivity bonuses will then have exactly the same effect - by producing some extra spent fuel cells. This becomes especially beneficial with mods like Nuclear Fuel, where the spent fuel cell could be a precious resource.
5. Pollution:
Since reactors don't produce pollution, this should probably stay unchanged. Therefore - no effect.
6. Quality:
Exactly same effects as in vanilla. If quality modules are inserted - they affect the quality of the produced spent fuel cells.
7. Beacons:
If beacons are allowed, this will allow to increase the reactor power to some ridiculous levels, allowing for about 2500% bonus. So should probably be disabled.
This thread seems to slowly convert itself from a LUA request into some ideas on a possible mod. Let's see where it could get us. I'm trying to think how this could be implemented. Any hints?
The best idea I have so far is based on what RealisticReactors do internally: they create two reactors, one for decorations and the UI and another that actually produces power. And that second one is the one that the mod tweaks by adding/removing energy from the heat buffer. However as the heat production is still done be the game itself, the whole system becomes very clunky because the game doesn't allow to easily control the efficiency and doesn't allow for reactor power changes at all.
I think that it might be easier to completely abandon the second reactor and just do the all power conversions directly in the LUA.
Re: [LUA REQUEST] Dynamically adjustable reactor/burner
That's for crafting. I'm asking you about burnt result. If you make a burner-powered crafter, does the burnt result get the quality increase?snakeru wrote: Tue Dec 03, 2024 5:33 pm Yes, that's how quality works, isn't it? You feed in items of quality X and you get the result of mostly quality X, but sometimes Y and sometimes even Z.
Re: [LUA REQUEST] Dynamically adjustable reactor/burner
Ah. I see. Yes, that's a good point. No, currently that affects only crafting, but not burning.curiosity wrote: Tue Dec 03, 2024 11:21 pmThat's for crafting. I'm asking you about burnt result. If you make a burner-powered crafter, does the burnt result get the quality increase?snakeru wrote: Tue Dec 03, 2024 5:33 pm Yes, that's how quality works, isn't it? You feed in items of quality X and you get the result of mostly quality X, but sometimes Y and sometimes even Z.
In this case I think that this part becomes too much trouble for too little gain and quality modifiers for the burner could be ignored. But I still find the idea of moduled reactor to be quite in-line with core concepts and very interesting.
Re: [LUA REQUEST] Dynamically adjustable reactor/burner
Actually, if thermal energy generation would be done to 100% in the LUA, then we can probably abuse a crafting machine? Let's say there is a recipe converting item A into item A in 1/60th of a second. Make the outer collision box big enough to form a small 1x1 region in the middle where the beacons can't reach. Put a small 1x1 crafting machine in that spot. Insert modules into it to spare the trouble of calculating the bonuses yourself. Treat number of produced items A as the amount of thermal energy that has to be added to the fake reactor.snakeru wrote: Tue Dec 03, 2024 5:33 pm I think that it might be easier to completely abandon the second reactor and just do the all power conversions directly in the LUA.
Should be doable.
========== UPDATE =============
Actually may be even easier: two overlapping machines - a burner-powered crafting machine and a hidden reactor.
Reactor connects to the thermal pipe network as usual, but is never fueled and therefore does not generate heat itself.
Burner-powered crafting machine is clickable so it provides the UI. It could only produce some fake item out of thin air, but consumes energy from the burner to do that. All the LUA has to do is to fake items produced, multiply that by some constant and add exactly that much centigrades to the reactor heat buffer. The game mechanics should do all the rest.
For example if "some constant" is 100, then the fake item recipe should be tuned to produce N items per cell where N is (T-15)*100 where T is the temperature of a reactor not connected to any heat pipe network after it consumed a single fuel cell.
Re: [LUA REQUEST] Dynamically adjustable reactor/burner
This is called a 'compound entity'. It's a common thing in the modding community when you want to push the boundaries of what the game supports.snakeru wrote: Wed Dec 04, 2024 6:30 amActually, if thermal energy generation would be done to 100% in the LUA, then we can probably abuse a crafting machine? Let's say there is a recipe converting item A into item A in 1/60th of a second. Make the outer collision box big enough to form a small 1x1 region in the middle where the beacons can't reach. Put a small 1x1 crafting machine in that spot. Insert modules into it to spare the trouble of calculating the bonuses yourself. Treat number of produced items A as the amount of thermal energy that has to be added to the fake reactor.snakeru wrote: Tue Dec 03, 2024 5:33 pm I think that it might be easier to completely abandon the second reactor and just do the all power conversions directly in the LUA.
Should be doable.
========== UPDATE =============
Actually may be even easier: two overlapping machines - a burner-powered crafting machine and a hidden reactor.
Reactor connects to the thermal pipe network as usual, but is never fueled and therefore does not generate heat itself.
Burner-powered crafting machine is clickable so it provides the UI. It could only produce some fake item out of thin air, but consumes energy from the burner to do that. All the LUA has to do is to fake items produced, multiply that by some constant and add exactly that much centigrades to the reactor heat buffer. The game mechanics should do all the rest.
For example if "some constant" is 100, then the fake item recipe should be tuned to produce N items per cell where N is (T-15)*100 where T is the temperature of a reactor not connected to any heat pipe network after it consumed a single fuel cell.
Regarding your update/edit... it's actually possible to skip the Lua code entirely. You can make a reactor prototype that runs on fluids and use linked fluid boxes to link the output of the machine you actually interact with to the input of the reactor. You can then have an assembler with a void energy source that has recipes using one or more types of fuel cells to achieve what you want.
These recipes could all output a dummy fluid that the reactor consumes, and since you can set up a fluid energy source to generate by temperature with a fixed consumption rate, you can set up variable power outputs per recipe.
Re: [LUA REQUEST] Dynamically adjustable reactor/burner
Thank you, braxbro, that is much better than my idea! I'll see when I find time to try it out. But I think I'll finish Space Age first, without any mods.braxbro wrote: Wed Dec 04, 2024 12:58 pm it's actually possible to skip the Lua code entirely. You can make a reactor prototype that runs on fluids and use linked fluid boxes to link the output of the machine you actually interact with to the input of the reactor. You can then have an assembler with a void energy source that has recipes using one or more types of fuel cells to achieve what you want.
These recipes could all output a dummy fluid that the reactor consumes, and since you can set up a fluid energy source to generate by temperature with a fixed consumption rate, you can set up variable power outputs per recipe.