2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.AI.Pathfinding.Pathfinders;
|
2020-06-18 22:52:44 +10:00
|
|
|
using Content.Shared.AI;
|
|
|
|
|
using JetBrains.Annotations;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.Map;
|
2020-06-18 22:52:44 +10:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.AI.Pathfinding
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
#if DEBUG
|
|
|
|
|
[UsedImplicitly]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class ServerPathfindingDebugSystem : EntitySystem
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
AStarPathfindingJob.DebugRoute += DispatchAStarDebug;
|
|
|
|
|
JpsPathfindingJob.DebugRoute += DispatchJpsDebug;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Shutdown()
|
|
|
|
|
{
|
|
|
|
|
base.Shutdown();
|
|
|
|
|
AStarPathfindingJob.DebugRoute -= DispatchAStarDebug;
|
|
|
|
|
JpsPathfindingJob.DebugRoute -= DispatchJpsDebug;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DispatchAStarDebug(SharedAiDebug.AStarRouteDebug routeDebug)
|
|
|
|
|
{
|
|
|
|
|
var mapManager = IoCManager.Resolve<IMapManager>();
|
|
|
|
|
var route = new List<Vector2>();
|
|
|
|
|
foreach (var tile in routeDebug.Route)
|
|
|
|
|
{
|
|
|
|
|
var tileGrid = mapManager.GetGrid(tile.GridIndex).GridTileToLocal(tile.GridIndices);
|
2020-09-06 16:11:53 +02:00
|
|
|
route.Add(tileGrid.ToMapPos(EntityManager));
|
2020-06-18 22:52:44 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var cameFrom = new Dictionary<Vector2, Vector2>();
|
|
|
|
|
foreach (var (from, to) in routeDebug.CameFrom)
|
|
|
|
|
{
|
|
|
|
|
var tileOneGrid = mapManager.GetGrid(from.GridIndex).GridTileToLocal(from.GridIndices);
|
2020-09-06 16:11:53 +02:00
|
|
|
var tileOneWorld = tileOneGrid.ToMapPos(EntityManager);
|
2020-06-18 22:52:44 +10:00
|
|
|
var tileTwoGrid = mapManager.GetGrid(to.GridIndex).GridTileToLocal(to.GridIndices);
|
2020-09-06 16:11:53 +02:00
|
|
|
var tileTwoWorld = tileTwoGrid.ToMapPos(EntityManager);
|
2021-11-06 11:49:59 +01:00
|
|
|
cameFrom[tileOneWorld] = tileTwoWorld;
|
2020-06-18 22:52:44 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var gScores = new Dictionary<Vector2, float>();
|
|
|
|
|
foreach (var (tile, score) in routeDebug.GScores)
|
|
|
|
|
{
|
|
|
|
|
var tileGrid = mapManager.GetGrid(tile.GridIndex).GridTileToLocal(tile.GridIndices);
|
2021-11-06 11:49:59 +01:00
|
|
|
gScores[tileGrid.ToMapPos(EntityManager)] = score;
|
2020-06-18 22:52:44 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var systemMessage = new SharedAiDebug.AStarRouteMessage(
|
|
|
|
|
routeDebug.EntityUid,
|
|
|
|
|
route,
|
|
|
|
|
cameFrom,
|
|
|
|
|
gScores,
|
|
|
|
|
routeDebug.TimeTaken
|
|
|
|
|
);
|
|
|
|
|
|
2021-04-14 14:12:11 +02:00
|
|
|
RaiseNetworkEvent(systemMessage);
|
2020-06-18 22:52:44 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DispatchJpsDebug(SharedAiDebug.JpsRouteDebug routeDebug)
|
|
|
|
|
{
|
|
|
|
|
var mapManager = IoCManager.Resolve<IMapManager>();
|
|
|
|
|
var route = new List<Vector2>();
|
|
|
|
|
foreach (var tile in routeDebug.Route)
|
|
|
|
|
{
|
|
|
|
|
var tileGrid = mapManager.GetGrid(tile.GridIndex).GridTileToLocal(tile.GridIndices);
|
2020-09-06 16:11:53 +02:00
|
|
|
route.Add(tileGrid.ToMapPos(EntityManager));
|
2020-06-18 22:52:44 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var jumpNodes = new List<Vector2>();
|
|
|
|
|
foreach (var tile in routeDebug.JumpNodes)
|
|
|
|
|
{
|
|
|
|
|
var tileGrid = mapManager.GetGrid(tile.GridIndex).GridTileToLocal(tile.GridIndices);
|
2020-09-06 16:11:53 +02:00
|
|
|
jumpNodes.Add(tileGrid.ToMapPos(EntityManager));
|
2020-06-18 22:52:44 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var systemMessage = new SharedAiDebug.JpsRouteMessage(
|
|
|
|
|
routeDebug.EntityUid,
|
|
|
|
|
route,
|
|
|
|
|
jumpNodes,
|
|
|
|
|
routeDebug.TimeTaken
|
|
|
|
|
);
|
|
|
|
|
|
2021-04-14 14:12:11 +02:00
|
|
|
RaiseNetworkEvent(systemMessage);
|
2020-06-18 22:52:44 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|