AI preset curves and expandable optimisation (#1346)

* AI preset curves and expandable optimisation

Added preset curves for considerations to use just to avoid repeating the same variables all over the shop.

Moved common considerations for expanded actions onto the expandable action e.g. you need a free hand to be able to PickUpGloves so we'll just check it the once rather than for each action.

* FIX PRAGMA

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2020-08-12 06:01:55 +10:00
committed by GitHub
parent c00a08f504
commit b34bd7c188
43 changed files with 409 additions and 127 deletions

View File

@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using Content.Server.AI.Utility.Actions;
using Content.Server.AI.WorldState;
@@ -12,6 +13,37 @@ namespace Content.Server.AI.Utility.ExpandableActions
{
public abstract float Bonus { get; }
/// <summary>
/// No point expanding nodes if none of them can ever be valid.
/// Fails if any of the common considerations is 0.0f (i.e. invalid)
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public bool IsValid(Blackboard context)
{
foreach (var con in GetCommonConsiderations(context))
{
// ReSharper disable once CompareOfFloatsByEqualityOperator
if (con.Invoke() == 0.0f) return false;
}
return true;
}
/// <summary>
/// Called by IsValid to try and early-out the expandable action.
/// No point going through all nearby clothes if we can't fit it in a slot.
/// </summary>
/// Similar to HTN's compound tasks where they can have overall conditions that have to be met before the actions are considered.
/// Ideally any binary early-outs that are common to all expanded actions would be checked once, e.g. a boolean free hand check
/// Use this if you want to optimise the expandable further.
/// <param name="context"></param>
/// <returns></returns>
protected virtual IEnumerable<Func<float>> GetCommonConsiderations(Blackboard context)
{
yield break;
}
// e.g. you may have a "PickupFood" action for all nearby food sources if you have the "Hungry" BehaviorSet.
public abstract IEnumerable<UtilityAction> GetActions(Blackboard context);
}