Makes machine parts stackable, removes unused field in stack prototypes (#28434)

* Makes machine parts stacks, removes unused field in stack prototypes

* forgor

* Fix tests

* Fixes lathe construction. Yes. This sucks but there's no better way that doesnt involve refactoring machine parts completely

* detail

* a
This commit is contained in:
AJCM-git
2024-06-01 13:49:28 -04:00
committed by GitHub
parent a29b6a6894
commit 09256cfaa5
22 changed files with 88 additions and 168 deletions

View File

@@ -59,23 +59,27 @@ public sealed class MachineFrameSystem : EntitySystem
return;
}
// Machine parts cannot currently satisfy stack/component/tag restrictions. Similarly stacks cannot satisfy
// component/tag restrictions. However, there is no reason this cannot be supported in the future. If this
// changes, then RegenerateProgress() also needs to be updated.
//
// If this changes in the future, then RegenerateProgress() also needs to be updated.
// Note that one entity is ALLOWED to satisfy more than one kind of component or tag requirements. This is
// necessary in order to avoid weird entity-ordering shenanigans in RegenerateProgress().
var stack = CompOrNull<StackComponent>(args.Used);
var machinePart = CompOrNull<MachinePartComponent>(args.Used);
if (stack != null && machinePart != null)
{
if (TryInsertPartStack(uid, args.Used, component, machinePart, stack))
args.Handled = true;
return;
}
// Handle parts
if (TryComp<MachinePartComponent>(args.Used, out var machinePart))
if (machinePart != null)
{
if (TryInsertPart(uid, args.Used, component, machinePart))
args.Handled = true;
return;
}
// Handle stacks
if (TryComp<StackComponent>(args.Used, out var stack))
if (stack != null)
{
if (TryInsertStack(uid, args.Used, component, stack))
args.Handled = true;
@@ -191,6 +195,44 @@ public sealed class MachineFrameSystem : EntitySystem
return true;
}
/// <returns>Whether or not the function had any effect. Does not indicate success.</returns>
private bool TryInsertPartStack(EntityUid uid, EntityUid used, MachineFrameComponent component, MachinePartComponent machinePart, StackComponent stack)
{
if (!component.Requirements.ContainsKey(machinePart.PartType))
return false;
var progress = component.Progress[machinePart.PartType];
var requirement = component.Requirements[machinePart.PartType];
var needed = requirement - progress;
if (needed <= 0)
return false;
var count = stack.Count;
if (count < needed)
{
if (!_container.Insert(used, component.PartContainer))
return true;
component.Progress[machinePart.PartType] += count;
return true;
}
var splitStack = _stack.Split(used, needed, Transform(uid).Coordinates, stack);
if (splitStack == null)
return false;
if (!_container.Insert(splitStack.Value, component.PartContainer))
return true;
component.Progress[machinePart.PartType] += needed;
if (IsComplete(component))
_popupSystem.PopupEntity(Loc.GetString("machine-frame-component-on-complete"), uid);
return true;
}
/// <returns>Whether or not the function had any effect. Does not indicate success.</returns>
private bool TryInsertStack(EntityUid uid, EntityUid used, MachineFrameComponent component, StackComponent stack)
{
@@ -328,8 +370,6 @@ public sealed class MachineFrameSystem : EntitySystem
{
if (TryComp<MachinePartComponent>(part, out var machinePart))
{
DebugTools.Assert(!HasComp<StackComponent>(part));
// Check this is part of the requirements...
if (!component.Requirements.ContainsKey(machinePart.PartType))
continue;
@@ -338,7 +378,6 @@ public sealed class MachineFrameSystem : EntitySystem
component.Progress[machinePart.PartType] = 1;
else
component.Progress[machinePart.PartType]++;
continue;
}