]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
SMES and substation require power cells as machine parts (#20344)
authorchromiumboy <50505512+chromiumboy@users.noreply.github.com>
Thu, 12 Oct 2023 16:06:03 +0000 (11:06 -0500)
committerGitHub <noreply@github.com>
Thu, 12 Oct 2023 16:06:03 +0000 (12:06 -0400)
* Initial commit

* Balancing and tweaks

Content.Server/Power/Components/UpgradeBatteryComponent.cs
Content.Server/Power/Components/UpgradePowerSupplyRampingComponent.cs [new file with mode: 0644]
Content.Server/Power/EntitySystems/UpgradeBatterySystem.cs
Content.Server/Power/EntitySystems/UpgradePowerSystem.cs
Resources/Locale/en-US/machine/machine.ftl
Resources/Prototypes/Entities/Objects/Devices/Circuitboards/Machine/production.yml
Resources/Prototypes/Entities/Objects/Power/powercells.yml
Resources/Prototypes/Entities/Structures/Power/smes.yml
Resources/Prototypes/Entities/Structures/Power/substation.yml
Resources/Prototypes/MachineParts/machine_parts.yml

index e1fc4d2bb822658c79a79a2cbc79cd1a5802d4c8..ff91cfa7559c91eeecf1418e8afc07e65c07622a 100644 (file)
@@ -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
diff --git a/Content.Server/Power/Components/UpgradePowerSupplyRampingComponent.cs b/Content.Server/Power/Components/UpgradePowerSupplyRampingComponent.cs
new file mode 100644 (file)
index 0000000..7bd29f2
--- /dev/null
@@ -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;
+    }
+}
index 6571e1cf0970a4d11e9a123ec855f428f32ea9dc..734cf9d89ced62765147f2f9692523064853c75d 100644 (file)
@@ -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);
             }
         }
 
index 0d43f60a2bfa31ea6d780ce35f52d832021c04b4..9cf28c386a6b6660a4235153420a6dc0bf8ce256 100644 (file)
@@ -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);
+    }
 }
index 1d086e4fdb5cbcfe070038d26e954f5bf2e6fbdf..20a7eb440ff93532594bc4fb2027793f3e89570a 100644 (file)
@@ -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
index 9c60e725350452185bbf3e96e9211c0939976db0..a25e5b7069d5a0b62d6f4b48abf36cf07f1ce7b5 100644 (file)
     - type: MachineBoard
       prototype: SMESBasicEmpty
       requirements:
-        Capacitor: 5
+        Capacitor: 1
+        PowerCell: 4
+      materialRequirements:
+        CableHV: 10
 
 - type: entity
   id: CellRechargerCircuitboard
     - type: MachineBoard
       prototype: SubstationBasicEmpty
       requirements:
-        Capacitor: 3
+        Capacitor: 1
+        PowerCell: 1
       materialRequirements:
         CableMV: 5
         CableHV: 5
index 4b1c910428562845dcafe781d1dabeb17b30a694..82c1bb37e96a6526191523470c4090c030a3c306 100644 (file)
@@ -62,6 +62,9 @@
   - type: Battery
     maxCharge: 360
     startingCharge: 360
+  - type: MachinePart
+    part: PowerCell
+    rating: 1
   - type: Tag
     tags:
       - PowerCellSmall
   - type: Battery
     maxCharge: 720
     startingCharge: 720
+  - type: MachinePart
+    part: PowerCell
+    rating: 2    
 
 - type: entity
   id: PowerCellMediumPrinted
   - type: Battery
     maxCharge: 1080
     startingCharge: 1080
-
+  - type: MachinePart
+    part: PowerCell
+    rating: 3
+    
 - type: entity
   id: PowerCellHighPrinted
   suffix: Empty
   - type: Battery
     maxCharge: 1800
     startingCharge: 1800
-
+  - type: MachinePart
+    part: PowerCell
+    rating: 4
+    
 - type: entity
   id: PowerCellHyperPrinted
   suffix: Empty
index 68d72f64f89d293ecf876e3ac7310a00485bfb45..92451918c7bf27a3779dbd12348772a626528af8 100644 (file)
@@ -32,6 +32,9 @@
     - type: UpgradeBattery
       maxChargeMultiplier: 2
       baseMaxCharge: 8000000
+    - type: UpgradePowerSupplyRamping
+      scaling: Linear
+      supplyRampingMultiplier: 1     
     - type: Appearance
     - type: Battery
       startingCharge: 0
index 6e3ef2f7f1a175390e6bee78c237e64790c119c0..bd3dcc4b8cac6f5d1aa758187595de79a0156e83 100644 (file)
@@ -20,6 +20,9 @@
   - type: UpgradeBattery
     maxChargeMultiplier: 2
     baseMaxCharge: 2500000
+  - type: UpgradePowerSupplyRamping
+    scaling: Linear
+    supplyRampingMultiplier: 1
   - type: Battery
     startingCharge: 0
   - type: ExaminableBattery
index 444bc37356c27efc34bb46a11c544a8c91359975..317e4b80866f80fd9c4f8e992f19fa7f2ae3e00d 100644 (file)
@@ -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
+