Files
tbd-station-14/Content.Server/Shuttles/Systems/ShuttleSystem.cs
metalgearsloth fc5c63ac09 Add ImplicitRoofComponent (#36112)
* Add ImplicitRoofComponent

So shuttles get marked as rooved.

* Early-out

So the new render doesn't suck up perf unnecessarily.
2025-05-18 17:47:35 +10:00

210 lines
8.1 KiB
C#

using Content.Server.Administration.Logs;
using Content.Server.Body.Systems;
using Content.Server.Buckle.Systems;
using Content.Server.Doors.Systems;
using Content.Server.Parallax;
using Content.Server.Procedural;
using Content.Server.Shuttles.Components;
using Content.Server.Shuttles.Events;
using Content.Server.Station.Systems;
using Content.Server.Stunnable;
using Content.Shared.Buckle.Components;
using Content.Shared.Damage;
using Content.Shared.GameTicking;
using Content.Shared.Light.Components;
using Content.Shared.Inventory;
using Content.Shared.Mobs.Systems;
using Content.Shared.Movement.Events;
using Content.Shared.Salvage;
using Content.Shared.Shuttles.Systems;
using Content.Shared.Throwing;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Server.GameStates;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Configuration;
using Robust.Shared.EntitySerialization.Systems;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Timing;
namespace Content.Server.Shuttles.Systems;
[UsedImplicitly]
public sealed partial class ShuttleSystem : SharedShuttleSystem
{
[Dependency] private readonly IAdminLogManager _logger = default!;
[Dependency] private readonly IComponentFactory _factory = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IPrototypeManager _protoManager = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ITileDefinitionManager _tileDefManager = default!;
[Dependency] private readonly BiomeSystem _biomes = default!;
[Dependency] private readonly BodySystem _bobby = default!;
[Dependency] private readonly BuckleSystem _buckle = default!;
[Dependency] private readonly DamageableSystem _damageSys = default!;
[Dependency] private readonly DockingSystem _dockSystem = default!;
[Dependency] private readonly DungeonSystem _dungeon = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly FixtureSystem _fixtures = default!;
[Dependency] private readonly InventorySystem _inventorySystem = default!;
[Dependency] private readonly MapLoaderSystem _loader = default!;
[Dependency] private readonly MapSystem _mapSystem = default!;
[Dependency] private readonly MetaDataSystem _metadata = default!;
[Dependency] private readonly PvsOverrideSystem _pvs = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly SharedSalvageSystem _salvage = default!;
[Dependency] private readonly ShuttleConsoleSystem _console = default!;
[Dependency] private readonly StationSystem _station = default!;
[Dependency] private readonly StunSystem _stuns = default!;
[Dependency] private readonly ThrowingSystem _throwing = default!;
[Dependency] private readonly ThrusterSystem _thruster = default!;
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
private EntityQuery<BuckleComponent> _buckleQuery;
private EntityQuery<MapGridComponent> _gridQuery;
private EntityQuery<PhysicsComponent> _physicsQuery;
private EntityQuery<TransformComponent> _xformQuery;
public const float TileDensityMultiplier = 0.5f;
public override void Initialize()
{
base.Initialize();
_buckleQuery = GetEntityQuery<BuckleComponent>();
_gridQuery = GetEntityQuery<MapGridComponent>();
_physicsQuery = GetEntityQuery<PhysicsComponent>();
_xformQuery = GetEntityQuery<TransformComponent>();
InitializeFTL();
InitializeGridFills();
InitializeIFF();
InitializeImpact();
SubscribeLocalEvent<ShuttleComponent, ComponentStartup>(OnShuttleStartup);
SubscribeLocalEvent<ShuttleComponent, ComponentShutdown>(OnShuttleShutdown);
SubscribeLocalEvent<ShuttleComponent, TileFrictionEvent>(OnTileFriction);
SubscribeLocalEvent<ShuttleComponent, FTLStartedEvent>(OnFTLStarted);
SubscribeLocalEvent<ShuttleComponent, FTLCompletedEvent>(OnFTLCompleted);
SubscribeLocalEvent<GridInitializeEvent>(OnGridInit);
SubscribeLocalEvent<FixturesComponent, GridFixtureChangeEvent>(OnGridFixtureChange);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
UpdateHyperspace();
}
private void OnGridFixtureChange(EntityUid uid, FixturesComponent manager, GridFixtureChangeEvent args)
{
foreach (var fixture in args.NewFixtures)
{
_physics.SetDensity(uid, fixture.Key, fixture.Value, TileDensityMultiplier, false, manager);
_fixtures.SetRestitution(uid, fixture.Key, fixture.Value, 0.1f, false, manager);
}
}
private void OnGridInit(GridInitializeEvent ev)
{
if (HasComp<MapComponent>(ev.EntityUid))
return;
EnsureComp<ShuttleComponent>(ev.EntityUid);
EnsureComp<ImplicitRoofComponent>(ev.EntityUid);
}
private void OnShuttleStartup(EntityUid uid, ShuttleComponent component, ComponentStartup args)
{
if (!EntityManager.HasComponent<MapGridComponent>(uid))
{
return;
}
if (!EntityManager.TryGetComponent(uid, out PhysicsComponent? physicsComponent))
{
return;
}
if (component.Enabled)
{
Enable(uid, component: physicsComponent, shuttle: component);
}
component.DampingModifier = component.BodyModifier;
}
public void Toggle(EntityUid uid, ShuttleComponent component)
{
if (!EntityManager.TryGetComponent(uid, out PhysicsComponent? physicsComponent))
return;
component.Enabled = !component.Enabled;
if (component.Enabled)
{
Enable(uid, component: physicsComponent, shuttle: component);
}
else
{
Disable(uid, component: physicsComponent);
}
}
public void Enable(EntityUid uid, FixturesComponent? manager = null, PhysicsComponent? component = null, ShuttleComponent? shuttle = null)
{
if (!Resolve(uid, ref manager, ref component, ref shuttle, false))
return;
_physics.SetBodyType(uid, BodyType.Dynamic, manager: manager, body: component);
_physics.SetBodyStatus(uid, component, BodyStatus.InAir);
_physics.SetFixedRotation(uid, false, manager: manager, body: component);
}
public void Disable(EntityUid uid, FixturesComponent? manager = null, PhysicsComponent? component = null)
{
if (!Resolve(uid, ref manager, ref component, false))
return;
_physics.SetBodyType(uid, BodyType.Static, manager: manager, body: component);
_physics.SetBodyStatus(uid, component, BodyStatus.OnGround);
_physics.SetFixedRotation(uid, true, manager: manager, body: component);
}
private void OnShuttleShutdown(EntityUid uid, ShuttleComponent component, ComponentShutdown args)
{
// None of the below is necessary for any cleanup if we're just deleting.
if (EntityManager.GetComponent<MetaDataComponent>(uid).EntityLifeStage >= EntityLifeStage.Terminating)
return;
Disable(uid);
}
private void OnTileFriction(Entity<ShuttleComponent> ent, ref TileFrictionEvent args)
{
args.Modifier *= ent.Comp.DampingModifier;
}
private void OnFTLStarted(Entity<ShuttleComponent> ent, ref FTLStartedEvent args)
{
ent.Comp.DampingModifier = 0f;
}
private void OnFTLCompleted(Entity<ShuttleComponent> ent, ref FTLCompletedEvent args)
{
ent.Comp.DampingModifier = ent.Comp.BodyModifier;
}
}