Skip to content

Commit

Permalink
SMES and substation require power cells as machine parts (#20344)
Browse files Browse the repository at this point in the history
* Initial commit

* Balancing and tweaks
  • Loading branch information
chromiumboy authored Oct 12, 2023
1 parent 3323b61 commit 535b013
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Content.Server/Power/Components/UpgradeBatteryComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public sealed partial class UpgradeBatteryComponent : Component
/// 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
6 changes: 4 additions & 2 deletions Content.Server/Power/EntitySystems/UpgradeBatterySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -17,11 +19,11 @@ public override void Initialize()

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);
}
}

Expand Down
43 changes: 41 additions & 2 deletions Content.Server/Power/EntitySystems/UpgradePowerSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Content.Server.Construction;
using Content.Server.Construction;
using Content.Server.Construction.Components;
using Content.Server.Power.Components;

Expand All @@ -20,6 +20,10 @@ public override void Initialize()
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)
Expand Down Expand Up @@ -76,7 +80,7 @@ private void OnSupplierRefreshParts(EntityUid uid, UpgradePowerSupplierComponent
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);
Expand All @@ -97,4 +101,39 @@ private void OnSupplierUpgradeExamine(EntityUid uid, UpgradePowerSupplierCompone
{
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);
}
}
1 change: 1 addition & 0 deletions Resources/Locale/en-US/machine/machine.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ machine-part-name-matter-bin = Matter Bin
upgrade-power-draw = power draw
upgrade-max-charge = max charge
upgrade-power-supply = power supply
upgrade-power-supply-ramping = power ramp rate
two-way-lever-left = push left
two-way-lever-right = push right
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,10 @@
- type: MachineBoard
prototype: SMESBasicEmpty
requirements:
Capacitor: 5
Capacitor: 1
PowerCell: 4
materialRequirements:
CableHV: 10

- type: entity
id: CellRechargerCircuitboard
Expand Down Expand Up @@ -553,7 +556,8 @@
- type: MachineBoard
prototype: SubstationBasicEmpty
requirements:
Capacitor: 3
Capacitor: 1
PowerCell: 1
materialRequirements:
CableMV: 5
CableHV: 5
Expand Down
16 changes: 14 additions & 2 deletions Resources/Prototypes/Entities/Objects/Power/powercells.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
- type: Battery
maxCharge: 360
startingCharge: 360
- type: MachinePart
part: PowerCell
rating: 1
- type: Tag
tags:
- PowerCellSmall
Expand Down Expand Up @@ -100,6 +103,9 @@
- type: Battery
maxCharge: 720
startingCharge: 720
- type: MachinePart
part: PowerCell
rating: 2

- type: entity
id: PowerCellMediumPrinted
Expand Down Expand Up @@ -135,7 +141,10 @@
- type: Battery
maxCharge: 1080
startingCharge: 1080

- type: MachinePart
part: PowerCell
rating: 3

- type: entity
id: PowerCellHighPrinted
suffix: Empty
Expand Down Expand Up @@ -170,7 +179,10 @@
- type: Battery
maxCharge: 1800
startingCharge: 1800

- type: MachinePart
part: PowerCell
rating: 4

- type: entity
id: PowerCellHyperPrinted
suffix: Empty
Expand Down
3 changes: 3 additions & 0 deletions Resources/Prototypes/Entities/Structures/Power/smes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
- type: UpgradeBattery
maxChargeMultiplier: 2
baseMaxCharge: 8000000
- type: UpgradePowerSupplyRamping
scaling: Linear
supplyRampingMultiplier: 1
- type: Appearance
- type: Battery
startingCharge: 0
Expand Down
3 changes: 3 additions & 0 deletions Resources/Prototypes/Entities/Structures/Power/substation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
- type: UpgradeBattery
maxChargeMultiplier: 2
baseMaxCharge: 2500000
- type: UpgradePowerSupplyRamping
scaling: Linear
supplyRampingMultiplier: 1
- type: Battery
startingCharge: 0
- type: ExaminableBattery
Expand Down
6 changes: 6 additions & 0 deletions Resources/Prototypes/MachineParts/machine_parts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@
id: MatterBin
name: machine-part-name-matter-bin
stockPartPrototype: MatterBinStockPart

- type: machinePart
id: PowerCell
name: machine-part-name-power-cell
stockPartPrototype: PowerCellSmall

0 comments on commit 535b013

Please sign in to comment.