Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix AI Being Eaten by Singulo #1637

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions Content.Server/Singularity/EntitySystems/EventHorizonSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ public sealed class EventHorizonSystem : SharedEventHorizonSystem
[Dependency] private readonly TagSystem _tagSystem = default!;
#endregion Dependencies

private EntityQuery<PhysicsComponent> _physicsQuery;

public override void Initialize()
{
base.Initialize();

_physicsQuery = GetEntityQuery<PhysicsComponent>();

SubscribeLocalEvent<MapGridComponent, EventHorizonAttemptConsumeEntityEvent>(PreventConsume);
SubscribeLocalEvent<GhostComponent, EventHorizonAttemptConsumeEntityEvent>(PreventConsume);
SubscribeLocalEvent<TelegnosticProjectionComponent, EventHorizonAttemptConsumeEntityEvent>(PreventConsume); ///Nyano - Summary: the telegnositic projection has the same trait as ghosts.
Expand Down Expand Up @@ -171,24 +175,19 @@ public bool CanConsumeEntity(EntityUid hungry, EntityUid uid, EventHorizonCompon
/// Attempts to consume all entities within a given distance of an entity;
/// Excludes the center entity.
/// </summary>
public void ConsumeEntitiesInRange(EntityUid uid, float range, TransformComponent? xform = null, EventHorizonComponent? eventHorizon = null)
public void ConsumeEntitiesInRange(EntityUid uid, float range, PhysicsComponent? body = null, EventHorizonComponent? eventHorizon = null)
{
if (!Resolve(uid, ref xform, ref eventHorizon))
if (!Resolve(uid, ref body, ref eventHorizon))
return;

var range2 = range * range;
var xformQuery = EntityManager.GetEntityQuery<TransformComponent>();
var epicenter = _xformSystem.GetWorldPosition(xform, xformQuery);
foreach (var entity in _lookup.GetEntitiesInRange(_xformSystem.GetMapCoordinates(uid, xform), range, flags: LookupFlags.Uncontained))
// TODO: Should be sundries + static-sundries but apparently this is load-bearing for SpawnAndDeleteAllEntitiesInTheSameSpot so go figure.
foreach (var entity in _lookup.GetEntitiesInRange(uid, range, flags: LookupFlags.Uncontained))
{
if (entity == uid)
continue;
if (!xformQuery.TryGetComponent(entity, out var entityXform))
continue;

// GetEntitiesInRange gets everything in a _square_ centered on the given position, but we are a _circle_. If we don't have this check and the station is rotated it is possible for the singularity to reach _outside of the containment field_ and eat the emitters.
var displacement = _xformSystem.GetWorldPosition(entityXform, xformQuery) - epicenter;
if (displacement.LengthSquared() > range2)
// See TODO above
if (_physicsQuery.TryComp(entity, out var otherBody) && !_physics.IsHardCollidable((uid, null, body), (entity, null, otherBody)))
continue;

AttemptConsumeEntity(uid, entity, eventHorizon);
Expand Down Expand Up @@ -330,11 +329,11 @@ public void ConsumeTilesInRange(EntityUid uid, float range, TransformComponent?
/// </summary>
public void ConsumeEverythingInRange(EntityUid uid, float range, TransformComponent? xform = null, EventHorizonComponent? eventHorizon = null)
{
if (!Resolve(uid, ref xform, ref eventHorizon))
if (!Resolve(uid, ref eventHorizon))
return;

if (eventHorizon.ConsumeEntities)
ConsumeEntitiesInRange(uid, range, xform, eventHorizon);
ConsumeEntitiesInRange(uid, range, null, eventHorizon);
if (eventHorizon.ConsumeTiles)
ConsumeTilesInRange(uid, range, xform, eventHorizon);
}
Expand Down
24 changes: 19 additions & 5 deletions Content.Server/Singularity/EntitySystems/GravityWellSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Content.Server.Singularity.Components;
using Content.Shared.Atmos.Components;
using Content.Shared.Ghost;
using Content.Shared.Physics;
using Content.Shared.Singularity.EntitySystems;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
Expand Down Expand Up @@ -33,9 +34,18 @@ public sealed class GravityWellSystem : SharedGravityWellSystem
/// </summary>
public const float MinGravPulseRange = 0.00001f;

private EntityQuery<GravityWellComponent> _wellQuery;
private EntityQuery<MapComponent> _mapQuery;
private EntityQuery<MapGridComponent> _gridQuery;
private EntityQuery<PhysicsComponent> _physicsQuery;

public override void Initialize()
{
base.Initialize();
_wellQuery = GetEntityQuery<GravityWellComponent>();
_mapQuery = GetEntityQuery<MapComponent>();
_gridQuery = GetEntityQuery<MapGridComponent>();
_physicsQuery = GetEntityQuery<PhysicsComponent>();
SubscribeLocalEvent<GravityWellComponent, ComponentStartup>(OnGravityWellStartup);

var vvHandle = _vvManager.GetTypeHandler<GravityWellComponent>();
Expand Down Expand Up @@ -114,11 +124,15 @@ private void Update(EntityUid uid, TimeSpan frameTime, GravityWellComponent? gra
/// <param name="entity">The entity to check.</param>
private bool CanGravPulseAffect(EntityUid entity)
{
return !(
EntityManager.HasComponent<GhostComponent>(entity) ||
EntityManager.HasComponent<MapGridComponent>(entity) ||
EntityManager.HasComponent<MapComponent>(entity) ||
EntityManager.HasComponent<GravityWellComponent>(entity)
if (_physicsQuery.TryComp(entity, out var physics))
{
if (physics.CollisionLayer == (int) CollisionGroup.GhostImpassable)
return false;
}

return !(_gridQuery.HasComp(entity) ||
_mapQuery.HasComp(entity) ||
_wellQuery.HasComp(entity)
);
}

Expand Down
4 changes: 4 additions & 0 deletions Content.Shared/Physics/CollisionGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ public enum CollisionGroup
GhostImpassable = 1 << 5, // 32 Things impassible by ghosts/observers, ie blessed tiles or forcefields
BulletImpassable = 1 << 6, // 64 Can be hit by bullets
InteractImpassable = 1 << 7, // 128 Blocks interaction/InRangeUnobstructed
// Y dis door passable when all the others impassable / collision.
DoorPassable = 1 << 8, // 256 Allows door to close over top, Like blast doors over conveyors for disposals rooms/cargo.

MapGrid = MapGridHelpers.CollisionGroup, // Map grids, like shuttles. This is the actual grid itself, not the walls or other entities connected to the grid.

// 32 possible groups
// Why dis exist
AllMask = -1,

SingularityLayer = Opaque | Impassable | MidImpassable | HighImpassable | LowImpassable | BulletImpassable | InteractImpassable | DoorPassable,

// Humanoids, etc.
MobMask = Impassable | HighImpassable | MidImpassable | LowImpassable,
MobLayer = Opaque | BulletImpassable,
Expand Down
8 changes: 4 additions & 4 deletions Resources/Prototypes/Entities/Mobs/Player/narsie.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@
restitution: 0.8
density: 99999
mask:
- AllMask
- SingularityLayer
layer:
- AllMask
- SingularityLayer
EventHorizonConsumer:
shape:
!type:PhysShapeCircle
radius: 5
hard: false
mask:
- AllMask
- SingularityLayer
layer:
- AllMask
- SingularityLayer
- type: Input
context: "ghost"
- type: MovementIgnoreGravity
Expand Down
2 changes: 1 addition & 1 deletion Resources/Prototypes/Entities/Mobs/Player/observer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
!type:PhysShapeCircle
radius: 0.35
density: 15
mask:
layer:
- GhostImpassable

- type: entity
Expand Down
8 changes: 4 additions & 4 deletions Resources/Prototypes/Entities/Mobs/Player/ratvar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@
restitution: 0.8
density: 1
mask:
- AllMask
- SingularityLayer
layer:
- AllMask
- SingularityLayer
EventHorizonConsumer:
shape:
!type:PhysShapeCircle
radius: 5
hard: false
mask:
- AllMask
- SingularityLayer
layer:
- AllMask
- SingularityLayer
- type: Input
context: "ghost"
- type: MovementIgnoreGravity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@
restitution: 0.8
density: 2000
mask:
- AllMask
- SingularityLayer
layer:
- AllMask
- SingularityLayer
EventHorizonConsumer:
shape:
!type:PhysShapeCircle
radius: 0.35
hard: false
mask:
- AllMask
- SingularityLayer
layer:
- AllMask
- SingularityLayer
- type: Singularity
energy: 180
level: 1
Expand Down
Loading