Solution rejig (#12428)

This commit is contained in:
Leon Friedrich
2023-01-12 16:41:40 +13:00
committed by GitHub
parent 38504f6412
commit 466384b081
61 changed files with 873 additions and 619 deletions

View File

@@ -36,9 +36,6 @@ namespace Content.Server.Fluids.Components
[DataField("spillSound")]
public SoundSpecifier SpillSound = new SoundPathSpecifier("/Audio/Effects/Fluids/splat.ogg");
[ViewVariables(VVAccess.ReadOnly)]
public FixedPoint2 CurrentVolume => EntitySystem.Get<PuddleSystem>().CurrentVolume(Owner);
[DataField("overflowVolume")]
public FixedPoint2 OverflowVolume = DefaultOverflowVolume;

View File

@@ -85,11 +85,11 @@ namespace Content.Server.Fluids.EntitySystems
// the puddle's remaining volume (making it cleanly zero)
// the drain's remaining volume in its buffer.
var transferSolution = _solutionSystem.SplitSolution(puddle, puddleSolution,
FixedPoint2.Min(FixedPoint2.New(amount), puddleSolution.CurrentVolume, drainSolution.AvailableVolume));
FixedPoint2.Min(FixedPoint2.New(amount), puddleSolution.Volume, drainSolution.AvailableVolume));
_solutionSystem.TryAddSolution(drain.Owner, drainSolution, transferSolution);
if (puddleSolution.CurrentVolume <= 0)
if (puddleSolution.Volume <= 0)
{
QueueDel(puddle);
}

View File

@@ -33,12 +33,12 @@ namespace Content.Server.Fluids.EntitySystems
if (evaporationComponent.EvaporationToggle == true)
{
_solutionContainerSystem.SplitSolution(uid, solution,
FixedPoint2.Min(FixedPoint2.New(1), solution.CurrentVolume)); // removes 1 unit, or solution current volume, whichever is lower.
FixedPoint2.Min(FixedPoint2.New(1), solution.Volume)); // removes 1 unit, or solution current volume, whichever is lower.
}
evaporationComponent.EvaporationToggle =
solution.CurrentVolume > evaporationComponent.LowerLimit
&& solution.CurrentVolume < evaporationComponent.UpperLimit;
solution.Volume > evaporationComponent.LowerLimit
&& solution.Volume < evaporationComponent.UpperLimit;
}
}

View File

