Minor AI system fixes (#1292)
* Add test to check all LogicNames in prototypes * Change CreateProcessor to AiLogicProcessor (I thought I'd already done this as I remember PJB telling me to do this but apparently I'm an idiot) * Temporarily remove invalid AiControllers Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
67
Content.IntegrationTests/Tests/AI/AiControllerTest.cs
Normal file
67
Content.IntegrationTests/Tests/AI/AiControllerTest.cs
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
using NUnit.Framework;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
|
using Robust.Shared.Interfaces.Map;
|
||||||
|
using Robust.Shared.Map;
|
||||||
|
using Robust.Shared.Prototypes;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Content.Server.GameObjects.Components.Movement;
|
||||||
|
using Content.Shared.VendingMachines;
|
||||||
|
using Robust.Server.AI;
|
||||||
|
using Robust.Shared.Log;
|
||||||
|
using Robust.Server.Interfaces.Maps;
|
||||||
|
using Robust.Server.Interfaces.Timing;
|
||||||
|
using Robust.Shared.Interfaces.Reflection;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
|
using Robust.Shared.Maths;
|
||||||
|
|
||||||
|
namespace Content.IntegrationTests.Tests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
[TestOf(typeof(AiControllerTest))]
|
||||||
|
public class AiControllerTest : ContentIntegrationTest
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public async Task AiProcessorNamesValidTest()
|
||||||
|
{
|
||||||
|
var server = StartServerDummyTicker();
|
||||||
|
|
||||||
|
server.Assert(() =>
|
||||||
|
{
|
||||||
|
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||||
|
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
||||||
|
var reflectionManager = IoCManager.Resolve<IReflectionManager>();
|
||||||
|
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||||
|
|
||||||
|
mapManager.CreateMap(new MapId(1));
|
||||||
|
var grid = mapManager.CreateGrid(new MapId(1));
|
||||||
|
|
||||||
|
var processorNames = new List<string>();
|
||||||
|
|
||||||
|
// Verify they all have the required attribute
|
||||||
|
foreach (var processor in reflectionManager.GetAllChildren(typeof(AiLogicProcessor)))
|
||||||
|
{
|
||||||
|
var attrib = (AiLogicProcessorAttribute) Attribute.GetCustomAttribute(processor, typeof(AiLogicProcessorAttribute));
|
||||||
|
Assert.That(attrib != null, $"No AiLogicProcessorAttribute found on {processor.Name}");
|
||||||
|
processorNames.Add(attrib.SerializeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var entity in prototypeManager.EnumeratePrototypes<EntityPrototype>())
|
||||||
|
{
|
||||||
|
var comps = entity.Components;
|
||||||
|
|
||||||
|
if (!comps.ContainsKey("AiController")) continue;
|
||||||
|
|
||||||
|
var aiEntity = entityManager.SpawnEntity(entity.ID, new GridCoordinates(new Vector2(0, 0), grid.Index));
|
||||||
|
var aiController = aiEntity.GetComponent<AiControllerComponent>();
|
||||||
|
Assert.That(processorNames.Contains(aiController.LogicName), $"Could not find valid processor named {aiController.LogicName} on entity {entity.ID}");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await server.WaitIdleAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,17 +40,15 @@ namespace Content.Server.GameObjects.EntitySystems.AI
|
|||||||
foreach (var processor in processors)
|
foreach (var processor in processors)
|
||||||
{
|
{
|
||||||
var att = (AiLogicProcessorAttribute)Attribute.GetCustomAttribute(processor, typeof(AiLogicProcessorAttribute));
|
var att = (AiLogicProcessorAttribute)Attribute.GetCustomAttribute(processor, typeof(AiLogicProcessorAttribute));
|
||||||
if (att != null)
|
// Tests should pick this up
|
||||||
{
|
DebugTools.AssertNotNull(att);
|
||||||
_processorTypes.Add(att.SerializeName, processor);
|
_processorTypes.Add(att.SerializeName, processor);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Update(float frameTime)
|
public override void Update(float frameTime)
|
||||||
{
|
{
|
||||||
|
|
||||||
var entities = EntityManager.GetEntities(EntityQuery);
|
var entities = EntityManager.GetEntities(EntityQuery);
|
||||||
foreach (var entity in entities)
|
foreach (var entity in entities)
|
||||||
{
|
{
|
||||||
@@ -77,15 +75,14 @@ namespace Content.Server.GameObjects.EntitySystems.AI
|
|||||||
if (controller.Processor != null) return;
|
if (controller.Processor != null) return;
|
||||||
controller.Processor = CreateProcessor(controller.LogicName);
|
controller.Processor = CreateProcessor(controller.LogicName);
|
||||||
controller.Processor.SelfEntity = controller.Owner;
|
controller.Processor.SelfEntity = controller.Owner;
|
||||||
controller.Processor.VisionRadius = controller.VisionRadius;
|
|
||||||
controller.Processor.Setup();
|
controller.Processor.Setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
private UtilityAi CreateProcessor(string name)
|
private AiLogicProcessor CreateProcessor(string name)
|
||||||
{
|
{
|
||||||
if (_processorTypes.TryGetValue(name, out var type))
|
if (_processorTypes.TryGetValue(name, out var type))
|
||||||
{
|
{
|
||||||
return (UtilityAi)_typeFactory.CreateInstance(type);
|
return (AiLogicProcessor)_typeFactory.CreateInstance(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
// processor needs to inherit AiLogicProcessor, and needs an AiLogicProcessorAttribute to define the YAML name
|
// processor needs to inherit AiLogicProcessor, and needs an AiLogicProcessorAttribute to define the YAML name
|
||||||
|
|||||||
@@ -19,9 +19,6 @@
|
|||||||
drawdepth: WallMountedItems
|
drawdepth: WallMountedItems
|
||||||
texture: Buildings/TurrTop.png
|
texture: Buildings/TurrTop.png
|
||||||
directional: false
|
directional: false
|
||||||
- type: AiController
|
|
||||||
logic: AimShootLife
|
|
||||||
vision: 6.0
|
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: TurretTopLight
|
id: TurretTopLight
|
||||||
@@ -34,9 +31,6 @@
|
|||||||
drawdepth: WallMountedItems
|
drawdepth: WallMountedItems
|
||||||
texture: Buildings/TurrLamp.png
|
texture: Buildings/TurrLamp.png
|
||||||
directional: false
|
directional: false
|
||||||
- type: AiController
|
|
||||||
logic: AimShootLife
|
|
||||||
vision: 6.0
|
|
||||||
- type: PointLight
|
- type: PointLight
|
||||||
radius: 512
|
radius: 512
|
||||||
mask: flashlight_mask
|
mask: flashlight_mask
|
||||||
|
|||||||
Reference in New Issue
Block a user