Refactor AI considerations (#1278)
Considerations are now instantiated under a manager and re-used between entities where they pass in their blackboard to get a score back. Also makes the API a bit nicer to use. Also some random cleanup. Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States.Utility;
|
||||
|
||||
namespace Content.Server.AI.Utility.Considerations.State
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple NullCheck on a StoredState
|
||||
/// </summary>
|
||||
public sealed class StoredStateEntityIsNullCon : Consideration
|
||||
{
|
||||
public StoredStateEntityIsNullCon Set(Type type, Blackboard context)
|
||||
{
|
||||
// Ideally we'd just use a variable but then if we were iterating through multiple AI at once it'd be
|
||||
// Stuffed so we need to store it on the AI's context.
|
||||
context.GetState<StoredStateIsNullState>().SetValue(type);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
var stateData = context.GetState<StoredStateIsNullState>().GetValue();
|
||||
return stateData == null ? 1.0f : 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
using Content.Server.AI.Utility.Curves;
|
||||
using Content.Server.AI.WorldState;
|
||||
|
||||
namespace Content.Server.AI.Utility.Considerations.State
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple NullCheck on a StoredState
|
||||
/// </summary>
|
||||
public sealed class StoredStateIsNullCon<T, U> : Consideration where T : StoredStateData<U>
|
||||
{
|
||||
public StoredStateIsNullCon(IResponseCurve curve) : base(curve) {}
|
||||
|
||||
public override float GetScore(Blackboard context)
|
||||
{
|
||||
var state = context.GetState<T>();
|
||||
if (state.GetValue() == null)
|
||||
{
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user