@@ -60,13 +60,13 @@ public sealed class MoppingSystem : EntitySystem
/// </summary>
private bool TryCreatePuddle(EntityUid user, EntityCoordinates clickLocation, AbsorbentComponent absorbent, Solution absorberSoln)
{
if (absorberSoln.CurrentVolume <= 0)
if (absorberSoln.Volume <= 0)
return false;
if (!_mapManager.TryGetGrid(clickLocation.GetGridUid(EntityManager), out var mapGrid))
return false;
var releaseAmount = FixedPoint2.Min(absorbent.ResidueAmount, absorberSoln.CurrentVolume);
var releaseAmount = FixedPoint2.Min(absorbent.ResidueAmount, absorberSoln.Volume);
var releasedSolution = _solutionSystem.SplitSolution(absorbent.Owner, absorberSoln, releaseAmount);
_spillableSystem.SpillAt(mapGrid.GetTileRef(clickLocation), releasedSolution, PuddlePrototypeId);
_popups.PopupEntity(Loc.GetString("mopping-system-release-to-floor"), user, user);
@@ -84,7 +84,7 @@ public sealed class MoppingSystem : EntitySystem
if (!_solutionSystem.TryGetDrainableSolution(target, out var drainableSolution))
return false;
if (drainableSolution.CurrentVolume <= 0)
if (drainableSolution.Volume <= 0)
{
var msg = Loc.GetString("mopping-system-target-container-empty", ("target", target));
_popups.PopupEntity(msg, user, user);
@@ -93,7 +93,7 @@ public sealed class MoppingSystem : EntitySystem
// Let's transfer up to to half the tool's available capacity to the tool.
var quantity = FixedPoint2.Max(component.PickupAmount, absorberSoln.AvailableVolume / 2);
quantity = FixedPoint2.Min(quantity, drainableSolution.CurrentVolume);
quantity = FixedPoint2.Min(quantity, drainableSolution.Volume);
DoMopInteraction(user, used, target, component, drainable.Solution, quantity, 1, "mopping-system-drainable-success", component.TransferSound);
return true;
@@ -104,7 +104,7 @@ public sealed class MoppingSystem : EntitySystem
/// </summary>
private bool TryEmptyAbsorber(EntityUid user, EntityUid used, EntityUid target, AbsorbentComponent component, Solution absorberSoln)
{
if (absorberSoln.CurrentVolume <= 0 || !TryComp(target, out RefillableSolutionComponent? refillable))
if (absorberSoln.Volume <= 0 || !TryComp(target, out RefillableSolutionComponent? refillable))
return false;
if (!_solutionSystem.TryGetRefillableSolution(target, out var targetSolution))
@@ -128,7 +128,7 @@ public sealed class MoppingSystem : EntitySystem
}
float delay;
FixedPoint2 quantity = absorberSoln.CurrentVolume;
FixedPoint2 quantity = absorberSoln.Volume;
// TODO this really needs cleaning up. Less magic numbers, more data-fields.
@@ -171,7 +171,7 @@ public sealed class MoppingSystem : EntitySystem
if (!TryComp(target, out PuddleComponent? puddle))
return false;
if (!_solutionSystem.TryGetSolution(target, puddle.SolutionName, out var puddleSolution) || puddleSolution.TotalVolume <= 0)
if (!_solutionSystem.TryGetSolution(target, puddle.SolutionName, out var puddleSolution) || puddleSolution.Volume <= 0)
return false;
FixedPoint2 quantity;
@@ -186,12 +186,12 @@ public sealed class MoppingSystem : EntitySystem
}
// Can our absorber even absorb any liquid?
if (puddleSolution.TotalVolume <= lowerLimit)
if (puddleSolution.Volume <= lowerLimit)
{
// Cannot absorb any more liquid. So clearly the user wants to add liquid to the puddle... right?
// This is the old behavior and I CBF fixing this, for the record I don't like this.
quantity = FixedPoint2.Min(absorber.ResidueAmount, absorberSoln.CurrentVolume);
quantity = FixedPoint2.Min(absorber.ResidueAmount, absorberSoln.Volume);
if (quantity <= 0)
return false;
@@ -208,7 +208,7 @@ public sealed class MoppingSystem : EntitySystem
return true;
}
quantity = FixedPoint2.Min(absorber.PickupAmount, puddleSolution.TotalVolume - lowerLimit, absorberSoln.AvailableVolume);
quantity = FixedPoint2.Min(absorber.PickupAmount, puddleSolution.Volume - lowerLimit, absorberSoln.AvailableVolume);
if (quantity <= 0)
return false;

View File

@@ -1,4 +1,4 @@
using Content.Server.Fluids.Components;
using Content.Server.Fluids.Components;
using Content.Shared.Fluids;
using Robust.Server.Player;
using Robust.Shared.Map;
@@ -10,6 +10,7 @@ public sealed class PuddleDebugDebugOverlaySystem : SharedPuddleDebugOverlaySyst
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly PuddleSystem _puddle = default!;
private readonly HashSet<IPlayerSession> _playerObservers = new();
@@ -72,7 +73,8 @@ public sealed class PuddleDebugDebugOverlaySystem : SharedPuddleDebugOverlaySyst
continue;
var pos = xform.Coordinates.ToVector2i(EntityManager, _mapManager);
data.Add(new PuddleDebugOverlayData(pos, puddle.CurrentVolume));
var vol = _puddle.CurrentVolume(uid, puddle);
data.Add(new PuddleDebugOverlayData(pos, vol));
}
RaiseNetworkEvent(new PuddleOverlayDebugMessage(gridUid, data.ToArray()));

View File

