From 99e877137475e0dd54a9f7cff5f81ad9022b3955 Mon Sep 17 00:00:00 2001 From: Whatstone Date: Tue, 28 Jan 2025 01:04:11 -0500 Subject: [PATCH 1/5] First pass at batching lathe jobs in the queue --- Content.Client/Lathe/UI/LatheMenu.xaml.cs | 10 +++--- Content.Server/Lathe/LatheSystem.cs | 42 ++++++++++++++--------- Content.Shared/Lathe/LatheComponent.cs | 19 +++++++++- Content.Shared/Lathe/LatheMessages.cs | 4 +-- 4 files changed, 52 insertions(+), 23 deletions(-) diff --git a/Content.Client/Lathe/UI/LatheMenu.xaml.cs b/Content.Client/Lathe/UI/LatheMenu.xaml.cs index 5b99ae084ff..a192b655330 100644 --- a/Content.Client/Lathe/UI/LatheMenu.xaml.cs +++ b/Content.Client/Lathe/UI/LatheMenu.xaml.cs @@ -216,20 +216,22 @@ public void UpdateCategories() /// Populates the build queue list with all queued items /// /// - public void PopulateQueueList(List queue) + public void PopulateQueueList(List queue) // Frontier: LatheRecipePrototype> GetAllBaseRecipes(LatheCompone return component.StaticRecipes.Union(component.DynamicRecipes).ToList(); } - public bool TryAddToQueue(EntityUid uid, LatheRecipePrototype recipe, LatheComponent? component = null) + public bool TryAddToQueue(EntityUid uid, LatheRecipePrototype recipe, int quantity, LatheComponent? component = null) // Frontier: add quantity { if (!Resolve(uid, ref component)) return false; - if (!CanProduce(uid, recipe, 1, component)) + // Frontier: argument check + if (quantity <= 0) + return false; + // Frontier: argument check + + if (!CanProduce(uid, recipe, quantity, component)) return false; foreach (var (mat, amount) in recipe.Materials) @@ -192,7 +197,14 @@ public bool TryAddToQueue(EntityUid uid, LatheRecipePrototype recipe, LatheCompo _materialStorage.TryChangeMaterialAmount(uid, mat, adjustedAmount); } - component.Queue.Add(recipe); + + // Frontier: queue up a batch + if (component.Queue.Count > 0 && component.Queue[^1].Recipe.ID == recipe.ID) + component.Queue[^1].ItemsRequested += quantity; + else + component.Queue.Add(new LatheRecipeBatch(recipe, 0, quantity)); + // End Frontier + // component.Queue.Add(recipe); // Frontier return true; } @@ -204,8 +216,13 @@ public bool TryStartProducing(EntityUid uid, LatheComponent? component = null) if (component.CurrentRecipe != null || component.Queue.Count <= 0 || !this.IsPowered(uid, EntityManager)) return false; - var recipe = component.Queue.First(); - component.Queue.RemoveAt(0); + // Frontier: handle batches + var batch = component.Queue.First(); + batch.ItemsPrinted++; + if (batch.ItemsPrinted > batch.ItemsRequested || batch.ItemsPrinted < 0) // Rollover sanity check + component.Queue.RemoveAt(0); + var recipe = batch.Recipe; + // End Frontier var time = _reagentSpeed.ApplySpeed(uid, recipe.CompleteTime) * component.TimeMultiplier; @@ -288,7 +305,7 @@ public void UpdateUserInterfaceState(EntityUid uid, LatheComponent? component = if (!Resolve(uid, ref component)) return; - var producing = component.CurrentRecipe ?? component.Queue.FirstOrDefault(); + var producing = component.CurrentRecipe ?? component.Queue.FirstOrDefault()?.Recipe; // Frontier var state = new LatheUpdateState(GetAvailableRecipes(uid, component), component.Queue, producing); _uiSys.SetUiState(uid, LatheUiKey.Key, state); @@ -396,19 +413,12 @@ private void OnLatheQueueRecipeMessage(EntityUid uid, LatheComponent component, { if (_proto.TryIndex(args.ID, out LatheRecipePrototype? recipe)) { - var count = 0; - for (var i = 0; i < args.Quantity; i++) - { - if (TryAddToQueue(uid, recipe, component)) - count++; - else - break; - } - if (count > 0) + // Frontier: batching recipes + if (TryAddToQueue(uid, recipe, args.Quantity, component)) { _adminLogger.Add(LogType.Action, LogImpact.Low, - $"{ToPrettyString(args.Actor):player} queued {count} {GetRecipeName(recipe)} at {ToPrettyString(uid):lathe}"); + $"{ToPrettyString(args.Actor):player} queued {args.Quantity} {GetRecipeName(recipe)} at {ToPrettyString(uid):lathe}"); } } TryStartProducing(uid, component); diff --git a/Content.Shared/Lathe/LatheComponent.cs b/Content.Shared/Lathe/LatheComponent.cs index 34e9552c3bc..63da1ef4385 100644 --- a/Content.Shared/Lathe/LatheComponent.cs +++ b/Content.Shared/Lathe/LatheComponent.cs @@ -25,7 +25,7 @@ public sealed partial class LatheComponent : Component /// The lathe's construction queue /// [DataField] - public List Queue = new(); + public List Queue = new(); // Frontier: LatheRecipePrototype /// The sound that plays when the lathe is producing an item, if any @@ -141,6 +141,23 @@ public LatheGetRecipesEvent(EntityUid lathe, bool forced) } } + // Frontier: batch lathe recipes + [Serializable] + public sealed partial class LatheRecipeBatch : EntityEventArgs + { + public LatheRecipePrototype Recipe; + public int ItemsPrinted; + public int ItemsRequested; + + public LatheRecipeBatch(LatheRecipePrototype recipe, int itemsPrinted, int itemsRequested) + { + Recipe = recipe; + ItemsPrinted = itemsPrinted; + ItemsRequested = itemsRequested; + } + } + // End Frontier + /// /// Event raised on a lathe when it starts producing a recipe. /// diff --git a/Content.Shared/Lathe/LatheMessages.cs b/Content.Shared/Lathe/LatheMessages.cs index 820c496d30c..6933dbf7b6f 100644 --- a/Content.Shared/Lathe/LatheMessages.cs +++ b/Content.Shared/Lathe/LatheMessages.cs @@ -9,11 +9,11 @@ public sealed class LatheUpdateState : BoundUserInterfaceState { public List> Recipes; - public List Queue; + public List Queue; // Frontier: LatheRecipePrototype> recipes, List queue, LatheRecipePrototype? currentlyProducing = null) + public LatheUpdateState(List> recipes, List queue, LatheRecipePrototype? currentlyProducing = null) // Frontier: change queue type { Recipes = recipes; Queue = queue; From 300801837d4904f24efdbcf688f5080ce9c6e0e6 Mon Sep 17 00:00:00 2001 From: Whatstone Date: Tue, 28 Jan 2025 01:09:08 -0500 Subject: [PATCH 2/5] Greater than or equal to. No freebies. --- Content.Server/Lathe/LatheSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Server/Lathe/LatheSystem.cs b/Content.Server/Lathe/LatheSystem.cs index d44f9614ea2..e9f873e21c3 100644 --- a/Content.Server/Lathe/LatheSystem.cs +++ b/Content.Server/Lathe/LatheSystem.cs @@ -219,7 +219,7 @@ public bool TryStartProducing(EntityUid uid, LatheComponent? component = null) // Frontier: handle batches var batch = component.Queue.First(); batch.ItemsPrinted++; - if (batch.ItemsPrinted > batch.ItemsRequested || batch.ItemsPrinted < 0) // Rollover sanity check + if (batch.ItemsPrinted >= batch.ItemsRequested || batch.ItemsPrinted < 0) // Rollover sanity check component.Queue.RemoveAt(0); var recipe = batch.Recipe; // End Frontier From dc12cf7d06b286b183dc8307c357f3fc116736f6 Mon Sep 17 00:00:00 2001 From: Whatstone Date: Tue, 28 Jan 2025 08:01:53 -0500 Subject: [PATCH 3/5] Base time of 60 ms (two ticks) for single sheets --- .../Nyanotrasen/Recipes/Lathes/bluespace.yml | 2 +- Resources/Prototypes/Recipes/Lathes/sheet.yml | 34 +++++++++---------- .../Prototypes/_NF/Recipes/Lathes/sheet.yml | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Resources/Prototypes/Nyanotrasen/Recipes/Lathes/bluespace.yml b/Resources/Prototypes/Nyanotrasen/Recipes/Lathes/bluespace.yml index ee0a106a88d..ff478645210 100644 --- a/Resources/Prototypes/Nyanotrasen/Recipes/Lathes/bluespace.yml +++ b/Resources/Prototypes/Nyanotrasen/Recipes/Lathes/bluespace.yml @@ -16,6 +16,6 @@ sprite: Nyanotrasen/Objects/Materials/materials.rsi state: bluespace result: MaterialBluespace1 - completetime: 0 + completetime: 0.06 materials: RawBluespace: 100 \ No newline at end of file diff --git a/Resources/Prototypes/Recipes/Lathes/sheet.yml b/Resources/Prototypes/Recipes/Lathes/sheet.yml index d4465f1ca07..50aa6eed8f8 100644 --- a/Resources/Prototypes/Recipes/Lathes/sheet.yml +++ b/Resources/Prototypes/Recipes/Lathes/sheet.yml @@ -1,7 +1,7 @@ - type: latheRecipe id: SheetSteel result: SheetSteel1 - completetime: 0 + completetime: 0.06 # Frontier: 0<0.06 (~2/30) materials: RawIron: 100 Coal: 30 @@ -17,7 +17,7 @@ - type: latheRecipe id: SheetGlass1 result: SheetGlass1 - completetime: 0 + completetime: 0.06 # Frontier: 0<0.06 (~2/30) materials: RawQuartz: 100 @@ -32,7 +32,7 @@ - type: latheRecipe id: SheetRGlass result: SheetRGlass1 - completetime: 0 + completetime: 0.06 # Frontier: 0<0.06 (~2/30) materials: Glass: 100 Steel: 50 @@ -41,7 +41,7 @@ - type: latheRecipe id: SheetRGlassRaw result: SheetRGlass1 - completetime: 0 + completetime: 0.06 # Frontier: 0<0.06 (~2/30) materials: RawQuartz: 100 RawIron: 50 @@ -59,7 +59,7 @@ - type: latheRecipe id: SheetPGlass1 result: SheetPGlass1 - completetime: 0 + completetime: 0.06 # Frontier: 0<0.06 (~2/30) materials: RawQuartz: 100 RawPlasma: 100 @@ -75,7 +75,7 @@ - type: latheRecipe id: SheetRPGlass1 result: SheetRPGlass1 - completetime: 0 + completetime: 0.06 # Frontier: 0<0.06 (~2/30) materials: RawQuartz: 100 RawPlasma: 100 @@ -95,7 +95,7 @@ - type: latheRecipe id: SheetPlasma1 result: SheetPlasma1 - completetime: 0 + completetime: 0.06 # Frontier: 0<0.06 (~2/30) materials: RawPlasma: 100 @@ -109,7 +109,7 @@ - type: latheRecipe id: SheetPlasteel1 result: SheetPlasteel1 - completetime: 0 + completetime: 0.06 # Frontier: 0<0.06 (~2/30) materials: RawPlasma: 100 RawIron: 200 #Twice as durable as steel, Twice the material cost @@ -118,7 +118,7 @@ - type: latheRecipe id: SheetPlasteel30 result: SheetPlasteel - completetime: 5 + completetime: 2 # Frontier: 5<2 materials: RawPlasma: 3000 RawIron: 6000 #Twice as durable as steel, Twice the material cost @@ -134,7 +134,7 @@ - type: latheRecipe id: SheetUGlass1 result: SheetUGlass1 - completetime: 0 + completetime: 0.06 # Frontier: 0<0.06 (~2/30) materials: RawUranium: 100 RawQuartz: 100 @@ -150,7 +150,7 @@ - type: latheRecipe id: SheetRUGlass1 result: SheetRUGlass1 - completetime: 0 + completetime: 0.06 # Frontier: 0<0.06 (~2/30) materials: RawUranium: 100 RawQuartz: 100 @@ -191,28 +191,28 @@ - type: latheRecipe id: MaterialDiamond result: MaterialDiamond1 - completetime: 0 + completetime: 0.06 # Frontier: 0<0.06 (~2/30) materials: RawDiamond: 100 - type: latheRecipe id: SheetUranium1 result: SheetUranium1 - completetime: 0 + completetime: 0.06 # Frontier: 0<0.06 (~2/30) materials: RawUranium: 100 - type: latheRecipe id: IngotGold1 result: IngotGold1 - completetime: 0 + completetime: 0.06 # Frontier: 0<0.06 (~2/30) materials: RawGold: 100 - type: latheRecipe id: IngotSilver1 result: IngotSilver1 - completetime: 0 + completetime: 0.06 # Frontier: 0<0.06 (~2/30) materials: RawSilver: 100 @@ -220,14 +220,14 @@ id: SheetPlastic result: SheetPlastic1 applyMaterialDiscount: false - completetime: 0 + completetime: 0.06 # Frontier: 0<0.06 (~2/30) materials: Plastic: 100 - type: latheRecipe id: MaterialBananium1 result: MaterialBananium1 - completetime: 0 + completetime: 0.06 # Frontier: 0<0.06 (~2/30) materials: RawBananium: 100 diff --git a/Resources/Prototypes/_NF/Recipes/Lathes/sheet.yml b/Resources/Prototypes/_NF/Recipes/Lathes/sheet.yml index c2f33a9661a..3e6f35aec1b 100644 --- a/Resources/Prototypes/_NF/Recipes/Lathes/sheet.yml +++ b/Resources/Prototypes/_NF/Recipes/Lathes/sheet.yml @@ -7,7 +7,7 @@ id: BaseMaterialsNoDiscountRecipe category: Materials applyMaterialDiscount: false - completetime: 0 + completetime: 0.06 # Recipes From 46682789f2a56add7412916d573c8c2104e98e16 Mon Sep 17 00:00:00 2001 From: Whatstone Date: Fri, 31 Jan 2025 11:19:53 -0500 Subject: [PATCH 4/5] Minor lathe cleanup, no numbers for singular jobs --- Content.Client/Lathe/UI/LatheMenu.xaml.cs | 5 ++++- Content.Server/Lathe/LatheSystem.cs | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Content.Client/Lathe/UI/LatheMenu.xaml.cs b/Content.Client/Lathe/UI/LatheMenu.xaml.cs index a192b655330..c574d4a63d3 100644 --- a/Content.Client/Lathe/UI/LatheMenu.xaml.cs +++ b/Content.Client/Lathe/UI/LatheMenu.xaml.cs @@ -230,7 +230,10 @@ public void PopulateQueueList(List queue) // Frontier: LatheRe queuedRecipeBox.AddChild(GetRecipeDisplayControl(batch.Recipe)); var queuedRecipeLabel = new Label(); - queuedRecipeLabel.Text = $"{idx}. {_lathe.GetRecipeName(batch.Recipe)} ({batch.ItemsPrinted}/{batch.ItemsRequested})"; // + if (batch.ItemsRequested > 1) + queuedRecipeLabel.Text = $"{idx}. {_lathe.GetRecipeName(batch.Recipe)} ({batch.ItemsPrinted}/{batch.ItemsRequested})"; + else + queuedRecipeLabel.Text = $"{idx}. {_lathe.GetRecipeName(batch.Recipe)}"; // End Frontier queuedRecipeBox.AddChild(queuedRecipeLabel); QueueList.AddChild(queuedRecipeBox); diff --git a/Content.Server/Lathe/LatheSystem.cs b/Content.Server/Lathe/LatheSystem.cs index e9f873e21c3..cea6be605bc 100644 --- a/Content.Server/Lathe/LatheSystem.cs +++ b/Content.Server/Lathe/LatheSystem.cs @@ -186,7 +186,7 @@ public bool TryAddToQueue(EntityUid uid, LatheRecipePrototype recipe, int quanti return false; // Frontier: argument check - if (!CanProduce(uid, recipe, quantity, component)) + if (!CanProduce(uid, recipe, quantity, component)) // Frontier: 1 Date: Fri, 31 Jan 2025 11:41:24 -0500 Subject: [PATCH 5/5] Multiply recipe cost by amount when adjusting mats --- Content.Server/Lathe/LatheSystem.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Content.Server/Lathe/LatheSystem.cs b/Content.Server/Lathe/LatheSystem.cs index cea6be605bc..78de33f3b6d 100644 --- a/Content.Server/Lathe/LatheSystem.cs +++ b/Content.Server/Lathe/LatheSystem.cs @@ -194,6 +194,7 @@ public bool TryAddToQueue(EntityUid uid, LatheRecipePrototype recipe, int quanti var adjustedAmount = recipe.ApplyMaterialDiscount ? (int) (-amount * component.FinalMaterialUseMultiplier) // Frontier: MaterialUseMultiplier