From bb5cdd2c009531012f629f195d0d9adb74dec36f Mon Sep 17 00:00:00 2001 From: Darkmajia Date: Thu, 5 Sep 2024 18:39:26 +0100 Subject: [PATCH] puddle viscosity again --- .../Fluids/EntitySystems/PuddleSystem.cs | 59 +++++++++---------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/Content.Server/Fluids/EntitySystems/PuddleSystem.cs b/Content.Server/Fluids/EntitySystems/PuddleSystem.cs index 2b29de96eaba89..2bba7473a91260 100644 --- a/Content.Server/Fluids/EntitySystems/PuddleSystem.cs +++ b/Content.Server/Fluids/EntitySystems/PuddleSystem.cs @@ -340,7 +340,7 @@ private void OnSolutionUpdate(Entity entity, ref SolutionContai _deletionQueue.Remove(entity); UpdateSlip(entity, entity.Comp, args.Solution); - UpdateSlow(entity, args.Solution); + UpdateSlow(entity, entity.Comp, args.Solution); UpdateEvaporation(entity, args.Solution); UpdateAppearance(entity, entity.Comp); } @@ -421,41 +421,36 @@ private void UpdateSlip(EntityUid entityUid, PuddleComponent component, Solution } } - private void UpdateSlow(EntityUid uid, Solution solution) + private void UpdateSlow(EntityUid uid, PuddleComponent component, Solution solution) { - /// declare a maximum viscosity variable - var maxViscosity = 0f; - /// declare a minimum viscosity variable - var minViscosity = 0f; - /// declare a total viscosity variable - var totalViscosity = 0f; - - /// for each reagent in the puddle, grab the reagent's information in the reagentProto variable. + var totalViscosity = 0f; + var totalQuantity = 0f; + var fullPuddleAmount = FixedPoint2.New(component.OverflowVolume.Float() * LowThreshold); + foreach (var (reagent, _) in solution.Contents) { + var reagentQuant = solution.GetReagentQuantity(reagent).Float(); var reagentProto = _prototypeManager.Index(reagent.Prototype); - /// set maximum viscosity to whichever is higher (zero on the left, the reagent's viscosity on the right) - maxViscosity = Math.Max(maxViscosity, reagentProto.Viscosity); - /// do the opposite to minimum viscosity. - minViscosity = Math.Min(minViscosity, reagentProto.Viscosity); - } - - /// total viscosity is the average of all viscosities in the solution - totalViscosity = maxViscosity + minViscosity; - - /// if totalviscosity is not zero, ensure that the uid has the speedmodifiercontactcomponent, and then modify its speed by the total viscosity - if (totalViscosity != 0) - { - var comp = EnsureComp(uid); - var speed = 1 - totalViscosity; - _speedModContacts.ChangeModifiers(uid, speed, comp); - } - - /// if totalviscosity *is* zero, remove the speedmodifiercontactcomponent, because it's not doing anything - else - { - RemComp(uid); - } + + totalViscosity += reagentQuant * reagentProto.Viscosity; + totalQuantity += reagentQuant; + } + + totalViscosity /= totalQuantity; + + if (totalQuantity < fullPuddleAmount) + totalViscosity /= 2; + + if (totalViscosity != 0) + { + var comp = EnsureComp(uid); + var speed = 1 - totalViscosity; + _speedModContacts.ChangeModifiers(uid, speed, comp); + } + else + { + RemComp(uid); + } } private void OnAnchorChanged(Entity entity, ref AnchorStateChangedEvent args)