@@ -10,6 +10,7 @@ using Robust.Shared.Audio;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Solution = Content.Shared.Chemistry.Components.Solution;
using Robust.Shared.Prototypes;
namespace Content.Server.Fluids.EntitySystems
{
@@ -19,6 +20,10 @@ namespace Content.Server.Fluids.EntitySystems
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
[Dependency] private readonly FluidSpreaderSystem _fluidSpreaderSystem = default!;
[Dependency] private readonly StepTriggerSystem _stepTrigger = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly IPrototypeManager _protoMan = default!;
public static float PuddleVolume = 1000;
// Using local deletion queue instead of the standard queue so that we can easily "undelete" if a puddle
// loses & then gains reagents in a single tick.
@@ -47,8 +52,7 @@ namespace Content.Server.Fluids.EntitySystems
private void OnPuddleInit(EntityUid uid, PuddleComponent component, ComponentInit args)
{
var solution = _solutionContainerSystem.EnsureSolution(uid, component.SolutionName);
solution.MaxVolume = FixedPoint2.New(1000);
_solutionContainerSystem.EnsureSolution(uid, component.SolutionName, FixedPoint2.New(PuddleVolume), out _);
}
private void OnSolutionUpdate(EntityUid uid, PuddleComponent component, SolutionChangedEvent args)
@@ -56,7 +60,7 @@ namespace Content.Server.Fluids.EntitySystems
if (args.Solution.Name != component.SolutionName)
return;
if (args.Solution.CurrentVolume <= 0)
if (args.Solution.Volume <= 0)
{
_deletionQueue.Add(uid);
return;
@@ -77,10 +81,10 @@ namespace Content.Server.Fluids.EntitySystems
// Opacity based on level of fullness to overflow
// Hard-cap lower bound for visibility reasons
var volumeScale = CurrentVolume(puddleComponent.Owner, puddleComponent).Float() /
var puddleSolution = _solutionContainerSystem.EnsureSolution(uid, puddleComponent.SolutionName);
var volumeScale = puddleSolution.Volume.Float() /
puddleComponent.OverflowVolume.Float() *
puddleComponent.OpacityModifier;
var puddleSolution = _solutionContainerSystem.EnsureSolution(uid, puddleComponent.SolutionName);
bool isEvaporating;
@@ -91,21 +95,24 @@ namespace Content.Server.Fluids.EntitySystems
}
else isEvaporating = false;
appearance.SetData(PuddleVisuals.VolumeScale, volumeScale);
appearance.SetData(PuddleVisuals.CurrentVolume, puddleComponent.CurrentVolume);
appearance.SetData(PuddleVisuals.SolutionColor, puddleSolution.Color);
appearance.SetData(PuddleVisuals.IsEvaporatingVisual, isEvaporating);
var color = puddleSolution.GetColor(_protoMan);
_appearance.SetData(uid, PuddleVisuals.VolumeScale, volumeScale, appearance);
_appearance.SetData(uid, PuddleVisuals.CurrentVolume, puddleSolution.Volume, appearance);
_appearance.SetData(uid, PuddleVisuals.SolutionColor, color, appearance);
_appearance.SetData(uid, PuddleVisuals.IsEvaporatingVisual, isEvaporating, appearance);
}
private void UpdateSlip(EntityUid entityUid, PuddleComponent puddleComponent)
{
var vol = CurrentVolume(puddleComponent.Owner, puddleComponent);
if ((puddleComponent.SlipThreshold == FixedPoint2.New(-1) ||
CurrentVolume(puddleComponent.Owner, puddleComponent) < puddleComponent.SlipThreshold) &&
vol < puddleComponent.SlipThreshold) &&
TryComp(entityUid, out StepTriggerComponent? stepTrigger))
{
_stepTrigger.SetActive(entityUid, false, stepTrigger);
}
else if (CurrentVolume(puddleComponent.Owner, puddleComponent) >= puddleComponent.SlipThreshold)
else if (vol >= puddleComponent.SlipThreshold)
{
var comp = EnsureComp<StepTriggerComponent>(entityUid);
_stepTrigger.SetActive(entityUid, true, comp);
@@ -143,7 +150,7 @@ namespace Content.Server.Fluids.EntitySystems
return _solutionContainerSystem.TryGetSolution(puddleComponent.Owner, puddleComponent.SolutionName,
out var solution)
? solution.CurrentVolume
? solution.Volume
: FixedPoint2.Zero;
}
@@ -165,15 +172,16 @@ namespace Content.Server.Fluids.EntitySystems
if (!Resolve(puddleUid, ref puddleComponent))
return false;
if (addedSolution.TotalVolume == 0 ||
if (addedSolution.Volume == 0 ||
!_solutionContainerSystem.TryGetSolution(puddleComponent.Owner, puddleComponent.SolutionName,
out var solution))
{
return false;
}
solution.AddSolution(addedSolution);
solution.AddSolution(addedSolution, _protoMan);
_solutionContainerSystem.UpdateChemicals(puddleUid, solution, true);
if (checkForOverflow && IsOverflowing(puddleUid, puddleComponent))
{
_fluidSpreaderSystem.AddOverflowingPuddle(puddleComponent.Owner, puddleComponent);
@@ -215,7 +223,7 @@ namespace Content.Server.Fluids.EntitySystems
out var destSolution))
continue;
var takeAmount = FixedPoint2.Max(0, dividedVolume - destSolution.CurrentVolume);
var takeAmount = FixedPoint2.Max(0, dividedVolume - destSolution.Volume);
TryAddSolution(destPuddle.Owner, srcSolution.SplitSolution(takeAmount), false, false, destPuddle);
if (stillOverflowing != null && IsOverflowing(destPuddle.Owner, destPuddle))
{
@@ -223,7 +231,7 @@ namespace Content.Server.Fluids.EntitySystems
}
}
if (stillOverflowing != null && srcSolution.CurrentVolume > sourcePuddleComponent.OverflowVolume)
if (stillOverflowing != null && srcSolution.Volume > sourcePuddleComponent.OverflowVolume)
{
stillOverflowing.Add(srcPuddle);
}
@@ -241,7 +249,7 @@ namespace Content.Server.Fluids.EntitySystems
if (!Resolve(uid, ref puddle))
return false;
return CurrentVolume(uid, puddle) + solution.TotalVolume > puddle.OverflowVolume;
return CurrentVolume(uid, puddle) + solution.Volume > puddle.OverflowVolume;
}
/// <summary>

