Lots of pathfinder bugfixes (#8248)
This commit is contained in:
@@ -263,7 +263,8 @@ namespace Content.Server.AI.Pathfinding
|
|||||||
|
|
||||||
DebugTools.Assert((PathfindingSystem.TrackedCollisionLayers & physicsComponent.CollisionLayer) != 0);
|
DebugTools.Assert((PathfindingSystem.TrackedCollisionLayers & physicsComponent.CollisionLayer) != 0);
|
||||||
|
|
||||||
if (physicsComponent.BodyType != BodyType.Static)
|
if (physicsComponent.BodyType != BodyType.Static ||
|
||||||
|
!physicsComponent.Hard)
|
||||||
{
|
{
|
||||||
_physicsLayers.TryAdd(entity, physicsComponent.CollisionLayer);
|
_physicsLayers.TryAdd(entity, physicsComponent.CollisionLayer);
|
||||||
}
|
}
|
||||||
@@ -285,18 +286,19 @@ namespace Content.Server.AI.Pathfinding
|
|||||||
// There's no guarantee that the entity isn't deleted
|
// There's no guarantee that the entity isn't deleted
|
||||||
// 90% of updates are probably entities moving around
|
// 90% of updates are probably entities moving around
|
||||||
// Entity can't be under multiple categories so just checking each once is fine.
|
// Entity can't be under multiple categories so just checking each once is fine.
|
||||||
if (_physicsLayers.ContainsKey(entity))
|
if (_physicsLayers.Remove(entity))
|
||||||
{
|
{
|
||||||
_physicsLayers.Remove(entity);
|
return;
|
||||||
}
|
}
|
||||||
else if (_accessReaders.ContainsKey(entity))
|
|
||||||
|
if (_accessReaders.Remove(entity))
|
||||||
{
|
{
|
||||||
_accessReaders.Remove(entity);
|
|
||||||
ParentChunk.Dirty();
|
ParentChunk.Dirty();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else if (_blockedCollidables.ContainsKey(entity))
|
|
||||||
|
if (_blockedCollidables.Remove(entity))
|
||||||
{
|
{
|
||||||
_blockedCollidables.Remove(entity);
|
|
||||||
GenerateMask();
|
GenerateMask();
|
||||||
ParentChunk.Dirty();
|
ParentChunk.Dirty();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,12 @@ using Robust.Shared.Utility;
|
|||||||
|
|
||||||
namespace Content.Server.AI.Pathfinding;
|
namespace Content.Server.AI.Pathfinding;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Handles pathfinding while on a grid.
|
|
||||||
/// </summary>
|
|
||||||
public sealed partial class PathfindingSystem
|
public sealed partial class PathfindingSystem
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* Handles pathfinding while on a grid.
|
||||||
|
*/
|
||||||
|
|
||||||
[Dependency] private readonly AccessReaderSystem _accessReader = default!;
|
[Dependency] private readonly AccessReaderSystem _accessReader = default!;
|
||||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||||
|
|
||||||
@@ -28,11 +29,23 @@ public sealed partial class PathfindingSystem
|
|||||||
SubscribeLocalEvent<AccessReaderChangeEvent>(OnAccessChange);
|
SubscribeLocalEvent<AccessReaderChangeEvent>(OnAccessChange);
|
||||||
SubscribeLocalEvent<GridAddEvent>(OnGridAdd);
|
SubscribeLocalEvent<GridAddEvent>(OnGridAdd);
|
||||||
SubscribeLocalEvent<TileChangedEvent>(OnTileChange);
|
SubscribeLocalEvent<TileChangedEvent>(OnTileChange);
|
||||||
|
SubscribeLocalEvent<PhysicsBodyTypeChangedEvent>(OnBodyTypeChange);
|
||||||
|
|
||||||
// Handle all the base grid changes
|
// Handle all the base grid changes
|
||||||
// Anything that affects traversal (i.e. collision layer) is handled separately.
|
// Anything that affects traversal (i.e. collision layer) is handled separately.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnBodyTypeChange(ref PhysicsBodyTypeChangedEvent ev)
|
||||||
|
{
|
||||||
|
var xform = Transform(ev.Entity);
|
||||||
|
|
||||||
|
if (!IsRelevant(xform, ev.Component)) return;
|
||||||
|
|
||||||
|
var node = GetNode(xform);
|
||||||
|
node?.RemoveEntity(ev.Entity);
|
||||||
|
node?.AddEntity(ev.Entity, ev.Component, EntityManager);
|
||||||
|
}
|
||||||
|
|
||||||
private void OnGridAdd(GridAddEvent ev)
|
private void OnGridAdd(GridAddEvent ev)
|
||||||
{
|
{
|
||||||
EnsureComp<GridPathfindingComponent>(ev.EntityUid);
|
EnsureComp<GridPathfindingComponent>(ev.EntityUid);
|
||||||
@@ -91,6 +104,8 @@ public sealed partial class PathfindingSystem
|
|||||||
return newChunk;
|
return newChunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return the corresponding PathfindingNode for this tile
|
/// Return the corresponding PathfindingNode for this tile
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -149,6 +164,27 @@ public sealed partial class PathfindingSystem
|
|||||||
node.RemoveEntity(entity);
|
node.RemoveEntity(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnEntityRemove(EntityUid entity, EntityCoordinates coordinates)
|
||||||
|
{
|
||||||
|
var gridId = coordinates.GetGridId(EntityManager);
|
||||||
|
if (!_mapManager.TryGetGrid(gridId, out var grid)) return;
|
||||||
|
|
||||||
|
var node = GetNode(grid.GetTileRef(coordinates));
|
||||||
|
node.RemoveEntity(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PathfindingNode? GetNode(TransformComponent xform)
|
||||||
|
{
|
||||||
|
if (!_mapManager.TryGetGrid(xform.GridID, out var grid)) return null;
|
||||||
|
return GetNode(grid.GetTileRef(xform.Coordinates));
|
||||||
|
}
|
||||||
|
|
||||||
|
private PathfindingNode? GetNode(EntityCoordinates coordinates)
|
||||||
|
{
|
||||||
|
if (!_mapManager.TryGetGrid(coordinates.GetGridId(EntityManager), out var grid)) return null;
|
||||||
|
return GetNode(grid.GetTileRef(coordinates));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// When an entity moves around we'll remove it from its old node and add it to its new node (if applicable)
|
/// When an entity moves around we'll remove it from its old node and add it to its new node (if applicable)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -159,27 +195,19 @@ public sealed partial class PathfindingSystem
|
|||||||
|
|
||||||
// If we've moved to space or the likes then remove us.
|
// If we've moved to space or the likes then remove us.
|
||||||
if (!TryComp<PhysicsComponent>(moveEvent.Sender, out var physics) ||
|
if (!TryComp<PhysicsComponent>(moveEvent.Sender, out var physics) ||
|
||||||
!IsRelevant(xform, physics) ||
|
!IsRelevant(xform, physics))
|
||||||
moveEvent.NewPosition.GetGridId(EntityManager) == GridId.Invalid)
|
|
||||||
{
|
{
|
||||||
OnEntityRemove(moveEvent.Sender, xform);
|
OnEntityRemove(moveEvent.Sender, moveEvent.OldPosition);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var oldGridId = moveEvent.OldPosition.GetGridId(EntityManager);
|
var oldNode = GetNode(moveEvent.OldPosition);
|
||||||
var gridId = moveEvent.NewPosition.GetGridId(EntityManager);
|
var newNode = GetNode(moveEvent.NewPosition);
|
||||||
|
|
||||||
if (_mapManager.TryGetGrid(oldGridId, out var oldGrid))
|
if (oldNode?.Equals(newNode) == true) return;
|
||||||
{
|
|
||||||
var oldNode = GetNode(oldGrid.GetTileRef(moveEvent.OldPosition));
|
|
||||||
oldNode.RemoveEntity(moveEvent.Sender);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_mapManager.TryGetGrid(gridId, out var grid))
|
oldNode?.RemoveEntity(moveEvent.Sender);
|
||||||
{
|
newNode?.AddEntity(moveEvent.Sender, physics, EntityManager);
|
||||||
var newNode = GetNode(grid.GetTileRef(moveEvent.OldPosition));
|
|
||||||
newNode.AddEntity(moveEvent.Sender, physics, EntityManager);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Need to rethink the pathfinder utils (traversable etc.). Maybe just chuck them all in PathfindingSystem
|
// TODO: Need to rethink the pathfinder utils (traversable etc.). Maybe just chuck them all in PathfindingSystem
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ namespace Content.Server.Disposal.Tube
|
|||||||
private static void BodyTypeChanged(
|
private static void BodyTypeChanged(
|
||||||
EntityUid uid,
|
EntityUid uid,
|
||||||
DisposalTubeComponent component,
|
DisposalTubeComponent component,
|
||||||
PhysicsBodyTypeChangedEvent args)
|
ref PhysicsBodyTypeChangedEvent args)
|
||||||
{
|
{
|
||||||
component.AnchoredChanged();
|
component.AnchoredChanged();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace Content.Server.ParticleAccelerator.EntitySystems
|
|||||||
private static void BodyTypeChanged(
|
private static void BodyTypeChanged(
|
||||||
EntityUid uid,
|
EntityUid uid,
|
||||||
ParticleAcceleratorPartComponent component,
|
ParticleAcceleratorPartComponent component,
|
||||||
PhysicsBodyTypeChangedEvent args)
|
ref PhysicsBodyTypeChangedEvent args)
|
||||||
{
|
{
|
||||||
component.OnAnchorChanged();
|
component.OnAnchorChanged();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace Content.Server.Singularity.EntitySystems
|
|||||||
private static void BodyTypeChanged(
|
private static void BodyTypeChanged(
|
||||||
EntityUid uid,
|
EntityUid uid,
|
||||||
ContainmentFieldGeneratorComponent component,
|
ContainmentFieldGeneratorComponent component,
|
||||||
PhysicsBodyTypeChangedEvent args)
|
ref PhysicsBodyTypeChangedEvent args)
|
||||||
{
|
{
|
||||||
component.OnAnchoredChanged();
|
component.OnAnchoredChanged();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
id: SimpleSpaceMobBase # Mob without barotrauma, freezing and asphyxiation (for space carps!?)
|
id: SimpleSpaceMobBase # Mob without barotrauma, freezing and asphyxiation (for space carps!?)
|
||||||
suffix: AI
|
suffix: AI
|
||||||
components:
|
components:
|
||||||
|
- type: Tag
|
||||||
|
tags:
|
||||||
|
- DoorBumpOpener
|
||||||
- type: Reactive
|
- type: Reactive
|
||||||
groups:
|
groups:
|
||||||
Flammable: [Touch]
|
Flammable: [Touch]
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
fixtures:
|
fixtures:
|
||||||
- shape:
|
- shape:
|
||||||
!type:PhysShapeCircle
|
!type:PhysShapeCircle
|
||||||
radius: 0.35
|
radius: 0.25
|
||||||
mass: 120
|
mass: 120
|
||||||
mask:
|
mask:
|
||||||
- MobMask
|
- MobMask
|
||||||
@@ -88,6 +88,8 @@
|
|||||||
- type: Tag
|
- type: Tag
|
||||||
tags:
|
tags:
|
||||||
- CannotSuicide
|
- CannotSuicide
|
||||||
|
- DoorBumpOpener
|
||||||
|
- FootstepSound
|
||||||
- type: NoSlip
|
- type: NoSlip
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
|
|||||||
Reference in New Issue
Block a user