Make radiation collector a power supplier (#24978)

This commit is contained in:
Kevin Zheng
2024-02-06 08:32:39 -08:00
committed by GitHub
parent 4dba9a5ea1
commit effcc5d827
3 changed files with 34 additions and 19 deletions

View File

@@ -11,12 +11,22 @@ namespace Content.Server.Singularity.Components;
public sealed partial class RadiationCollectorComponent : Component
{
/// <summary>
/// How much joules will collector generate for each rad.
/// Power output (in Watts) per unit of radiation collected.
/// </summary>
[DataField]
[ViewVariables(VVAccess.ReadWrite)]
public float ChargeModifier = 30000f;
/// <summary>
/// Number of power ticks that the power supply can remain active for. This is needed since
/// power and radiation don't update at the same tickrate, and since radiation does not provide
/// an update when radiation is removed. When this goes to zero, zero out the power supplier
/// to model the radiation source going away.
/// </summary>
[DataField]
[ViewVariables(VVAccess.ReadWrite)]
public int PowerTicksLeft = 0;
/// <summary>
/// Is the machine enabled.
/// </summary>

View File

@@ -38,6 +38,7 @@ public sealed class RadiationCollectorSystem : EntitySystem
SubscribeLocalEvent<RadiationCollectorComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<RadiationCollectorComponent, EntInsertedIntoContainerMessage>(OnTankChanged);
SubscribeLocalEvent<RadiationCollectorComponent, EntRemovedFromContainerMessage>(OnTankChanged);
SubscribeLocalEvent<NetworkBatteryPostSync>(PostSync);
}
private bool TryGetLoadedGasTank(EntityUid uid, [NotNullWhen(true)] out GasTankComponent? gasTankComponent)
@@ -107,20 +108,34 @@ public sealed class RadiationCollectorSystem : EntitySystem
}
}
// No idea if this is even vaguely accurate to the previous logic.
// The maths is copied from that logic even though it works differently.
// But the previous logic would also make the radiation collectors never ever stop providing energy.
// And since frameTime was used there, I'm assuming that this is what the intent was.
// This still won't stop things being potentially hilariously unbalanced though.
if (TryComp<BatteryComponent>(uid, out var batteryComponent))
if (TryComp<PowerSupplierComponent>(uid, out var comp))
{
_batterySystem.SetCharge(uid, charge, batteryComponent);
int powerHoldoverTicks = _gameTiming.TickRate * 2; // number of ticks to hold radiation
component.PowerTicksLeft = powerHoldoverTicks;
comp.MaxSupply = component.Enabled ? charge : 0;
}
// Update appearance
UpdatePressureIndicatorAppearance(uid, component, gasTankComponent);
}
private void PostSync(NetworkBatteryPostSync ev)
{
// This is run every power tick. Used to decrement the PowerTicksLeft counter.
var query = EntityQueryEnumerator<RadiationCollectorComponent>();
while (query.MoveNext(out var uid, out var component))
{
if (component.PowerTicksLeft > 0)
{
component.PowerTicksLeft -= 1;
}
else if (TryComp<PowerSupplierComponent>(uid, out var comp))
{
comp.MaxSupply = 0;
}
}
}
private void OnExamined(EntityUid uid, RadiationCollectorComponent component, ExaminedEvent args)
{
if (!TryGetLoadedGasTank(uid, out var gasTank))

View File

@@ -62,21 +62,11 @@
- reactantPrototype: Plasma
powerGenerationEfficiency: 1
reactantBreakdownRate: 0.0001
# Note that this doesn't matter too much (see next comment)
# However it does act as a cap on power receivable via the collector.
- type: Battery
maxCharge: 100000
startingCharge: 0
- type: BatteryDischarger
# This is JUST a default. It has to be dynamically adjusted to ensure that the battery doesn't discharge "too fast" & run out immediately, while still scaling by input power.
activeSupplyRate: 100000
- type: RadiationReceiver
- type: PowerSupplier
- type: Anchorable
- type: Rotatable
- type: Pullable
- type: PowerNetworkBattery
maxSupply: 1000000000
supplyRampTolerance: 1000000000
- type: GuideHelp
guides: [ Singularity, Power ]
- type: ContainerContainer