Make radiation collector a power supplier (#24978)
This commit is contained in:
@@ -11,12 +11,22 @@ namespace Content.Server.Singularity.Components;
|
|||||||
public sealed partial class RadiationCollectorComponent : Component
|
public sealed partial class RadiationCollectorComponent : Component
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// How much joules will collector generate for each rad.
|
/// Power output (in Watts) per unit of radiation collected.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField]
|
[DataField]
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
public float ChargeModifier = 30000f;
|
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>
|
/// <summary>
|
||||||
/// Is the machine enabled.
|
/// Is the machine enabled.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ public sealed class RadiationCollectorSystem : EntitySystem
|
|||||||
SubscribeLocalEvent<RadiationCollectorComponent, MapInitEvent>(OnMapInit);
|
SubscribeLocalEvent<RadiationCollectorComponent, MapInitEvent>(OnMapInit);
|
||||||
SubscribeLocalEvent<RadiationCollectorComponent, EntInsertedIntoContainerMessage>(OnTankChanged);
|
SubscribeLocalEvent<RadiationCollectorComponent, EntInsertedIntoContainerMessage>(OnTankChanged);
|
||||||
SubscribeLocalEvent<RadiationCollectorComponent, EntRemovedFromContainerMessage>(OnTankChanged);
|
SubscribeLocalEvent<RadiationCollectorComponent, EntRemovedFromContainerMessage>(OnTankChanged);
|
||||||
|
SubscribeLocalEvent<NetworkBatteryPostSync>(PostSync);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool TryGetLoadedGasTank(EntityUid uid, [NotNullWhen(true)] out GasTankComponent? gasTankComponent)
|
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.
|
if (TryComp<PowerSupplierComponent>(uid, out var comp))
|
||||||
// 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))
|
|
||||||
{
|
{
|
||||||
_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
|
// Update appearance
|
||||||
UpdatePressureIndicatorAppearance(uid, component, gasTankComponent);
|
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)
|
private void OnExamined(EntityUid uid, RadiationCollectorComponent component, ExaminedEvent args)
|
||||||
{
|
{
|
||||||
if (!TryGetLoadedGasTank(uid, out var gasTank))
|
if (!TryGetLoadedGasTank(uid, out var gasTank))
|
||||||
|
|||||||
@@ -62,21 +62,11 @@
|
|||||||
- reactantPrototype: Plasma
|
- reactantPrototype: Plasma
|
||||||
powerGenerationEfficiency: 1
|
powerGenerationEfficiency: 1
|
||||||
reactantBreakdownRate: 0.0001
|
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: RadiationReceiver
|
||||||
|
- type: PowerSupplier
|
||||||
- type: Anchorable
|
- type: Anchorable
|
||||||
- type: Rotatable
|
- type: Rotatable
|
||||||
- type: Pullable
|
- type: Pullable
|
||||||
- type: PowerNetworkBattery
|
|
||||||
maxSupply: 1000000000
|
|
||||||
supplyRampTolerance: 1000000000
|
|
||||||
- type: GuideHelp
|
- type: GuideHelp
|
||||||
guides: [ Singularity, Power ]
|
guides: [ Singularity, Power ]
|
||||||
- type: ContainerContainer
|
- type: ContainerContainer
|
||||||
|
|||||||
Reference in New Issue
Block a user