]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
make lube speed up lathes (#25515)
authordeltanedas <39013340+deltanedas@users.noreply.github.com>
Tue, 7 May 2024 18:20:43 +0000 (18:20 +0000)
committerGitHub <noreply@github.com>
Tue, 7 May 2024 18:20:43 +0000 (14:20 -0400)
* add LatheGetSpeedEvent

* add LatheLube system

* make typical lathes accept lube

* spill

* :trollface:

* rework to generic ReagentSpeedSystem

* hyperlathe ops

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
Content.Server/Lathe/LatheSystem.cs
Content.Shared/ReagentSpeed/ReagentSpeedComponent.cs [new file with mode: 0644]
Content.Shared/ReagentSpeed/ReagentSpeedSystem.cs [new file with mode: 0644]
Resources/Prototypes/Entities/Structures/Machines/lathe.yml

index 2b3b810fba7ae9c572faf9252b847409c13dfcd5..7448a9b84dd25154359a5cbe1db321e01389b9bb 100644 (file)
@@ -14,6 +14,7 @@ using Content.Shared.Database;
 using Content.Shared.Emag.Components;
 using Content.Shared.Lathe;
 using Content.Shared.Materials;
+using Content.Shared.ReagentSpeed;
 using Content.Shared.Research.Components;
 using Content.Shared.Research.Prototypes;
 using JetBrains.Annotations;
@@ -35,6 +36,7 @@ namespace Content.Server.Lathe
         [Dependency] private readonly SharedAudioSystem _audio = default!;
         [Dependency] private readonly UserInterfaceSystem _uiSys = default!;
         [Dependency] private readonly MaterialStorageSystem _materialStorage = default!;
+        [Dependency] private readonly ReagentSpeedSystem _reagentSpeed = default!;
         [Dependency] private readonly StackSystem _stack = default!;
         [Dependency] private readonly TransformSystem _transform = default!;
 
@@ -186,9 +188,11 @@ namespace Content.Server.Lathe
             var recipe = component.Queue.First();
             component.Queue.RemoveAt(0);
 
+            var time = _reagentSpeed.ApplySpeed(uid, recipe.CompleteTime);
+
             var lathe = EnsureComp<LatheProducingComponent>(uid);
             lathe.StartTime = _timing.CurTime;
-            lathe.ProductionLength = recipe.CompleteTime * component.TimeMultiplier;
+            lathe.ProductionLength = time * component.TimeMultiplier;
             component.CurrentRecipe = recipe;
 
             var ev = new LatheStartPrintingEvent(recipe);
diff --git a/Content.Shared/ReagentSpeed/ReagentSpeedComponent.cs b/Content.Shared/ReagentSpeed/ReagentSpeedComponent.cs
new file mode 100644 (file)
index 0000000..d233cad
--- /dev/null
@@ -0,0 +1,34 @@
+using Content.Shared.Chemistry.Reagent;
+using Content.Shared.FixedPoint;
+using Robust.Shared.Prototypes;
+
+namespace Content.Shared.ReagentSpeed;
+
+/// <summary>
+/// Makes a device work faster by consuming reagents on each use.
+/// Other systems must use <see cref="ReagentSpeedSystem.ApplySpeed"/> for this to do anything.
+/// </summary>
+[RegisterComponent, Access(typeof(ReagentSpeedSystem))]
+public sealed partial class ReagentSpeedComponent : Component
+{
+    /// <summary>
+    /// Solution that will be checked.
+    /// Anything that isn't in <c>Modifiers</c> is left alone.
+    /// </summary>
+    [DataField(required: true)]
+    public string Solution = string.Empty;
+
+    /// <summary>
+    /// How much reagent from the solution to use up for each use.
+    /// This is per-modifier-reagent and not shared between them.
+    /// </summary>
+    [DataField]
+    public FixedPoint2 Cost = 5;
+
+    /// <summary>
+    /// Reagents and how much they modify speed at full purity.
+    /// Small number means faster large number means slower.
+    /// </summary>
+    [DataField(required: true)]
+    public Dictionary<ProtoId<ReagentPrototype>, float> Modifiers = new();
+}
diff --git a/Content.Shared/ReagentSpeed/ReagentSpeedSystem.cs b/Content.Shared/ReagentSpeed/ReagentSpeedSystem.cs
new file mode 100644 (file)
index 0000000..8561c7b
--- /dev/null
@@ -0,0 +1,33 @@
+using Content.Shared.Chemistry.EntitySystems;
+
+namespace Content.Shared.ReagentSpeed;
+
+public sealed class ReagentSpeedSystem : EntitySystem
+{
+    [Dependency] private readonly SharedSolutionContainerSystem _solution = default!;
+
+    /// <summary>
+    /// Consumes reagents and modifies the duration.
+    /// This can be production time firing delay etc.
+    /// </summary>
+    public TimeSpan ApplySpeed(Entity<ReagentSpeedComponent?> ent, TimeSpan time)
+    {
+        if (!Resolve(ent, ref ent.Comp, false))
+            return time;
+
+        if (!_solution.TryGetSolution(ent.Owner, ent.Comp.Solution, out _, out var solution))
+            return time;
+
+        foreach (var (reagent, fullModifier) in ent.Comp.Modifiers)
+        {
+            var used = solution.RemoveReagent(reagent, ent.Comp.Cost);
+            var efficiency = (used / ent.Comp.Cost).Float();
+            // scale the speed modifier so microdosing has less effect
+            var reduction = (1f - fullModifier) * efficiency;
+            var modifier = 1f - reduction;
+            time *= modifier;
+        }
+
+        return time;
+    }
+}
index e4ae1c42e8b31493ad788fa1192564f79834abb0..294a97418434325cf9e6f184332ab9d914d1b549 100644 (file)
   - type: ResearchClient
   - type: TechnologyDatabase
 
+# a lathe that can be sped up with space lube / slowed down with glue
 - type: entity
-  id: Autolathe
+  abstract: true
   parent: BaseLathe
+  id: BaseLatheLube
+  components:
+  - type: ReagentSpeed
+    solution: lube
+    modifiers:
+      SpaceLube: 0.25
+      SpaceGlue: 5
+  - type: SolutionContainerManager
+    solutions:
+      lube:
+        maxVol: 250
+  - type: Spillable
+    solution: lube
+  - type: RefillableSolution
+    solution: lube
+  - type: ExaminableSolution
+    solution: lube
+
+- type: entity
+  abstract: true
+  id: BaseHyperlathe
+  components:
+  - type: Lathe
+    materialUseMultiplier: 0.5
+    timeMultiplier: 1.5
+  - type: LatheHeatProducing
+  - type: ReagentSpeed
+    modifiers:
+      SpaceLube: 0.8 # being faster means less heat so lube needs to be nerfed
+      SpaceGlue: 5 # no change from normal lathe, overheat!!!
+
+- type: entity
+  id: Autolathe
+  parent: BaseLatheLube
   name: autolathe
   description: It produces items using metal and glass.
   components:
 
 - type: entity
   id: AutolatheHyperConvection
-  parent: Autolathe
+  parent: [Autolathe, BaseHyperlathe]
   name: hyper convection autolathe
   description: A highly-experimental autolathe that harnesses the power of extreme heat to slowly create objects more cost-effectively.
   components:
   - type: Sprite
     sprite: Structures/Machines/autolathe_hypercon.rsi
-  - type: Lathe
-    materialUseMultiplier: 0.5
-    timeMultiplier: 1.5
-  - type: LatheHeatProducing
   - type: Machine
     board: AutolatheHyperConvectionMachineCircuitboard
 
 - type: entity
   id: Protolathe
-  parent: BaseLathe
+  parent: BaseLatheLube
   name: protolathe
   description: Converts raw materials into useful objects.
   components:
 
 - type: entity
   id: ProtolatheHyperConvection
-  parent: Protolathe
+  parent: [Protolathe, BaseHyperlathe]
   name: hyper convection protolathe
   description: A highly-experimental protolathe that harnesses the power of extreme heat to slowly create objects more cost-effectively.
   components:
   - type: Sprite
     sprite: Structures/Machines/protolathe_hypercon.rsi
-  - type: Lathe
-    materialUseMultiplier: 0.5
-    timeMultiplier: 1.5
-  - type: LatheHeatProducing
   - type: Machine
     board: ProtolatheHyperConvectionMachineCircuitboard
 
 - type: entity
   id: CircuitImprinter
-  parent: BaseLathe
+  parent: BaseLatheLube
   name: circuit imprinter
   description: Prints circuit boards for machines.
   components:
 
 - type: entity
   id: ExosuitFabricator
-  parent: BaseLathe
+  parent: BaseLatheLube
   name: exosuit fabricator
   description: Creates parts for robotics and other mechanical needs
   components:
 
 - type: entity
   id: SecurityTechFab
-  parent: BaseLathe
+  parent: BaseLatheLube
   name: security techfab
   description: Prints equipment for use by security crew.
   components:
 
 - type: entity
   id: AmmoTechFab
-  parent: BaseLathe
+  parent: BaseLatheLube
   name: ammo techfab
   description: Prints the bare minimum of bullets that any budget military or armory could need. Nothing fancy.
   components:
 
 - type: entity
   id: MedicalTechFab
-  parent: BaseLathe
+  parent: BaseLatheLube
   name: medical techfab
   description: Prints equipment for use by the medbay.
   components: