Fixed Kudzu Spread Falling Asleep After Containment (#18218)
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
@@ -4,6 +4,7 @@ using Content.Shared.Atmos;
|
|||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Map.Components;
|
using Robust.Shared.Map.Components;
|
||||||
|
using Content.Shared.Destructible;
|
||||||
|
|
||||||
namespace Content.Server.Atmos.EntitySystems
|
namespace Content.Server.Atmos.EntitySystems
|
||||||
{
|
{
|
||||||
@@ -90,7 +91,7 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
airtight.CurrentAirBlockedDirection = (int) Rotate((AtmosDirection)airtight.InitialAirBlockedDirection, ev.NewRotation);
|
airtight.CurrentAirBlockedDirection = (int) Rotate((AtmosDirection)airtight.InitialAirBlockedDirection, ev.NewRotation);
|
||||||
UpdatePosition(airtight, ev.Component);
|
UpdatePosition(airtight, ev.Component);
|
||||||
var airtightEv = new AirtightChanged(uid, airtight);
|
var airtightEv = new AirtightChanged(uid, airtight);
|
||||||
RaiseLocalEvent(uid, ref airtightEv);
|
RaiseLocalEvent(uid, ref airtightEv, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +105,7 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
airtight.AirBlocked = airblocked;
|
airtight.AirBlocked = airblocked;
|
||||||
UpdatePosition(airtight, xform);
|
UpdatePosition(airtight, xform);
|
||||||
var airtightEv = new AirtightChanged(uid, airtight);
|
var airtightEv = new AirtightChanged(uid, airtight);
|
||||||
RaiseLocalEvent(uid, ref airtightEv);
|
RaiseLocalEvent(uid, ref airtightEv, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdatePosition(AirtightComponent airtight, TransformComponent? xform = null)
|
public void UpdatePosition(AirtightComponent airtight, TransformComponent? xform = null)
|
||||||
|
|||||||
@@ -4,4 +4,4 @@ namespace Content.Server.Spreader;
|
|||||||
/// Raised every tick to determine how many updates a particular spreading node group is allowed.
|
/// Raised every tick to determine how many updates a particular spreading node group is allowed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ByRefEvent]
|
[ByRefEvent]
|
||||||
public record struct SpreadGroupUpdateRate(string Name, int UpdatesPerSecond = 16);
|
public record struct SpreadGroupUpdateRate(string Name, int UpdatesPerSecond = 16);
|
||||||
|
|||||||
@@ -87,7 +87,6 @@ public sealed class SpreaderSystem : EntitySystem
|
|||||||
private void OnGridInit(GridInitializeEvent ev)
|
private void OnGridInit(GridInitializeEvent ev)
|
||||||
{
|
{
|
||||||
var comp = EnsureComp<SpreaderGridComponent>(ev.EntityUid);
|
var comp = EnsureComp<SpreaderGridComponent>(ev.EntityUid);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
@@ -95,7 +94,7 @@ public sealed class SpreaderSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
var curTime = _timing.CurTime;
|
var curTime = _timing.CurTime;
|
||||||
|
|
||||||
// Check which grids are valid for spreading.
|
// Check which grids are valid for spreading
|
||||||
var spreadable = new ValueList<EntityUid>();
|
var spreadable = new ValueList<EntityUid>();
|
||||||
var spreadGrids = EntityQueryEnumerator<SpreaderGridComponent>();
|
var spreadGrids = EntityQueryEnumerator<SpreaderGridComponent>();
|
||||||
|
|
||||||
@@ -116,10 +115,13 @@ public sealed class SpreaderSystem : EntitySystem
|
|||||||
var xformQuery = GetEntityQuery<TransformComponent>();
|
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||||
var gridQuery = GetEntityQuery<SpreaderGridComponent>();
|
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 groupUpdates = new Dictionary<INodeGroup, int>();
|
||||||
|
|
||||||
var spreaders = new List<(EntityUid Uid, EdgeSpreaderComponent Comp)>(Count<EdgeSpreaderComponent>());
|
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))
|
while (query.MoveNext(out var uid, out var comp))
|
||||||
{
|
{
|
||||||
spreaders.Add((uid, comp));
|
spreaders.Add((uid, comp));
|
||||||
@@ -127,6 +129,8 @@ public sealed class SpreaderSystem : EntitySystem
|
|||||||
|
|
||||||
_robustRandom.Shuffle(spreaders);
|
_robustRandom.Shuffle(spreaders);
|
||||||
|
|
||||||
|
// Remove the EdgeSpreaderComponent from any entity
|
||||||
|
// that doesn't meet a few trivial prerequisites
|
||||||
foreach (var (uid, comp) in spreaders)
|
foreach (var (uid, comp) in spreaders)
|
||||||
{
|
{
|
||||||
if (!xformQuery.TryGetComponent(uid, out var xform) ||
|
if (!xformQuery.TryGetComponent(uid, out var xform) ||
|
||||||
@@ -139,7 +143,7 @@ public sealed class SpreaderSystem : EntitySystem
|
|||||||
|
|
||||||
foreach (var sGroup in _spreaderGroups)
|
foreach (var sGroup in _spreaderGroups)
|
||||||
{
|
{
|
||||||
// Cleanup
|
// Get the NodeContainer and Node from every EdgeSpreader entity found
|
||||||
if (!nodeQuery.TryGetComponent(uid, out var nodeContainer))
|
if (!nodeQuery.TryGetComponent(uid, out var nodeContainer))
|
||||||
{
|
{
|
||||||
RemCompDeferred<EdgeSpreaderComponent>(uid);
|
RemCompDeferred<EdgeSpreaderComponent>(uid);
|
||||||
@@ -147,7 +151,9 @@ public sealed class SpreaderSystem : EntitySystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!_nodeContainer.TryGetNode<SpreaderNode>(nodeContainer, sGroup, out var node))
|
if (!_nodeContainer.TryGetNode<SpreaderNode>(nodeContainer, sGroup, out var node))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Not allowed this tick?
|
// Not allowed this tick?
|
||||||
if (node.NodeGroup == null ||
|
if (node.NodeGroup == null ||
|
||||||
@@ -156,8 +162,8 @@ public sealed class SpreaderSystem : EntitySystem
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// While we could check if it's an edge here the subscribing system may have its own definition
|
// Try get an integer update rate associated with a node group,
|
||||||
// of an edge so we'll let them handle it.
|
// getting it instead from the spreader itself on failure
|
||||||
if (!groupUpdates.TryGetValue(node.NodeGroup, out var updates))
|
if (!groupUpdates.TryGetValue(node.NodeGroup, out var updates))
|
||||||
{
|
{
|
||||||
var spreadEv = new SpreadGroupUpdateRate(node.Name);
|
var spreadEv = new SpreadGroupUpdateRate(node.Name);
|
||||||
@@ -165,11 +171,17 @@ public sealed class SpreaderSystem : EntitySystem
|
|||||||
updates = (int) (spreadEv.UpdatesPerSecond * SpreadCooldown / TimeSpan.FromSeconds(1));
|
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)
|
if (updates <= 0)
|
||||||
{
|
{
|
||||||
continue;
|
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);
|
Spread(uid, node, node.NodeGroup, ref updates);
|
||||||
groupUpdates[node.NodeGroup] = updates;
|
groupUpdates[node.NodeGroup] = updates;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user