mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-19 07:01:09 +03:00
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
This commit is contained in:
parent
c5e2901479
commit
8d1829335e
3 changed files with 36 additions and 12 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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<PowerGridCheckRuleComponent>
|
||||
{
|
||||
[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<ApcComponent, TransformComponent>();
|
||||
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<StationMemberComponent>(transform.GridUid)?.Station == chosenStation)
|
||||
component.Powered.Add(apcUid);
|
||||
if (!apc.MainBreakerEnabled)
|
||||
continue;
|
||||
|
||||
if (CompOrNull<StationMemberComponent>(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<PowerGridCheckRuleComponent, ActiveGameRuleComponent>();
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue