Thrusters (shuttle go nyoom) (#5352)

This commit is contained in:
metalgearsloth
2021-11-21 17:09:49 +11:00
committed by GitHub
parent c21a9e32b1
commit bdead40a80
37 changed files with 1100 additions and 140 deletions

View File

@@ -0,0 +1,21 @@
using Content.Shared.Shuttles;
using Content.Shared.Shuttles.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Physics.Dynamics.Joints;
using Robust.Shared.ViewVariables;
namespace Content.Server.Shuttles.Components
{
[RegisterComponent]
public sealed class DockingComponent : SharedDockingComponent
{
[ViewVariables]
public DockingComponent? DockedWith;
[ViewVariables]
public Joint? DockJoint;
[ViewVariables]
public override bool Docked => DockedWith != null;
}
}

View File

@@ -0,0 +1,37 @@
using System.Collections.Generic;
using Content.Shared.Shuttles.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
using Robust.Shared.ViewVariables;
namespace Content.Server.Shuttles.Components
{
[RegisterComponent]
public sealed class ShuttleComponent : SharedShuttleComponent
{
/// <summary>
/// The cached impulse available for each cardinal direction
/// </summary>
[ViewVariables]
public readonly float[] LinearThrusterImpulse = new float[4];
/// <summary>
/// The thrusters contributing to each direction for impulse.
/// </summary>
public readonly List<ThrusterComponent>[] LinearThrusters = new List<ThrusterComponent>[4];
/// <summary>
/// The thrusters contributing to the angular impulse of the shuttle.
/// </summary>
public readonly List<ThrusterComponent> AngularThrusters = new List<ThrusterComponent>();
[ViewVariables]
public float AngularThrust = 0f;
/// <summary>
/// A bitmask of all the directions we are considered thrusting.
/// </summary>
[ViewVariables]
public DirectionFlag ThrustDirections = DirectionFlag.None;
}
}

View File

@@ -1,9 +1,10 @@
using System.Collections.Generic;
using Content.Shared.Shuttles;
using Content.Shared.Shuttles.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.ViewVariables;
namespace Content.Server.Shuttles
namespace Content.Server.Shuttles.Components
{
[RegisterComponent]
[ComponentReference(typeof(SharedShuttleConsoleComponent))]

View File

@@ -0,0 +1,86 @@
using System.Collections.Generic;
using Content.Server.Shuttles.EntitySystems;
using Content.Shared.Damage;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Server.Shuttles.Components
{
[RegisterComponent]
[Friend(typeof(ThrusterSystem))]
public sealed class ThrusterComponent : Component
{
public override string Name => "Thruster";
/// <summary>
/// Whether the thruster has been force to be enabled / disable (e.g. VV, interaction, etc.)
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("enabled")]
public bool Enabled
{
get => _enabled;
set
{
if (_enabled == value) return;
_enabled = value;
var system = EntitySystem.Get<ThrusterSystem>();
if (!_enabled)
{
system.DisableThruster(OwnerUid, this);
}
else if (system.CanEnable(OwnerUid, this))
{
system.EnableThruster(OwnerUid, this);
}
}
}
private bool _enabled = true;
/// <summary>
/// This determines whether the thruster is actually enabled for the purposes of thrust
/// </summary>
public bool IsOn;
[ViewVariables]
[DataField("impulse")]
public float Impulse = 5f;
[ViewVariables]
[DataField("thrusterType")]
public ThrusterType Type = ThrusterType.Linear;
[DataField("burnShape")] public List<Vector2> BurnPoly = new()
{
new Vector2(-0.4f, 0.5f),
new Vector2(-0.1f, 1.2f),
new Vector2(0.1f, 1.2f),
new Vector2(0.4f, 0.5f)
};
/// <summary>
/// How much damage is done per second to anything colliding with our thrust.
/// </summary>
[ViewVariables] [DataField("damage")] public DamageSpecifier? Damage = new();
// Used for burns
public List<EntityUid> Colliding = new();
public bool Firing = false;
}
public enum ThrusterType
{
Linear,
// Angular meaning rotational.
Angular,
}
}

View File

@@ -1,8 +1,7 @@
using System;
using Content.Server.Doors.Components;
using Content.Server.Power.Components;
using Content.Server.Shuttles.Components;
using Content.Shared.Doors;
using Content.Shared.Shuttles;
using Content.Shared.Verbs;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -13,25 +12,10 @@ using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Physics.Dynamics.Joints;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
namespace Content.Server.Shuttles
namespace Content.Server.Shuttles.EntitySystems
{
[RegisterComponent]
public sealed class DockingComponent : SharedDockingComponent
{
[ViewVariables]
public DockingComponent? DockedWith;
[ViewVariables]
public Joint? DockJoint;
[ViewVariables]
public override bool Docked => DockedWith != null;
}
public sealed class DockingSystem : EntitySystem
{
[Dependency] private readonly IMapManager _mapManager = default!;

View File

@@ -1,20 +1,19 @@
using System.Linq;
using Content.Server.Alert;
using Content.Server.Power.Components;
using Content.Server.Shuttles.Components;
using Content.Shared.ActionBlocker;
using Content.Shared.Alert;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Shared.Shuttles;
using Content.Shared.Shuttles.Components;
using Content.Shared.Tag;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Physics;
using Robust.Shared.Utility;
namespace Content.Server.Shuttles
namespace Content.Server.Shuttles.EntitySystems
{
internal sealed class ShuttleConsoleSystem : SharedShuttleConsoleSystem
{

View File

@@ -1,86 +1,54 @@
using System;
using Content.Shared.Shuttles;
using System.Collections.Generic;
using Content.Server.Shuttles.Components;
using JetBrains.Annotations;
using Robust.Server.Physics;
using Robust.Shared.Configuration;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Physics;
namespace Content.Server.Shuttles
namespace Content.Server.Shuttles.EntitySystems
{
[UsedImplicitly]
internal sealed class ShuttleSystem : EntitySystem
{
private const float TileMassMultiplier = 1f;
private const float TileMassMultiplier = 4f;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ShuttleComponent, ComponentStartup>(HandleShuttleStartup);
SubscribeLocalEvent<ShuttleComponent, ComponentShutdown>(HandleShuttleShutdown);
SubscribeLocalEvent<ShuttleComponent, ComponentAdd>(OnShuttleAdd);
SubscribeLocalEvent<ShuttleComponent, ComponentStartup>(OnShuttleStartup);
SubscribeLocalEvent<ShuttleComponent, ComponentShutdown>(OnShuttleShutdown);
SubscribeLocalEvent<GridInitializeEvent>(HandleGridInit);
SubscribeLocalEvent<GridFixtureChangeEvent>(HandleGridFixtureChange);
SubscribeLocalEvent<GridInitializeEvent>(OnGridInit);
SubscribeLocalEvent<GridFixtureChangeEvent>(OnGridFixtureChange);
}
private void HandleGridFixtureChange(GridFixtureChangeEvent args)
private void OnShuttleAdd(EntityUid uid, ShuttleComponent component, ComponentAdd args)
{
// Easier than doing it in the comp and they don't have constructors.
for (var i = 0; i < component.LinearThrusters.Length; i++)
{
component.LinearThrusters[i] = new List<ThrusterComponent>();
}
}
private void OnGridFixtureChange(GridFixtureChangeEvent args)
{
// Look this is jank but it's a placeholder until we design it.
if (args.NewFixtures.Count == 0) return;
var body = args.NewFixtures[0].Body;
foreach (var fixture in args.NewFixtures)
{
fixture.Mass = fixture.Area * TileMassMultiplier;
fixture.Restitution = 0.1f;
}
if (body.Owner.TryGetComponent(out ShuttleComponent? shuttleComponent))
{
RecalculateSpeedMultiplier(shuttleComponent, body);
}
}
private void HandleGridInit(GridInitializeEvent ev)
private void OnGridInit(GridInitializeEvent ev)
{
EntityManager.GetEntity(ev.EntityUid).EnsureComponent<ShuttleComponent>();
}
/// <summary>
/// Cache the thrust available to this shuttle.
/// </summary>
private void RecalculateSpeedMultiplier(SharedShuttleComponent shuttle, PhysicsComponent physics)
{
// TODO: Need per direction speed (Never Eat Soggy Weetbix).
// TODO: This will need hella tweaking.
var thrusters = physics.FixtureCount;
if (thrusters == 0)
{
shuttle.SpeedMultipler = 0f;
}
const float ThrustPerThruster = 0.25f;
const float MinimumThrustRequired = 0.005f;
// Just so someone can't slap a single thruster on a station and call it a day; need to hit a minimum amount.
var thrustRatio = Math.Max(0, thrusters * ThrustPerThruster / physics.Mass);
if (thrustRatio < MinimumThrustRequired)
shuttle.SpeedMultipler = 0f;
const float MaxThrust = 10f;
// This doesn't need to align with MinimumThrustRequired; if you set this higher it just means the first few additional
// thrusters won't do anything.
const float MinThrust = MinimumThrustRequired;
shuttle.SpeedMultipler = MathF.Max(MinThrust, MathF.Min(MaxThrust, thrustRatio));
}
private void HandleShuttleStartup(EntityUid uid, ShuttleComponent component, ComponentStartup args)
private void OnShuttleStartup(EntityUid uid, ShuttleComponent component, ComponentStartup args)
{
if (!component.Owner.HasComponent<IMapGridComponent>())
{
@@ -96,11 +64,6 @@ namespace Content.Server.Shuttles
{
Enable(physicsComponent);
}
if (component.Owner.TryGetComponent(out ShuttleComponent? shuttleComponent))
{
RecalculateSpeedMultiplier(shuttleComponent, physicsComponent);
}
}
public void Toggle(ShuttleComponent component)
@@ -136,7 +99,7 @@ namespace Content.Server.Shuttles
component.FixedRotation = true;
}
private void HandleShuttleShutdown(EntityUid uid, ShuttleComponent component, ComponentShutdown args)
private void OnShuttleShutdown(EntityUid uid, ShuttleComponent component, ComponentShutdown args)
{
if (!component.Owner.TryGetComponent(out PhysicsComponent? physicsComponent))
{

View File

@@ -0,0 +1,476 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using Content.Server.Atmos.Components;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Audio;
using Content.Server.Power.Components;
using Content.Server.Shuttles.Components;
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
using Content.Shared.FixedPoint;
using Content.Shared.Interaction;
using Content.Shared.Maps;
using Content.Shared.Physics;
using Content.Shared.Shuttles.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Server.Shuttles.EntitySystems
{
public sealed class ThrusterSystem : EntitySystem
{
[Robust.Shared.IoC.Dependency] private readonly IMapManager _mapManager = default!;
[Robust.Shared.IoC.Dependency] private readonly AmbientSoundSystem _ambient = default!;
[Robust.Shared.IoC.Dependency] private readonly SharedBroadphaseSystem _broadphase = default!;
[Robust.Shared.IoC.Dependency] private readonly DamageableSystem _damageable = default!;
// Essentially whenever thruster enables we update the shuttle's available impulses which are used for movement.
// This is done for each direction available.
public const string BurnFixture = "thruster-burn";
private readonly HashSet<ThrusterComponent> _activeThrusters = new();
// Used for accumulating burn if someone touches a firing thruster.
private float _accumulator;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ThrusterComponent, ActivateInWorldEvent>(OnActivateThruster);
SubscribeLocalEvent<ThrusterComponent, ComponentInit>(OnThrusterInit);
SubscribeLocalEvent<ThrusterComponent, ComponentShutdown>(OnThrusterShutdown);
SubscribeLocalEvent<ThrusterComponent, PowerChangedEvent>(OnPowerChange);
SubscribeLocalEvent<ThrusterComponent, AnchorStateChangedEvent>(OnAnchorChange);
SubscribeLocalEvent<ThrusterComponent, RotateEvent>(OnRotate);
SubscribeLocalEvent<ThrusterComponent, StartCollideEvent>(OnStartCollide);
SubscribeLocalEvent<ThrusterComponent, EndCollideEvent>(OnEndCollide);
_mapManager.TileChanged += OnTileChange;
}
public override void Shutdown()
{
base.Shutdown();
_mapManager.TileChanged -= OnTileChange;
}
private void OnTileChange(object? sender, TileChangedEventArgs e)
{
// If the old tile was space but the new one isn't then disable all adjacent thrusters
if (e.NewTile.IsSpace() || !e.OldTile.IsSpace()) return;
var tilePos = e.NewTile.GridIndices;
for (var x = -1; x <= 1; x++)
{
for (var y = -1; y <= 1; y++)
{
if (x != 0 && y != 0) continue;
var checkPos = tilePos + new Vector2i(x, y);
foreach (var ent in _mapManager.GetGrid(e.NewTile.GridIndex).GetAnchoredEntities(checkPos))
{
if (!EntityManager.TryGetComponent(ent, out ThrusterComponent? thruster) || thruster.Type == ThrusterType.Angular) continue;
// Work out if the thruster is facing this direction
var direction = EntityManager.GetComponent<TransformComponent>(ent).LocalRotation.ToWorldVec();
if (new Vector2i((int) direction.X, (int) direction.Y) != new Vector2i(x, y)) continue;
DisableThruster(ent, thruster);
}
}
}
}
private void OnActivateThruster(EntityUid uid, ThrusterComponent component, ActivateInWorldEvent args)
{
component.Enabled ^= true;
}
/// <summary>
/// If the thruster rotates change the direction where the linear thrust is applied
/// </summary>
private void OnRotate(EntityUid uid, ThrusterComponent component, ref RotateEvent args)
{
// TODO: Disable visualizer for old direction
if (!component.IsOn ||
component.Type != ThrusterType.Linear ||
!EntityManager.TryGetComponent(uid, out TransformComponent? xform) ||
!_mapManager.TryGetGrid(xform.GridID, out var grid) ||
!EntityManager.TryGetComponent(grid.GridEntityId, out ShuttleComponent? shuttleComponent)) return;
var oldDirection = (int) args.OldRotation.GetCardinalDir() / 2;
var direction = (int) args.NewRotation.GetCardinalDir() / 2;
shuttleComponent.LinearThrusterImpulse[oldDirection] -= component.Impulse;
DebugTools.Assert(shuttleComponent.LinearThrusters[oldDirection].Contains(component));
shuttleComponent.LinearThrusters[oldDirection].Remove(component);
shuttleComponent.LinearThrusterImpulse[direction] += component.Impulse;
DebugTools.Assert(!shuttleComponent.LinearThrusters[direction].Contains(component));
shuttleComponent.LinearThrusters[direction].Add(component);
}
private void OnAnchorChange(EntityUid uid, ThrusterComponent component, ref AnchorStateChangedEvent args)
{
if (args.Anchored && CanEnable(uid, component))
{
EnableThruster(uid, component);
}
else
{
DisableThruster(uid, component);
}
}
private void OnThrusterInit(EntityUid uid, ThrusterComponent component, ComponentInit args)
{
_ambient.SetAmbience(uid, false);
if (!component.Enabled)
{
return;
}
if (CanEnable(uid, component))
{
EnableThruster(uid, component);
}
}
private void OnThrusterShutdown(EntityUid uid, ThrusterComponent component, ComponentShutdown args)
{
DisableThruster(uid, component);
}
private void OnPowerChange(EntityUid uid, ThrusterComponent component, PowerChangedEvent args)
{
if (args.Powered && CanEnable(uid, component))
{
EnableThruster(uid, component);
}
else
{
DisableThruster(uid, component);
}
}
/// <summary>
/// Tries to enable the thruster and turn it on. If it's already enabled it does nothing.
/// </summary>
public void EnableThruster(EntityUid uid, ThrusterComponent component, TransformComponent? xform = null)
{
if (component.IsOn ||
!Resolve(uid, ref xform) ||
!_mapManager.TryGetGrid(xform.GridID, out var grid)) return;
component.IsOn = true;
if (!EntityManager.TryGetComponent(grid.GridEntityId, out ShuttleComponent? shuttleComponent)) return;
Logger.DebugS("thruster", $"Enabled thruster {uid}");
switch (component.Type)
{
case ThrusterType.Linear:
var direction = (int) xform.LocalRotation.GetCardinalDir() / 2;
shuttleComponent.LinearThrusterImpulse[direction] += component.Impulse;
DebugTools.Assert(!shuttleComponent.LinearThrusters[direction].Contains(component));
shuttleComponent.LinearThrusters[direction].Add(component);
// Don't just add / remove the fixture whenever the thruster fires because perf
if (EntityManager.TryGetComponent(uid, out PhysicsComponent? physicsComponent) &&
component.BurnPoly.Count > 0)
{
var shape = new PolygonShape();
shape.SetVertices(component.BurnPoly);
var fixture = new Fixture(physicsComponent, shape)
{
ID = BurnFixture,
Hard = false,
CollisionLayer = (int) CollisionGroup.MobImpassable
};
_broadphase.CreateFixture(physicsComponent, fixture);
}
break;
case ThrusterType.Angular:
shuttleComponent.AngularThrust += component.Impulse;
DebugTools.Assert(!shuttleComponent.AngularThrusters.Contains(component));
shuttleComponent.AngularThrusters.Add(component);
break;
default:
throw new ArgumentOutOfRangeException();
}
if (EntityManager.TryGetComponent(uid, out SharedAppearanceComponent? appearanceComponent))
{
appearanceComponent.SetData(ThrusterVisualState.State, true);
}
_ambient.SetAmbience(uid, true);
}
/// <summary>
/// Tries to disable the thruster.
/// </summary>
/// <param name="uid"></param>
/// <param name="component"></param>
/// <param name="xform"></param>
/// <exception cref="ArgumentOutOfRangeException"></exception>
public void DisableThruster(EntityUid uid, ThrusterComponent component, TransformComponent? xform = null)
{
if (!component.IsOn ||
!Resolve(uid, ref xform) ||
!_mapManager.TryGetGrid(xform.GridID, out var grid)) return;
component.IsOn = false;
if (!EntityManager.TryGetComponent(grid.GridEntityId, out ShuttleComponent? shuttleComponent)) return;
Logger.DebugS("thruster", $"Disabled thruster {uid}");
switch (component.Type)
{
case ThrusterType.Linear:
var direction = ((int) xform.LocalRotation.GetCardinalDir() / 2);
shuttleComponent.LinearThrusterImpulse[direction] -= component.Impulse;
DebugTools.Assert(shuttleComponent.LinearThrusters[direction].Contains(component));
shuttleComponent.LinearThrusters[direction].Remove(component);
break;
case ThrusterType.Angular:
shuttleComponent.AngularThrust -= component.Impulse;
DebugTools.Assert(shuttleComponent.AngularThrusters.Contains(component));
shuttleComponent.AngularThrusters.Remove(component);
break;
default:
throw new ArgumentOutOfRangeException();
}
if (EntityManager.TryGetComponent(uid, out SharedAppearanceComponent? appearanceComponent))
{
appearanceComponent.SetData(ThrusterVisualState.State, false);
}
_ambient.SetAmbience(uid, false);
if (EntityManager.TryGetComponent(uid, out PhysicsComponent? physicsComponent))
{
_broadphase.DestroyFixture(physicsComponent, BurnFixture);
}
_activeThrusters.Remove(component);
component.Colliding.Clear();
}
public bool CanEnable(EntityUid uid, ThrusterComponent component)
{
if (!component.Enabled) return false;
var xform = EntityManager.GetComponent<TransformComponent>(uid);
if (!xform.Anchored ||
EntityManager.TryGetComponent(uid, out ApcPowerReceiverComponent? receiver) && !receiver.Powered)
{
return false;
}
if (component.Type == ThrusterType.Angular)
return true;
var (x, y) = xform.LocalPosition + xform.LocalRotation.Opposite().ToWorldVec();
var tile = _mapManager.GetGrid(xform.GridID).GetTileRef(new Vector2i((int) Math.Floor(x), (int) Math.Floor(y)));
return tile.Tile.IsSpace();
}
#region Burning
public override void Update(float frameTime)
{
base.Update(frameTime);
_accumulator += frameTime;
if (_accumulator < 1) return;
_accumulator -= 1;
foreach (var comp in _activeThrusters.ToArray())
{
if (!comp.Firing || comp.Damage == null || comp.Paused || comp.Deleted) continue;
DebugTools.Assert(comp.Colliding.Count > 0);
foreach (var uid in comp.Colliding.ToArray())
{
_damageable.TryChangeDamage(uid, comp.Damage);
}
}
}
private void OnStartCollide(EntityUid uid, ThrusterComponent component, StartCollideEvent args)
{
if (args.OurFixture.ID != BurnFixture) return;
_activeThrusters.Add(component);
component.Colliding.Add(args.OtherFixture.Body.OwnerUid);
}
private void OnEndCollide(EntityUid uid, ThrusterComponent component, EndCollideEvent args)
{
if (args.OurFixture.ID != BurnFixture) return;
component.Colliding.Remove(args.OtherFixture.Body.OwnerUid);
if (component.Colliding.Count == 0)
{
_activeThrusters.Remove(component);
}
}
/// <summary>
/// Considers a thrust direction as being active.
/// </summary>
public void EnableThrustDirection(ShuttleComponent component, DirectionFlag direction)
{
if ((component.ThrustDirections & direction) != 0x0) return;
component.ThrustDirections |= direction;
if ((direction & (DirectionFlag.East | DirectionFlag.West)) != 0x0)
{
switch (component.Mode)
{
case ShuttleMode.Cruise:
foreach (var comp in component.AngularThrusters)
{
if (!EntityManager.TryGetComponent(comp.OwnerUid, out SharedAppearanceComponent? appearanceComponent))
continue;
comp.Firing = true;
appearanceComponent.SetData(ThrusterVisualState.Thrusting, true);
}
break;
case ShuttleMode.Docking:
var index = GetFlagIndex(direction);
foreach (var comp in component.LinearThrusters[index])
{
if (!EntityManager.TryGetComponent(comp.OwnerUid, out SharedAppearanceComponent? appearanceComponent))
continue;
comp.Firing = true;
appearanceComponent.SetData(ThrusterVisualState.Thrusting, true);
}
break;
}
}
else
{
var index = GetFlagIndex(direction);
foreach (var comp in component.LinearThrusters[index])
{
if (!EntityManager.TryGetComponent(comp.OwnerUid, out SharedAppearanceComponent? appearanceComponent))
continue;
comp.Firing = true;
appearanceComponent.SetData(ThrusterVisualState.Thrusting, true);
}
}
}
/// <summary>
/// Disables a thrust direction.
/// </summary>
public void DisableThrustDirection(ShuttleComponent component, DirectionFlag direction)
{
if ((component.ThrustDirections & direction) == 0x0) return;
component.ThrustDirections &= ~direction;
if ((direction & (DirectionFlag.East | DirectionFlag.West)) != 0x0)
{
switch (component.Mode)
{
case ShuttleMode.Cruise:
foreach (var comp in component.AngularThrusters)
{
if (!EntityManager.TryGetComponent(comp.OwnerUid, out SharedAppearanceComponent? appearanceComponent))
continue;
comp.Firing = false;
appearanceComponent.SetData(ThrusterVisualState.Thrusting, false);
}
break;
case ShuttleMode.Docking:
var index = GetFlagIndex(direction);
foreach (var comp in component.LinearThrusters[index])
{
if (!EntityManager.TryGetComponent(comp.OwnerUid, out SharedAppearanceComponent? appearanceComponent))
continue;
comp.Firing = false;
appearanceComponent.SetData(ThrusterVisualState.Thrusting, false);
}
break;
}
}
else
{
var index = GetFlagIndex(direction);
foreach (var comp in component.LinearThrusters[index])
{
if (!EntityManager.TryGetComponent(comp.OwnerUid, out SharedAppearanceComponent? appearanceComponent))
continue;
comp.Firing = false;
appearanceComponent.SetData(ThrusterVisualState.Thrusting, false);
}
}
}
public void DisableAllThrustDirections(ShuttleComponent component)
{
foreach (DirectionFlag dir in Enum.GetValues(typeof(DirectionFlag)))
{
DisableThrustDirection(component, dir);
}
DebugTools.Assert(component.ThrustDirections == DirectionFlag.None);
}
#endregion
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private int GetFlagIndex(DirectionFlag flag)
{
return (int) Math.Log2((int) flag);
}
}
}

View File

@@ -1,8 +0,0 @@
using Content.Shared.Shuttles;
using Robust.Shared.GameObjects;
namespace Content.Server.Shuttles
{
[RegisterComponent]
public sealed class ShuttleComponent : SharedShuttleComponent {}
}