Fix thruster postmapinit (#15623)
This commit is contained in:
@@ -100,7 +100,7 @@ namespace Content.Server.Construction.Completions
|
||||
|
||||
if (entityManager.TryGetComponent(machine, out MachineComponent? machineComp))
|
||||
{
|
||||
constructionSystem.RefreshParts(machineComp);
|
||||
constructionSystem.RefreshParts(machine, machineComp);
|
||||
}
|
||||
|
||||
var entChangeEv = new ConstructionChangeEntityEvent(machine, uid);
|
||||
|
||||
@@ -5,6 +5,7 @@ using Content.Shared.Construction.Components;
|
||||
using Content.Shared.Construction.Prototypes;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Construction;
|
||||
@@ -28,8 +29,8 @@ public sealed partial class ConstructionSystem
|
||||
|
||||
private void OnMachineMapInit(EntityUid uid, MachineComponent component, MapInitEvent args)
|
||||
{
|
||||
CreateBoardAndStockParts(component);
|
||||
RefreshParts(component);
|
||||
CreateBoardAndStockParts(uid, component);
|
||||
RefreshParts(uid, component);
|
||||
}
|
||||
|
||||
private void OnMachineExaminableVerb(EntityUid uid, MachineComponent component, GetVerbsEvent<ExamineVerb> args)
|
||||
@@ -99,21 +100,21 @@ public sealed partial class ConstructionSystem
|
||||
return output;
|
||||
}
|
||||
|
||||
public void RefreshParts(MachineComponent component)
|
||||
public void RefreshParts(EntityUid uid, MachineComponent component)
|
||||
{
|
||||
var parts = GetAllParts(component);
|
||||
EntityManager.EventBus.RaiseLocalEvent(component.Owner, new RefreshPartsEvent
|
||||
EntityManager.EventBus.RaiseLocalEvent(uid, new RefreshPartsEvent
|
||||
{
|
||||
Parts = parts,
|
||||
PartRatings = GetPartsRatings(parts),
|
||||
}, true);
|
||||
}
|
||||
|
||||
public void CreateBoardAndStockParts(MachineComponent component)
|
||||
private void CreateBoardAndStockParts(EntityUid uid, MachineComponent component)
|
||||
{
|
||||
// Entity might not be initialized yet.
|
||||
var boardContainer = _container.EnsureContainer<Container>(component.Owner, MachineFrameComponent.BoardContainerName);
|
||||
var partContainer = _container.EnsureContainer<Container>(component.Owner, MachineFrameComponent.PartContainerName);
|
||||
var boardContainer = _container.EnsureContainer<Container>(uid, MachineFrameComponent.BoardContainerName);
|
||||
var partContainer = _container.EnsureContainer<Container>(uid, MachineFrameComponent.PartContainerName);
|
||||
|
||||
if (string.IsNullOrEmpty(component.BoardPrototype))
|
||||
return;
|
||||
@@ -122,11 +123,11 @@ public sealed partial class ConstructionSystem
|
||||
if (boardContainer.ContainedEntities.Count > 0)
|
||||
return;
|
||||
|
||||
var board = EntityManager.SpawnEntity(component.BoardPrototype, Transform(component.Owner).Coordinates);
|
||||
var board = EntityManager.SpawnEntity(component.BoardPrototype, Transform(uid).Coordinates);
|
||||
|
||||
if (!component.BoardContainer.Insert(board))
|
||||
{
|
||||
throw new Exception($"Couldn't insert board with prototype {component.BoardPrototype} to machine with prototype {MetaData(component.Owner).EntityPrototype?.ID ?? "N/A"}!");
|
||||
throw new Exception($"Couldn't insert board with prototype {component.BoardPrototype} to machine with prototype {MetaData(uid).EntityPrototype?.ID ?? "N/A"}!");
|
||||
}
|
||||
|
||||
if (!TryComp<MachineBoardComponent?>(board, out var machineBoard))
|
||||
@@ -134,7 +135,7 @@ public sealed partial class ConstructionSystem
|
||||
throw new Exception($"Entity with prototype {component.BoardPrototype} doesn't have a {nameof(MachineBoardComponent)}!");
|
||||
}
|
||||
|
||||
var xform = Transform(component.Owner);
|
||||
var xform = Transform(uid);
|
||||
foreach (var (part, amount) in machineBoard.Requirements)
|
||||
{
|
||||
var partProto = _prototypeManager.Index<MachinePartPrototype>(part);
|
||||
@@ -149,20 +150,20 @@ public sealed partial class ConstructionSystem
|
||||
|
||||
foreach (var (stackType, amount) in machineBoard.MaterialRequirements)
|
||||
{
|
||||
var stack = _stackSystem.Spawn(amount, stackType, Transform(component.Owner).Coordinates);
|
||||
var stack = _stackSystem.Spawn(amount, stackType, Transform(uid).Coordinates);
|
||||
|
||||
if (!partContainer.Insert(stack))
|
||||
throw new Exception($"Couldn't insert machine material of type {stackType} to machine with prototype {MetaData(component.Owner).EntityPrototype?.ID ?? "N/A"}");
|
||||
throw new Exception($"Couldn't insert machine material of type {stackType} to machine with prototype {MetaData(uid).EntityPrototype?.ID ?? "N/A"}");
|
||||
}
|
||||
|
||||
foreach (var (compName, info) in machineBoard.ComponentRequirements)
|
||||
{
|
||||
for (var i = 0; i < info.Amount; i++)
|
||||
{
|
||||
var c = EntityManager.SpawnEntity(info.DefaultPrototype, Transform(component.Owner).Coordinates);
|
||||
var c = EntityManager.SpawnEntity(info.DefaultPrototype, Transform(uid).Coordinates);
|
||||
|
||||
if(!partContainer.Insert(c))
|
||||
throw new Exception($"Couldn't insert machine component part with default prototype '{compName}' to machine with prototype {MetaData(component.Owner).EntityPrototype?.ID ?? "N/A"}");
|
||||
throw new Exception($"Couldn't insert machine component part with default prototype '{compName}' to machine with prototype {MetaData(uid).EntityPrototype?.ID ?? "N/A"}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,10 +171,10 @@ public sealed partial class ConstructionSystem
|
||||
{
|
||||
for (var i = 0; i < info.Amount; i++)
|
||||
{
|
||||
var c = EntityManager.SpawnEntity(info.DefaultPrototype, Transform(component.Owner).Coordinates);
|
||||
var c = EntityManager.SpawnEntity(info.DefaultPrototype, Transform(uid).Coordinates);
|
||||
|
||||
if(!partContainer.Insert(c))
|
||||
throw new Exception($"Couldn't insert machine component part with default prototype '{tagName}' to machine with prototype {MetaData(component.Owner).EntityPrototype?.ID ?? "N/A"}");
|
||||
throw new Exception($"Couldn't insert machine component part with default prototype '{tagName}' to machine with prototype {MetaData(uid).EntityPrototype?.ID ?? "N/A"}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ public sealed class PartExchangerSystem : EntitySystem
|
||||
storage.Storage.Insert(unused.Owner);
|
||||
_storage.Insert(uid, unused.Owner, null, false);
|
||||
}
|
||||
_construction.RefreshParts(machine);
|
||||
_construction.RefreshParts(args.Args.Target.Value, machine);
|
||||
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
@@ -15,12 +15,12 @@ namespace Content.Server.Shuttles.Components
|
||||
/// <summary>
|
||||
/// The thrusters contributing to each direction for impulse.
|
||||
/// </summary>
|
||||
public readonly List<ThrusterComponent>[] LinearThrusters = new List<ThrusterComponent>[4];
|
||||
public readonly List<EntityUid>[] LinearThrusters = new List<EntityUid>[4];
|
||||
|
||||
/// <summary>
|
||||
/// The thrusters contributing to the angular impulse of the shuttle.
|
||||
/// </summary>
|
||||
public readonly List<ThrusterComponent> AngularThrusters = new();
|
||||
public readonly List<EntityUid> AngularThrusters = new();
|
||||
|
||||
[ViewVariables]
|
||||
public float AngularThrust = 0f;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Server.Shuttles.Systems;
|
||||
using Content.Shared.Construction.Prototypes;
|
||||
using Content.Shared.Damage;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.Shuttles.Components
|
||||
@@ -42,7 +43,8 @@ namespace Content.Server.Shuttles.Components
|
||||
/// </summary>
|
||||
public bool IsOn;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
// Need to serialize this because RefreshParts isn't called on Init and this will break post-mapinit maps!
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("thrust")]
|
||||
public float Thrust;
|
||||
|
||||
[DataField("baseThrust"), ViewVariables(VVAccess.ReadWrite)]
|
||||
@@ -73,6 +75,12 @@ namespace Content.Server.Shuttles.Components
|
||||
|
||||
public bool Firing = false;
|
||||
|
||||
/// <summary>
|
||||
/// Next time we tick damage for anyone colliding.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("nextFire", customTypeSerializer:typeof(TimeOffsetSerializer))]
|
||||
public TimeSpan NextFire;
|
||||
|
||||
[DataField("machinePartThrust", customTypeSerializer: typeof(PrototypeIdSerializer<MachinePartPrototype>))]
|
||||
public string MachinePartThrust = "Laser";
|
||||
|
||||
|
||||
@@ -12,11 +12,11 @@ using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Shuttles.Systems
|
||||
namespace Content.Server.Shuttles.Systems;
|
||||
|
||||
[UsedImplicitly]
|
||||
public sealed partial class ShuttleSystem : SharedShuttleSystem
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed partial class ShuttleSystem : SharedShuttleSystem
|
||||
{
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly AirlockSystem _airlock = default!;
|
||||
@@ -75,7 +75,7 @@ namespace Content.Server.Shuttles.Systems
|
||||
// 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>();
|
||||
component.LinearThrusters[i] = new List<EntityUid>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +163,8 @@ namespace Content.Server.Shuttles.Systems
|
||||
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;
|
||||
if (EntityManager.GetComponent<MetaDataComponent>(uid).EntityLifeStage >= EntityLifeStage.Terminating)
|
||||
return;
|
||||
|
||||
if (!EntityManager.TryGetComponent(uid, out PhysicsComponent? physicsComponent))
|
||||
{
|
||||
@@ -172,5 +173,4 @@ namespace Content.Server.Shuttles.Systems
|
||||
|
||||
Disable(uid, physicsComponent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,12 +17,14 @@ using Robust.Shared.Physics.Collision.Shapes;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Events;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Shuttles.Systems
|
||||
namespace Content.Server.Shuttles.Systems;
|
||||
|
||||
public sealed class ThrusterSystem : EntitySystem
|
||||
{
|
||||
public sealed class ThrusterSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly ITileDefinitionManager _tileDefManager = default!;
|
||||
[Dependency] private readonly AmbientSoundSystem _ambient = default!;
|
||||
@@ -35,18 +37,13 @@ namespace Content.Server.Shuttles.Systems
|
||||
|
||||
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, MapInitEvent>(OnThrusterMapInit);
|
||||
SubscribeLocalEvent<ThrusterComponent, PowerChangedEvent>(OnPowerChange);
|
||||
SubscribeLocalEvent<ThrusterComponent, AnchorStateChangedEvent>(OnAnchorChange);
|
||||
SubscribeLocalEvent<ThrusterComponent, ReAnchorEvent>(OnThrusterReAnchor);
|
||||
@@ -95,7 +92,8 @@ namespace Content.Server.Shuttles.Systems
|
||||
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;
|
||||
if (args.NewTile.IsSpace(_tileDefManager) || !args.OldTile.IsSpace(_tileDefManager))
|
||||
return;
|
||||
|
||||
var tilePos = args.NewTile.GridIndices;
|
||||
var grid = _mapManager.GetGrid(uid);
|
||||
@@ -106,20 +104,23 @@ namespace Content.Server.Shuttles.Systems
|
||||
{
|
||||
for (var y = -1; y <= 1; y++)
|
||||
{
|
||||
if (x != 0 && y != 0) continue;
|
||||
if (x != 0 && y != 0)
|
||||
continue;
|
||||
|
||||
var checkPos = tilePos + new Vector2i(x, y);
|
||||
var enumerator = grid.GetAnchoredEntitiesEnumerator(checkPos);
|
||||
|
||||
while (enumerator.MoveNext(out var ent))
|
||||
{
|
||||
if (!thrusterQuery.TryGetComponent(ent.Value, out var thruster) || !thruster.RequireSpace) continue;
|
||||
if (!thrusterQuery.TryGetComponent(ent.Value, out var thruster) || !thruster.RequireSpace)
|
||||
continue;
|
||||
|
||||
// Work out if the thruster is facing this direction
|
||||
var xform = xformQuery.GetComponent(ent.Value);
|
||||
var direction = xform.LocalRotation.ToWorldVec();
|
||||
|
||||
if (new Vector2i((int) direction.X, (int) direction.Y) != new Vector2i(x, y)) continue;
|
||||
if (new Vector2i((int) direction.X, (int) direction.Y) != new Vector2i(x, y))
|
||||
continue;
|
||||
|
||||
DisableThruster(ent.Value, thruster, xform.GridUid);
|
||||
}
|
||||
@@ -142,8 +143,7 @@ namespace Content.Server.Shuttles.Systems
|
||||
if (!component.Enabled ||
|
||||
component.Type != ThrusterType.Linear ||
|
||||
!EntityManager.TryGetComponent(uid, out TransformComponent? xform) ||
|
||||
!_mapManager.TryGetGrid(xform.GridUid, out var grid) ||
|
||||
!EntityManager.TryGetComponent(grid.Owner, out ShuttleComponent? shuttleComponent))
|
||||
!EntityManager.TryGetComponent(xform.GridUid, out ShuttleComponent? shuttleComponent))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -151,7 +151,8 @@ namespace Content.Server.Shuttles.Systems
|
||||
var canEnable = CanEnable(uid, component);
|
||||
|
||||
// If it's not on then don't enable it inadvertantly (given we don't have an old rotation)
|
||||
if (!canEnable && !component.IsOn) return;
|
||||
if (!canEnable && !component.IsOn)
|
||||
return;
|
||||
|
||||
// Enable it if it was turned off but new tile is valid
|
||||
if (!component.IsOn && canEnable)
|
||||
@@ -171,12 +172,12 @@ namespace Content.Server.Shuttles.Systems
|
||||
var direction = (int) args.NewRotation.GetCardinalDir() / 2;
|
||||
|
||||
shuttleComponent.LinearThrust[oldDirection] -= component.Thrust;
|
||||
DebugTools.Assert(shuttleComponent.LinearThrusters[oldDirection].Contains(component));
|
||||
shuttleComponent.LinearThrusters[oldDirection].Remove(component);
|
||||
DebugTools.Assert(shuttleComponent.LinearThrusters[oldDirection].Contains(uid));
|
||||
shuttleComponent.LinearThrusters[oldDirection].Remove(uid);
|
||||
|
||||
shuttleComponent.LinearThrust[direction] += component.Thrust;
|
||||
DebugTools.Assert(!shuttleComponent.LinearThrusters[direction].Contains(component));
|
||||
shuttleComponent.LinearThrusters[direction].Add(component);
|
||||
DebugTools.Assert(!shuttleComponent.LinearThrusters[direction].Contains(uid));
|
||||
shuttleComponent.LinearThrusters[direction].Add(uid);
|
||||
}
|
||||
|
||||
private void OnAnchorChange(EntityUid uid, ThrusterComponent component, ref AnchorStateChangedEvent args)
|
||||
@@ -199,6 +200,12 @@ namespace Content.Server.Shuttles.Systems
|
||||
EnableThruster(uid, component);
|
||||
}
|
||||
|
||||
private void OnThrusterMapInit(EntityUid uid, ThrusterComponent component, MapInitEvent args)
|
||||
{
|
||||
if (component.NextFire < _timing.CurTime)
|
||||
component.NextFire = _timing.CurTime;
|
||||
}
|
||||
|
||||
private void OnThrusterInit(EntityUid uid, ThrusterComponent component, ComponentInit args)
|
||||
{
|
||||
_ambient.SetAmbience(uid, false);
|
||||
@@ -237,12 +244,15 @@ namespace Content.Server.Shuttles.Systems
|
||||
public void EnableThruster(EntityUid uid, ThrusterComponent component, TransformComponent? xform = null)
|
||||
{
|
||||
if (component.IsOn ||
|
||||
!Resolve(uid, ref xform) ||
|
||||
!_mapManager.TryGetGrid(xform.GridUid, out var grid)) return;
|
||||
!Resolve(uid, ref xform))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
component.IsOn = true;
|
||||
|
||||
if (!EntityManager.TryGetComponent(grid.Owner, out ShuttleComponent? shuttleComponent)) return;
|
||||
if (!EntityManager.TryGetComponent(xform.GridUid, out ShuttleComponent? shuttleComponent))
|
||||
return;
|
||||
|
||||
// Logger.DebugS("thruster", $"Enabled thruster {uid}");
|
||||
|
||||
@@ -252,8 +262,8 @@ namespace Content.Server.Shuttles.Systems
|
||||
var direction = (int) xform.LocalRotation.GetCardinalDir() / 2;
|
||||
|
||||
shuttleComponent.LinearThrust[direction] += component.Thrust;
|
||||
DebugTools.Assert(!shuttleComponent.LinearThrusters[direction].Contains(component));
|
||||
shuttleComponent.LinearThrusters[direction].Add(component);
|
||||
DebugTools.Assert(!shuttleComponent.LinearThrusters[direction].Contains(uid));
|
||||
shuttleComponent.LinearThrusters[direction].Add(uid);
|
||||
|
||||
// Don't just add / remove the fixture whenever the thruster fires because perf
|
||||
if (EntityManager.TryGetComponent(uid, out PhysicsComponent? physicsComponent) &&
|
||||
@@ -261,14 +271,14 @@ namespace Content.Server.Shuttles.Systems
|
||||
{
|
||||
var shape = new PolygonShape();
|
||||
shape.SetVertices(component.BurnPoly);
|
||||
_fixtureSystem.TryCreateFixture(uid, shape, BurnFixture, hard: false, collisionLayer: (int) CollisionGroup.FullTileMask);
|
||||
_fixtureSystem.TryCreateFixture(uid, shape, BurnFixture, hard: false, collisionLayer: (int) CollisionGroup.FullTileMask, body: physicsComponent);
|
||||
}
|
||||
|
||||
break;
|
||||
case ThrusterType.Angular:
|
||||
shuttleComponent.AngularThrust += component.Thrust;
|
||||
DebugTools.Assert(!shuttleComponent.AngularThrusters.Contains(component));
|
||||
shuttleComponent.AngularThrusters.Add(component);
|
||||
DebugTools.Assert(!shuttleComponent.AngularThrusters.Contains(uid));
|
||||
shuttleComponent.AngularThrusters.Add(uid);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
@@ -299,12 +309,15 @@ namespace Content.Server.Shuttles.Systems
|
||||
public void DisableThruster(EntityUid uid, ThrusterComponent component, EntityUid? gridId, TransformComponent? xform = null, Angle? angle = null)
|
||||
{
|
||||
if (!component.IsOn ||
|
||||
!Resolve(uid, ref xform) ||
|
||||
!_mapManager.TryGetGrid(gridId, out var grid)) return;
|
||||
!Resolve(uid, ref xform))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
component.IsOn = false;
|
||||
|
||||
if (!EntityManager.TryGetComponent(grid.Owner, out ShuttleComponent? shuttleComponent)) return;
|
||||
if (!EntityManager.TryGetComponent(gridId, out ShuttleComponent? shuttleComponent))
|
||||
return;
|
||||
|
||||
// Logger.DebugS("thruster", $"Disabled thruster {uid}");
|
||||
|
||||
@@ -315,13 +328,13 @@ namespace Content.Server.Shuttles.Systems
|
||||
var direction = (int) angle.Value.GetCardinalDir() / 2;
|
||||
|
||||
shuttleComponent.LinearThrust[direction] -= component.Thrust;
|
||||
DebugTools.Assert(shuttleComponent.LinearThrusters[direction].Contains(component));
|
||||
shuttleComponent.LinearThrusters[direction].Remove(component);
|
||||
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(component));
|
||||
shuttleComponent.AngularThrusters.Remove(component);
|
||||
DebugTools.Assert(shuttleComponent.AngularThrusters.Contains(uid));
|
||||
shuttleComponent.AngularThrusters.Remove(uid);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
@@ -344,14 +357,16 @@ namespace Content.Server.Shuttles.Systems
|
||||
_fixtureSystem.DestroyFixture(uid, BurnFixture, body: physicsComponent);
|
||||
}
|
||||
|
||||
_activeThrusters.Remove(component);
|
||||
component.Colliding.Clear();
|
||||
}
|
||||
|
||||
public bool CanEnable(EntityUid uid, ThrusterComponent component)
|
||||
{
|
||||
if (!component.Enabled) return false;
|
||||
if (component.LifeStage > ComponentLifeStage.Running) return false;
|
||||
if (!component.Enabled)
|
||||
return false;
|
||||
|
||||
if (component.LifeStage > ComponentLifeStage.Running)
|
||||
return false;
|
||||
|
||||
var xform = Transform(uid);
|
||||
|
||||
@@ -383,19 +398,15 @@ namespace Content.Server.Shuttles.Systems
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
_accumulator += frameTime;
|
||||
var query = EntityQueryEnumerator<ThrusterComponent>();
|
||||
var curTime = _timing.CurTime;
|
||||
|
||||
if (_accumulator < 1) return;
|
||||
|
||||
_accumulator -= 1;
|
||||
|
||||
foreach (var comp in _activeThrusters.ToArray())
|
||||
while (query.MoveNext(out var comp))
|
||||
{
|
||||
MetaDataComponent? metaData = null;
|
||||
if (!comp.Firing || comp.Colliding.Count == 0 || comp.Damage == null || comp.NextFire < curTime)
|
||||
continue;
|
||||
|
||||
if (!comp.Firing || comp.Damage == null || Paused(comp.Owner, metaData) || Deleted(comp.Owner, metaData)) continue;
|
||||
|
||||
DebugTools.Assert(comp.Colliding.Count > 0);
|
||||
comp.NextFire += TimeSpan.FromSeconds(1);
|
||||
|
||||
foreach (var uid in comp.Colliding.ToArray())
|
||||
{
|
||||
@@ -406,22 +417,18 @@ namespace Content.Server.Shuttles.Systems
|
||||
|
||||
private void OnStartCollide(EntityUid uid, ThrusterComponent component, ref StartCollideEvent args)
|
||||
{
|
||||
if (args.OurFixture.ID != BurnFixture) return;
|
||||
if (args.OurFixture.ID != BurnFixture)
|
||||
return;
|
||||
|
||||
_activeThrusters.Add(component);
|
||||
component.Colliding.Add((args.OtherFixture.Body).Owner);
|
||||
component.Colliding.Add(args.OtherEntity);
|
||||
}
|
||||
|
||||
private void OnEndCollide(EntityUid uid, ThrusterComponent component, ref EndCollideEvent args)
|
||||
{
|
||||
if (args.OurFixture.ID != BurnFixture) return;
|
||||
if (args.OurFixture.ID != BurnFixture)
|
||||
return;
|
||||
|
||||
component.Colliding.Remove((args.OtherFixture.Body).Owner);
|
||||
|
||||
if (component.Colliding.Count == 0)
|
||||
{
|
||||
_activeThrusters.Remove(component);
|
||||
}
|
||||
component.Colliding.Remove(args.OtherEntity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -429,16 +436,23 @@ namespace Content.Server.Shuttles.Systems
|
||||
/// </summary>
|
||||
public void EnableLinearThrustDirection(ShuttleComponent component, DirectionFlag direction)
|
||||
{
|
||||
if ((component.ThrustDirections & direction) != 0x0) return;
|
||||
if ((component.ThrustDirections & direction) != 0x0)
|
||||
return;
|
||||
|
||||
component.ThrustDirections |= direction;
|
||||
|
||||
var index = GetFlagIndex(direction);
|
||||
var appearanceQuery = GetEntityQuery<AppearanceComponent>();
|
||||
var thrusterQuery = GetEntityQuery<ThrusterComponent>();
|
||||
|
||||
foreach (var comp in component.LinearThrusters[index])
|
||||
foreach (var uid in component.LinearThrusters[index])
|
||||
{
|
||||
if (!thrusterQuery.TryGetComponent(uid, out var comp))
|
||||
continue;
|
||||
|
||||
comp.Firing = true;
|
||||
_appearance.SetData(comp.Owner, ThrusterVisualState.Thrusting, true);
|
||||
appearanceQuery.TryGetComponent(uid, out var appearance);
|
||||
_appearance.SetData(uid, ThrusterVisualState.Thrusting, true, appearance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -447,16 +461,23 @@ namespace Content.Server.Shuttles.Systems
|
||||
/// </summary>
|
||||
public void DisableLinearThrustDirection(ShuttleComponent component, DirectionFlag direction)
|
||||
{
|
||||
if ((component.ThrustDirections & direction) == 0x0) return;
|
||||
if ((component.ThrustDirections & direction) == 0x0)
|
||||
return;
|
||||
|
||||
component.ThrustDirections &= ~direction;
|
||||
|
||||
var index = GetFlagIndex(direction);
|
||||
var appearanceQuery = GetEntityQuery<AppearanceComponent>();
|
||||
var thrusterQuery = GetEntityQuery<ThrusterComponent>();
|
||||
|
||||
foreach (var comp in component.LinearThrusters[index])
|
||||
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(comp.Owner, ThrusterVisualState.Thrusting, false);
|
||||
_appearance.SetData(uid, ThrusterVisualState.Thrusting, false, appearance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -472,20 +493,31 @@ namespace Content.Server.Shuttles.Systems
|
||||
|
||||
public void SetAngularThrust(ShuttleComponent component, bool on)
|
||||
{
|
||||
var appearanceQuery = GetEntityQuery<AppearanceComponent>();
|
||||
var thrusterQuery = GetEntityQuery<ThrusterComponent>();
|
||||
|
||||
if (on)
|
||||
{
|
||||
foreach (var comp in component.AngularThrusters)
|
||||
foreach (var uid in component.AngularThrusters)
|
||||
{
|
||||
if (!thrusterQuery.TryGetComponent(uid, out var comp))
|
||||
continue;
|
||||
|
||||
appearanceQuery.TryGetComponent(uid, out var appearance);
|
||||
comp.Firing = true;
|
||||
_appearance.SetData(comp.Owner, ThrusterVisualState.Thrusting, true);
|
||||
_appearance.SetData(uid, ThrusterVisualState.Thrusting, true, appearance);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var comp in component.AngularThrusters)
|
||||
foreach (var uid in component.AngularThrusters)
|
||||
{
|
||||
if (!thrusterQuery.TryGetComponent(uid, out var comp))
|
||||
continue;
|
||||
|
||||
appearanceQuery.TryGetComponent(uid, out var appearance);
|
||||
comp.Firing = false;
|
||||
_appearance.SetData(comp.Owner, ThrusterVisualState.Thrusting, false);
|
||||
_appearance.SetData(uid, ThrusterVisualState.Thrusting, false, appearance);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -508,5 +540,4 @@ namespace Content.Server.Shuttles.Systems
|
||||
{
|
||||
return (int) Math.Log2((int) flag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user