Fix rat pathfinding (#12951)
Fixes https://github.com/space-wizards/space-station-14/issues/12950
This commit is contained in:
@@ -458,10 +458,11 @@ public sealed partial class PathfindingSystem
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// TODO: Inefficient af
|
// TODO: Inefficient af
|
||||||
foreach (var (_, fixture) in fixtures.Fixtures)
|
foreach (var fixture in fixtures.Fixtures.Values)
|
||||||
{
|
{
|
||||||
// Don't need to re-do it.
|
// Don't need to re-do it.
|
||||||
if ((collisionMask & fixture.CollisionMask) == fixture.CollisionMask &&
|
if (!fixture.Hard ||
|
||||||
|
(collisionMask & fixture.CollisionMask) == fixture.CollisionMask &&
|
||||||
(collisionLayer & fixture.CollisionLayer) == fixture.CollisionLayer)
|
(collisionLayer & fixture.CollisionLayer) == fixture.CollisionLayer)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ using Content.Shared.NPC;
|
|||||||
using Robust.Server.Player;
|
using Robust.Server.Player;
|
||||||
using Robust.Shared.Enums;
|
using Robust.Shared.Enums;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
|
using Robust.Shared.Physics;
|
||||||
using Robust.Shared.Physics.Components;
|
using Robust.Shared.Physics.Components;
|
||||||
using Robust.Shared.Physics.Systems;
|
using Robust.Shared.Physics.Systems;
|
||||||
using Robust.Shared.Players;
|
using Robust.Shared.Players;
|
||||||
@@ -43,6 +44,7 @@ namespace Content.Server.NPC.Pathfinding
|
|||||||
[Dependency] private readonly IRobustRandom _random = default!;
|
[Dependency] private readonly IRobustRandom _random = default!;
|
||||||
[Dependency] private readonly DestructibleSystem _destructible = default!;
|
[Dependency] private readonly DestructibleSystem _destructible = default!;
|
||||||
[Dependency] private readonly FixtureSystem _fixtures = default!;
|
[Dependency] private readonly FixtureSystem _fixtures = default!;
|
||||||
|
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||||
|
|
||||||
private ISawmill _sawmill = default!;
|
private ISawmill _sawmill = default!;
|
||||||
|
|
||||||
@@ -239,10 +241,9 @@ namespace Content.Server.NPC.Pathfinding
|
|||||||
var layer = 0;
|
var layer = 0;
|
||||||
var mask = 0;
|
var mask = 0;
|
||||||
|
|
||||||
if (TryComp<PhysicsComponent>(entity, out var body))
|
if (TryComp<FixturesComponent>(entity, out var fixtures))
|
||||||
{
|
{
|
||||||
layer = body.CollisionLayer;
|
(layer, mask) = _physics.GetHardCollision(entity, fixtures);
|
||||||
mask = body.CollisionMask;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var request = new BFSPathRequest(maxRange, limit, start.Coordinates, flags, layer, mask, cancelToken);
|
var request = new BFSPathRequest(maxRange, limit, start.Coordinates, flags, layer, mask, cancelToken);
|
||||||
@@ -386,10 +387,9 @@ namespace Content.Server.NPC.Pathfinding
|
|||||||
var layer = 0;
|
var layer = 0;
|
||||||
var mask = 0;
|
var mask = 0;
|
||||||
|
|
||||||
if (TryComp<PhysicsComponent>(entity, out var body))
|
if (TryComp<FixturesComponent>(entity, out var fixtures))
|
||||||
{
|
{
|
||||||
layer = body.CollisionLayer;
|
(layer, mask) = _physics.GetHardCollision(entity, fixtures);
|
||||||
mask = body.CollisionMask;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AStarPathRequest(start, end, flags, range, layer, mask, cancelToken);
|
return new AStarPathRequest(start, end, flags, range, layer, mask, cancelToken);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using Content.Server.NPC.Pathfinding;
|
|||||||
using Content.Shared.Doors.Components;
|
using Content.Shared.Doors.Components;
|
||||||
using Content.Shared.NPC;
|
using Content.Shared.NPC;
|
||||||
using Content.Shared.Weapons.Melee;
|
using Content.Shared.Weapons.Melee;
|
||||||
|
using Robust.Shared.Physics;
|
||||||
using Robust.Shared.Physics.Components;
|
using Robust.Shared.Physics.Components;
|
||||||
|
|
||||||
namespace Content.Server.NPC.Systems;
|
namespace Content.Server.NPC.Systems;
|
||||||
@@ -35,20 +36,29 @@ public sealed partial class NPCSteeringSystem
|
|||||||
if (poly.Data.IsFreeSpace)
|
if (poly.Data.IsFreeSpace)
|
||||||
return SteeringObstacleStatus.Completed;
|
return SteeringObstacleStatus.Completed;
|
||||||
|
|
||||||
if (!bodyQuery.TryGetComponent(component.Owner, out var body))
|
|
||||||
return SteeringObstacleStatus.Failed;
|
|
||||||
|
|
||||||
// TODO: Store PathFlags on the steering comp
|
// TODO: Store PathFlags on the steering comp
|
||||||
// and be able to re-check it.
|
// and be able to re-check it.
|
||||||
|
|
||||||
|
var layer = 0;
|
||||||
|
var mask = 0;
|
||||||
|
|
||||||
|
if (TryComp<FixturesComponent>(component.Owner, out var manager))
|
||||||
|
{
|
||||||
|
(layer, mask) = _physics.GetHardCollision(component.Owner, manager);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return SteeringObstacleStatus.Failed;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Should cache the fact we're doing this somewhere.
|
// TODO: Should cache the fact we're doing this somewhere.
|
||||||
// See https://github.com/space-wizards/space-station-14/issues/11475
|
// See https://github.com/space-wizards/space-station-14/issues/11475
|
||||||
if ((poly.Data.CollisionLayer & body.CollisionMask) != 0x0 ||
|
if ((poly.Data.CollisionLayer & mask) != 0x0 ||
|
||||||
(poly.Data.CollisionMask & body.CollisionLayer) != 0x0)
|
(poly.Data.CollisionMask & layer) != 0x0)
|
||||||
{
|
{
|
||||||
var obstacleEnts = new List<EntityUid>();
|
var obstacleEnts = new List<EntityUid>();
|
||||||
|
|
||||||
GetObstacleEntities(poly, body.CollisionMask, body.CollisionLayer, bodyQuery, obstacleEnts);
|
GetObstacleEntities(poly, mask, layer, bodyQuery, obstacleEnts);
|
||||||
var isDoor = (poly.Data.Flags & PathfindingBreadcrumbFlag.Door) != 0x0;
|
var isDoor = (poly.Data.Flags & PathfindingBreadcrumbFlag.Door) != 0x0;
|
||||||
var isAccess = (poly.Data.Flags & PathfindingBreadcrumbFlag.Access) != 0x0;
|
var isAccess = (poly.Data.Flags & PathfindingBreadcrumbFlag.Access) != 0x0;
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ namespace Content.Server.NPC.Systems
|
|||||||
[Dependency] private readonly SharedInteractionSystem _interaction = default!;
|
[Dependency] private readonly SharedInteractionSystem _interaction = default!;
|
||||||
[Dependency] private readonly SharedMeleeWeaponSystem _melee = default!;
|
[Dependency] private readonly SharedMeleeWeaponSystem _melee = default!;
|
||||||
[Dependency] private readonly SharedMoverController _mover = default!;
|
[Dependency] private readonly SharedMoverController _mover = default!;
|
||||||
|
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||||
|
|
||||||
// This will likely get moved onto an abstract pathfinding node that specifies the max distance allowed from the coordinate.
|
// This will likely get moved onto an abstract pathfinding node that specifies the max distance allowed from the coordinate.
|
||||||
private const float TileTolerance = 0.40f;
|
private const float TileTolerance = 0.40f;
|
||||||
|
|||||||
Reference in New Issue
Block a user