Adjust file namespace scope (#19824)
This commit is contained in:
@@ -1,90 +1,87 @@
|
|||||||
using Content.Server.Singularity.EntitySystems;
|
using Content.Server.Singularity.EntitySystems;
|
||||||
using Content.Shared.Atmos;
|
using Content.Shared.Atmos;
|
||||||
using Content.Shared.Atmos.Prototypes;
|
|
||||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
|
||||||
|
|
||||||
namespace Content.Server.Singularity.Components
|
namespace Content.Server.Singularity.Components;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generates electricity from radiation.
|
||||||
|
/// </summary>
|
||||||
|
[RegisterComponent]
|
||||||
|
[Access(typeof(RadiationCollectorSystem))]
|
||||||
|
public sealed partial class RadiationCollectorComponent : Component
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generates electricity from radiation.
|
/// How much joules will collector generate for each rad.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[RegisterComponent]
|
[DataField("chargeModifier")]
|
||||||
[Access(typeof(RadiationCollectorSystem))]
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
public sealed partial class RadiationCollectorComponent : Component
|
public float ChargeModifier = 30000f;
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// How much joules will collector generate for each rad.
|
|
||||||
/// </summary>
|
|
||||||
[DataField("chargeModifier")]
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
|
||||||
public float ChargeModifier = 30000f;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Cooldown time between users interaction.
|
|
||||||
/// </summary>
|
|
||||||
[DataField("cooldown")]
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
|
||||||
public TimeSpan Cooldown = TimeSpan.FromSeconds(0.81f);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Was machine activated by user?
|
|
||||||
/// </summary>
|
|
||||||
[ViewVariables(VVAccess.ReadOnly)]
|
|
||||||
public bool Enabled;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Timestamp when machine can be deactivated again.
|
|
||||||
/// </summary>
|
|
||||||
public TimeSpan CoolDownEnd;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// List of gases that will react to the radiation passing through the collector
|
|
||||||
/// </summary>
|
|
||||||
[DataField("radiationReactiveGases")]
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
|
||||||
public List<RadiationReactiveGas>? RadiationReactiveGases;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Describes how a gas reacts to the collected radiation
|
/// Cooldown time between users interaction.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataDefinition]
|
[DataField("cooldown")]
|
||||||
public sealed partial class RadiationReactiveGas
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
{
|
public TimeSpan Cooldown = TimeSpan.FromSeconds(0.81f);
|
||||||
/// <summary>
|
|
||||||
/// The reactant gas
|
|
||||||
/// </summary>
|
|
||||||
[DataField("reactantPrototype", required: true)]
|
|
||||||
public Gas Reactant = Gas.Plasma;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Multipier for the amount of power produced by the radiation collector when using this gas
|
/// Was machine activated by user?
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("powerGenerationEfficiency")]
|
[ViewVariables(VVAccess.ReadOnly)]
|
||||||
public float PowerGenerationEfficiency = 1f;
|
public bool Enabled;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Controls the rate (molar percentage per rad) at which the reactant breaks down when exposed to radiation
|
/// Timestamp when machine can be deactivated again.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// /// <remarks>
|
public TimeSpan CoolDownEnd;
|
||||||
/// Set to zero if the reactant does not deplete
|
|
||||||
/// </remarks>
|
|
||||||
[DataField("reactantBreakdownRate")]
|
|
||||||
public float ReactantBreakdownRate = 1f;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A byproduct gas that is generated when the reactant breaks down
|
/// List of gases that will react to the radiation passing through the collector
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
[DataField("radiationReactiveGases")]
|
||||||
/// Leave null if the reactant no byproduct gas is to be formed
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
/// </remarks>
|
public List<RadiationReactiveGas>? RadiationReactiveGases;
|
||||||
[DataField("byproductPrototype")]
|
}
|
||||||
public Gas? Byproduct = null;
|
|
||||||
|
/// <summary>
|
||||||
/// <summary>
|
/// Describes how a gas reacts to the collected radiation
|
||||||
/// The molar ratio of the byproduct gas generated from the reactant gas
|
/// </summary>
|
||||||
/// </summary>
|
[DataDefinition]
|
||||||
[DataField("molarRatio")]
|
public sealed partial class RadiationReactiveGas
|
||||||
public float MolarRatio = 1f;
|
{
|
||||||
}
|
/// <summary>
|
||||||
|
/// The reactant gas
|
||||||
|
/// </summary>
|
||||||
|
[DataField("reactantPrototype", required: true)]
|
||||||
|
public Gas Reactant = Gas.Plasma;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Multipier for the amount of power produced by the radiation collector when using this gas
|
||||||
|
/// </summary>
|
||||||
|
[DataField("powerGenerationEfficiency")]
|
||||||
|
public float PowerGenerationEfficiency = 1f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Controls the rate (molar percentage per rad) at which the reactant breaks down when exposed to radiation
|
||||||
|
/// </summary>
|
||||||
|
/// /// <remarks>
|
||||||
|
/// Set to zero if the reactant does not deplete
|
||||||
|
/// </remarks>
|
||||||
|
[DataField("reactantBreakdownRate")]
|
||||||
|
public float ReactantBreakdownRate = 1f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A byproduct gas that is generated when the reactant breaks down
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Leave null if the reactant no byproduct gas is to be formed
|
||||||
|
/// </remarks>
|
||||||
|
[DataField("byproductPrototype")]
|
||||||
|
public Gas? Byproduct = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The molar ratio of the byproduct gas generated from the reactant gas
|
||||||
|
/// </summary>
|
||||||
|
[DataField("molarRatio")]
|
||||||
|
public float MolarRatio = 1f;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,151 +11,150 @@ using Content.Shared.Examine;
|
|||||||
using Content.Server.Atmos;
|
using Content.Server.Atmos;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
namespace Content.Server.Singularity.EntitySystems
|
namespace Content.Server.Singularity.EntitySystems;
|
||||||
|
|
||||||
|
public sealed class RadiationCollectorSystem : EntitySystem
|
||||||
{
|
{
|
||||||
public sealed class RadiationCollectorSystem : EntitySystem
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||||
|
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||||
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||||
|
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
base.Initialize();
|
||||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
SubscribeLocalEvent<RadiationCollectorComponent, InteractHandEvent>(OnInteractHand);
|
||||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
SubscribeLocalEvent<RadiationCollectorComponent, OnIrradiatedEvent>(OnRadiation);
|
||||||
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
|
SubscribeLocalEvent<RadiationCollectorComponent, ExaminedEvent>(OnExamined);
|
||||||
|
SubscribeLocalEvent<RadiationCollectorComponent, GasAnalyzerScanEvent>(OnAnalyzed);
|
||||||
|
}
|
||||||
|
|
||||||
public override void Initialize()
|
private bool TryGetLoadedGasTank(EntityUid uid, [NotNullWhen(true)] out GasTankComponent? gasTankComponent)
|
||||||
|
{
|
||||||
|
gasTankComponent = null;
|
||||||
|
var container = _containerSystem.EnsureContainer<ContainerSlot>(uid, "GasTank");
|
||||||
|
|
||||||
|
if (container.ContainedEntity == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!EntityManager.TryGetComponent(container.ContainedEntity, out gasTankComponent))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnInteractHand(EntityUid uid, RadiationCollectorComponent component, InteractHandEvent args)
|
||||||
|
{
|
||||||
|
var curTime = _gameTiming.CurTime;
|
||||||
|
|
||||||
|
if (curTime < component.CoolDownEnd)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ToggleCollector(uid, args.User, component);
|
||||||
|
component.CoolDownEnd = curTime + component.Cooldown;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnRadiation(EntityUid uid, RadiationCollectorComponent component, OnIrradiatedEvent args)
|
||||||
|
{
|
||||||
|
if (!component.Enabled || component.RadiationReactiveGases == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!TryGetLoadedGasTank(uid, out var gasTankComponent))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var charge = 0f;
|
||||||
|
|
||||||
|
foreach (var gas in component.RadiationReactiveGases)
|
||||||
{
|
{
|
||||||
base.Initialize();
|
float reactantMol = gasTankComponent.Air.GetMoles(gas.Reactant);
|
||||||
SubscribeLocalEvent<RadiationCollectorComponent, InteractHandEvent>(OnInteractHand);
|
float delta = args.TotalRads * reactantMol * gas.ReactantBreakdownRate;
|
||||||
SubscribeLocalEvent<RadiationCollectorComponent, OnIrradiatedEvent>(OnRadiation);
|
|
||||||
SubscribeLocalEvent<RadiationCollectorComponent, ExaminedEvent>(OnExamined);
|
|
||||||
SubscribeLocalEvent<RadiationCollectorComponent, GasAnalyzerScanEvent>(OnAnalyzed);
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool TryGetLoadedGasTank(EntityUid uid, [NotNullWhen(true)] out GasTankComponent? gasTankComponent)
|
// We need to offset the huge power gains possible when using very cold gases
|
||||||
{
|
// (they allow you to have a much higher molar concentrations of gas in the tank).
|
||||||
gasTankComponent = null;
|
// Hence power output is modified using the Michaelis-Menten equation,
|
||||||
var container = _containerSystem.EnsureContainer<ContainerSlot>(uid, "GasTank");
|
// it will heavily penalise the power output of low temperature reactions:
|
||||||
|
// 300K = 100% power output, 73K = 49% power output, 1K = 1% power output
|
||||||
|
float temperatureMod = 1.5f * gasTankComponent.Air.Temperature / (150f + gasTankComponent.Air.Temperature);
|
||||||
|
charge += args.TotalRads * reactantMol * component.ChargeModifier * gas.PowerGenerationEfficiency * temperatureMod;
|
||||||
|
|
||||||
if (container.ContainedEntity == null)
|
if (delta > 0)
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!EntityManager.TryGetComponent(container.ContainedEntity, out gasTankComponent))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnInteractHand(EntityUid uid, RadiationCollectorComponent component, InteractHandEvent args)
|
|
||||||
{
|
|
||||||
var curTime = _gameTiming.CurTime;
|
|
||||||
|
|
||||||
if (curTime < component.CoolDownEnd)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ToggleCollector(uid, args.User, component);
|
|
||||||
component.CoolDownEnd = curTime + component.Cooldown;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnRadiation(EntityUid uid, RadiationCollectorComponent component, OnIrradiatedEvent args)
|
|
||||||
{
|
|
||||||
if (!component.Enabled || component.RadiationReactiveGases == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!TryGetLoadedGasTank(uid, out var gasTankComponent))
|
|
||||||
return;
|
|
||||||
|
|
||||||
var charge = 0f;
|
|
||||||
|
|
||||||
foreach (var gas in component.RadiationReactiveGases)
|
|
||||||
{
|
{
|
||||||
float reactantMol = gasTankComponent.Air.GetMoles(gas.Reactant);
|
gasTankComponent.Air.AdjustMoles(gas.Reactant, -Math.Min(delta, reactantMol));
|
||||||
float delta = args.TotalRads * reactantMol * gas.ReactantBreakdownRate;
|
|
||||||
|
|
||||||
// We need to offset the huge power gains possible when using very cold gases
|
|
||||||
// (they allow you to have a much higher molar concentrations of gas in the tank).
|
|
||||||
// Hence power output is modified using the Michaelis-Menten equation,
|
|
||||||
// it will heavily penalise the power output of low temperature reactions:
|
|
||||||
// 300K = 100% power output, 73K = 49% power output, 1K = 1% power output
|
|
||||||
float temperatureMod = 1.5f * gasTankComponent.Air.Temperature / (150f + gasTankComponent.Air.Temperature);
|
|
||||||
charge += args.TotalRads * reactantMol * component.ChargeModifier * gas.PowerGenerationEfficiency * temperatureMod;
|
|
||||||
|
|
||||||
if (delta > 0)
|
|
||||||
{
|
|
||||||
gasTankComponent.Air.AdjustMoles(gas.Reactant, -Math.Min(delta, reactantMol));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gas.Byproduct != null)
|
|
||||||
{
|
|
||||||
gasTankComponent.Air.AdjustMoles((int) gas.Byproduct, delta * gas.MolarRatio);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// No idea if this is even vaguely accurate to the previous logic.
|
if (gas.Byproduct != null)
|
||||||
// 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))
|
|
||||||
{
|
{
|
||||||
batteryComponent.CurrentCharge += charge;
|
gasTankComponent.Air.AdjustMoles((int) gas.Byproduct, delta * gas.MolarRatio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnExamined(EntityUid uid, RadiationCollectorComponent component, ExaminedEvent args)
|
// 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 (!TryGetLoadedGasTank(uid, out var gasTankComponent))
|
batteryComponent.CurrentCharge += charge;
|
||||||
{
|
|
||||||
args.PushMarkup(Loc.GetString("power-radiation-collector-gas-tank-missing"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
args.PushMarkup(Loc.GetString("power-radiation-collector-gas-tank-present"));
|
|
||||||
|
|
||||||
if (gasTankComponent.IsLowPressure)
|
|
||||||
{
|
|
||||||
args.PushMarkup(Loc.GetString("power-radiation-collector-gas-tank-low-pressure"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnAnalyzed(EntityUid uid, RadiationCollectorComponent component, GasAnalyzerScanEvent args)
|
|
||||||
{
|
|
||||||
if (!TryGetLoadedGasTank(uid, out var gasTankComponent))
|
|
||||||
return;
|
|
||||||
|
|
||||||
args.GasMixtures = new Dictionary<string, GasMixture?> { { Name(uid), gasTankComponent.Air } };
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ToggleCollector(EntityUid uid, EntityUid? user = null, RadiationCollectorComponent? component = null)
|
|
||||||
{
|
|
||||||
if (!Resolve(uid, ref component))
|
|
||||||
return;
|
|
||||||
|
|
||||||
SetCollectorEnabled(uid, !component.Enabled, user, component);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetCollectorEnabled(EntityUid uid, bool enabled, EntityUid? user = null, RadiationCollectorComponent? component = null)
|
|
||||||
{
|
|
||||||
if (!Resolve(uid, ref component))
|
|
||||||
return;
|
|
||||||
|
|
||||||
component.Enabled = enabled;
|
|
||||||
|
|
||||||
// Show message to the player
|
|
||||||
if (user != null)
|
|
||||||
{
|
|
||||||
var msg = component.Enabled ? "radiation-collector-component-use-on" : "radiation-collector-component-use-off";
|
|
||||||
_popupSystem.PopupEntity(Loc.GetString(msg), uid);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update appearance
|
|
||||||
UpdateAppearance(uid, component);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateAppearance(EntityUid uid, RadiationCollectorComponent? component, AppearanceComponent? appearance = null)
|
|
||||||
{
|
|
||||||
if (!Resolve(uid, ref component, ref appearance))
|
|
||||||
return;
|
|
||||||
|
|
||||||
var state = component.Enabled ? RadiationCollectorVisualState.Active : RadiationCollectorVisualState.Deactive;
|
|
||||||
_appearance.SetData(uid, RadiationCollectorVisuals.VisualState, state, appearance);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnExamined(EntityUid uid, RadiationCollectorComponent component, ExaminedEvent args)
|
||||||
|
{
|
||||||
|
if (!TryGetLoadedGasTank(uid, out var gasTankComponent))
|
||||||
|
{
|
||||||
|
args.PushMarkup(Loc.GetString("power-radiation-collector-gas-tank-missing"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
args.PushMarkup(Loc.GetString("power-radiation-collector-gas-tank-present"));
|
||||||
|
|
||||||
|
if (gasTankComponent.IsLowPressure)
|
||||||
|
{
|
||||||
|
args.PushMarkup(Loc.GetString("power-radiation-collector-gas-tank-low-pressure"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnAnalyzed(EntityUid uid, RadiationCollectorComponent component, GasAnalyzerScanEvent args)
|
||||||
|
{
|
||||||
|
if (!TryGetLoadedGasTank(uid, out var gasTankComponent))
|
||||||
|
return;
|
||||||
|
|
||||||
|
args.GasMixtures = new Dictionary<string, GasMixture?> { { Name(uid), gasTankComponent.Air } };
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ToggleCollector(EntityUid uid, EntityUid? user = null, RadiationCollectorComponent? component = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(uid, ref component))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SetCollectorEnabled(uid, !component.Enabled, user, component);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetCollectorEnabled(EntityUid uid, bool enabled, EntityUid? user = null, RadiationCollectorComponent? component = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(uid, ref component))
|
||||||
|
return;
|
||||||
|
|
||||||
|
component.Enabled = enabled;
|
||||||
|
|
||||||
|
// Show message to the player
|
||||||
|
if (user != null)
|
||||||
|
{
|
||||||
|
var msg = component.Enabled ? "radiation-collector-component-use-on" : "radiation-collector-component-use-off";
|
||||||
|
_popupSystem.PopupEntity(Loc.GetString(msg), uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update appearance
|
||||||
|
UpdateAppearance(uid, component);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateAppearance(EntityUid uid, RadiationCollectorComponent? component, AppearanceComponent? appearance = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(uid, ref component, ref appearance))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var state = component.Enabled ? RadiationCollectorVisualState.Active : RadiationCollectorVisualState.Deactive;
|
||||||
|
_appearance.SetData(uid, RadiationCollectorVisuals.VisualState, state, appearance);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user