Files
tbd-station-14/Content.Shared/APC/SharedApc.cs
Partmedia a5c223c0c3 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
2025-11-21 15:01:23 +00:00

238 lines
7.1 KiB
C#

using Robust.Shared.Serialization;
namespace Content.Shared.APC
{
[Serializable, NetSerializable]
public enum ApcVisuals : byte
{
/// <summary>
/// APC locks.
/// </summary>
LockState,
/// <summary>
/// APC channels.
/// </summary>
ChannelState,
/// <summary>
/// APC lights/HUD.
/// </summary>
ChargeState,
}
[Serializable, NetSerializable]
public enum ApcPanelState : sbyte
{
/// <summary>
/// APC is closed.
/// </summary>
Closed = 0,
/// <summary>
/// APC is opened.
/// </summary>
Open = 1,
/// <summary>
/// APC is oaisdoj.
/// </summary>
Error = -1,
}
/// <summary>
/// The state of the APC interface lock.
/// None of this is implemented.
/// </summary>
[Serializable, NetSerializable]
public enum ApcLockState : sbyte
{
/// <summary>
/// Empty bitmask.
/// </summary>
None = 0,
/// <summary>
/// Bitfield indicating status of APC lock indicator.
/// </summary>
Lock = (1<<0),
/// <summary>
/// Bit state indicating that the given APC lock is unlocked.
/// </summary>
Unlocked = None,
/// <summary>
/// Bit state indicating that the given APC lock is locked.
/// </summary>
Locked = (1<<0),
/// <summary>
/// Bitmask for the full state for a given APC lock indicator.
/// </summary>
All = (Lock),
/// <summary>
/// The log 2 width in bits of the bitfields indicating the status of an APC lock indicator.
/// Used for bit shifting operations (Mask for the state for indicator i is (All << (i << LogWidth))).
/// </summary>
LogWidth = 0,
}
/// <summary>
/// APC power channel states.
/// None of this is implemented.
/// </summary>
public enum ApcChannelState : sbyte
{
/// <summary>
/// Empty bitmask.
/// </summary>
None = 0,
/// <summary>
/// Bitfield indicating whether the APC is automatically regulating the given channel.
/// </summary>
Control = (1<<0),
/// <summary>
/// Bit state indicating that the APC has been set to automatically toggle the given channel depending on available power.
/// </summary>
Auto = None,
/// <summary>
/// Bit state indicating that the APC has been set to always provide/not provide power on the given channel if possible.
/// </summary>
Manual = Control,
/// <summary>
/// Bitfield indicating whether the APC is currently providing power on the given channel.
/// </summary>
Power = (1<<1),
/// <summary>
/// Bit state indicating that the APC is currently not providing power on the given channel.
/// </summary>
Off = None,
/// <summary>
/// Bit state indicating that the APC is currently providing power on the given channel.
/// </summary>
On = Power,
/// <summary>
/// Bitmask for the full state for a given APC power channel.
/// </summary>
All = Power | Control,
/// <summary>
/// State that indicates the given channel has been automatically disabled.
/// </summary>
AutoOff = (Off | Auto),
/// <summary>
/// State that indicates the given channel has been automatically enabled.
/// </summary>
AutoOn = (On | Auto),
/// <summary>
/// State that indicates the given channel has been manually disabled.
/// </summary>
ManualOff = (Off | Manual),
/// <summary>
/// State that indicates the given channel has been manually enabled.
/// </summary>
ManualOn = (On | Manual),
/// <summary>
/// The log 2 width in bits of the bitfields indicating the status of an APC power channel.
/// Used for bit shifting operations (Mask for the state for channel i is (All << (i << LogWidth))).
/// </summary>
LogWidth = 1,
}
[Serializable, NetSerializable]
public enum ApcChargeState : sbyte
{
/// <summary>
/// APC does not have enough power to charge cell (if necessary) and keep powering the area.
/// </summary>
Lack = 0,
/// <summary>
/// APC is not full but has enough power.
/// </summary>
Charging = 1,
/// <summary>
/// APC battery is full and has enough power.
/// </summary>
Full = 2,
/// <summary>
/// APC is being remotely accessed.
/// Currently unimplemented, though the corresponding sprite state exists in the RSI.
/// </summary>
Remote = 3,
/// <summary>
/// The number of valid states charge states the APC can be in.
/// </summary>
NumStates = 4,
/// <summary>
/// APC is emagged (and not displaying other useful power colors at a glance)
/// </summary>
Emag = -1,
}
[Serializable, NetSerializable]
public sealed class ApcBoundInterfaceState : BoundUserInterfaceState, IEquatable<ApcBoundInterfaceState>
{
public readonly bool MainBreaker;
public readonly int Power;
public readonly ApcExternalPowerState ApcExternalPower;
public readonly float Charge;
public readonly float MaxLoad;
public readonly bool Tripped;
public ApcBoundInterfaceState(bool mainBreaker, int power, ApcExternalPowerState apcExternalPower, float charge, float maxLoad, bool tripped)
{
MainBreaker = mainBreaker;
Power = power;
ApcExternalPower = apcExternalPower;
Charge = charge;
MaxLoad = maxLoad;
Tripped = tripped;
}
public bool Equals(ApcBoundInterfaceState? other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return MainBreaker == other.MainBreaker &&
Power == other.Power &&
ApcExternalPower == other.ApcExternalPower &&
MathHelper.CloseTo(Charge, other.Charge) &&
MathHelper.CloseTo(MaxLoad, other.MaxLoad) &&
Tripped == other.Tripped;
}
public override bool Equals(object? obj)
{
return ReferenceEquals(this, obj) || obj is ApcBoundInterfaceState other && Equals(other);
}
public override int GetHashCode()
{
return HashCode.Combine(MainBreaker, Power, (int) ApcExternalPower, Charge, MaxLoad, Tripped);
}
}
[Serializable, NetSerializable]
public sealed class ApcToggleMainBreakerMessage : BoundUserInterfaceMessage
{
}
public enum ApcExternalPowerState : byte
{
None,
Low,
Good,
}
[NetSerializable, Serializable]
public enum ApcUiKey : byte
{
Key,
}
}