View File

@@ -67,11 +67,11 @@ public sealed class SpillableSystem : EntitySystem
if (!_solutionContainerSystem.TryGetSolution(uid, component.SolutionName, out var solution))
return;
if (solution.TotalVolume == 0)
if (solution.Volume == 0)
return;
// spill all solution on the player
var drainedSolution = _solutionContainerSystem.Drain(uid, solution, solution.DrainAvailable);
var drainedSolution = _solutionContainerSystem.Drain(uid, solution, solution.Volume);
SpillAt(args.Equipee, drainedSolution, "PuddleSmear");
}
@@ -108,7 +108,7 @@ public sealed class SpillableSystem : EntitySystem
$"{ToPrettyString(uid):entity} spilled a solution {SolutionContainerSystem.ToPrettyString(solution):solution} on landing");
}
var drainedSolution = _solutionContainerSystem.Drain(uid, solution, solution.DrainAvailable);
var drainedSolution = _solutionContainerSystem.Drain(uid, solution, solution.Volume);
SpillAt(drainedSolution, EntityManager.GetComponent<TransformComponent>(uid).Coordinates, "PuddleSmear");
}
@@ -123,7 +123,7 @@ public sealed class SpillableSystem : EntitySystem
if (TryComp<DrinkComponent>(args.Target, out var drink) && (!drink.Opened))
return;
if (solution.DrainAvailable == FixedPoint2.Zero)
if (solution.Volume == FixedPoint2.Zero)
return;
Verb verb = new();
@@ -134,7 +134,7 @@ public sealed class SpillableSystem : EntitySystem
verb.Act = () =>
{
var puddleSolution = _solutionContainerSystem.SplitSolution(args.Target,
solution, solution.DrainAvailable);
solution, solution.Volume);
SpillAt(puddleSolution, Transform(args.Target).Coordinates, "PuddleSmear");
};
}
@@ -176,7 +176,7 @@ public sealed class SpillableSystem : EntitySystem
public PuddleComponent? SpillAt(Solution solution, EntityCoordinates coordinates, string prototype,
bool overflow = true, bool sound = true, bool combine = true)
{
if (solution.TotalVolume == 0) return null;
if (solution.Volume == 0) return null;
if (!_mapManager.TryGetGrid(coordinates.GetGridUid(EntityManager), out var mapGrid))
@@ -204,7 +204,7 @@ public sealed class SpillableSystem : EntitySystem
public PuddleComponent? SpillAt(TileRef tileRef, Solution solution, string prototype,
bool overflow = true, bool sound = true, bool noTileReact = false, bool combine = true)
{
if (solution.TotalVolume <= 0) return null;
if (solution.Volume <= 0) return null;
// If space return early, let that spill go out into the void
if (tileRef.Tile.IsEmpty) return null;
@@ -226,7 +226,7 @@ public sealed class SpillableSystem : EntitySystem
}
// Tile reactions used up everything.
if (solution.CurrentVolume == FixedPoint2.Zero)
if (solution.Volume == FixedPoint2.Zero)
return null;
// Get normalized co-ordinate for spill location and spill it in the centre
@@ -268,11 +268,11 @@ public sealed class SpillableSystem : EntitySystem
component.CancelToken = null;
//solution gone by other means before doafter completes
if (ev.Solution == null || ev.Solution.CurrentVolume == 0)
if (ev.Solution == null || ev.Solution.Volume == 0)
return;
var puddleSolution = _solutionContainerSystem.SplitSolution(uid,
ev.Solution, ev.Solution.DrainAvailable);
ev.Solution, ev.Solution.Volume);
SpillAt(puddleSolution, Transform(component.Owner).Coordinates, "PuddleSmear");
}

