Files

608 lines
21 KiB
C#
Raw Permalink Normal View History

using System.Numerics;
2021-11-21 17:09:49 +11:00
using Content.Server.Audio;
Upstream core (#282) * yes (cherry picked from commit a6b5e1c66dfe4241977bcde753af594392164eca) * Is real, navernoe (#944) * its real * fix shield * remove comments game preset * maximum predicted * fixes * АААААААААААААААААААААААААААА ПОМОГИТЕ Я ЕБНУЛСЯ ПОКА ФИКСИЛ ЭТУ ЗАЛУПУ * govnoedit * secret (cherry picked from commit 22c7b68048590b5098efbfff0d0f5205d3a64c48) * [Feature/Tweaks] Raznoe (#934) * make thruster great again * make hardsuit hos great again * new ficha for medical hud * fix * vrode da * GOOOVNO REMIX REVERB EXTRA * fix * правки --------- Co-authored-by: BIGZi0348 <svalker0348@gmail.com> (cherry picked from commit 141e61a0449873842f46d83eff9e9ce857147d60) * Automatic changelog update (cherry picked from commit d14fe5fb6c934ed522df0b5bc453e4c04707a6db) * [Feature] Executions (#932) * based * cleanup * cleanup + fixes * fix * fix * fix ftl * Update Resources/Locale/ru-RU/_white/executions/execution.ftl Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update execution.ftl * правки * vrode norm * da --------- Co-authored-by: BIGZi0348 <118811750+BIGZi0348@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: BIGZi0348 <svalker0348@gmail.com> (cherry picked from commit 83e164172f8e290acee7634f14ac51281be020ad) * Automatic changelog update (cherry picked from commit 71f907c563a30a1fc7ef5751a4d6f2c780a14f4c) * hotfix (#946) (cherry picked from commit f577caec41ab277ee8fc1c18fe64f7e26a6e50f5) --------- Co-authored-by: RavmorganButOnCocaine <valtos@nextmail.ru>
2025-04-13 19:03:49 +05:00
using Content.Server.DeviceLinking.Events;
2021-11-21 17:09:49 +11:00
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
2021-11-21 17:09:49 +11:00
using Content.Server.Shuttles.Components;
using Content.Shared.Damage;
2021-11-23 17:44:08 +11:00
using Content.Shared.Examine;
2021-11-21 17:09:49 +11:00
using Content.Shared.Interaction;
using Content.Shared.Maps;
using Content.Shared.Physics;
using Content.Shared.Shuttles.Components;
using Content.Shared.Temperature;
2021-11-21 17:09:49 +11:00
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
2021-11-21 17:09:49 +11:00
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Events;
using Robust.Shared.Physics.Systems;
2023-04-21 20:04:20 +10:00
using Robust.Shared.Timing;
2021-11-21 17:09:49 +11:00
using Robust.Shared.Utility;
2023-04-21 20:04:20 +10:00
namespace Content.Server.Shuttles.Systems;
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
public sealed class ThrusterSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly ITileDefinitionManager _tileDefManager = default!;
[Dependency] private readonly AmbientSoundSystem _ambient = default!;
[Dependency] private readonly FixtureSystem _fixtureSystem = default!;
[Dependency] private readonly DamageableSystem _damageable = default!;
2023-09-11 19:18:06 +10:00
[Dependency] private readonly SharedPointLightSystem _light = default!;
2023-04-21 20:04:20 +10:00
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
// Essentially whenever thruster enables we update the shuttle's available impulses which are used for movement.
// This is done for each direction available.
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
public const string BurnFixture = "thruster-burn";
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
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, MoveEvent>(OnRotate);
SubscribeLocalEvent<ThrusterComponent, IsHotEvent>(OnIsHotEvent);
SubscribeLocalEvent<ThrusterComponent, StartCollideEvent>(OnStartCollide);
SubscribeLocalEvent<ThrusterComponent, EndCollideEvent>(OnEndCollide);
Upstream core (#282) * yes (cherry picked from commit a6b5e1c66dfe4241977bcde753af594392164eca) * Is real, navernoe (#944) * its real * fix shield * remove comments game preset * maximum predicted * fixes * АААААААААААААААААААААААААААА ПОМОГИТЕ Я ЕБНУЛСЯ ПОКА ФИКСИЛ ЭТУ ЗАЛУПУ * govnoedit * secret (cherry picked from commit 22c7b68048590b5098efbfff0d0f5205d3a64c48) * [Feature/Tweaks] Raznoe (#934) * make thruster great again * make hardsuit hos great again * new ficha for medical hud * fix * vrode da * GOOOVNO REMIX REVERB EXTRA * fix * правки --------- Co-authored-by: BIGZi0348 <svalker0348@gmail.com> (cherry picked from commit 141e61a0449873842f46d83eff9e9ce857147d60) * Automatic changelog update (cherry picked from commit d14fe5fb6c934ed522df0b5bc453e4c04707a6db) * [Feature] Executions (#932) * based * cleanup * cleanup + fixes * fix * fix * fix ftl * Update Resources/Locale/ru-RU/_white/executions/execution.ftl Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update execution.ftl * правки * vrode norm * da --------- Co-authored-by: BIGZi0348 <118811750+BIGZi0348@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: BIGZi0348 <svalker0348@gmail.com> (cherry picked from commit 83e164172f8e290acee7634f14ac51281be020ad) * Automatic changelog update (cherry picked from commit 71f907c563a30a1fc7ef5751a4d6f2c780a14f4c) * hotfix (#946) (cherry picked from commit f577caec41ab277ee8fc1c18fe64f7e26a6e50f5) --------- Co-authored-by: RavmorganButOnCocaine <valtos@nextmail.ru>
2025-04-13 19:03:49 +05:00
SubscribeLocalEvent<ThrusterComponent, SignalReceivedEvent>(OnSignalReceived);
2023-04-21 20:04:20 +10:00
SubscribeLocalEvent<ThrusterComponent, ExaminedEvent>(OnThrusterExamine);
SubscribeLocalEvent<ShuttleComponent, TileChangedEvent>(OnShuttleTileChange);
}
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
private void OnThrusterExamine(EntityUid uid, ThrusterComponent component, ExaminedEvent args)
{
// Powered is already handled by other power components
var enabled = Loc.GetString(component.Enabled ? "thruster-comp-enabled" : "thruster-comp-disabled");
2021-11-21 17:09:49 +11:00
using (args.PushGroup(nameof(ThrusterComponent)))
2021-11-23 17:44:08 +11:00
{
args.PushMarkup(enabled);
if (component.Type == ThrusterType.Linear &&
EntityManager.TryGetComponent(uid, out TransformComponent? xform) &&
xform.Anchored)
{
var nozzleDir = Loc.GetString("thruster-comp-nozzle-direction",
("direction", xform.LocalRotation.Opposite().ToWorldVec().GetDir().ToString().ToLowerInvariant()));
2021-11-23 17:44:08 +11:00
args.PushMarkup(nozzleDir);
2021-11-23 17:44:08 +11:00
var exposed = NozzleExposed(xform);
2021-11-23 17:44:08 +11:00
var nozzleText =
Loc.GetString(exposed ? "thruster-comp-nozzle-exposed" : "thruster-comp-nozzle-not-exposed");
2021-11-23 17:44:08 +11:00
args.PushMarkup(nozzleText);
}
2021-11-23 17:44:08 +11:00
}
2023-04-21 20:04:20 +10:00
}
2021-11-23 17:44:08 +11:00
2023-04-21 20:04:20 +10:00
private void OnIsHotEvent(EntityUid uid, ThrusterComponent component, IsHotEvent args)
{
args.IsHot = component.Type != ThrusterType.Angular && component.IsOn;
}
2023-04-21 20:04:20 +10:00
private void OnShuttleTileChange(EntityUid uid, ShuttleComponent component, ref TileChangedEvent args)
{
// If the old tile was space but the new one isn't then disable all adjacent thrusters
if (args.NewTile.IsSpace(_tileDefManager) || !args.OldTile.IsSpace(_tileDefManager))
return;
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
var tilePos = args.NewTile.GridIndices;
var grid = Comp<MapGridComponent>(uid);
2023-04-21 20:04:20 +10:00
var xformQuery = GetEntityQuery<TransformComponent>();
var thrusterQuery = GetEntityQuery<ThrusterComponent>();
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
for (var x = -1; x <= 1; x++)
{
for (var y = -1; y <= 1; y++)
2021-11-21 17:09:49 +11:00
{
2023-04-21 20:04:20 +10:00
if (x != 0 && y != 0)
continue;
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
var checkPos = tilePos + new Vector2i(x, y);
var enumerator = grid.GetAnchoredEntitiesEnumerator(checkPos);
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
while (enumerator.MoveNext(out var ent))
{
if (!thrusterQuery.TryGetComponent(ent.Value, out var thruster) || !thruster.RequireSpace)
continue;
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
// Work out if the thruster is facing this direction
var xform = xformQuery.GetComponent(ent.Value);
var direction = xform.LocalRotation.ToWorldVec();
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
if (new Vector2i((int) direction.X, (int) direction.Y) != new Vector2i(x, y))
continue;
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
DisableThruster(ent.Value, thruster, xform.GridUid);
2021-11-21 17:09:49 +11:00
}
}
}
2023-04-21 20:04:20 +10:00
}
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
private void OnActivateThruster(EntityUid uid, ThrusterComponent component, ActivateInWorldEvent args)
{
component.Enabled ^= true;
if (!component.Enabled)
{
DisableThruster(uid, component);
}
else if (CanEnable(uid, component))
{
EnableThruster(uid, component);
}
2023-04-21 20:04:20 +10:00
}
/// <summary>
/// If the thruster rotates change the direction where the linear thrust is applied
/// </summary>
private void OnRotate(EntityUid uid, ThrusterComponent component, ref MoveEvent args)
{
// TODO: Disable visualizer for old direction
// TODO: Don't make them rotatable and make it require anchoring.
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
if (!component.Enabled ||
!EntityManager.TryGetComponent(uid, out TransformComponent? xform) ||
!EntityManager.TryGetComponent(xform.GridUid, out ShuttleComponent? shuttleComponent))
2021-11-21 17:09:49 +11:00
{
2023-04-21 20:04:20 +10:00
return;
}
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
var canEnable = CanEnable(uid, component);
2021-11-28 13:03:46 +11:00
2023-04-21 20:04:20 +10:00
// If it's not on then don't enable it inadvertantly (given we don't have an old rotation)
if (!canEnable && !component.IsOn)
return;
2021-11-28 13:03:46 +11:00
2023-04-21 20:04:20 +10:00
// Enable it if it was turned off but new tile is valid
if (!component.IsOn && canEnable)
{
EnableThruster(uid, component);
return;
}
2021-11-28 13:03:46 +11:00
2023-04-21 20:04:20 +10:00
// Disable if new tile invalid
if (component.IsOn && !canEnable)
{
DisableThruster(uid, component, args.OldPosition.EntityId, xform, args.OldRotation);
2023-04-21 20:04:20 +10:00
return;
}
2021-11-28 13:03:46 +11:00
2023-04-21 20:04:20 +10:00
var oldDirection = (int) args.OldRotation.GetCardinalDir() / 2;
var direction = (int) args.NewRotation.GetCardinalDir() / 2;
var oldShuttleComponent = shuttleComponent;
2021-11-21 17:09:49 +11:00
if (args.ParentChanged)
{
oldShuttleComponent = Comp<ShuttleComponent>(args.OldPosition.EntityId);
2021-11-21 17:09:49 +11:00
// If no parent change doesn't matter for angular.
if (component.Type == ThrusterType.Angular)
{
oldShuttleComponent.AngularThrust -= component.Thrust;
DebugTools.Assert(oldShuttleComponent.AngularThrusters.Contains(uid));
oldShuttleComponent.AngularThrusters.Remove(uid);
shuttleComponent.AngularThrust += component.Thrust;
DebugTools.Assert(!shuttleComponent.AngularThrusters.Contains(uid));
shuttleComponent.AngularThrusters.Add(uid);
return;
}
}
if (component.Type == ThrusterType.Linear)
{
oldShuttleComponent.LinearThrust[oldDirection] -= component.Thrust;
DebugTools.Assert(oldShuttleComponent.LinearThrusters[oldDirection].Contains(uid));
oldShuttleComponent.LinearThrusters[oldDirection].Remove(uid);
shuttleComponent.LinearThrust[direction] += component.Thrust;
DebugTools.Assert(!shuttleComponent.LinearThrusters[direction].Contains(uid));
shuttleComponent.LinearThrusters[direction].Add(uid);
}
2023-04-21 20:04:20 +10:00
}
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
private void OnAnchorChange(EntityUid uid, ThrusterComponent component, ref AnchorStateChangedEvent args)
{
if (args.Anchored && CanEnable(uid, component))
{
EnableThruster(uid, component);
2021-11-21 17:09:49 +11:00
}
2023-04-21 20:04:20 +10:00
else
2021-11-21 17:09:49 +11:00
{
2023-04-21 20:04:20 +10:00
DisableThruster(uid, component);
2021-11-21 17:09:49 +11:00
}
2023-04-21 20:04:20 +10:00
}
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
private void OnThrusterInit(EntityUid uid, ThrusterComponent component, ComponentInit args)
{
_ambient.SetAmbience(uid, false);
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
if (!component.Enabled)
{
return;
2021-11-21 17:09:49 +11:00
}
2023-04-21 20:04:20 +10:00
if (CanEnable(uid, component))
2021-11-21 17:09:49 +11:00
{
2023-04-21 20:04:20 +10:00
EnableThruster(uid, component);
2021-11-21 17:09:49 +11:00
}
2023-04-21 20:04:20 +10:00
}
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
private void OnThrusterShutdown(EntityUid uid, ThrusterComponent component, ComponentShutdown args)
{
DisableThruster(uid, component);
}
private void OnPowerChange(EntityUid uid, ThrusterComponent component, ref PowerChangedEvent args)
{
if (args.Powered && CanEnable(uid, component))
2021-11-21 17:09:49 +11:00
{
2023-04-21 20:04:20 +10:00
EnableThruster(uid, component);
}
else
{
DisableThruster(uid, component);
2021-11-21 17:09:49 +11:00
}
2023-04-21 20:04:20 +10:00
}
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
/// <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))
2021-11-21 17:09:49 +11:00
{
2023-04-21 20:04:20 +10:00
return;
}
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
component.IsOn = true;
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
if (!EntityManager.TryGetComponent(xform.GridUid, out ShuttleComponent? shuttleComponent))
return;
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
// Logger.DebugS("thruster", $"Enabled thruster {uid}");
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
switch (component.Type)
{
case ThrusterType.Linear:
var direction = (int) xform.LocalRotation.GetCardinalDir() / 2;
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
shuttleComponent.LinearThrust[direction] += component.Thrust;
DebugTools.Assert(!shuttleComponent.LinearThrusters[direction].Contains(uid));
shuttleComponent.LinearThrusters[direction].Add(uid);
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
// 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.Set(component.BurnPoly);
2023-04-21 20:04:20 +10:00
_fixtureSystem.TryCreateFixture(uid, shape, BurnFixture, hard: false, collisionLayer: (int) CollisionGroup.FullTileMask, body: physicsComponent);
}
2023-04-21 20:04:20 +10:00
break;
case ThrusterType.Angular:
shuttleComponent.AngularThrust += component.Thrust;
DebugTools.Assert(!shuttleComponent.AngularThrusters.Contains(uid));
shuttleComponent.AngularThrusters.Add(uid);
break;
default:
throw new ArgumentOutOfRangeException();
2021-11-21 17:09:49 +11:00
}
2023-04-21 20:04:20 +10:00
if (EntityManager.TryGetComponent(uid, out AppearanceComponent? appearance))
{
2023-04-21 20:04:20 +10:00
_appearance.SetData(uid, ThrusterVisualState.State, true, appearance);
}
2023-09-11 19:18:06 +10:00
if (_light.TryGetLight(uid, out var pointLightComponent))
2021-11-21 17:09:49 +11:00
{
2023-09-11 19:18:06 +10:00
_light.SetEnabled(uid, true, pointLightComponent);
2023-04-21 20:04:20 +10:00
}
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
_ambient.SetAmbience(uid, true);
2023-04-29 18:17:31 +10:00
RefreshCenter(uid, shuttleComponent);
}
/// <summary>
/// Refreshes the center of thrust for movement calculations.
/// </summary>
private void RefreshCenter(EntityUid uid, ShuttleComponent shuttle)
{
// TODO: Only refresh relevant directions.
var center = Vector2.Zero;
var thrustQuery = GetEntityQuery<ThrusterComponent>();
var xformQuery = GetEntityQuery<TransformComponent>();
foreach (var dir in new[]
{ Direction.South, Direction.East, Direction.North, Direction.West })
{
var index = (int) dir / 2;
var pop = shuttle.LinearThrusters[index];
var totalThrust = 0f;
foreach (var ent in pop)
{
if (!thrustQuery.TryGetComponent(ent, out var thruster) || !xformQuery.TryGetComponent(ent, out var xform))
continue;
center += xform.LocalPosition * thruster.Thrust;
totalThrust += thruster.Thrust;
}
center /= pop.Count * totalThrust;
shuttle.CenterOfThrust[index] = center;
}
2023-04-21 20:04:20 +10:00
}
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
public void DisableThruster(EntityUid uid, ThrusterComponent component, TransformComponent? xform = null, Angle? angle = null)
{
if (!Resolve(uid, ref xform)) return;
DisableThruster(uid, component, xform.GridUid, xform);
}
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
/// <summary>
/// Tries to disable the thruster.
/// </summary>
public void DisableThruster(EntityUid uid, ThrusterComponent component, EntityUid? gridId, TransformComponent? xform = null, Angle? angle = null)
{
if (!component.IsOn ||
!Resolve(uid, ref xform))
{
return;
}
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
component.IsOn = false;
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
if (!EntityManager.TryGetComponent(gridId, out ShuttleComponent? shuttleComponent))
return;
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
// Logger.DebugS("thruster", $"Disabled thruster {uid}");
2023-04-21 20:04:20 +10:00
switch (component.Type)
{
case ThrusterType.Linear:
angle ??= xform.LocalRotation;
var direction = (int) angle.Value.GetCardinalDir() / 2;
shuttleComponent.LinearThrust[direction] -= component.Thrust;
DebugTools.Assert(shuttleComponent.LinearThrusters[direction].Contains(uid));
shuttleComponent.LinearThrusters[direction].Remove(uid);
break;
case ThrusterType.Angular:
shuttleComponent.AngularThrust -= component.Thrust;
DebugTools.Assert(shuttleComponent.AngularThrusters.Contains(uid));
shuttleComponent.AngularThrusters.Remove(uid);
break;
default:
throw new ArgumentOutOfRangeException();
}
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
if (EntityManager.TryGetComponent(uid, out AppearanceComponent? appearance))
{
_appearance.SetData(uid, ThrusterVisualState.State, false, appearance);
}
2021-11-21 17:09:49 +11:00
2023-09-11 19:18:06 +10:00
if (_light.TryGetLight(uid, out var pointLightComponent))
2023-04-21 20:04:20 +10:00
{
2023-09-11 19:18:06 +10:00
_light.SetEnabled(uid, false, pointLightComponent);
2021-11-21 17:09:49 +11:00
}
2023-04-21 20:04:20 +10:00
_ambient.SetAmbience(uid, false);
if (EntityManager.TryGetComponent(uid, out PhysicsComponent? physicsComponent))
2021-11-21 17:09:49 +11:00
{
2023-04-21 20:04:20 +10:00
_fixtureSystem.DestroyFixture(uid, BurnFixture, body: physicsComponent);
}
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
component.Colliding.Clear();
2023-04-29 18:17:31 +10:00
RefreshCenter(uid, shuttleComponent);
2023-04-21 20:04:20 +10:00
}
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
public bool CanEnable(EntityUid uid, ThrusterComponent component)
{
if (!component.Enabled)
return false;
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
if (component.LifeStage > ComponentLifeStage.Running)
return false;
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
var xform = Transform(uid);
2021-11-23 17:44:08 +11:00
2023-04-21 20:04:20 +10:00
if (!xform.Anchored ||!this.IsPowered(uid, EntityManager))
2021-11-23 17:44:08 +11:00
{
2023-04-21 20:04:20 +10:00
return false;
}
2022-06-20 12:14:35 +12:00
2023-04-21 20:04:20 +10:00
if (!component.RequireSpace)
return true;
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
return NozzleExposed(xform);
}
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
private bool NozzleExposed(TransformComponent xform)
{
if (xform.GridUid == null)
return true;
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
var (x, y) = xform.LocalPosition + xform.LocalRotation.Opposite().ToWorldVec();
var tile = Comp<MapGridComponent>(xform.GridUid.Value).GetTileRef(new Vector2i((int) Math.Floor(x), (int) Math.Floor(y)));
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
return tile.Tile.IsSpace();
}
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
#region Burning
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
public override void Update(float frameTime)
{
base.Update(frameTime);
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
var query = EntityQueryEnumerator<ThrusterComponent>();
var curTime = _timing.CurTime;
2022-01-26 17:57:48 +11:00
2023-04-21 20:04:20 +10:00
while (query.MoveNext(out var comp))
{
if (!comp.Firing || comp.Colliding.Count == 0 || comp.Damage == null || comp.NextFire < curTime)
continue;
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
comp.NextFire += TimeSpan.FromSeconds(1);
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
foreach (var uid in comp.Colliding.ToArray())
{
_damageable.TryChangeDamage(uid, comp.Damage);
2021-11-21 17:09:49 +11:00
}
}
2023-04-21 20:04:20 +10:00
}
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
private void OnStartCollide(EntityUid uid, ThrusterComponent component, ref StartCollideEvent args)
{
2023-08-23 18:55:58 +10:00
if (args.OurFixtureId != BurnFixture)
2023-04-21 20:04:20 +10:00
return;
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
component.Colliding.Add(args.OtherEntity);
}
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
private void OnEndCollide(EntityUid uid, ThrusterComponent component, ref EndCollideEvent args)
{
2023-08-23 18:55:58 +10:00
if (args.OurFixtureId != BurnFixture)
2023-04-21 20:04:20 +10:00
return;
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
component.Colliding.Remove(args.OtherEntity);
}
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
/// <summary>
/// Considers a thrust direction as being active.
/// </summary>
public void EnableLinearThrustDirection(ShuttleComponent component, DirectionFlag direction)
{
if ((component.ThrustDirections & direction) != 0x0)
return;
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
component.ThrustDirections |= direction;
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
var index = GetFlagIndex(direction);
var appearanceQuery = GetEntityQuery<AppearanceComponent>();
var thrusterQuery = GetEntityQuery<ThrusterComponent>();
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
foreach (var uid in component.LinearThrusters[index])
{
if (!thrusterQuery.TryGetComponent(uid, out var comp))
continue;
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
comp.Firing = true;
appearanceQuery.TryGetComponent(uid, out var appearance);
_appearance.SetData(uid, ThrusterVisualState.Thrusting, true, appearance);
2021-11-21 17:09:49 +11:00
}
2023-04-21 20:04:20 +10:00
}
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
/// <summary>
/// Disables a thrust direction.
/// </summary>
public void DisableLinearThrustDirection(ShuttleComponent component, DirectionFlag direction)
{
if ((component.ThrustDirections & direction) == 0x0)
return;
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
component.ThrustDirections &= ~direction;
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
var index = GetFlagIndex(direction);
var appearanceQuery = GetEntityQuery<AppearanceComponent>();
var thrusterQuery = GetEntityQuery<ThrusterComponent>();
2023-04-21 20:04:20 +10:00
foreach (var uid in component.LinearThrusters[index])
{
if (!thrusterQuery.TryGetComponent(uid, out var comp))
continue;
appearanceQuery.TryGetComponent(uid, out var appearance);
comp.Firing = false;
_appearance.SetData(uid, ThrusterVisualState.Thrusting, false, appearance);
}
2023-04-21 20:04:20 +10:00
}
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
public void DisableLinearThrusters(ShuttleComponent component)
{
foreach (DirectionFlag dir in Enum.GetValues(typeof(DirectionFlag)))
{
2023-04-21 20:04:20 +10:00
DisableLinearThrustDirection(component, dir);
}
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
DebugTools.Assert(component.ThrustDirections == DirectionFlag.None);
}
public void SetAngularThrust(ShuttleComponent component, bool on)
{
var appearanceQuery = GetEntityQuery<AppearanceComponent>();
var thrusterQuery = GetEntityQuery<ThrusterComponent>();
if (on)
{
2023-04-21 20:04:20 +10:00
foreach (var uid in component.AngularThrusters)
{
2023-04-21 20:04:20 +10:00
if (!thrusterQuery.TryGetComponent(uid, out var comp))
continue;
appearanceQuery.TryGetComponent(uid, out var appearance);
comp.Firing = true;
_appearance.SetData(uid, ThrusterVisualState.Thrusting, true, appearance);
2021-11-21 17:09:49 +11:00
}
2023-04-21 20:04:20 +10:00
}
else
{
foreach (var uid in component.AngularThrusters)
2021-11-21 17:09:49 +11:00
{
2023-04-21 20:04:20 +10:00
if (!thrusterQuery.TryGetComponent(uid, out var comp))
continue;
appearanceQuery.TryGetComponent(uid, out var appearance);
comp.Firing = false;
_appearance.SetData(uid, ThrusterVisualState.Thrusting, false, appearance);
2021-11-21 17:09:49 +11:00
}
}
2023-04-21 20:04:20 +10:00
}
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
#endregion
2021-11-21 17:09:49 +11:00
2023-04-21 20:04:20 +10:00
private int GetFlagIndex(DirectionFlag flag)
{
return (int) Math.Log2((int) flag);
2021-11-21 17:09:49 +11:00
}
Upstream core (#282) * yes (cherry picked from commit a6b5e1c66dfe4241977bcde753af594392164eca) * Is real, navernoe (#944) * its real * fix shield * remove comments game preset * maximum predicted * fixes * АААААААААААААААААААААААААААА ПОМОГИТЕ Я ЕБНУЛСЯ ПОКА ФИКСИЛ ЭТУ ЗАЛУПУ * govnoedit * secret (cherry picked from commit 22c7b68048590b5098efbfff0d0f5205d3a64c48) * [Feature/Tweaks] Raznoe (#934) * make thruster great again * make hardsuit hos great again * new ficha for medical hud * fix * vrode da * GOOOVNO REMIX REVERB EXTRA * fix * правки --------- Co-authored-by: BIGZi0348 <svalker0348@gmail.com> (cherry picked from commit 141e61a0449873842f46d83eff9e9ce857147d60) * Automatic changelog update (cherry picked from commit d14fe5fb6c934ed522df0b5bc453e4c04707a6db) * [Feature] Executions (#932) * based * cleanup * cleanup + fixes * fix * fix * fix ftl * Update Resources/Locale/ru-RU/_white/executions/execution.ftl Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update execution.ftl * правки * vrode norm * da --------- Co-authored-by: BIGZi0348 <118811750+BIGZi0348@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: BIGZi0348 <svalker0348@gmail.com> (cherry picked from commit 83e164172f8e290acee7634f14ac51281be020ad) * Automatic changelog update (cherry picked from commit 71f907c563a30a1fc7ef5751a4d6f2c780a14f4c) * hotfix (#946) (cherry picked from commit f577caec41ab277ee8fc1c18fe64f7e26a6e50f5) --------- Co-authored-by: RavmorganButOnCocaine <valtos@nextmail.ru>
2025-04-13 19:03:49 +05:00
// Parsec edit start
private void OnSignalReceived(EntityUid uid, ThrusterComponent component, ref SignalReceivedEvent args)
{
if (args.Port == component.OffPort && component.IsOn)
{
DisableThruster(uid, component);
return;
}
if (args.Port == component.OnPort && !component.IsOn)
{
EnableThruster(uid, component);
return;
}
switch (component.IsOn && args.Port == component.TogglePort)
{
case true:
DisableThruster(uid, component);
break;
case false:
EnableThruster(uid, component);
break;
}
}
// Parsec edit end
2021-11-21 17:09:49 +11:00
}