From 8d1829335efe2a48347f73fb5e51ecd3aa561abc Mon Sep 17 00:00:00 2001 From: Krunklehorn <42424291+Krunklehorn@users.noreply.github.com> Date: Tue, 11 Aug 2026 00:55:02 -0400 Subject: [PATCH] Power outages are shorter and only affect the main (largest) grid (#37841) * Cancel if APC is in unpowered list * Also prevent re-power via re-construction * Revert useless dependency * Reduced event time by 10-20 seconds * Move to ApcSystem * Also verify game rule is active * Empty commit * Move station and affected checking * Check for main station grid * Fix format warnings * Somehow this got duplicated * Make GetRuleAffectingEntity() also check for BecomesStationComponent * Make APCSystem also check for ActivegameRuleComponent * Removed redundant checks and duplicate logic * Add GridEventEligibleComponent with flag for PowerGridChecks * Propagate GridEventEligibleComponent. * Revert GridEventEligible * Use GetLargestGrid --- .../Power/EntitySystems/ApcSystem.cs | 2 +- .../Events/PowerGridCheckRule.cs | 42 +++++++++++++++---- Resources/Prototypes/GameRules/events.yml | 4 +- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/Content.Server/Power/EntitySystems/ApcSystem.cs b/Content.Server/Power/EntitySystems/ApcSystem.cs index 8b7598340b..640db0ea89 100644 --- a/Content.Server/Power/EntitySystems/ApcSystem.cs +++ b/Content.Server/Power/EntitySystems/ApcSystem.cs @@ -91,7 +91,7 @@ public sealed partial class ApcSystem : EntitySystem component.NeedStateUpdate = true; } - private static void OnApcStartup(EntityUid uid, ApcComponent component, ComponentStartup args) + private void OnApcStartup(EntityUid uid, ApcComponent component, ref ComponentStartup args) { // We cannot update immediately, as various network/battery state is not valid yet. // Defer until the next tick. diff --git a/Content.Server/StationEvents/Events/PowerGridCheckRule.cs b/Content.Server/StationEvents/Events/PowerGridCheckRule.cs index 137900bb97..95620ca707 100644 --- a/Content.Server/StationEvents/Events/PowerGridCheckRule.cs +++ b/Content.Server/StationEvents/Events/PowerGridCheckRule.cs @@ -1,8 +1,10 @@ using System.Threading; using Content.Server.Power.Components; using Content.Server.Power.EntitySystems; +using Content.Server.Station.Components; using Content.Server.StationEvents.Components; using Content.Shared.GameTicking.Components; +using Content.Shared.Station; using Content.Shared.Station.Components; using JetBrains.Annotations; using Robust.Shared.Audio; @@ -17,6 +19,7 @@ namespace Content.Server.StationEvents.Events public sealed partial class PowerGridCheckRule : StationEventSystem { [Dependency] private ApcSystem _apcSystem = default!; + [Dependency] private SharedStationSystem _stationSystem = default!; public override void Initialize() { @@ -34,11 +37,24 @@ namespace Content.Server.StationEvents.Events component.AffectedStation = chosenStation.Value; + var largestGrid = _stationSystem.GetLargestGrid(chosenStation.Value); + + if (largestGrid == null) + return; + var query = AllEntityQuery(); - while (query.MoveNext(out var apcUid ,out var apc, out var transform)) + while (query.MoveNext(out var apcUid, out var apc, out var transform)) { - if (apc.MainBreakerEnabled && CompOrNull(transform.GridUid)?.Station == chosenStation) - component.Powered.Add(apcUid); + if (!apc.MainBreakerEnabled) + continue; + + if (CompOrNull(transform.GridUid)?.Station != chosenStation) + continue; + + if (transform.GridUid != largestGrid.Value) + continue; + + component.Powered.Add(apcUid); } RobustRandom.Shuffle(component.Powered); @@ -89,10 +105,18 @@ namespace Content.Server.StationEvents.Events var activeRules = AllEntityQuery(); while (activeRules.MoveNext(out var _entity, out var powerGridRule, out var _activeGameRule)) { - if (stationMemberComp.Station == powerGridRule.AffectedStation) - { - return powerGridRule; - } + if (stationMemberComp.Station != powerGridRule.AffectedStation) + continue; + + var largestGrid = _stationSystem.GetLargestGrid(powerGridRule.AffectedStation); + + if (largestGrid == null) + continue; + + if (xform.GridUid != largestGrid.Value) + continue; + + return powerGridRule; } return null; @@ -109,7 +133,7 @@ namespace Content.Server.StationEvents.Events if (TryComp(entity, out ApcComponent? apcComponent)) { - if(!apcComponent.MainBreakerEnabled) + if (!apcComponent.MainBreakerEnabled) _apcSystem.ApcToggleBreaker(entity, apcComponent); } } @@ -132,7 +156,7 @@ namespace Content.Server.StationEvents.Events component.FrameTimeAccumulator += frameTime; if (component.FrameTimeAccumulator > component.UpdateRate) { - updates = (int) (component.FrameTimeAccumulator / component.UpdateRate); + updates = (int)(component.FrameTimeAccumulator / component.UpdateRate); component.FrameTimeAccumulator -= component.UpdateRate * updates; } diff --git a/Resources/Prototypes/GameRules/events.yml b/Resources/Prototypes/GameRules/events.yml index 00130e0d4c..8492ada023 100644 --- a/Resources/Prototypes/GameRules/events.yml +++ b/Resources/Prototypes/GameRules/events.yml @@ -347,8 +347,8 @@ path: /Audio/Announcements/power_off.ogg params: volume: -4 - duration: 60 - maxDuration: 120 + duration: 50 + maxDuration: 100 - type: PowerGridCheckRule - type: entity