View File

@@ -12,6 +12,7 @@ using Content.Shared.Vapor;
using Robust.Shared.Audio;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
namespace Content.Server.Fluids.EntitySystems;
@@ -19,6 +20,7 @@ namespace Content.Server.Fluids.EntitySystems;
public sealed class SpraySystem : EntitySystem
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
@@ -51,7 +53,7 @@ public sealed class SpraySystem : EntitySystem
&& curTime < cooldown.CooldownEnd)
return;
if (solution.CurrentVolume <= 0)
if (solution.Volume <= 0)
{
_popupSystem.PopupEntity(Loc.GetString("spray-component-is-empty-message"), uid,
args.User);
@@ -76,7 +78,7 @@ public sealed class SpraySystem : EntitySystem
var threeQuarters = diffNorm * 0.75f;
var quarter = diffNorm * 0.25f;
var amount = Math.Max(Math.Min((solution.CurrentVolume / component.TransferAmount).Int(), component.VaporAmount), 1);
var amount = Math.Max(Math.Min((solution.Volume / component.TransferAmount).Int(), component.VaporAmount), 1);
var spread = component.VaporSpread / amount;
for (var i = 0; i < amount; i++)
@@ -94,7 +96,7 @@ public sealed class SpraySystem : EntitySystem
var newSolution = _solutionContainerSystem.SplitSolution(uid, solution, component.TransferAmount);
if (newSolution.TotalVolume <= FixedPoint2.Zero)
if (newSolution.Volume <= FixedPoint2.Zero)
break;
// Spawn the vapor cloud onto the grid/map the user is present on. Offset the start position based on how far the target destination is.
@@ -106,7 +108,7 @@ public sealed class SpraySystem : EntitySystem
if (TryComp(vapor, out AppearanceComponent? appearance))
{
appearance.SetData(VaporVisuals.Color, solution.Color.WithAlpha(1f));
appearance.SetData(VaporVisuals.Color, solution.GetColor(_proto).WithAlpha(1f));
appearance.SetData(VaporVisuals.State, true);
}