2021-11-21 17:09:49 +11:00
|
|
|
using Content.Server.Shuttles.Components;
|
2022-03-07 02:03:53 -03:00
|
|
|
using Content.Shared.CCVar;
|
2022-06-26 15:20:45 +10:00
|
|
|
using Content.Shared.GameTicking;
|
2022-07-15 14:11:41 +10:00
|
|
|
using Content.Shared.Shuttles.Systems;
|
2021-07-21 21:15:12 +10:00
|
|
|
using JetBrains.Annotations;
|
2022-06-26 15:20:45 +10:00
|
|
|
using Robust.Server.GameObjects;
|
2022-03-07 02:03:53 -03:00
|
|
|
using Robust.Shared.Configuration;
|
2022-06-26 15:20:45 +10:00
|
|
|
using Robust.Shared.Map;
|
2022-11-22 13:12:04 +11:00
|
|
|
using Robust.Shared.Map.Components;
|
2021-07-21 21:15:12 +10:00
|
|
|
using Robust.Shared.Physics;
|
2022-09-14 17:26:26 +10:00
|
|
|
using Robust.Shared.Physics.Components;
|
|
|
|
|
using Robust.Shared.Physics.Systems;
|
2021-07-21 21:15:12 +10:00
|
|
|
|
2022-06-16 15:28:16 +10:00
|
|
|
namespace Content.Server.Shuttles.Systems
|
2021-07-21 21:15:12 +10:00
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
2022-07-15 14:11:41 +10:00
|
|
|
public sealed partial class ShuttleSystem : SharedShuttleSystem
|
2021-07-21 21:15:12 +10:00
|
|
|
{
|
2022-06-26 15:20:45 +10:00
|
|
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
2022-04-24 13:54:25 +10:00
|
|
|
[Dependency] private readonly FixtureSystem _fixtures = default!;
|
2022-10-04 16:00:44 +11:00
|
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
2022-10-04 15:48:23 +11:00
|
|
|
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
2022-06-26 15:20:45 +10:00
|
|
|
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
|
|
|
|
|
|
|
|
|
|
private ISawmill _sawmill = default!;
|
2022-04-24 13:54:25 +10:00
|
|
|
|
|
|
|
|
public const float TileMassMultiplier = 0.5f;
|
2021-07-21 21:15:12 +10:00
|
|
|
|
2022-07-17 19:36:08 +10:00
|
|
|
public const float ShuttleLinearDamping = 0.05f;
|
|
|
|
|
public const float ShuttleAngularDamping = 0.05f;
|
2021-12-03 13:03:06 +11:00
|
|
|
|
2021-07-21 21:15:12 +10:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
2022-06-26 15:20:45 +10:00
|
|
|
_sawmill = Logger.GetSawmill("shuttles");
|
|
|
|
|
|
|
|
|
|
InitializeEmergencyConsole();
|
|
|
|
|
InitializeEscape();
|
2022-07-15 14:11:41 +10:00
|
|
|
InitializeFTL();
|
2022-08-12 02:58:44 +10:00
|
|
|
InitializeIFF();
|
2022-10-04 16:00:44 +11:00
|
|
|
InitializeImpact();
|
2022-06-26 15:20:45 +10:00
|
|
|
|
2021-11-21 17:09:49 +11:00
|
|
|
SubscribeLocalEvent<ShuttleComponent, ComponentAdd>(OnShuttleAdd);
|
|
|
|
|
SubscribeLocalEvent<ShuttleComponent, ComponentStartup>(OnShuttleStartup);
|
|
|
|
|
SubscribeLocalEvent<ShuttleComponent, ComponentShutdown>(OnShuttleShutdown);
|
2021-07-21 21:15:12 +10:00
|
|
|
|
2022-06-26 15:20:45 +10:00
|
|
|
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundRestart);
|
|
|
|
|
|
2021-11-21 17:09:49 +11:00
|
|
|
SubscribeLocalEvent<GridInitializeEvent>(OnGridInit);
|
|
|
|
|
SubscribeLocalEvent<GridFixtureChangeEvent>(OnGridFixtureChange);
|
2022-03-07 02:03:53 -03:00
|
|
|
}
|
|
|
|
|
|
2022-06-26 15:20:45 +10:00
|
|
|
public override void Update(float frameTime)
|
|
|
|
|
{
|
|
|
|
|
base.Update(frameTime);
|
|
|
|
|
UpdateEmergencyConsole(frameTime);
|
|
|
|
|
UpdateHyperspace(frameTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnRoundRestart(RoundRestartCleanupEvent ev)
|
|
|
|
|
{
|
|
|
|
|
CleanupEmergencyConsole();
|
|
|
|
|
CleanupEmergencyShuttle();
|
|
|
|
|
CleanupHyperspace();
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-07 02:03:53 -03:00
|
|
|
public override void Shutdown()
|
|
|
|
|
{
|
|
|
|
|
base.Shutdown();
|
2022-06-27 15:19:40 +10:00
|
|
|
ShutdownEscape();
|
2022-06-26 15:20:45 +10:00
|
|
|
ShutdownEmergencyConsole();
|
2021-07-21 21:15:12 +10:00
|
|
|
}
|
|
|
|
|
|
2021-11-21 17:09:49 +11:00
|
|
|
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)
|
2021-07-21 21:15:12 +10:00
|
|
|
{
|
2021-09-20 21:08:10 +10:00
|
|
|
// Look this is jank but it's a placeholder until we design it.
|
|
|
|
|
if (args.NewFixtures.Count == 0) return;
|
2021-07-21 21:15:12 +10:00
|
|
|
|
2023-01-15 15:38:59 +11:00
|
|
|
var uid = args.NewFixtures[0].Body.Owner;
|
|
|
|
|
var manager = Comp<FixturesComponent>(uid);
|
2022-04-24 13:54:25 +10:00
|
|
|
|
2021-09-20 21:08:10 +10:00
|
|
|
foreach (var fixture in args.NewFixtures)
|
|
|
|
|
{
|
2023-01-15 15:38:59 +11:00
|
|
|
_physics.SetDensity(uid, fixture, TileMassMultiplier, false, manager);
|
|
|
|
|
_fixtures.SetRestitution(uid, fixture, 0.1f, false, manager);
|
2021-09-20 21:08:10 +10:00
|
|
|
}
|
2022-04-24 13:54:25 +10:00
|
|
|
|
2023-01-15 15:38:59 +11:00
|
|
|
_fixtures.FixtureUpdate(uid, manager: manager);
|
2021-07-21 21:15:12 +10:00
|
|
|
}
|
|
|
|
|
|
2021-11-21 17:09:49 +11:00
|
|
|
private void OnGridInit(GridInitializeEvent ev)
|
2021-07-21 21:15:12 +10:00
|
|
|
{
|
2023-01-09 14:10:30 +11:00
|
|
|
if (HasComp<MapComponent>(ev.EntityUid))
|
|
|
|
|
return;
|
|
|
|
|
|
2021-12-05 10:56:17 -08:00
|
|
|
EntityManager.EnsureComponent<ShuttleComponent>(ev.EntityUid);
|
2021-07-21 21:15:12 +10:00
|
|
|
}
|
|
|
|
|
|
2021-11-21 17:09:49 +11:00
|
|
|
private void OnShuttleStartup(EntityUid uid, ShuttleComponent component, ComponentStartup args)
|
2021-07-21 21:15:12 +10:00
|
|
|
{
|
2022-11-04 10:12:25 +11:00
|
|
|
if (!EntityManager.HasComponent<MapGridComponent>(component.Owner))
|
2021-07-21 21:15:12 +10:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-08 13:00:43 +01:00
|
|
|
if (!EntityManager.TryGetComponent(component.Owner, out PhysicsComponent? physicsComponent))
|
2021-07-21 21:15:12 +10:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (component.Enabled)
|
|
|
|
|
{
|
2023-01-15 15:38:59 +11:00
|
|
|
Enable(uid, physicsComponent);
|
2021-07-21 21:15:12 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-15 15:38:59 +11:00
|
|
|
public void Toggle(EntityUid uid, ShuttleComponent component)
|
2021-07-21 21:15:12 +10:00
|
|
|
{
|
2021-12-08 13:00:43 +01:00
|
|
|
if (!EntityManager.TryGetComponent(component.Owner, out PhysicsComponent? physicsComponent)) return;
|
2021-07-21 21:15:12 +10:00
|
|
|
|
|
|
|
|
component.Enabled = !component.Enabled;
|
|
|
|
|
|
|
|
|
|
if (component.Enabled)
|
|
|
|
|
{
|
2023-01-15 15:38:59 +11:00
|
|
|
Enable(uid, physicsComponent);
|
2021-07-21 21:15:12 +10:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-01-15 15:38:59 +11:00
|
|
|
Disable(uid, physicsComponent);
|
2021-07-21 21:15:12 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-15 15:38:59 +11:00
|
|
|
private void Enable(EntityUid uid, PhysicsComponent component)
|
2021-07-21 21:15:12 +10:00
|
|
|
{
|
2023-01-15 15:38:59 +11:00
|
|
|
FixturesComponent? manager = null;
|
|
|
|
|
|
|
|
|
|
_physics.SetBodyType(uid, BodyType.Dynamic, manager: manager, body: component);
|
|
|
|
|
_physics.SetBodyStatus(component, BodyStatus.InAir);
|
|
|
|
|
_physics.SetFixedRotation(uid, false, manager: manager, body: component);
|
|
|
|
|
_physics.SetLinearDamping(component, ShuttleLinearDamping);
|
|
|
|
|
_physics.SetAngularDamping(component, ShuttleAngularDamping);
|
2021-07-21 21:15:12 +10:00
|
|
|
}
|
|
|
|
|
|
2023-01-15 15:38:59 +11:00
|
|
|
private void Disable(EntityUid uid, PhysicsComponent component)
|
2021-07-21 21:15:12 +10:00
|
|
|
{
|
2023-01-15 15:38:59 +11:00
|
|
|
FixturesComponent? manager = null;
|
|
|
|
|
|
|
|
|
|
_physics.SetBodyType(uid, BodyType.Static, manager: manager, body: component);
|
|
|
|
|
_physics.SetBodyStatus(component, BodyStatus.OnGround);
|
|
|
|
|
_physics.SetFixedRotation(uid, true, manager: manager, body: component);
|
2021-07-21 21:15:12 +10:00
|
|
|
}
|
|
|
|
|
|
2021-11-21 17:09:49 +11:00
|
|
|
private void OnShuttleShutdown(EntityUid uid, ShuttleComponent component, ComponentShutdown args)
|
2021-07-21 21:15:12 +10:00
|
|
|
{
|
2021-12-01 18:32:37 +11:00
|
|
|
// None of the below is necessary for any cleanup if we're just deleting.
|
|
|
|
|
if (EntityManager.GetComponent<MetaDataComponent>(uid).EntityLifeStage >= EntityLifeStage.Terminating) return;
|
|
|
|
|
|
2021-12-08 13:00:43 +01:00
|
|
|
if (!EntityManager.TryGetComponent(component.Owner, out PhysicsComponent? physicsComponent))
|
2021-07-21 21:15:12 +10:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-15 15:38:59 +11:00
|
|
|
Disable(uid, physicsComponent);
|
2021-07-21 21:15:12 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|