Fix apc battery state (#15568)
This commit is contained in:
@@ -143,7 +143,7 @@ namespace Content.Server.Power.EntitySystems
|
|||||||
|
|
||||||
var state = new ApcBoundInterfaceState(apc.MainBreakerEnabled, apc.HasAccess,
|
var state = new ApcBoundInterfaceState(apc.MainBreakerEnabled, apc.HasAccess,
|
||||||
(int) MathF.Ceiling(battery.CurrentSupply), apc.LastExternalState,
|
(int) MathF.Ceiling(battery.CurrentSupply), apc.LastExternalState,
|
||||||
battery.AvailableSupply / battery.Capacity);
|
battery.CurrentStorage / battery.Capacity);
|
||||||
|
|
||||||
_ui.TrySetUiState(uid, ApcUiKey.Key, state, ui: ui);
|
_ui.TrySetUiState(uid, ApcUiKey.Key, state, ui: ui);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace Content.Server.Power.EntitySystems
|
|||||||
|
|
||||||
private void OnBatteryRejuvenate(EntityUid uid, BatteryComponent component, RejuvenateEvent args)
|
private void OnBatteryRejuvenate(EntityUid uid, BatteryComponent component, RejuvenateEvent args)
|
||||||
{
|
{
|
||||||
component.CurrentCharge = component.MaxCharge;
|
SetCharge(uid, component.MaxCharge, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnExamine(EntityUid uid, ExaminableBatteryComponent component, ExaminedEvent args)
|
private void OnExamine(EntityUid uid, ExaminableBatteryComponent component, ExaminedEvent args)
|
||||||
@@ -74,28 +74,18 @@ namespace Content.Server.Power.EntitySystems
|
|||||||
var enumerator = AllEntityQuery<PowerNetworkBatteryComponent, BatteryComponent>();
|
var enumerator = AllEntityQuery<PowerNetworkBatteryComponent, BatteryComponent>();
|
||||||
while (enumerator.MoveNext(out var uid, out var netBat, out var bat))
|
while (enumerator.MoveNext(out var uid, out var netBat, out var bat))
|
||||||
{
|
{
|
||||||
var netCharge = netBat.NetworkBattery.CurrentStorage;
|
SetCharge(uid, netBat.NetworkBattery.CurrentStorage, bat);
|
||||||
|
|
||||||
bat.Charge = netCharge;
|
|
||||||
DebugTools.Assert(bat.Charge <= bat.MaxCharge && bat.Charge >= 0);
|
|
||||||
|
|
||||||
// TODO maybe decrease tolerance & track the charge at the time the event was most recently raised.
|
|
||||||
// Ensures that events aren't skipped when there are many tiny power changes.
|
|
||||||
if (MathHelper.CloseTo(bat.CurrentCharge, netCharge))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var changeEv = new ChargeChangedEvent(netCharge, bat.MaxCharge);
|
|
||||||
RaiseLocalEvent(uid, ref changeEv);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(float frameTime)
|
public override void Update(float frameTime)
|
||||||
{
|
{
|
||||||
foreach (var (comp, batt) in EntityManager.EntityQuery<BatterySelfRechargerComponent, BatteryComponent>())
|
var query = EntityQueryEnumerator<BatterySelfRechargerComponent, BatteryComponent>();
|
||||||
|
while (query.MoveNext(out var uid, out var comp, out var batt))
|
||||||
{
|
{
|
||||||
if (!comp.AutoRecharge) continue;
|
if (!comp.AutoRecharge) continue;
|
||||||
if (batt.IsFullyCharged) continue;
|
if (batt.IsFullyCharged) continue;
|
||||||
batt.CurrentCharge += comp.AutoRechargeRate * frameTime;
|
SetCharge(uid, batt.CurrentCharge + comp.AutoRechargeRate * frameTime, batt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -437,7 +437,7 @@ namespace Content.Server.Power.Pow3r
|
|||||||
public bool LoadingMarked;
|
public bool LoadingMarked;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Amount of supply that the battery can provider this tick.
|
/// Amount of supply that the battery can provide this tick.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables(VVAccess.ReadWrite)] [JsonIgnore]
|
[ViewVariables(VVAccess.ReadWrite)] [JsonIgnore]
|
||||||
public float AvailableSupply;
|
public float AvailableSupply;
|
||||||
|
|||||||
Reference in New Issue
Block a user