Trip APCs when they exceed a power limit (#41377)
* Implement APC overloading * Add power test * Review * Some more reviews * Show map coordinates for test failures * Widen column 2 * Reduce singularity beacon power consumption * Try to get grid coordinates
This commit is contained in:
@@ -43,11 +43,12 @@ public sealed class ApcSystem : EntitySystem
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
var query = EntityQueryEnumerator<ApcComponent, PowerNetworkBatteryComponent, UserInterfaceComponent>();
|
||||
var curTime = _gameTiming.CurTime;
|
||||
while (query.MoveNext(out var uid, out var apc, out var battery, out var ui))
|
||||
{
|
||||
if (apc.LastUiUpdate + ApcComponent.VisualsChangeDelay < _gameTiming.CurTime && _ui.IsUiOpen((uid, ui), ApcUiKey.Key))
|
||||
if (apc.LastUiUpdate + ApcComponent.VisualsChangeDelay < curTime && _ui.IsUiOpen((uid, ui), ApcUiKey.Key))
|
||||
{
|
||||
apc.LastUiUpdate = _gameTiming.CurTime;
|
||||
apc.LastUiUpdate = curTime;
|
||||
UpdateUIState(uid, apc, battery);
|
||||
}
|
||||
|
||||
@@ -55,6 +56,28 @@ public sealed class ApcSystem : EntitySystem
|
||||
{
|
||||
UpdateApcState(uid, apc, battery);
|
||||
}
|
||||
|
||||
// Overload
|
||||
if (apc.MainBreakerEnabled && battery.CurrentSupply > apc.MaxLoad)
|
||||
{
|
||||
// Not already overloaded, start timer
|
||||
if (apc.TripStartTime == null)
|
||||
{
|
||||
apc.TripStartTime = curTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (curTime - apc.TripStartTime > apc.TripTime)
|
||||
{
|
||||
apc.TripFlag = true;
|
||||
ApcToggleBreaker(uid, apc, battery); // off, we already checked MainBreakerEnabled above
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
apc.TripStartTime = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +129,9 @@ public sealed class ApcSystem : EntitySystem
|
||||
apc.MainBreakerEnabled = !apc.MainBreakerEnabled;
|
||||
battery.CanDischarge = apc.MainBreakerEnabled;
|
||||
|
||||
if (apc.MainBreakerEnabled)
|
||||
apc.TripFlag = false;
|
||||
|
||||
UpdateUIState(uid, apc);
|
||||
_audio.PlayPvs(apc.OnReceiveMessageSound, uid, AudioParams.Default.WithVolume(-2f));
|
||||
}
|
||||
@@ -169,7 +195,9 @@ public sealed class ApcSystem : EntitySystem
|
||||
|
||||
var state = new ApcBoundInterfaceState(apc.MainBreakerEnabled,
|
||||
(int) MathF.Ceiling(battery.CurrentSupply), apc.LastExternalState,
|
||||
charge);
|
||||
charge,
|
||||
apc.MaxLoad,
|
||||
apc.TripFlag);
|
||||
|
||||
_ui.SetUiState((uid, ui), ApcUiKey.Key, state);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user