Drain fix (#11432)
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
|
using Content.Server.Chemistry.Components.SolutionManager;
|
||||||
using Content.Server.Fluids.Components;
|
using Content.Server.Fluids.Components;
|
||||||
using Content.Server.Chemistry.EntitySystems;
|
using Content.Server.Chemistry.EntitySystems;
|
||||||
using Content.Shared.FixedPoint;
|
using Content.Shared.FixedPoint;
|
||||||
using Content.Shared.Audio;
|
using Content.Shared.Audio;
|
||||||
|
using Robust.Shared.Collections;
|
||||||
|
|
||||||
namespace Content.Server.Fluids.EntitySystems
|
namespace Content.Server.Fluids.EntitySystems
|
||||||
{
|
{
|
||||||
@@ -11,10 +13,14 @@ namespace Content.Server.Fluids.EntitySystems
|
|||||||
[Dependency] private readonly SolutionContainerSystem _solutionSystem = default!;
|
[Dependency] private readonly SolutionContainerSystem _solutionSystem = default!;
|
||||||
[Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!;
|
[Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!;
|
||||||
|
|
||||||
|
|
||||||
public override void Update(float frameTime)
|
public override void Update(float frameTime)
|
||||||
{
|
{
|
||||||
base.Update(frameTime);
|
base.Update(frameTime);
|
||||||
|
var managerQuery = GetEntityQuery<SolutionContainerManagerComponent>();
|
||||||
|
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||||
|
var puddleQuery = GetEntityQuery<PuddleComponent>();
|
||||||
|
var puddles = new ValueList<(EntityUid Entity, string Solution)>();
|
||||||
|
|
||||||
foreach (var drain in EntityQuery<DrainComponent>())
|
foreach (var drain in EntityQuery<DrainComponent>())
|
||||||
{
|
{
|
||||||
drain.Accumulator += frameTime;
|
drain.Accumulator += frameTime;
|
||||||
@@ -24,27 +30,33 @@ namespace Content.Server.Fluids.EntitySystems
|
|||||||
}
|
}
|
||||||
drain.Accumulator -= drain.DrainFrequency;
|
drain.Accumulator -= drain.DrainFrequency;
|
||||||
|
|
||||||
/// Best to do this one every second rather than once every tick...
|
if (!managerQuery.TryGetComponent(drain.Owner, out var manager))
|
||||||
_solutionSystem.TryGetSolution(drain.Owner, DrainComponent.SolutionName, out var drainSolution);
|
continue;
|
||||||
|
|
||||||
|
// Best to do this one every second rather than once every tick...
|
||||||
|
_solutionSystem.TryGetSolution(drain.Owner, DrainComponent.SolutionName, out var drainSolution, manager);
|
||||||
|
|
||||||
if (drainSolution is null)
|
if (drainSolution is null)
|
||||||
return;
|
continue;
|
||||||
|
|
||||||
/// Remove a bit from the buffer
|
// Remove a bit from the buffer
|
||||||
_solutionSystem.SplitSolution(drain.Owner, drainSolution, (drain.UnitsDestroyedPerSecond * drain.DrainFrequency));
|
_solutionSystem.SplitSolution(drain.Owner, drainSolution, (drain.UnitsDestroyedPerSecond * drain.DrainFrequency));
|
||||||
|
|
||||||
/// This will ensure that UnitsPerSecond is per second...
|
// This will ensure that UnitsPerSecond is per second...
|
||||||
var amount = drain.UnitsPerSecond * drain.DrainFrequency;
|
var amount = drain.UnitsPerSecond * drain.DrainFrequency;
|
||||||
var xform = Transform(drain.Owner);
|
|
||||||
List<PuddleComponent> puddles = new();
|
if (!xformQuery.TryGetComponent(drain.Owner, out var xform))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
puddles.Clear();
|
||||||
|
|
||||||
foreach (var entity in _lookup.GetEntitiesInRange(xform.MapPosition, drain.Range))
|
foreach (var entity in _lookup.GetEntitiesInRange(xform.MapPosition, drain.Range))
|
||||||
{
|
{
|
||||||
/// No InRangeUnobstructed because there's no collision group that fits right now
|
// No InRangeUnobstructed because there's no collision group that fits right now
|
||||||
/// and these are placed by mappers and not buildable/movable so shouldnt really be a problem...
|
// and these are placed by mappers and not buildable/movable so shouldnt really be a problem...
|
||||||
if (TryComp<PuddleComponent>(entity, out var puddleComp))
|
if (puddleQuery.TryGetComponent(entity, out var puddle))
|
||||||
{
|
{
|
||||||
puddles.Add(puddleComp);
|
puddles.Add((entity, puddle.SolutionName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,28 +70,28 @@ namespace Content.Server.Fluids.EntitySystems
|
|||||||
|
|
||||||
amount /= puddles.Count;
|
amount /= puddles.Count;
|
||||||
|
|
||||||
foreach (var puddle in puddles)
|
foreach (var (puddle, solution) in puddles)
|
||||||
{
|
{
|
||||||
/// Queue the solution deletion if it's empty. EvaporationSystem might also do this
|
// Queue the solution deletion if it's empty. EvaporationSystem might also do this
|
||||||
/// but queuedelete should be pretty safe.
|
// but queuedelete should be pretty safe.
|
||||||
if (!_solutionSystem.TryGetSolution(puddle.Owner, puddle.SolutionName, out var puddleSolution))
|
if (!_solutionSystem.TryGetSolution(puddle, solution, out var puddleSolution))
|
||||||
{
|
{
|
||||||
EntityManager.QueueDeleteEntity(puddle.Owner);
|
EntityManager.QueueDeleteEntity(puddle);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes the lowest of:
|
// Removes the lowest of:
|
||||||
/// the drain component's units per second adjusted for # of puddles
|
// the drain component's units per second adjusted for # of puddles
|
||||||
/// the puddle's remaining volume (making it cleanly zero)
|
// the puddle's remaining volume (making it cleanly zero)
|
||||||
/// the drain's remaining volume in its buffer.
|
// the drain's remaining volume in its buffer.
|
||||||
var transferSolution = _solutionSystem.SplitSolution(puddle.Owner, puddleSolution,
|
var transferSolution = _solutionSystem.SplitSolution(puddle, puddleSolution,
|
||||||
FixedPoint2.Min(FixedPoint2.New(amount), puddleSolution.CurrentVolume, drainSolution.AvailableVolume));
|
FixedPoint2.Min(FixedPoint2.New(amount), puddleSolution.CurrentVolume, drainSolution.AvailableVolume));
|
||||||
|
|
||||||
_solutionSystem.TryAddSolution(drain.Owner, drainSolution, transferSolution);
|
_solutionSystem.TryAddSolution(drain.Owner, drainSolution, transferSolution);
|
||||||
|
|
||||||
if (puddleSolution.CurrentVolume <= 0)
|
if (puddleSolution.CurrentVolume <= 0)
|
||||||
{
|
{
|
||||||
EntityManager.QueueDeleteEntity(puddle.Owner);
|
QueueDel(puddle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user