Page 1 of 1

[Lua/FactorioAPI Request] Add an Output_fluid_box function/property to GeneratorPrototype

Posted: Sat Jun 08, 2024 10:49 am
by ThelianTech
GeneratorPrototype and an output_fluid_box for it
I am a new modder for Factorio, and I'm Currently learning a lot about Lua/FactorioAPI, One thing I have noticed that its currently not possible to use a GeneratorPrototype to generate electricity and have a fluid output, As the way vanilla and pretty much all mods, use for example, a steam turbine, to consume 60/s of 500c steam to generate 5.82MW of electrical power, (keyword consume).
Backstory/usage scenarios/proof of concept for adding an output_fluid_box
So I was going about to try to see how I could change the way we use steam powered electric power generation in a clever and unique way, By creating a way to simulate Real Life energy physics through the Law of Conservation of Energy, also known as the first law of thermodynamics, which is energy is neither created or destroyed but just changes states.With this image in mind and seeing that Steam is coded to have a maximum temp at 1000c I thought it would be cool to design a tiered boiler or heat exchanger that will heat steam to different states of energy (different Temperatures) that can be used in relevant tiered steam engines or turbines, and by following thermodynamics, code it so the turbines don't fully consume the steam, but instead output steam at a lower temperature(balance for not consuming the steam outright) that can be then used in a lower tiered turbine to again do the same thing repeating down to what can be Steam left at a very low temperature simulating a fluid that is now currently depleted of all its "stored" energy and it can either be piped off to a modded fluid void like flare stacks, be piped to a cooling tower that will allow the steam to fully cool and condense back down to water (reusability), or can be piped back into a boiler/heat exchanger to be reheated back up to whatever tiered temp it started at (again reusability) and the final example of using the different energy states of steam for use in recipes(Vanilla or Modded), Like I can get slightly more Advanced Oil outputs of Heavy/Light/Petrol by using heated steam compared to the vanilla usage of water. (Last 3 Examples Proven to be a cool crafting and power generation mechanic by the game Captain of Industry with potential for amazing uses here in factorio :P)
Proposed Implementation
Which leads to my current request of Adding an output_fluid_box to the generator prototype, Should be fairly simple since That is how the BoilerPrototype currently works, It just Consumes Energy (fuel) instead of producing Energy to create the steam from water. Just copy the code and implement that property. After a bit of discussion in the discord. I've realized that there could still be some things that would prevent this addition from being implemented properly with the way the current engine handles the game and GeneratorPrototype code. With being brand new to modding factorio. I'm sure that I have very little understanding on how this could potentially impact the current performance of the game. As I know that one of the things you Developers work hard on is keeping everything running as fast and as optimized as yall can, So Im sure its probably not as simple as it seems. If by adding a output_fluid_box to the prototype does that make the steam gen and the steam turbine automatically need to have it in their code as well and actively being used, or can you have a way to check if its needed or not, One way I thought about this is there could be a function to add a boolean check on the entity code where its being defined on to enable or disable one port on the IO fluidbox and then to enable the output_fluid_box port. This way you can still have the ability for modders to use this new function/property if they desire, and still not have to worry about reinventing the steam generators currently ingame and have the potential for adding a new water conservation way of steam power in 2.0 and in Space Age. I can also see the potential for modders to create new ways of creating fluids needed in high tier/ mid to late game components/products in mods by taking a fluid named xyz and processing it by burning it for power to then create a new endgame fluid named xyz that used in endgame recipes. I think it could be a cool way of adding a small but potentially expansive new mechanic for power generation and fluid creation, one that is outside of chemical plants/refineries/modded-machines that consume power to generate a new fluid or usage of this mechanic for an interesting potential way of simulating some real world physics in a cool and unique matter.
Summary TL/DR

In Summary I see a unique and potentially expansive new mechanic or function by adding an output_fluid_box to GeneratorPrototype for power generation, and unique alternative crafting mechanics. These above mentioned examples can be done currently ingame with workaround scripting to achieve the same design. But I figured I would ask what is potentially more UPS intensive, using scripting workarounds, or this mechanic added into the game natively and potentially way more streamlined to be performant due to, well you are the developers after all.

P.S Note I've wrote all of this in about 3 hours, all during the night time hours between 2am and 5am.... So I apologize in advance if I have wrote anything here that has no logical understanding, due to my sleep deprived very new to modding factorio brain of mine. As Always Happy Coding :ugeek: