Tweak shuttle movement (#6468)

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
Radrark
2022-03-07 02:03:53 -03:00
committed by GitHub
parent 19136505d9
commit 401ccfba0a
7 changed files with 126 additions and 44 deletions

View File

@@ -10,10 +10,10 @@ namespace Content.Server.Shuttles.Components
public sealed class ShuttleComponent : SharedShuttleComponent
{
/// <summary>
/// The cached impulse available for each cardinal direction
/// The cached thrust available for each cardinal direction
/// </summary>
[ViewVariables]
public readonly float[] LinearThrusterImpulse = new float[4];
public readonly float[] LinearThrust = new float[4];
/// <summary>
/// The thrusters contributing to each direction for impulse.

View File

@@ -47,9 +47,9 @@ namespace Content.Server.Shuttles.Components
/// </summary>
public bool IsOn;
[ViewVariables]
[DataField("impulse")]
public float Impulse = 450f;
[ViewVariables(VVAccess.ReadWrite)]
[DataField("thrust")]
public float Thrust = 750f;
[ViewVariables]
[DataField("thrusterType")]
@@ -68,6 +68,9 @@ namespace Content.Server.Shuttles.Components
/// </summary>
[ViewVariables] [DataField("damage")] public DamageSpecifier? Damage = new();
[ViewVariables] [DataField("requireSpace")]
public bool RequireSpace = true;
// Used for burns
public List<EntityUid> Colliding = new();

View File

@@ -1,6 +1,8 @@
using System.Collections.Generic;
using Content.Server.Shuttles.Components;
using Content.Shared.CCVar;
using JetBrains.Annotations;
using Robust.Shared.Configuration;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Physics;
@@ -12,11 +14,14 @@ namespace Content.Server.Shuttles.EntitySystems
{
private const float TileMassMultiplier = 4f;
public float ShuttleIdleLinearDamping = 0.1f;
public float ShuttleIdleAngularDamping = 0.2f;
public float ShuttleMaxLinearSpeed;
public float ShuttleMovingLinearDamping = 0.05f;
public float ShuttleMovingAngularDamping = 0.05f;
public float ShuttleMaxAngularMomentum;
public float ShuttleMaxAngularAcc;
public float ShuttleMaxAngularSpeed;
public float ShuttleIdleLinearDamping;
public float ShuttleIdleAngularDamping;
public override void Initialize()
{
@@ -27,6 +32,32 @@ namespace Content.Server.Shuttles.EntitySystems
SubscribeLocalEvent<GridInitializeEvent>(OnGridInit);
SubscribeLocalEvent<GridFixtureChangeEvent>(OnGridFixtureChange);
var configManager = IoCManager.Resolve<IConfigurationManager>();
configManager.OnValueChanged(CCVars.ShuttleMaxLinearSpeed, SetShuttleMaxLinearSpeed, true);
configManager.OnValueChanged(CCVars.ShuttleMaxAngularSpeed, SetShuttleMaxAngularSpeed, true);
configManager.OnValueChanged(CCVars.ShuttleIdleLinearDamping, SetShuttleIdleLinearDamping, true);
configManager.OnValueChanged(CCVars.ShuttleIdleAngularDamping, SetShuttleIdleAngularDamping, true);
configManager.OnValueChanged(CCVars.ShuttleMaxAngularAcc, SetShuttleMaxAngularAcc, true);
configManager.OnValueChanged(CCVars.ShuttleMaxAngularMomentum, SetShuttleMaxAngularMomentum, true);
}
private void SetShuttleMaxLinearSpeed(float value) => ShuttleMaxLinearSpeed = value;
private void SetShuttleMaxAngularSpeed(float value) => ShuttleMaxAngularSpeed = value;
private void SetShuttleMaxAngularAcc(float value) => ShuttleMaxAngularAcc = value;
private void SetShuttleMaxAngularMomentum(float value) => ShuttleMaxAngularMomentum = value;
private void SetShuttleIdleLinearDamping(float value) => ShuttleIdleLinearDamping = value;
private void SetShuttleIdleAngularDamping(float value) => ShuttleIdleAngularDamping = value;
public override void Shutdown()
{
base.Shutdown();
var configManager = IoCManager.Resolve<IConfigurationManager>();
configManager.UnsubValueChanged(CCVars.ShuttleMaxLinearSpeed, SetShuttleMaxLinearSpeed);
configManager.UnsubValueChanged(CCVars.ShuttleMaxAngularSpeed, SetShuttleMaxAngularSpeed);
configManager.UnsubValueChanged(CCVars.ShuttleIdleLinearDamping, SetShuttleIdleLinearDamping);
configManager.UnsubValueChanged(CCVars.ShuttleIdleAngularDamping, SetShuttleIdleAngularDamping);
configManager.UnsubValueChanged(CCVars.ShuttleMaxAngularMomentum, SetShuttleMaxAngularMomentum);
}
private void OnShuttleAdd(EntityUid uid, ShuttleComponent component, ComponentAdd args)

View File

@@ -118,7 +118,7 @@ namespace Content.Server.Shuttles.EntitySystems
foreach (var ent in _mapManager.GetGrid(e.NewTile.GridIndex).GetAnchoredEntities(checkPos))
{
if (!EntityManager.TryGetComponent(ent, out ThrusterComponent? thruster) || thruster.Type == ThrusterType.Angular) continue;
if (!EntityManager.TryGetComponent(ent, out ThrusterComponent? thruster) || !thruster.RequireSpace) continue;
// Work out if the thruster is facing this direction
var direction = EntityManager.GetComponent<TransformComponent>(ent).LocalRotation.ToWorldVec();
@@ -174,11 +174,11 @@ namespace Content.Server.Shuttles.EntitySystems
var oldDirection = (int) args.OldRotation.GetCardinalDir() / 2;
var direction = (int) args.NewRotation.GetCardinalDir() / 2;
shuttleComponent.LinearThrusterImpulse[oldDirection] -= component.Impulse;
shuttleComponent.LinearThrust[oldDirection] -= component.Thrust;
DebugTools.Assert(shuttleComponent.LinearThrusters[oldDirection].Contains(component));
shuttleComponent.LinearThrusters[oldDirection].Remove(component);
shuttleComponent.LinearThrusterImpulse[direction] += component.Impulse;
shuttleComponent.LinearThrust[direction] += component.Thrust;
DebugTools.Assert(!shuttleComponent.LinearThrusters[direction].Contains(component));
shuttleComponent.LinearThrusters[direction].Add(component);
}
@@ -247,7 +247,7 @@ namespace Content.Server.Shuttles.EntitySystems
case ThrusterType.Linear:
var direction = (int) xform.LocalRotation.GetCardinalDir() / 2;
shuttleComponent.LinearThrusterImpulse[direction] += component.Impulse;
shuttleComponent.LinearThrust[direction] += component.Thrust;
DebugTools.Assert(!shuttleComponent.LinearThrusters[direction].Contains(component));
shuttleComponent.LinearThrusters[direction].Add(component);
@@ -271,7 +271,7 @@ namespace Content.Server.Shuttles.EntitySystems
break;
case ThrusterType.Angular:
shuttleComponent.AngularThrust += component.Impulse;
shuttleComponent.AngularThrust += component.Thrust;
DebugTools.Assert(!shuttleComponent.AngularThrusters.Contains(component));
shuttleComponent.AngularThrusters.Add(component);
break;
@@ -313,12 +313,12 @@ namespace Content.Server.Shuttles.EntitySystems
angle ??= xform.LocalRotation;
var direction = (int) angle.Value.GetCardinalDir() / 2;
shuttleComponent.LinearThrusterImpulse[direction] -= component.Impulse;
shuttleComponent.LinearThrust[direction] -= component.Thrust;
DebugTools.Assert(shuttleComponent.LinearThrusters[direction].Contains(component));
shuttleComponent.LinearThrusters[direction].Remove(component);
break;
case ThrusterType.Angular:
shuttleComponent.AngularThrust -= component.Impulse;
shuttleComponent.AngularThrust -= component.Thrust;
DebugTools.Assert(shuttleComponent.AngularThrusters.Contains(component));
shuttleComponent.AngularThrusters.Remove(component);
break;
@@ -359,7 +359,7 @@ namespace Content.Server.Shuttles.EntitySystems
return false;
}
if (component.Type == ThrusterType.Angular)
if (!component.RequireSpace)
return true;
return NozzleExposed(xform);