Files
tbd-station-14/Content.Server/Physics/Controllers/PullController.cs
Vera Aguilera Puerto a2b737d945 Atmos pipe rework (#3833)
* Initial

* Cleanup a bunch of things

* some changes dunno

* RequireAnchored

* a

* stuff

* more work

* Lots of progress

* delete pipe visualizer

* a

* b

* pipenet and pipenode cleanup

* Fixes

* Adds GasValve

* Adds GasMiner

* Fix stuff, maybe?

* More fixes

* Ignored components on the client

* Adds thermomachine behavior, change a bunch of stuff

* Remove Anchored

* some work, but it's shitcode

* significantly more ECS

* ECS AtmosDevices

* Cleanup

* fix appearance

* when the pipe direction is sus

* Gas tanks and canisters

* pipe anchoring and stuff

* coding is my passion

* Unsafe pipes take longer to unanchor

* turns out we're no longer using eris canisters

* Gas canister inserted tank appearance, improvements

* Work on a bunch of appearances

* Scrubber appearance

* Reorganize AtmosphereSystem.Piping into a bunch of different systems

* Appearance for vent/scrubber/pump turns off when leaving atmosphere

* ThermoMachine appearance

* Cleanup gas tanks

* Remove passive gate unused imports

* remove old canister UI functionality

* PipeNode environment air, make everything use AssumeAir instead of merging manually

* a

* Reorganize atmos to follow new structure

* ?????

* Canister UI, restructure client

* Restructure shared

* Fix build tho

* listen, at least the canister UI works entirely...

* fix build : )

* Atmos device prototypes have names and descriptions

* gas canister ui slider doesn't jitter

* trinary prototypes

* sprite for miners

* ignore components

* fix YAML

* Fix port system doing useless thing

* Fix build

* fix thinking moment

* fix build again because

* canister direction

* pipenode is a word

* GasTank Air will throw on invalid states

* fix build....

* Unhardcode volume pump thresholds

* Volume pump and filter take time into account

* Rename Join/Leave atmosphere events to AtmosDeviceEnabled/Disabled Event

* Gas tank node volume is set by initial mixtuer

* I love node container
2021-06-19 13:25:05 +02:00

111 lines
5.0 KiB
C#

#nullable enable
using System;
using System.Collections.Generic;
using Content.Shared.Pulling;
using Robust.Shared.GameObjects;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Controllers;
using Robust.Shared.Maths;
using Robust.Shared.Utility;
namespace Content.Server.Physics.Controllers
{
public class PullController : VirtualController
{
// Parameterization for pulling:
// Speeds. Note that the speed is mass-independent (multiplied by mass).
// Instead, tuning to mass is done via the mass values below.
// Note that setting the speed too high results in overshoots (stabilized by drag, but bad)
private const float AccelModifierHigh = 15f;
private const float AccelModifierLow = 60.0f;
// High/low-mass marks. Curve is constant-lerp-constant, i.e. if you can even pull an item,
// you'll always get at least AccelModifierLow and no more than AccelModifierHigh.
private const float AccelModifierHighMass = 70.0f; // roundstart saltern emergency closet
private const float AccelModifierLowMass = 5.0f; // roundstart saltern emergency crowbar
// Used to control settling (turns off pulling).
private const float MaximumSettleVelocity = 0.1f;
private const float MaximumSettleDistance = 0.01f;
// Settle shutdown control.
// Mustn't be too massive, as that causes severe mispredicts *and can prevent it ever resolving*.
// Exists to bleed off "I pulled my crowbar" overshoots.
// Minimum velocity for shutdown to be necessary. This prevents stuff getting stuck b/c too much shutdown.
private const float SettleMinimumShutdownVelocity = 0.25f;
// Distance in which settle shutdown multiplier is at 0. It then scales upwards linearly with closer distances.
private const float SettleShutdownDistance = 1.0f;
// Velocity change of -LinearVelocity * frameTime * this
private const float SettleShutdownMultiplier = 20.0f;
private SharedPullingSystem _pullableSystem = default!;
public override List<Type> UpdatesAfter => new() {typeof(MoverController)};
public override void Initialize()
{
base.Initialize();
_pullableSystem = EntitySystem.Get<SharedPullingSystem>();
}
public override void UpdateBeforeSolve(bool prediction, float frameTime)
{
base.UpdateBeforeSolve(prediction, frameTime);
foreach (var pullable in _pullableSystem.Moving)
{
if (pullable.Deleted)
{
continue;
}
if (pullable.MovingTo == null)
{
continue;
}
DebugTools.AssertNotNull(pullable.Puller);
var pullerPosition = pullable.Puller!.Transform.MapPosition;
if (pullable.MovingTo.Value.MapId != pullerPosition.MapId)
{
pullable.MovingTo = null;
continue;
}
if (!pullable.Owner.TryGetComponent<PhysicsComponent>(out var physics) ||
physics.BodyType == BodyType.Static ||
pullable.MovingTo.Value.MapId != pullable.Owner.Transform.MapID)
{
pullable.MovingTo = null;
continue;
}
var movingPosition = pullable.MovingTo.Value.Position;
var ownerPosition = pullable.Owner.Transform.MapPosition.Position;
if (movingPosition.EqualsApprox(ownerPosition, MaximumSettleDistance) && (physics.LinearVelocity.Length < MaximumSettleVelocity))
{
physics.LinearVelocity = Vector2.Zero;
pullable.MovingTo = null;
continue;
}
var diff = movingPosition - ownerPosition;
var diffLength = diff.Length;
var impulseModifierLerp = Math.Min(1.0f, Math.Max(0.0f, (physics.Mass - AccelModifierLowMass) / (AccelModifierHighMass - AccelModifierLowMass)));
var impulseModifier = MathHelper.Lerp(AccelModifierLow, AccelModifierHigh, impulseModifierLerp);
var multiplier = diffLength < 1 ? impulseModifier * diffLength : impulseModifier;
// Note the implication that the real rules of physics don't apply to pulling control.
var accel = diff.Normalized * multiplier;
// Now for the part where velocity gets shutdown...
if ((diffLength < SettleShutdownDistance) && (physics.LinearVelocity.Length >= SettleMinimumShutdownVelocity))
{
// Shutdown velocity increases as we get closer to centre
var scaling = (SettleShutdownDistance - diffLength) / SettleShutdownDistance;
accel -= physics.LinearVelocity * SettleShutdownMultiplier * scaling;
}
physics.ApplyLinearImpulse(accel * physics.Mass * frameTime);
}
}
}
}