PFQNiet / Satisfactorio

Factorio mod that brings Satisfactory mechanics
GNU General Public License v3.0
11 stars 2 forks source link

Blackout #14

Closed PFQNiet closed 3 years ago

PFQNiet commented 3 years ago

When power demand exceeds production, rather than just scaling down, the entire network should trip out.

To this end, each "generator" should track its power production to see if it maxes out at any point. If it does, it should be disabled.

The API doesn't appear to give easy access to "max power output", but it can be worked out:

entity.energy_generated_last_tick
entity.fluidbox[1].temperature
game.entity_prototypes[entity.name].fluid_usage_per_tick
game.fluid_prototypes[entity.fluidbox[1].name].default_temperature
game.fluid_prototypes[entity.fluidbox[1].name].heat_capacity

energy_generated_last_tick should not exceed (or get too close to) capacity (temp - default_temp) fluid_per_tick, or else it triggers a blackout.

This can be checked every nth-tick, and possibly optimised by keeping a list of power networks that have already been checked so we don't bother checking multiple generators in the same network. Alternatively, do! The player may disconnect networks while the power is down, and in this case should reset each network independently.

Keep a global table of "tripped power networks". When opening the GUI of a generator, if it is part of a tripped network, present an additional GUI to reset the fuse. This will disable the "blackout" interfaces on the network, to be checked again next nth-tick event. Note this means the generator has to have an openable GUI, so for multi-entity structures make sure this works!