Skip to content

Commit

Permalink
Reapply "FTL + AI fixes (#31952)" (#31968) (#32094)
Browse files Browse the repository at this point in the history
* Reapply "FTL + AI fixes (#31952)" (#31968)

This reverts commit c46a4ab.

* Update
  • Loading branch information
metalgearsloth committed Sep 12, 2024
1 parent 934b0a6 commit 2a58fa1
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 16 deletions.
61 changes: 50 additions & 11 deletions Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ public sealed partial class ShuttleSystem

private readonly HashSet<EntityUid> _lookupEnts = new();
private readonly HashSet<EntityUid> _immuneEnts = new();
private readonly HashSet<Entity<NoFTLComponent>> _noFtls = new();

private EntityQuery<BodyComponent> _bodyQuery;
private EntityQuery<BuckleComponent> _buckleQuery;
private EntityQuery<FTLBeaconComponent> _beaconQuery;
private EntityQuery<GhostComponent> _ghostQuery;
private EntityQuery<FTLSmashImmuneComponent> _immuneQuery;
private EntityQuery<PhysicsComponent> _physicsQuery;
private EntityQuery<StatusEffectsComponent> _statusQuery;
private EntityQuery<TransformComponent> _xformQuery;
Expand All @@ -86,8 +86,7 @@ private void InitializeFTL()

_bodyQuery = GetEntityQuery<BodyComponent>();
_buckleQuery = GetEntityQuery<BuckleComponent>();
_beaconQuery = GetEntityQuery<FTLBeaconComponent>();
_ghostQuery = GetEntityQuery<GhostComponent>();
_immuneQuery = GetEntityQuery<FTLSmashImmuneComponent>();
_physicsQuery = GetEntityQuery<PhysicsComponent>();
_statusQuery = GetEntityQuery<StatusEffectsComponent>();
_xformQuery = GetEntityQuery<TransformComponent>();
Expand All @@ -102,7 +101,7 @@ private void InitializeFTL()

private void OnFtlShutdown(Entity<FTLComponent> ent, ref ComponentShutdown args)
{
Del(ent.Comp.VisualizerEntity);
QueueDel(ent.Comp.VisualizerEntity);
ent.Comp.VisualizerEntity = null;
}

Expand Down Expand Up @@ -404,7 +403,12 @@ private void UpdateFTLStarting(Entity<FTLComponent, ShuttleComponent> entity)
// Offset the start by buffer range just to avoid overlap.
var ftlStart = new EntityCoordinates(ftlMap, new Vector2(_index + width / 2f, 0f) - shuttleCenter);

// Store the matrix for the grid prior to movement. This means any entities we need to leave behind we can make sure their positions are updated.
// Setting the entity to map directly may run grid traversal (at least at time of writing this).
var oldMapUid = xform.MapUid;
var oldGridMatrix = _transform.GetWorldMatrix(xform);
_transform.SetCoordinates(entity.Owner, ftlStart);
LeaveNoFTLBehind((entity.Owner, xform), oldGridMatrix, oldMapUid);

// Reset rotation so they always face the same direction.
xform.LocalRotation = Angle.Zero;
Expand Down Expand Up @@ -476,6 +480,9 @@ private void UpdateFTLArriving(Entity<FTLComponent, ShuttleComponent> entity)

MapId mapId;

QueueDel(entity.Comp1.VisualizerEntity);
entity.Comp1.VisualizerEntity = null;

if (!Exists(entity.Comp1.TargetCoordinates.EntityId))
{
// Uhh good luck
Expand Down Expand Up @@ -628,6 +635,31 @@ private void DoTheDinosaur(TransformComponent xform)
}
}

private void LeaveNoFTLBehind(Entity<TransformComponent> grid, Matrix3x2 oldGridMatrix, EntityUid? oldMapUid)
{
if (oldMapUid == null)
return;

_noFtls.Clear();
var oldGridRotation = oldGridMatrix.Rotation();
_lookup.GetGridEntities(grid.Owner, _noFtls);

foreach (var childUid in _noFtls)
{
if (!_xformQuery.TryComp(childUid, out var childXform))
continue;

// If we're not parented directly to the grid the matrix may be wrong.
var relative = _physics.GetRelativePhysicsTransform(childUid.Owner, (grid.Owner, grid.Comp));

_transform.SetCoordinates(
childUid,
childXform,
new EntityCoordinates(oldMapUid.Value,
Vector2.Transform(relative.Position, oldGridMatrix)), rotation: relative.Quaternion2D.Angle + oldGridRotation);
}
}

private void KnockOverKids(TransformComponent xform, ref ValueList<EntityUid> toKnock)
{
// Not recursive because probably not necessary? If we need it to be that's why this method is separate.
Expand Down Expand Up @@ -924,8 +956,11 @@ private void Smimsh(EntityUid uid, FixturesComponent? manager = null, MapGridCom
if (!Resolve(uid, ref manager, ref grid, ref xform) || xform.MapUid == null)
return;

if (!TryComp(xform.MapUid, out BroadphaseComponent? lookup))
return;

// Flatten anything not parented to a grid.
var transform = _physics.GetPhysicsTransform(uid, xform);
var transform = _physics.GetRelativePhysicsTransform((uid, xform), xform.MapUid.Value);
var aabbs = new List<Box2>(manager.Fixtures.Count);
var tileSet = new List<(Vector2i, Tile)>();

Expand All @@ -946,7 +981,8 @@ private void Smimsh(EntityUid uid, FixturesComponent? manager = null, MapGridCom
_biomes.ReserveTiles(xform.MapUid.Value, aabb, tileSet);
_lookupEnts.Clear();
_immuneEnts.Clear();
_lookup.GetEntitiesIntersecting(xform.MapUid.Value, aabb, _lookupEnts, LookupFlags.Uncontained);
// TODO: Ideally we'd query first BEFORE moving grid but needs adjustments above.
_lookup.GetLocalEntitiesIntersecting(xform.MapUid.Value, fixture.Shape, transform, _lookupEnts, flags: LookupFlags.Uncontained, lookup: lookup);

foreach (var ent in _lookupEnts)
{
Expand All @@ -955,7 +991,13 @@ private void Smimsh(EntityUid uid, FixturesComponent? manager = null, MapGridCom
continue;
}

if (_ghostQuery.HasComponent(ent) || _beaconQuery.HasComponent(ent))
// If it's on our grid ignore it.
if (!_xformQuery.TryComp(ent, out var childXform) || childXform.GridUid == uid)
{
continue;
}

if (_immuneQuery.HasComponent(ent))
{
continue;
}
Expand All @@ -969,9 +1011,6 @@ private void Smimsh(EntityUid uid, FixturesComponent? manager = null, MapGridCom
continue;
}

if (HasComp<FTLBeaconComponent>(ent))
continue;

QueueDel(ent);
}
}
Expand Down
9 changes: 9 additions & 0 deletions Content.Shared/Shuttles/Components/FTLSmashImmuneComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Robust.Shared.GameStates;

namespace Content.Shared.Shuttles.Components;

/// <summary>
/// Makes the entity immune to FTL arrival landing AKA smimsh.
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed partial class FTLSmashImmuneComponent : Component;
12 changes: 12 additions & 0 deletions Content.Shared/Shuttles/Components/NoFTLComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Robust.Shared.GameStates;

namespace Content.Shared.Shuttles.Components;

/// <summary>
/// Prevents the attached entity from taking FTL.
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed partial class NoFTLComponent : Component
{

}
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Markers/shuttle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
parent: MarkerBase
name: FTL point
components:
- type: FTLSmashImmune
- type: FTLBeacon
- type: Sprite
state: pink
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Mobs/Player/observer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
noRot: true
overrideContainerOcclusion: true # Always show up regardless of where they're contained.
drawdepth: Ghosts
- type: FTLSmashImmune
- type: CargoSellBlacklist
- type: MovementSpeedModifier
baseSprintSpeed: 12
Expand Down
11 changes: 6 additions & 5 deletions Resources/Prototypes/Entities/Mobs/Player/silicon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
state: std_mod
- type: SiliconLawProvider
laws: PaladinLawset

- type: entity
id: LiveLetLiveCircuitBoard
parent: BaseElectronics
Expand All @@ -158,7 +158,7 @@
state: std_mod
- type: SiliconLawProvider
laws: LiveLetLiveLaws

- type: entity
id: StationEfficiencyCircuitBoard
parent: BaseElectronics
Expand All @@ -182,7 +182,7 @@
state: std_mod
- type: SiliconLawProvider
laws: RobocopLawset

- type: entity
id: OverlordCircuitBoard
parent: BaseElectronics
Expand All @@ -194,7 +194,7 @@
state: std_mod
- type: SiliconLawProvider
laws: OverlordLawset

- type: entity
id: DungeonMasterCircuitBoard
parent: BaseElectronics
Expand Down Expand Up @@ -230,7 +230,7 @@
state: std_mod
- type: SiliconLawProvider
laws: AntimovLawset

- type: entity
id: NutimovCircuitBoard
parent: BaseElectronics
Expand Down Expand Up @@ -376,6 +376,7 @@
noSpawn: true
suffix: DO NOT MAP
components:
- type: NoFTL
- type: WarpPoint
follow: true
- type: Eye
Expand Down

0 comments on commit 2a58fa1

Please sign in to comment.