From 535b013f63e3628ad690f446462afe32160bce54 Mon Sep 17 00:00:00 2001 From: chromiumboy <50505512+chromiumboy@users.noreply.github.com> Date: Thu, 12 Oct 2023 11:06:03 -0500 Subject: [PATCH] SMES and substation require power cells as machine parts (#20344) * Initial commit * Balancing and tweaks --- .../Components/UpgradeBatteryComponent.cs | 2 +- .../UpgradePowerSupplyRampingComponent.cs | 38 ++++++++++++++++ .../EntitySystems/UpgradeBatterySystem.cs | 6 ++- .../Power/EntitySystems/UpgradePowerSystem.cs | 43 ++++++++++++++++++- Resources/Locale/en-US/machine/machine.ftl | 1 + .../Circuitboards/Machine/production.yml | 8 +++- .../Entities/Objects/Power/powercells.yml | 16 ++++++- .../Entities/Structures/Power/smes.yml | 3 ++ .../Entities/Structures/Power/substation.yml | 3 ++ .../Prototypes/MachineParts/machine_parts.yml | 6 +++ 10 files changed, 117 insertions(+), 9 deletions(-) create mode 100644 Content.Server/Power/Components/UpgradePowerSupplyRampingComponent.cs diff --git a/Content.Server/Power/Components/UpgradeBatteryComponent.cs b/Content.Server/Power/Components/UpgradeBatteryComponent.cs index e1fc4d2bb822..ff91cfa7559c 100644 --- a/Content.Server/Power/Components/UpgradeBatteryComponent.cs +++ b/Content.Server/Power/Components/UpgradeBatteryComponent.cs @@ -11,7 +11,7 @@ public sealed partial class UpgradeBatteryComponent : Component /// The machine part that affects the power capacity. /// [DataField("machinePartPowerCapacity", customTypeSerializer: typeof(PrototypeIdSerializer))] - public string MachinePartPowerCapacity = "Capacitor"; + public string MachinePartPowerCapacity = "PowerCell"; /// /// The machine part rating is raised to this power when calculating power gain diff --git a/Content.Server/Power/Components/UpgradePowerSupplyRampingComponent.cs b/Content.Server/Power/Components/UpgradePowerSupplyRampingComponent.cs new file mode 100644 index 000000000000..7bd29f2de713 --- /dev/null +++ b/Content.Server/Power/Components/UpgradePowerSupplyRampingComponent.cs @@ -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; + + /// + /// The machine part that affects the power supply ramping + /// + [DataField("machinePartPowerCapacity", customTypeSerializer: typeof(PrototypeIdSerializer))] + public string MachinePartRampRate = "Capacitor"; + + /// + /// The multiplier used for scaling the power supply ramping + /// + [DataField("supplyRampingMultiplier")] + public float SupplyRampingMultiplier = 1f; + + /// + /// What type of scaling is being used? + /// + [DataField("scaling", required: true), ViewVariables(VVAccess.ReadWrite)] + public MachineUpgradeScalingType Scaling; + + /// + /// The current value that the power supply is being scaled by + /// + [DataField("actualScalar"), ViewVariables(VVAccess.ReadWrite)] + public float ActualScalar = 1f; + } +} diff --git a/Content.Server/Power/EntitySystems/UpgradeBatterySystem.cs b/Content.Server/Power/EntitySystems/UpgradeBatterySystem.cs index 6571e1cf0970..734cf9d89ced 100644 --- a/Content.Server/Power/EntitySystems/UpgradeBatterySystem.cs +++ b/Content.Server/Power/EntitySystems/UpgradeBatterySystem.cs @@ -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 @@ 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(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); } } diff --git a/Content.Server/Power/EntitySystems/UpgradePowerSystem.cs b/Content.Server/Power/EntitySystems/UpgradePowerSystem.cs index 0d43f60a2bfa..9cf28c386a6b 100644 --- a/Content.Server/Power/EntitySystems/UpgradePowerSystem.cs +++ b/Content.Server/Power/EntitySystems/UpgradePowerSystem.cs @@ -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 override void Initialize() SubscribeLocalEvent(OnSupplierMapInit); SubscribeLocalEvent(OnSupplierRefreshParts); SubscribeLocalEvent(OnSupplierUpgradeExamine); + + SubscribeLocalEvent(OnSupplyRampingMapInit); + SubscribeLocalEvent(OnSupplyRampingRefreshParts); + SubscribeLocalEvent(OnSupplyRampingUpgradeExamine); } private void OnMapInit(EntityUid uid, UpgradePowerDrawComponent component, MapInitEvent args) @@ -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); @@ -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(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(uid, out var battery)) + battery.SupplyRampRate = rampRate; + } + + private void OnSupplyRampingUpgradeExamine(EntityUid uid, UpgradePowerSupplyRampingComponent component, UpgradeExamineEvent args) + { + args.AddPercentageUpgrade("upgrade-power-supply-ramping", component.ActualScalar); + } } diff --git a/Resources/Locale/en-US/machine/machine.ftl b/Resources/Locale/en-US/machine/machine.ftl index 1d086e4fdb5c..20a7eb440ff9 100644 --- a/Resources/Locale/en-US/machine/machine.ftl +++ b/Resources/Locale/en-US/machine/machine.ftl @@ -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 diff --git a/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/Machine/production.yml b/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/Machine/production.yml index 9c60e7253504..a25e5b7069d5 100644 --- a/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/Machine/production.yml +++ b/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/Machine/production.yml @@ -476,7 +476,10 @@ - type: MachineBoard prototype: SMESBasicEmpty requirements: - Capacitor: 5 + Capacitor: 1 + PowerCell: 4 + materialRequirements: + CableHV: 10 - type: entity id: CellRechargerCircuitboard @@ -553,7 +556,8 @@ - type: MachineBoard prototype: SubstationBasicEmpty requirements: - Capacitor: 3 + Capacitor: 1 + PowerCell: 1 materialRequirements: CableMV: 5 CableHV: 5 diff --git a/Resources/Prototypes/Entities/Objects/Power/powercells.yml b/Resources/Prototypes/Entities/Objects/Power/powercells.yml index 4b1c91042856..82c1bb37e96a 100644 --- a/Resources/Prototypes/Entities/Objects/Power/powercells.yml +++ b/Resources/Prototypes/Entities/Objects/Power/powercells.yml @@ -62,6 +62,9 @@ - type: Battery maxCharge: 360 startingCharge: 360 + - type: MachinePart + part: PowerCell + rating: 1 - type: Tag tags: - PowerCellSmall @@ -100,6 +103,9 @@ - type: Battery maxCharge: 720 startingCharge: 720 + - type: MachinePart + part: PowerCell + rating: 2 - type: entity id: PowerCellMediumPrinted @@ -135,7 +141,10 @@ - type: Battery maxCharge: 1080 startingCharge: 1080 - + - type: MachinePart + part: PowerCell + rating: 3 + - type: entity id: PowerCellHighPrinted suffix: Empty @@ -170,7 +179,10 @@ - type: Battery maxCharge: 1800 startingCharge: 1800 - + - type: MachinePart + part: PowerCell + rating: 4 + - type: entity id: PowerCellHyperPrinted suffix: Empty diff --git a/Resources/Prototypes/Entities/Structures/Power/smes.yml b/Resources/Prototypes/Entities/Structures/Power/smes.yml index 68d72f64f89d..92451918c7bf 100644 --- a/Resources/Prototypes/Entities/Structures/Power/smes.yml +++ b/Resources/Prototypes/Entities/Structures/Power/smes.yml @@ -32,6 +32,9 @@ - type: UpgradeBattery maxChargeMultiplier: 2 baseMaxCharge: 8000000 + - type: UpgradePowerSupplyRamping + scaling: Linear + supplyRampingMultiplier: 1 - type: Appearance - type: Battery startingCharge: 0 diff --git a/Resources/Prototypes/Entities/Structures/Power/substation.yml b/Resources/Prototypes/Entities/Structures/Power/substation.yml index 6e3ef2f7f1a1..bd3dcc4b8cac 100644 --- a/Resources/Prototypes/Entities/Structures/Power/substation.yml +++ b/Resources/Prototypes/Entities/Structures/Power/substation.yml @@ -20,6 +20,9 @@ - type: UpgradeBattery maxChargeMultiplier: 2 baseMaxCharge: 2500000 + - type: UpgradePowerSupplyRamping + scaling: Linear + supplyRampingMultiplier: 1 - type: Battery startingCharge: 0 - type: ExaminableBattery diff --git a/Resources/Prototypes/MachineParts/machine_parts.yml b/Resources/Prototypes/MachineParts/machine_parts.yml index 444bc37356c2..317e4b80866f 100644 --- a/Resources/Prototypes/MachineParts/machine_parts.yml +++ b/Resources/Prototypes/MachineParts/machine_parts.yml @@ -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 +