Puddle Code Slipping Cleanup (#35845)
* Init Commit * windows yelling at me to update commit * working commit, need prediciton and more dehardcoding * Project 0 warnings * Working Commit (Near Final) * ryder got confused commit * I love Merge Conflicts :) * Working commit, no prediction * Forgot the yaml changes * Comments and typos * Apparently while the reduced launch mult of lube was initialized it was never used so I revered back to default * Fixed an incorrect divisor * bit of cleanup * Prediciton fixed, and puddles now affect all entities * FORGOT TO RENAME A VERY IMPORTANT VARIABLE OOPS * Really big I forgor moment * Even bigger I forgor moment * four more merge conflicts to fix four more oopsies * fixed actual divide by zero moment and also im very dumb * Even bigger I forgor moment * four more merge conflicts to fix four more oopsies * fixed actual divide by zero moment and also im very dumb * Fix all test fails * code cleanup * Webedit whitespace * Code cleaup * whitespace webedit * whitespace webedit * whitespace webedit * whitespace removal * Comments and cleanup * Re-Added 20 warnings as per Ork's request * Cleanups * Spacing fix * bugfixes and cleanup * Small bugfix * Actually dirty the slipComp for real * Added Friction field to Reagent Prototype per design discussion * Sliding system is kill
This commit is contained in:
committed by
GitHub
parent
c2857c5247
commit
251cfbd8be
@@ -71,8 +71,6 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
|
||||
private static string[] _standoutReagents = [Blood, Slime, CopperBlood];
|
||||
|
||||
public static readonly 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.
|
||||
private HashSet<EntityUid> _deletionQueue = [];
|
||||
@@ -94,7 +92,6 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
// Shouldn't need re-anchoring.
|
||||
SubscribeLocalEvent<PuddleComponent, AnchorStateChangedEvent>(OnAnchorChanged);
|
||||
SubscribeLocalEvent<PuddleComponent, SolutionContainerChangedEvent>(OnSolutionUpdate);
|
||||
SubscribeLocalEvent<PuddleComponent, ComponentInit>(OnPuddleInit);
|
||||
SubscribeLocalEvent<PuddleComponent, SpreadNeighborsEvent>(OnPuddleSpread);
|
||||
SubscribeLocalEvent<PuddleComponent, SlipEvent>(OnPuddleSlip);
|
||||
|
||||
@@ -327,11 +324,6 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
TickEvaporation();
|
||||
}
|
||||
|
||||
private void OnPuddleInit(Entity<PuddleComponent> entity, ref ComponentInit args)
|
||||
{
|
||||
_solutionContainerSystem.EnsureSolution(entity.Owner, entity.Comp.SolutionName, out _, FixedPoint2.New(PuddleVolume));
|
||||
}
|
||||
|
||||
private void OnSolutionUpdate(Entity<PuddleComponent> entity, ref SolutionContainerChangedEvent args)
|
||||
{
|
||||
if (args.SolutionId != entity.Comp.SolutionName)
|
||||
@@ -344,7 +336,7 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
}
|
||||
|
||||
_deletionQueue.Remove(entity);
|
||||
UpdateSlip(entity, entity.Comp, args.Solution);
|
||||
UpdateSlip((entity, entity.Comp), args.Solution);
|
||||
UpdateSlow(entity, args.Solution);
|
||||
UpdateEvaporation(entity, args.Solution);
|
||||
UpdateAppearance(entity, entity.Comp);
|
||||
@@ -389,62 +381,89 @@ public sealed partial class PuddleSystem : SharedPuddleSystem
|
||||
_appearance.SetData(uid, PuddleVisuals.SolutionColor, color, appearance);
|
||||
}
|
||||
|
||||
private void UpdateSlip(EntityUid entityUid, PuddleComponent component, Solution solution)
|
||||
private void UpdateSlip(Entity<PuddleComponent> entity, Solution solution)
|
||||
{
|
||||
var isSlippery = false;
|
||||
var isSuperSlippery = false;
|
||||
// The base sprite is currently at 0.3 so we require at least 2nd tier to be slippery or else it's too hard to see.
|
||||
var amountRequired = FixedPoint2.New(component.OverflowVolume.Float() * LowThreshold);
|
||||
var slipperyAmount = FixedPoint2.Zero;
|
||||
if (!TryComp<StepTriggerComponent>(entity, out var comp))
|
||||
return;
|
||||
|
||||
// Utilize the defaults from their relevant systems... this sucks, and is a bandaid
|
||||
var launchForwardsMultiplier = SlipperyComponent.DefaultLaunchForwardsMultiplier;
|
||||
var paralyzeTime = SlipperyComponent.DefaultParalyzeTime;
|
||||
var requiredSlipSpeed = StepTriggerComponent.DefaultRequiredTriggeredSpeed;
|
||||
// This is the base amount of reagent needed before a puddle can be considered slippery. Is defined based on
|
||||
// the sprite threshold for a puddle larger than 5 pixels.
|
||||
var smallPuddleThreshold = FixedPoint2.New(entity.Comp.OverflowVolume.Float() * LowThreshold);
|
||||
|
||||
// Stores how many units of slippery reagents a puddle has
|
||||
var slipperyUnits = FixedPoint2.Zero;
|
||||
// Stores how many units of super slippery reagents a puddle has
|
||||
var superSlipperyUnits = FixedPoint2.Zero;
|
||||
|
||||
// These three values will be averaged later and all start at zero so the calculations work
|
||||
// A cumulative weighted amount of minimum speed to slip values
|
||||
var puddleFriction = FixedPoint2.Zero;
|
||||
// A cumulative weighted amount of minimum speed to slip values
|
||||
var slipStepTrigger = FixedPoint2.Zero;
|
||||
// A cumulative weighted amount of launch multipliers from slippery reagents
|
||||
var launchMult = FixedPoint2.Zero;
|
||||
// A cumulative weighted amount of stun times from slippery reagents
|
||||
var stunTimer = TimeSpan.Zero;
|
||||
|
||||
// Check if the puddle is big enough to slip in to avoid doing unnecessary logic
|
||||
if (solution.Volume <= smallPuddleThreshold)
|
||||
{
|
||||
_stepTrigger.SetActive(entity, false, comp);
|
||||
_tile.SetModifier(entity, TileFrictionController.DefaultFriction);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TryComp<SlipperyComponent>(entity, out var slipComp))
|
||||
return;
|
||||
|
||||
foreach (var (reagent, quantity) in solution.Contents)
|
||||
{
|
||||
var reagentProto = _prototypeManager.Index<ReagentPrototype>(reagent.Prototype);
|
||||
|
||||
if (!reagentProto.Slippery)
|
||||
// Calculate the minimum speed needed to slip in the puddle. Average the overall slip thresholds for all reagents
|
||||
var deltaSlipTrigger = reagentProto.SlipData?.RequiredSlipSpeed ?? entity.Comp.DefaultSlippery;
|
||||
slipStepTrigger += quantity * deltaSlipTrigger;
|
||||
|
||||
// Aggregate Friction based on quantity
|
||||
puddleFriction += reagentProto.Friction * quantity;
|
||||
|
||||
if (reagentProto.SlipData == null)
|
||||
continue;
|
||||
slipperyAmount += quantity;
|
||||
|
||||
if (slipperyAmount <= amountRequired)
|
||||
continue;
|
||||
isSlippery = true;
|
||||
slipperyUnits += quantity;
|
||||
// Aggregate launch speed based on quantity
|
||||
launchMult += reagentProto.SlipData.LaunchForwardsMultiplier * quantity;
|
||||
// Aggregate stun times based on quantity
|
||||
stunTimer += reagentProto.SlipData.ParalyzeTime * (float)quantity;
|
||||
|
||||
foreach (var tileReaction in reagentProto.TileReactions)
|
||||
{
|
||||
if (tileReaction is not SpillTileReaction spillTileReaction)
|
||||
continue;
|
||||
isSuperSlippery = spillTileReaction.SuperSlippery;
|
||||
launchForwardsMultiplier = launchForwardsMultiplier < spillTileReaction.LaunchForwardsMultiplier ? spillTileReaction.LaunchForwardsMultiplier : launchForwardsMultiplier;
|
||||
requiredSlipSpeed = requiredSlipSpeed > spillTileReaction.RequiredSlipSpeed ? spillTileReaction.RequiredSlipSpeed : requiredSlipSpeed;
|
||||
paralyzeTime = paralyzeTime < spillTileReaction.ParalyzeTime ? spillTileReaction.ParalyzeTime : paralyzeTime;
|
||||
}
|
||||
if (reagentProto.SlipData.SuperSlippery)
|
||||
superSlipperyUnits += quantity;
|
||||
}
|
||||
|
||||
if (isSlippery)
|
||||
// Turn on the step trigger if it's slippery
|
||||
_stepTrigger.SetActive(entity, slipperyUnits > smallPuddleThreshold, comp);
|
||||
|
||||
// This is based of the total volume and not just the slippery volume because there is a default
|
||||
// slippery for all reagents even if they aren't technically slippery.
|
||||
slipComp.SlipData.RequiredSlipSpeed = (float)(slipStepTrigger / solution.Volume);
|
||||
_stepTrigger.SetRequiredTriggerSpeed(entity, slipComp.SlipData.RequiredSlipSpeed);
|
||||
|
||||
// Divide these both by only total amount of slippery reagents.
|
||||
// A puddle with 10 units of lube vs a puddle with 10 of lube and 20 catchup should stun and launch forward the same amount.
|
||||
if (slipperyUnits > 0)
|
||||
{
|
||||
var comp = EnsureComp<StepTriggerComponent>(entityUid);
|
||||
_stepTrigger.SetActive(entityUid, true, comp);
|
||||
var friction = EnsureComp<TileFrictionModifierComponent>(entityUid);
|
||||
_tile.SetModifier(entityUid, TileFrictionController.DefaultFriction * 0.5f, friction);
|
||||
|
||||
if (!TryComp<SlipperyComponent>(entityUid, out var slipperyComponent))
|
||||
return;
|
||||
slipperyComponent.SuperSlippery = isSuperSlippery;
|
||||
_stepTrigger.SetRequiredTriggerSpeed(entityUid, requiredSlipSpeed);
|
||||
slipperyComponent.LaunchForwardsMultiplier = launchForwardsMultiplier;
|
||||
slipperyComponent.ParalyzeTime = paralyzeTime;
|
||||
|
||||
}
|
||||
else if (TryComp<StepTriggerComponent>(entityUid, out var comp))
|
||||
{
|
||||
_stepTrigger.SetActive(entityUid, false, comp);
|
||||
RemCompDeferred<TileFrictionModifierComponent>(entityUid);
|
||||
slipComp.SlipData.LaunchForwardsMultiplier = (float)(launchMult/slipperyUnits);
|
||||
slipComp.SlipData.ParalyzeTime = (stunTimer/(float)slipperyUnits);
|
||||
}
|
||||
|
||||
// Only make it super slippery if there is enough super slippery units for its own puddle
|
||||
slipComp.SlipData.SuperSlippery = superSlipperyUnits >= smallPuddleThreshold;
|
||||
|
||||
// Lower tile friction based on how slippery it is, lets items slide across a puddle of lube
|
||||
slipComp.SlipData.SlipFriction = (float)(puddleFriction/solution.Volume);
|
||||
_tile.SetModifier(entity, TileFrictionController.DefaultFriction * slipComp.SlipData.SlipFriction);
|
||||
|
||||
Dirty(entity, slipComp);
|
||||
}
|
||||
|
||||
private void UpdateSlow(EntityUid uid, Solution solution)
|
||||
|
||||
Reference in New Issue
Block a user