add breakers to power batteries (#16903)

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2023-06-07 19:43:54 +00:00
committed by GitHub
parent 5b5a3bae76
commit 6acfe53e5f
6 changed files with 70 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
using Content.Server.Power.EntitySystems;
namespace Content.Server.Power.Components;
[RegisterComponent]
[Access(typeof(BreakerSystem))]
public sealed class BreakerComponent : Component
{
/// <summary>
/// Once power supplied exceeds this limit the breaker will pop.
/// </summary>
[DataField("limit", required: true), ViewVariables(VVAccess.ReadWrite)]
public float Limit;
}

View File

@@ -1,6 +1,7 @@
using Content.Server.Emp;
using Content.Server.Popups;
using Content.Server.Power.Components;
using Content.Server.Power.Events;
using Content.Server.Power.Pow3r;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
@@ -36,6 +37,7 @@ namespace Content.Server.Power.EntitySystems
SubscribeLocalEvent<ApcComponent, ChargeChangedEvent>(OnBatteryChargeChanged);
SubscribeLocalEvent<ApcComponent, ApcToggleMainBreakerMessage>(OnToggleMainBreaker);
SubscribeLocalEvent<ApcComponent, GotEmaggedEvent>(OnEmagged);
SubscribeLocalEvent<ApcComponent, BreakerPoppedEvent>(OnBreakerPopped);
SubscribeLocalEvent<ApcComponent, EmpPulseEvent>(OnEmpPulse);
}
@@ -111,6 +113,18 @@ namespace Content.Server.Power.EntitySystems
args.Handled = true;
}
private void OnBreakerPopped(EntityUid uid, ApcComponent comp, BreakerPoppedEvent args)
{
// already disabled, do nothing
if (!comp.MainBreakerEnabled)
return;
ApcToggleBreaker(uid, comp);
// popup so its clear what happened
_popup.PopupEntity(Loc.GetString("apc-component-breaker-popped"), uid);
}
public void UpdateApcState(EntityUid uid,
ApcComponent? apc=null,
PowerNetworkBatteryComponent? battery = null)

View File

@@ -0,0 +1,30 @@
using Content.Server.Administration.Logs;
using Content.Server.Power.Components;
using Content.Server.Power.Events;
using Content.Shared.Database;
namespace Content.Server.Power.EntitySystems;
/// <summary>
/// Handles raising BreakerPopEvent when a power provider exceeds its maximum power.
/// </summary>
public sealed class BreakerSystem : EntitySystem
{
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
/// <inheritdoc/>
public override void Update(float frameTime)
{
base.Update(frameTime);
var query = EntityQueryEnumerator<BreakerComponent, PowerNetworkBatteryComponent>();
while (query.MoveNext(out var uid, out var breaker, out var battery))
{
if (battery.CurrentSupply > breaker.Limit)
{
_adminLogger.Add(LogType.Action, LogImpact.Low, $"Breaker of {ToPrettyString(uid):battery)} popped from supplying {battery.CurrentSupply} with a breaker limit of {breaker.Limit}");
RaiseLocalEvent(uid, new BreakerPoppedEvent());
}
}
}
}

View File

@@ -0,0 +1,8 @@
namespace Content.Server.Power.Events;
/// <summary>
/// Invoked on a target power provider when its power exceeds BreakerComponent MaxPower, popping the breaker or blowing the fuse.
/// </summary>
public sealed class BreakerPoppedEvent : EntityEventArgs
{
}

View File

@@ -2,3 +2,4 @@ apc-component-insufficient-access = Insufficient access!
apc-component-on-examine-panel-open = The [color=lightgray]APC electronics panel[/color] is [color=red]open[/color].
apc-component-on-examine-panel-closed = The [color=lightgray]APC electronics panel[/color] is [color=darkgreen]closed[/color].
apc-component-on-toggle-cancel = It does nothing!
apc-component-breaker-popped = The APC's breaker popped!

View File

@@ -70,6 +70,9 @@
voltage: Medium
- type: PowerProvider
voltage: Apc
- type: Breaker
# 100A at 240V - 24kW
limit: 24000
- type: Apc
voltage: Apc
- type: ExtensionCableProvider