Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch lathe jobs #2798

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Content.Client/Lathe/UI/LatheMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,20 +216,25 @@ public void UpdateCategories()
/// Populates the build queue list with all queued items
/// </summary>
/// <param name="queue"></param>
public void PopulateQueueList(List<LatheRecipePrototype> queue)
public void PopulateQueueList(List<LatheRecipeBatch> queue) // Frontier: LatheRecipePrototype<LatheRecipeBatch
{
QueueList.DisposeAllChildren();

var idx = 1;
foreach (var recipe in queue)
foreach (var batch in queue) // Frontier: recipe<batch
{
var queuedRecipeBox = new BoxContainer();
queuedRecipeBox.Orientation = BoxContainer.LayoutOrientation.Horizontal;

queuedRecipeBox.AddChild(GetRecipeDisplayControl(recipe));
// Frontier: batch handling
queuedRecipeBox.AddChild(GetRecipeDisplayControl(batch.Recipe));

var queuedRecipeLabel = new Label();
queuedRecipeLabel.Text = $"{idx}. {_lathe.GetRecipeName(recipe)}";
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);
idx++;
Expand Down
44 changes: 28 additions & 16 deletions Content.Server/Lathe/LatheSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,36 @@ public static List<ProtoId<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)) // Frontier: 1<quantity
return false;

foreach (var (mat, amount) in recipe.Materials)
{
var adjustedAmount = recipe.ApplyMaterialDiscount
? (int) (-amount * component.FinalMaterialUseMultiplier) // Frontier: MaterialUseMultiplier<FinalMaterialUseMultiplier
: -amount;
adjustedAmount *= quantity; // Frontier

_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;
}
Expand All @@ -204,8 +217,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;

Expand Down Expand Up @@ -288,7 +306,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: add ?.Recipe

var state = new LatheUpdateState(GetAvailableRecipes(uid, component), component.Queue, producing);
_uiSys.SetUiState(uid, LatheUiKey.Key, state);
Expand Down Expand Up @@ -396,20 +414,14 @@ 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}");
}
// End Frontier
}
TryStartProducing(uid, component);
UpdateUserInterfaceState(uid, component);
Expand Down
19 changes: 18 additions & 1 deletion Content.Shared/Lathe/LatheComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public sealed partial class LatheComponent : Component
/// The lathe's construction queue
/// </summary>
[DataField]
public List<LatheRecipePrototype> Queue = new();
public List<LatheRecipeBatch> Queue = new(); // Frontier: LatheRecipePrototype<LatheRecipeBatch

/// <summary>
/// The sound that plays when the lathe is producing an item, if any
Expand Down Expand Up @@ -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

/// <summary>
/// Event raised on a lathe when it starts producing a recipe.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions Content.Shared/Lathe/LatheMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ public sealed class LatheUpdateState : BoundUserInterfaceState
{
public List<ProtoId<LatheRecipePrototype>> Recipes;

public List<LatheRecipePrototype> Queue;
public List<LatheRecipeBatch> Queue; // Frontier: LatheRecipePrototype<LatheRecipeBatch

public LatheRecipePrototype? CurrentlyProducing;

public LatheUpdateState(List<ProtoId<LatheRecipePrototype>> recipes, List<LatheRecipePrototype> queue, LatheRecipePrototype? currentlyProducing = null)
public LatheUpdateState(List<ProtoId<LatheRecipePrototype>> recipes, List<LatheRecipeBatch> queue, LatheRecipePrototype? currentlyProducing = null) // Frontier: change queue type
{
Recipes = recipes;
Queue = queue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
sprite: Nyanotrasen/Objects/Materials/materials.rsi
state: bluespace
result: MaterialBluespace1
completetime: 0
completetime: 0.06
materials:
RawBluespace: 100
34 changes: 17 additions & 17 deletions Resources/Prototypes/Recipes/Lathes/sheet.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -17,7 +17,7 @@
- type: latheRecipe
id: SheetGlass1
result: SheetGlass1
completetime: 0
completetime: 0.06 # Frontier: 0<0.06 (~2/30)
materials:
RawQuartz: 100

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -95,7 +95,7 @@
- type: latheRecipe
id: SheetPlasma1
result: SheetPlasma1
completetime: 0
completetime: 0.06 # Frontier: 0<0.06 (~2/30)
materials:
RawPlasma: 100

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -191,43 +191,43 @@
- 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

- type: latheRecipe
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

Expand Down
2 changes: 1 addition & 1 deletion Resources/Prototypes/_NF/Recipes/Lathes/sheet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
id: BaseMaterialsNoDiscountRecipe
category: Materials
applyMaterialDiscount: false
completetime: 0
completetime: 0.06

# Recipes

Expand Down
Loading