Fixed Kudzu Spread Falling Asleep After Containment (#18218)

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
Bixkitts
2023-08-06 08:08:07 +02:00
committed by GitHub
parent 0f54ac0090
commit 956e8b46dd
3 changed files with 22 additions and 9 deletions

View File

@@ -87,7 +87,6 @@ public sealed class SpreaderSystem : EntitySystem
private void OnGridInit(GridInitializeEvent ev)
{
var comp = EnsureComp<SpreaderGridComponent>(ev.EntityUid);
}
/// <inheritdoc/>
@@ -95,7 +94,7 @@ public sealed class SpreaderSystem : EntitySystem
{
var curTime = _timing.CurTime;
// Check which grids are valid for spreading.
// Check which grids are valid for spreading
var spreadable = new ValueList<EntityUid>();
var spreadGrids = EntityQueryEnumerator<SpreaderGridComponent>();
@@ -116,10 +115,13 @@ public sealed class SpreaderSystem : EntitySystem
var xformQuery = GetEntityQuery<TransformComponent>();
var gridQuery = GetEntityQuery<SpreaderGridComponent>();
// Events and stuff
// Each INode group has a certain number of updates
// allowed per SpreadCooldown
var groupUpdates = new Dictionary<INodeGroup, int>();
var spreaders = new List<(EntityUid Uid, EdgeSpreaderComponent Comp)>(Count<EdgeSpreaderComponent>());
// Build a list of all existing Edgespreaders, shuffle them
while (query.MoveNext(out var uid, out var comp))
{
spreaders.Add((uid, comp));
@@ -127,6 +129,8 @@ public sealed class SpreaderSystem : EntitySystem
_robustRandom.Shuffle(spreaders);
// Remove the EdgeSpreaderComponent from any entity
// that doesn't meet a few trivial prerequisites
foreach (var (uid, comp) in spreaders)
{
if (!xformQuery.TryGetComponent(uid, out var xform) ||
@@ -139,7 +143,7 @@ public sealed class SpreaderSystem : EntitySystem
foreach (var sGroup in _spreaderGroups)
{
// Cleanup
// Get the NodeContainer and Node from every EdgeSpreader entity found
if (!nodeQuery.TryGetComponent(uid, out var nodeContainer))
{
RemCompDeferred<EdgeSpreaderComponent>(uid);
@@ -147,7 +151,9 @@ public sealed class SpreaderSystem : EntitySystem
}
if (!_nodeContainer.TryGetNode<SpreaderNode>(nodeContainer, sGroup, out var node))
{
continue;
}
// Not allowed this tick?
if (node.NodeGroup == null ||
@@ -156,8 +162,8 @@ public sealed class SpreaderSystem : EntitySystem
continue;
}
// While we could check if it's an edge here the subscribing system may have its own definition
// of an edge so we'll let them handle it.
// Try get an integer update rate associated with a node group,
// getting it instead from the spreader itself on failure
if (!groupUpdates.TryGetValue(node.NodeGroup, out var updates))
{
var spreadEv = new SpreadGroupUpdateRate(node.Name);
@@ -165,11 +171,17 @@ public sealed class SpreaderSystem : EntitySystem
updates = (int) (spreadEv.UpdatesPerSecond * SpreadCooldown / TimeSpan.FromSeconds(1));
}
// "updates" integer dictates the amount of nodes that
// are to be spawned around a NodeGroup
if (updates <= 0)
{
continue;
}
// Edge detection logic is to be handled
// by the subscribing system, see KudzuSystem
// for a simple example
Spread(uid, node, node.NodeGroup, ref updates);
groupUpdates[node.NodeGroup] = updates;
}