space-wizards / space-station-14

A multiplayer game about paranoia and chaos on a space station. Remake of the cult-classic Space Station 13.
https://spacestation14.io
MIT License
2.7k stars 3.38k forks source link

TEG can function as an infinite power source #29893

Closed Plykiya closed 1 month ago

Plykiya commented 4 months ago

Description

It stays at the value it was generating before being destroyed.

Reproduction

  1. Get hit by a meteor
  2. Lizard round #59181

Screenshots

Screenshot 2024-07-10 170607 Screenshot 2024-07-10 170628

Additional context

luizwritescode commented 3 months ago

I was able to replicate the issue like this:

  1. first you need to power the TEG, so pick any 2 canisters
  2. use viewvaribles to massively increase the temp inside one canister
  3. now fill both loops and run the TEG
  4. delete one of the circulators to simulate it being hit by a meteor
  5. TEG's PowerSupplierComponent is now stuck in the last value it had

I digged some more and found that inside TegSystem:

the code that updates power is inside GeneratorUpdate

 private void GeneratorUpdate(EntityUid uid, TegGeneratorComponent component, ref AtmosDeviceUpdateEvent args)
    {
        var tegGroup = GetNodeGroup(uid);
        if (tegGroup is not { IsFullyBuilt: true })
            return;

        var supplier = Comp<PowerSupplierComponent>(uid);
        var powerReceiver = Comp<ApcPowerReceiverComponent>(uid);
        if (!powerReceiver.Powered)
        {
            supplier.MaxSupply = 0;
            return;
        }

a bugged half built TEG will hit the first return (as it should on most cases) but then because of it never reaches the second check to update power

replacing the order of the checks seems to fix things on my end