6
StarHorizon_Public/Content.Server/_NF/Power/Components/PowerTransmissionComponent.cs
2026-01-24 12:49:55 +03:00

109 lines
3.6 KiB
C#

using Content.Shared._NF.Bank.Components;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Server._NF.Power.Components;
/// <summary>
/// An entity with this will pay out a given sector bank account regularly depending on the amount of power received.
/// Payouts occur at a fixed period, but the rate of pay depends on the average power input over that period.
/// At high power input, the incremental rate of pay diminishes logarithmically.
/// </summary>
[RegisterComponent, AutoGenerateComponentPause]
public sealed partial class PowerTransmissionComponent : Component
{
#region Power
///<summary>
/// The name of the node to be connected/disconnected.
///</summary>
[DataField]
public string NodeName = "input";
///<summary>
/// The period between depositing money into a sector account.
/// Also the T in Tk*a^(log10(x/T)-R) for rate calculation
///</summary>
[DataField]
public TimeSpan DepositPeriod = TimeSpan.FromSeconds(20);
///<summary>
/// The next time this power plant is selling accumulated power.
/// Should not be changedduring runtime, will cause errors in deposit amounts.
///</summary>
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), AutoPausedField]
public TimeSpan NextDeposit;
///<summary>
/// The total energy accumulated, in joules.
///</summary>
[DataField]
public float AccumulatedEnergy;
///<summary>
/// The account to deposit funds from sold energy into.
///</summary>
[DataField(required: true)]
public SectorBankAccount Account = SectorBankAccount.Invalid;
#endregion Power Sale
#region Linear Rates
///<summary>
/// The rate per joule to credit the account while in the linear mode.
///</summary>
[DataField]
public float LinearRate = 0.00006f; // $6/100 kJ // Horizon 0.00003>>0.00006
///<summary>
/// The maximum value (inclusive) of the linear mode per deposit, in watts
///</summary>
[DataField]
public float LinearMaxValue = 5_000_000; // 5 MW ($300/s) // Horizon 1_000_000>>5_000_000
#endregion Linear Rates
// Logarithmic fields: at very high levels of power generation, incremental gains decrease logarithmically to prevent runaway cash generation
#region Logarithmic Rates
///<summary>
/// The base on power the logarithmic mode: a in Tk*a^(log10(x/T)-R)
///</summary>
[DataField]
public float LogarithmRateBase = 2.5f;
///<summary>
/// The coefficient of the logarithmic mode: k in Tk*a^(log10(x/T)-R)
/// Note: should be set to LinearRate*LinearMaxValue for a continuous function.
///</summary>
[DataField]
public float LogarithmCoefficient = 300f; // Horizon 30>>300
///<summary>
/// The exponential subtrahend of the logarithmic mode: R in Tk*a^(log10(x/T)-R)
/// Note: should be set to log10(LinearMaxValue) for a continuous function.
///</summary>
[DataField]
public float LogarithmSubtrahend = 6.69f; // log10(5_000_000) // Horizon 6>>6.69
#endregion Logarithmic Rates
///<summary>
///</summary>
[DataField]
public float MaxValuePerSecond = 450.0f; // ~57 MW, ~$540k/h // Horizon 150>>450
///<summary>
/// True if the entity was powered last tick.
///</summary>
[ViewVariables]
public bool LastPowered;
///<summary>
/// The minimum requestable power, in watts.
///</summary>
[DataField]
public float MinimumRequestablePower = 500; // 500 W
///<summary>
/// The maximum requestable power, in watts.
///</summary>
[DataField]
public float MaximumRequestablePower = 100_000_000_000; // 100 GW
}