2021-06-27 05:40:03 +02:00
|
|
|
using System;
|
2020-06-18 22:52:44 +10:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.AI.Components;
|
2020-06-18 22:52:44 +10:00
|
|
|
using Content.Shared.Physics;
|
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
using Robust.Shared.Map;
|
|
|
|
|
using Robust.Shared.Maths;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.Physics;
|
2021-03-08 04:09:59 +11:00
|
|
|
using Robust.Shared.Physics.Broadphase;
|
2020-06-18 22:52:44 +10:00
|
|
|
|
|
|
|
|
namespace Content.Server.AI.Utils
|
|
|
|
|
{
|
|
|
|
|
public static class Visibility
|
|
|
|
|
{
|
|
|
|
|
// Should this be in robust or something? Fark it
|
2020-09-06 16:11:53 +02:00
|
|
|
public static IEnumerable<IEntity> GetNearestEntities(EntityCoordinates grid, Type component, float range)
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
var inRange = GetEntitiesInRange(grid, component, range).ToList();
|
2020-09-06 16:11:53 +02:00
|
|
|
var sortedInRange = inRange.OrderBy(o => (o.Transform.Coordinates.Position - grid.Position).Length);
|
2020-06-18 22:52:44 +10:00
|
|
|
|
|
|
|
|
return sortedInRange;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-06 16:11:53 +02:00
|
|
|
public static IEnumerable<IEntity> GetEntitiesInRange(EntityCoordinates grid, Type component, float range)
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
var entityManager = IoCManager.Resolve<IEntityManager>();
|
2021-09-28 13:35:29 +02:00
|
|
|
foreach (var entity in entityManager.GetAllComponents(component).Select(c => c.Owner))
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
2020-09-06 16:11:53 +02:00
|
|
|
if (entity.Transform.Coordinates.GetGridId(entityManager) != grid.GetGridId(entityManager))
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-06 16:11:53 +02:00
|
|
|
if ((entity.Transform.Coordinates.Position - grid.Position).Length <= range)
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
yield return entity;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|