SMES and substation require power cells as machine parts (#20344)
* Initial commit * Balancing and tweaks
This commit is contained in:
@@ -11,7 +11,7 @@ namespace Content.Server.Power.Components
|
||||
/// The machine part that affects the power capacity.
|
||||
/// </summary>
|
||||
[DataField("machinePartPowerCapacity", customTypeSerializer: typeof(PrototypeIdSerializer<MachinePartPrototype>))]
|
||||
public string MachinePartPowerCapacity = "Capacitor";
|
||||
public string MachinePartPowerCapacity = "PowerCell";
|
||||
|
||||
/// <summary>
|
||||
/// The machine part rating is raised to this power when calculating power gain
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
using Content.Server.Construction.Components;
|
||||
using Content.Shared.Construction.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.Power.Components
|
||||
{
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed partial class UpgradePowerSupplyRampingComponent : Component
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float BaseRampRate;
|
||||
|
||||
/// <summary>
|
||||
/// The machine part that affects the power supply ramping
|
||||
/// </summary>
|
||||
[DataField("machinePartPowerCapacity", customTypeSerializer: typeof(PrototypeIdSerializer<MachinePartPrototype>))]
|
||||
public string MachinePartRampRate = "Capacitor";
|
||||
|
||||
/// <summary>
|
||||
/// The multiplier used for scaling the power supply ramping
|
||||
/// </summary>
|
||||
[DataField("supplyRampingMultiplier")]
|
||||
public float SupplyRampingMultiplier = 1f;
|
||||
|
||||
/// <summary>
|
||||
/// What type of scaling is being used?
|
||||
/// </summary>
|
||||
[DataField("scaling", required: true), ViewVariables(VVAccess.ReadWrite)]
|
||||
public MachineUpgradeScalingType Scaling;
|
||||
|
||||
/// <summary>
|
||||
/// The current value that the power supply is being scaled by
|
||||
/// </summary>
|
||||
[DataField("actualScalar"), ViewVariables(VVAccess.ReadWrite)]
|
||||
public float ActualScalar = 1f;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@ namespace Content.Server.Power.EntitySystems
|
||||
[UsedImplicitly]
|
||||
public sealed class UpgradeBatterySystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly BatterySystem _batterySystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -17,11 +19,11 @@ namespace Content.Server.Power.EntitySystems
|
||||
|
||||
public void OnRefreshParts(EntityUid uid, UpgradeBatteryComponent component, RefreshPartsEvent args)
|
||||
{
|
||||
var capacitorRating = args.PartRatings[component.MachinePartPowerCapacity];
|
||||
var powerCellRating = args.PartRatings[component.MachinePartPowerCapacity];
|
||||
|
||||
if (TryComp<BatteryComponent>(uid, out var batteryComp))
|
||||
{
|
||||
batteryComp.MaxCharge = MathF.Pow(component.MaxChargeMultiplier, capacitorRating - 1) * component.BaseMaxCharge;
|
||||
_batterySystem.SetMaxCharge(uid, MathF.Pow(component.MaxChargeMultiplier, powerCellRating - 1) * component.BaseMaxCharge, batteryComp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Content.Server.Construction;
|
||||
using Content.Server.Construction;
|
||||
using Content.Server.Construction.Components;
|
||||
using Content.Server.Power.Components;
|
||||
|
||||
@@ -20,6 +20,10 @@ public sealed class UpgradePowerSystem : EntitySystem
|
||||
SubscribeLocalEvent<UpgradePowerSupplierComponent, MapInitEvent>(OnSupplierMapInit);
|
||||
SubscribeLocalEvent<UpgradePowerSupplierComponent, RefreshPartsEvent>(OnSupplierRefreshParts);
|
||||
SubscribeLocalEvent<UpgradePowerSupplierComponent, UpgradeExamineEvent>(OnSupplierUpgradeExamine);
|
||||
|
||||
SubscribeLocalEvent<UpgradePowerSupplyRampingComponent, MapInitEvent>(OnSupplyRampingMapInit);
|
||||
SubscribeLocalEvent<UpgradePowerSupplyRampingComponent, RefreshPartsEvent>(OnSupplyRampingRefreshParts);
|
||||
SubscribeLocalEvent<UpgradePowerSupplyRampingComponent, UpgradeExamineEvent>(OnSupplyRampingUpgradeExamine);
|
||||
}
|
||||
|
||||
private void OnMapInit(EntityUid uid, UpgradePowerDrawComponent component, MapInitEvent args)
|
||||
@@ -76,7 +80,7 @@ public sealed class UpgradePowerSystem : EntitySystem
|
||||
switch (component.Scaling)
|
||||
{
|
||||
case MachineUpgradeScalingType.Linear:
|
||||
supply += component.BaseSupplyRate * (rating - 1);
|
||||
supply += component.PowerSupplyMultiplier * component.BaseSupplyRate * (rating - 1);
|
||||
break;
|
||||
case MachineUpgradeScalingType.Exponential:
|
||||
supply *= MathF.Pow(component.PowerSupplyMultiplier, rating - 1);
|
||||
@@ -97,4 +101,39 @@ public sealed class UpgradePowerSystem : EntitySystem
|
||||
{
|
||||
args.AddPercentageUpgrade("upgrade-power-supply", component.ActualScalar);
|
||||
}
|
||||
|
||||
private void OnSupplyRampingMapInit(EntityUid uid, UpgradePowerSupplyRampingComponent component, MapInitEvent args)
|
||||
{
|
||||
if (TryComp<PowerNetworkBatteryComponent>(uid, out var battery))
|
||||
component.BaseRampRate = battery.SupplyRampRate;
|
||||
}
|
||||
|
||||
private void OnSupplyRampingRefreshParts(EntityUid uid, UpgradePowerSupplyRampingComponent component, RefreshPartsEvent args)
|
||||
{
|
||||
var rampRate = component.BaseRampRate;
|
||||
var rating = args.PartRatings[component.MachinePartRampRate];
|
||||
switch (component.Scaling)
|
||||
{
|
||||
case MachineUpgradeScalingType.Linear:
|
||||
rampRate += component.SupplyRampingMultiplier * component.BaseRampRate * (rating - 1);
|
||||
break;
|
||||
case MachineUpgradeScalingType.Exponential:
|
||||
rampRate *= MathF.Pow(component.SupplyRampingMultiplier, rating - 1);
|
||||
break;
|
||||
default:
|
||||
Log.Error($"invalid power supply ramping type for {ToPrettyString(uid)}.");
|
||||
rampRate = component.BaseRampRate;
|
||||
break;
|
||||
}
|
||||
|
||||
component.ActualScalar = rampRate / component.BaseRampRate;
|
||||
|
||||
if (TryComp<PowerNetworkBatteryComponent>(uid, out var battery))
|
||||
battery.SupplyRampRate = rampRate;
|
||||
}
|
||||
|
||||
private void OnSupplyRampingUpgradeExamine(EntityUid uid, UpgradePowerSupplyRampingComponent component, UpgradeExamineEvent args)
|
||||
{
|
||||
args.AddPercentageUpgrade("upgrade-power-supply-ramping", component.ActualScalar);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user