Puddle fixes (#15820)

This commit is contained in:
metalgearsloth
2023-04-26 21:29:31 +10:00
committed by GitHub
parent d1d7c1107e
commit f12f277c35
3 changed files with 10 additions and 17 deletions

View File

@@ -36,7 +36,7 @@ public sealed class PuddleSystem : SharedPuddleSystem
args.Sprite.LayerSetState(0, $"{smooth.StateBase}a"); args.Sprite.LayerSetState(0, $"{smooth.StateBase}a");
_smooth.SetEnabled(uid, false, smooth); _smooth.SetEnabled(uid, false, smooth);
} }
else if (volume < 0.6f) else if (volume < MediumThreshold)
{ {
args.Sprite.LayerSetState(0, $"{smooth.StateBase}b"); args.Sprite.LayerSetState(0, $"{smooth.StateBase}b");
_smooth.SetEnabled(uid, false, smooth); _smooth.SetEnabled(uid, false, smooth);

View File

@@ -105,7 +105,7 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
continue; continue;
} }
var remaining = neighborSolution.Volume - puddle.OverflowVolume; var remaining = puddle.OverflowVolume - neighborSolution.Volume;
if (remaining <= FixedPoint2.Zero) if (remaining <= FixedPoint2.Zero)
continue; continue;
@@ -129,20 +129,13 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
} }
} }
// Then we go to free tiles -> only overflow if we can go up to capacity at least. // Then we go to free tiles.
// Need to go even if we have a little remainder to avoid solution sploshing around internally
// for ages.
if (args.NeighborFreeTiles.Count > 0 && args.Updates > 0) if (args.NeighborFreeTiles.Count > 0 && args.Updates > 0)
{ {
// We'll only spill if we have the minimum threshold per tile.
var spillCount = (int) Math.Floor(overflow.Volume.Float() / component.OverflowVolume.Float());
if (spillCount == 0)
{
return;
}
_random.Shuffle(args.NeighborFreeTiles); _random.Shuffle(args.NeighborFreeTiles);
spillCount = Math.Min(args.NeighborFreeTiles.Count, spillCount); var spillAmount = overflow.Volume / args.NeighborFreeTiles.Count;
var spillAmount = overflow.Volume / spillCount;
foreach (var neighbor in args.NeighborFreeTiles) foreach (var neighbor in args.NeighborFreeTiles)
{ {
@@ -165,12 +158,10 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
foreach (var neighbor in args.Neighbors) foreach (var neighbor in args.Neighbors)
{ {
// Overflow to neighbours but not if they're already at the cap // Overflow to neighbours (unless it's pure water)
// This is to avoid diluting solutions too much.
if (!puddleQuery.TryGetComponent(neighbor, out var puddle) || if (!puddleQuery.TryGetComponent(neighbor, out var puddle) ||
!_solutionContainerSystem.TryGetSolution(neighbor, puddle.SolutionName, out var neighborSolution) || !_solutionContainerSystem.TryGetSolution(neighbor, puddle.SolutionName, out var neighborSolution) ||
CanFullyEvaporate(neighborSolution) || CanFullyEvaporate(neighborSolution))
neighborSolution.Volume >= puddle.OverflowVolume)
{ {
continue; continue;
} }

View File

@@ -11,6 +11,8 @@ public abstract class SharedPuddleSystem : EntitySystem
/// </summary> /// </summary>
public const float LowThreshold = 0.3f; public const float LowThreshold = 0.3f;
public const float MediumThreshold = 0.6f;
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();