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:
@@ -3,11 +3,9 @@ using System.Collections.Generic;
|
||||
using Content.Server.AI.Operators;
|
||||
using Content.Server.AI.Operators.Inventory;
|
||||
using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Clothing;
|
||||
using Content.Server.AI.Utility.Considerations.Inventory;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
@@ -44,9 +42,7 @@ namespace Content.Server.AI.Utility.Actions.Clothing.Gloves
|
||||
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<ClothingInSlotCon>().Slot(EquipmentSlotDefines.Slots.GLOVES, context)
|
||||
.InverseBoolCurve(context),
|
||||
considerationsManager.Get<CanPutTargetInHandsCon>()
|
||||
considerationsManager.Get<CanPutTargetInInventoryCon>()
|
||||
.BoolCurve(context),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Clothing;
|
||||
using Content.Server.AI.Utility.Considerations.Containers;
|
||||
using Content.Server.AI.Utility.Considerations.Inventory;
|
||||
using Content.Server.AI.Utility.Considerations.Movement;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
@@ -40,13 +41,11 @@ namespace Content.Server.AI.Utility.Actions.Clothing.Gloves
|
||||
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<ClothingInSlotCon>().Slot(EquipmentSlotDefines.Slots.GLOVES, context)
|
||||
.InverseBoolCurve(context),
|
||||
considerationsManager.Get<CanPutTargetInHandsCon>()
|
||||
considerationsManager.Get<CanPutTargetInInventoryCon>()
|
||||
.BoolCurve(context),
|
||||
considerationsManager.Get<ClothingInInventoryCon>().Slot(EquipmentSlotDefines.SlotFlags.GLOVES, context)
|
||||
.InverseBoolCurve(context),
|
||||
considerationsManager.Get<TargetAccessibleCon>()
|
||||
considerationsManager.Get<TargetDistanceCon>()
|
||||
.PresetCurve(context, PresetCurve.Distance),
|
||||
considerationsManager.Get<TargetAccessibleCon>()
|
||||
.BoolCurve(context),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -44,9 +44,7 @@ namespace Content.Server.AI.Utility.Actions.Clothing.Head
|
||||
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<ClothingInSlotCon>().Slot(EquipmentSlotDefines.Slots.HEAD, context)
|
||||
.InverseBoolCurve(context),
|
||||
considerationsManager.Get<CanPutTargetInHandsCon>()
|
||||
considerationsManager.Get<CanPutTargetInInventoryCon>()
|
||||
.BoolCurve(context),
|
||||
};
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Clothing;
|
||||
using Content.Server.AI.Utility.Considerations.Containers;
|
||||
using Content.Server.AI.Utility.Considerations.Inventory;
|
||||
using Content.Server.AI.Utility.Considerations.Movement;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
@@ -40,13 +41,11 @@ namespace Content.Server.AI.Utility.Actions.Clothing.Head
|
||||
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<ClothingInSlotCon>().Slot(EquipmentSlotDefines.Slots.HEAD, context)
|
||||
.InverseBoolCurve(context),
|
||||
considerationsManager.Get<CanPutTargetInHandsCon>()
|
||||
considerationsManager.Get<CanPutTargetInInventoryCon>()
|
||||
.BoolCurve(context),
|
||||
considerationsManager.Get<ClothingInInventoryCon>().Slot(EquipmentSlotDefines.SlotFlags.HEAD, context)
|
||||
.InverseBoolCurve(context),
|
||||
considerationsManager.Get<TargetAccessibleCon>()
|
||||
considerationsManager.Get<TargetDistanceCon>()
|
||||
.PresetCurve(context, PresetCurve.Distance),
|
||||
considerationsManager.Get<TargetAccessibleCon>()
|
||||
.BoolCurve(context),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -44,9 +44,7 @@ namespace Content.Server.AI.Utility.Actions.Clothing.OuterClothing
|
||||
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<ClothingInSlotCon>().Slot(EquipmentSlotDefines.Slots.OUTERCLOTHING, context)
|
||||
.InverseBoolCurve(context),
|
||||
considerationsManager.Get<CanPutTargetInHandsCon>()
|
||||
considerationsManager.Get<CanPutTargetInInventoryCon>()
|
||||
.BoolCurve(context),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Clothing;
|
||||
using Content.Server.AI.Utility.Considerations.Containers;
|
||||
using Content.Server.AI.Utility.Considerations.Inventory;
|
||||
using Content.Server.AI.Utility.Considerations.Movement;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
@@ -40,12 +41,10 @@ namespace Content.Server.AI.Utility.Actions.Clothing.OuterClothing
|
||||
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<ClothingInSlotCon>().Slot(EquipmentSlotDefines.Slots.OUTERCLOTHING, context)
|
||||
.InverseBoolCurve(context),
|
||||
considerationsManager.Get<CanPutTargetInHandsCon>()
|
||||
considerationsManager.Get<CanPutTargetInInventoryCon>()
|
||||
.BoolCurve(context),
|
||||
considerationsManager.Get<ClothingInInventoryCon>().Slot(EquipmentSlotDefines.SlotFlags.OUTERCLOTHING, context)
|
||||
.InverseBoolCurve(context),
|
||||
considerationsManager.Get<TargetDistanceCon>()
|
||||
.PresetCurve(context, PresetCurve.Distance),
|
||||
considerationsManager.Get<TargetAccessibleCon>()
|
||||
.BoolCurve(context),
|
||||
};
|
||||
|
||||
@@ -44,9 +44,7 @@ namespace Content.Server.AI.Utility.Actions.Clothing.Shoes
|
||||
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<ClothingInSlotCon>().Slot(EquipmentSlotDefines.Slots.SHOES, context)
|
||||
.InverseBoolCurve(context),
|
||||
considerationsManager.Get<CanPutTargetInHandsCon>()
|
||||
considerationsManager.Get<CanPutTargetInInventoryCon>()
|
||||
.BoolCurve(context),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Clothing;
|
||||
using Content.Server.AI.Utility.Considerations.Containers;
|
||||
using Content.Server.AI.Utility.Considerations.Inventory;
|
||||
using Content.Server.AI.Utility.Considerations.Movement;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
@@ -40,12 +41,10 @@ namespace Content.Server.AI.Utility.Actions.Clothing.Shoes
|
||||
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<ClothingInSlotCon>().Slot(EquipmentSlotDefines.Slots.SHOES, context)
|
||||
.InverseBoolCurve(context),
|
||||
considerationsManager.Get<CanPutTargetInHandsCon>()
|
||||
considerationsManager.Get<CanPutTargetInInventoryCon>()
|
||||
.BoolCurve(context),
|
||||
considerationsManager.Get<ClothingInInventoryCon>().Slot(EquipmentSlotDefines.SlotFlags.SHOES, context)
|
||||
.InverseBoolCurve(context),
|
||||
considerationsManager.Get<TargetDistanceCon>()
|
||||
.PresetCurve(context, PresetCurve.Distance),
|
||||
considerationsManager.Get<TargetAccessibleCon>()
|
||||
.BoolCurve(context),
|
||||
};
|
||||
|
||||
@@ -44,9 +44,7 @@ namespace Content.Server.AI.Utility.Actions.Combat.Melee
|
||||
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<MeleeWeaponEquippedCon>()
|
||||
.InverseBoolCurve(context),
|
||||
considerationsManager.Get<CanPutTargetInHandsCon>()
|
||||
considerationsManager.Get<CanPutTargetInInventoryCon>()
|
||||
.BoolCurve(context),
|
||||
considerationsManager.Get<MeleeWeaponSpeedCon>()
|
||||
.QuadraticCurve(context, 1.0f, 0.5f, 0.0f, 0.0f),
|
||||
|
||||
@@ -66,16 +66,14 @@ namespace Content.Server.AI.Utility.Actions.Combat.Melee
|
||||
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<MeleeWeaponEquippedCon>()
|
||||
.BoolCurve(context),
|
||||
considerationsManager.Get<TargetIsDeadCon>()
|
||||
.InverseBoolCurve(context),
|
||||
considerationsManager.Get<TargetIsCritCon>()
|
||||
.QuadraticCurve(context, -0.8f, 1.0f, 1.0f, 0.0f),
|
||||
considerationsManager.Get<DistanceCon>()
|
||||
.QuadraticCurve(context, 1.0f, 1.0f, 0.02f, 0.0f),
|
||||
considerationsManager.Get<TargetDistanceCon>()
|
||||
.PresetCurve(context, PresetCurve.Distance),
|
||||
considerationsManager.Get<TargetHealthCon>()
|
||||
.QuadraticCurve(context, 1.0f, 0.4f, 0.0f, -0.02f),
|
||||
.PresetCurve(context, PresetCurve.TargetHealth),
|
||||
considerationsManager.Get<MeleeWeaponSpeedCon>()
|
||||
.QuadraticCurve(context, 1.0f, 0.5f, 0.0f, 0.0f),
|
||||
considerationsManager.Get<MeleeWeaponDamageCon>()
|
||||
|
||||
@@ -42,12 +42,8 @@ namespace Content.Server.AI.Utility.Actions.Combat.Melee
|
||||
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<FreeHandCon>()
|
||||
.BoolCurve(context),
|
||||
considerationsManager.Get<HasMeleeWeaponCon>()
|
||||
.InverseBoolCurve(context),
|
||||
considerationsManager.Get<DistanceCon>()
|
||||
.QuadraticCurve(context, 1.0f, 1.0f, 0.02f, 0.0f),
|
||||
considerationsManager.Get<TargetDistanceCon>()
|
||||
.PresetCurve(context, PresetCurve.Distance),
|
||||
considerationsManager.Get<MeleeWeaponDamageCon>()
|
||||
.QuadraticCurve(context, 1.0f, 0.25f, 0.0f, 0.0f),
|
||||
considerationsManager.Get<MeleeWeaponSpeedCon>()
|
||||
|
||||
@@ -64,16 +64,14 @@ namespace Content.Server.AI.Utility.Actions.Combat.Melee
|
||||
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<CanUnarmedCombatCon>()
|
||||
.BoolCurve(context),
|
||||
considerationsManager.Get<TargetIsDeadCon>()
|
||||
.InverseBoolCurve(context),
|
||||
considerationsManager.Get<TargetIsCritCon>()
|
||||
.QuadraticCurve(context, -0.8f, 1.0f, 1.0f, 0.0f),
|
||||
considerationsManager.Get<DistanceCon>()
|
||||
.QuadraticCurve(context, -1.0f, 1.0f, 1.02f, 0.0f),
|
||||
considerationsManager.Get<TargetDistanceCon>()
|
||||
.PresetCurve(context, PresetCurve.Distance),
|
||||
considerationsManager.Get<TargetHealthCon>()
|
||||
.QuadraticCurve(context, 1.0f, 0.4f, 0.0f, -0.02f),
|
||||
.PresetCurve(context, PresetCurve.TargetHealth),
|
||||
considerationsManager.Get<TargetAccessibleCon>()
|
||||
.BoolCurve(context),
|
||||
// TODO: Consider our Speed and Damage to compare this to using a weapon
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Content.Server.AI.Utility.Actions.Idle
|
||||
/// </summary>
|
||||
public sealed class CloseLastEntityStorage : UtilityAction
|
||||
{
|
||||
public override float Bonus => 1.5f;
|
||||
public override float Bonus => IdleBonus + 0.01f;
|
||||
|
||||
public CloseLastEntityStorage(IEntity owner) : base(owner) {}
|
||||
|
||||
@@ -50,9 +50,9 @@ namespace Content.Server.AI.Utility.Actions.Idle
|
||||
{
|
||||
considerationsManager.Get<StoredStateEntityIsNullCon>().Set(typeof(LastOpenedStorageState), context)
|
||||
.InverseBoolCurve(context),
|
||||
considerationsManager.Get<DistanceCon>()
|
||||
.QuadraticCurve(context, 1.0f, 1.0f, 0.02f, 0.0f),
|
||||
considerationsManager.Get<TargetAccessibleCon>()
|
||||
considerationsManager.Get<TargetDistanceCon>()
|
||||
.PresetCurve(context, PresetCurve.Distance),
|
||||
considerationsManager.Get<TargetAccessibleCon>()
|
||||
.BoolCurve(context),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -43,9 +43,9 @@ namespace Content.Server.AI.Utility.Actions.Nutrition.Drink
|
||||
considerationsManager.Get<FreeHandCon>()
|
||||
.BoolCurve(context),
|
||||
considerationsManager.Get<ThirstCon>()
|
||||
.LogisticCurve(context, 1000f, 1.3f, -1.0f, 0.5f),
|
||||
considerationsManager.Get<DistanceCon>()
|
||||
.QuadraticCurve(context, 1.0f, 1.0f, 0.02f, 0.0f),
|
||||
.PresetCurve(context, PresetCurve.Nutrition),
|
||||
considerationsManager.Get<TargetDistanceCon>()
|
||||
.PresetCurve(context, PresetCurve.Distance),
|
||||
considerationsManager.Get<DrinkValueCon>()
|
||||
.QuadraticCurve(context, 1.0f, 0.4f, 0.0f, 0.0f),
|
||||
considerationsManager.Get<TargetAccessibleCon>()
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using Content.Server.AI.Operators;
|
||||
using Content.Server.AI.Operators.Inventory;
|
||||
using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Hands;
|
||||
using Content.Server.AI.Utility.Considerations.Inventory;
|
||||
using Content.Server.AI.Utility.Considerations.Nutrition.Drink;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
@@ -43,10 +43,8 @@ namespace Content.Server.AI.Utility.Actions.Nutrition.Drink
|
||||
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<TargetInOurHandsCon>()
|
||||
considerationsManager.Get<TargetInOurInventoryCon>()
|
||||
.BoolCurve(context),
|
||||
considerationsManager.Get<ThirstCon>()
|
||||
.LogisticCurve(context, 1000f, 1.3f, -0.3f, 0.5f),
|
||||
considerationsManager.Get<DrinkValueCon>()
|
||||
.QuadraticCurve(context, 1.0f, 0.4f, 0.0f, 0.0f),
|
||||
};
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using Content.Server.AI.Operators.Sequences;
|
||||
using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Containers;
|
||||
using Content.Server.AI.Utility.Considerations.Hands;
|
||||
using Content.Server.AI.Utility.Considerations.Movement;
|
||||
using Content.Server.AI.Utility.Considerations.Nutrition.Food;
|
||||
using Content.Server.AI.WorldState;
|
||||
@@ -40,12 +39,8 @@ namespace Content.Server.AI.Utility.Actions.Nutrition.Food
|
||||
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<FreeHandCon>()
|
||||
.BoolCurve(context),
|
||||
considerationsManager.Get<HungerCon>()
|
||||
.LogisticCurve(context, 1000f, 1.3f, -1.0f, 0.5f),
|
||||
considerationsManager.Get<DistanceCon>()
|
||||
.QuadraticCurve(context, 1.0f, 1.0f, 0.02f, 0.0f),
|
||||
considerationsManager.Get<TargetDistanceCon>()
|
||||
.PresetCurve(context, PresetCurve.Distance),
|
||||
considerationsManager.Get<FoodValueCon>()
|
||||
.QuadraticCurve(context, 1.0f, 0.4f, 0.0f, 0.0f),
|
||||
considerationsManager.Get<TargetAccessibleCon>()
|
||||
|
||||
@@ -3,8 +3,7 @@ using System.Collections.Generic;
|
||||
using Content.Server.AI.Operators;
|
||||
using Content.Server.AI.Operators.Inventory;
|
||||
using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Containers;
|
||||
using Content.Server.AI.Utility.Considerations.Hands;
|
||||
using Content.Server.AI.Utility.Considerations.Inventory;
|
||||
using Content.Server.AI.Utility.Considerations.Nutrition.Food;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
@@ -44,13 +43,10 @@ namespace Content.Server.AI.Utility.Actions.Nutrition.Food
|
||||
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<TargetInOurHandsCon>()
|
||||
considerationsManager.Get<TargetInOurInventoryCon>()
|
||||
.BoolCurve(context),
|
||||
considerationsManager.Get<HungerCon>()
|
||||
.LogisticCurve(context, 1000f, 1.3f, -0.3f, 0.5f),
|
||||
considerationsManager.Get<FoodValueCon>()
|
||||
.QuadraticCurve(context, 1.0f, 0.4f, 0.0f, 0.0f),
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +106,6 @@ namespace Content.Server.AI.Utility.Actions
|
||||
/// This is where the magic happens
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <param name="bonus"></param>
|
||||
/// <param name="min"></param>
|
||||
/// <returns></returns>
|
||||
public float GetScore(Blackboard context, float min)
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Content.Server.AI.Utility.BehaviorSets
|
||||
Actions = new IAiUtility[]
|
||||
{
|
||||
new PickUpNearbyDrinkExp(),
|
||||
new UseDrinkInHandsExp(),
|
||||
new UseDrinkInInventoryExp(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States.Utility;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Content.Server.AI.Utility.Considerations
|
||||
{
|
||||
@@ -18,50 +19,114 @@ namespace Content.Server.AI.Utility.Considerations
|
||||
return Math.Clamp(adjustedScore, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
[Pure]
|
||||
private static float BoolCurve(float x)
|
||||
{
|
||||
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
||||
return x == 1.0f ? 1.0f : 0.0f;
|
||||
}
|
||||
|
||||
public Func<float> BoolCurve(Blackboard context)
|
||||
{
|
||||
float Result()
|
||||
{
|
||||
var adjustedScore = GetAdjustedScore(context);
|
||||
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
||||
return adjustedScore == 1.0f ? 1.0f : 0.0f;
|
||||
return BoolCurve(adjustedScore);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
[Pure]
|
||||
private static float InverseBoolCurve(float x)
|
||||
{
|
||||
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
||||
return x == 1.0f ? 0.0f : 1.0f;
|
||||
}
|
||||
|
||||
public Func<float> InverseBoolCurve(Blackboard context)
|
||||
{
|
||||
float Result()
|
||||
{
|
||||
var adjustedScore = GetAdjustedScore(context);
|
||||
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
||||
return adjustedScore == 1.0f ? 0.0f : 1.0f;
|
||||
return InverseBoolCurve(adjustedScore);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
[Pure]
|
||||
private static float LogisticCurve(float x, float slope, float exponent, float yOffset, float xOffset)
|
||||
{
|
||||
return Math.Clamp(
|
||||
exponent * (1 / (1 + (float) Math.Pow(Math.Log(1000) * slope, -1 * x + xOffset))) + yOffset, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
public Func<float> LogisticCurve(Blackboard context, float slope, float exponent, float yOffset, float xOffset)
|
||||
{
|
||||
float Result()
|
||||
{
|
||||
var adjustedScore = GetAdjustedScore(context);
|
||||
return Math.Clamp(exponent * (1 / (1 + (float) Math.Pow(Math.Log(1000) * slope, -1 * adjustedScore + xOffset))) + yOffset, 0.0f, 1.0f);
|
||||
return LogisticCurve(adjustedScore, slope, exponent, yOffset, xOffset);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
[Pure]
|
||||
private static float QuadraticCurve(float x, float slope, float exponent, float yOffset, float xOffset)
|
||||
{
|
||||
return Math.Clamp(slope * (float) Math.Pow(x - xOffset, exponent) + yOffset, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
public Func<float> QuadraticCurve(Blackboard context, float slope, float exponent, float yOffset, float xOffset)
|
||||
{
|
||||
float Result()
|
||||
{
|
||||
var adjustedScore = GetAdjustedScore(context);
|
||||
return Math.Clamp(slope * (float) Math.Pow(adjustedScore - xOffset, exponent) + yOffset, 0.0f, 1.0f);
|
||||
return QuadraticCurve(adjustedScore, slope, exponent, yOffset, xOffset);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For any curves that are re-used across actions so you only need to update it once.
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <param name="preset"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentOutOfRangeException"></exception>
|
||||
public Func<float> PresetCurve(Blackboard context, PresetCurve preset)
|
||||
{
|
||||
float Result()
|
||||
{
|
||||
var adjustedScore = GetAdjustedScore(context);
|
||||
|
||||
switch (preset)
|
||||
{
|
||||
case Considerations.PresetCurve.Distance:
|
||||
return QuadraticCurve(adjustedScore, -1.0f, 1.0f, 1.0f, 0.02f);
|
||||
case Considerations.PresetCurve.Nutrition:
|
||||
return QuadraticCurve(adjustedScore, 2.0f, 1.0f, -1.0f, -0.2f);
|
||||
case Considerations.PresetCurve.TargetHealth:
|
||||
return QuadraticCurve(adjustedScore, 1.0f, 0.4f, 0.0f, -0.02f);
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(preset), preset, null);
|
||||
}
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Preset response curves for considerations
|
||||
/// </summary>
|
||||
public enum PresetCurve
|
||||
{
|
||||
Distance,
|
||||
Nutrition,
|
||||
TargetHealth,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.GameObjects.Components;
|
||||
using Content.Server.GameObjects.Components.GUI;
|
||||
|
||||
namespace Content.Server.AI.Utility.Considerations.Hands
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns 1 if in our hands else 0
|
||||
/// </summary>
|
||||
public sealed class TargetInOurHandsCon : Consideration
|
||||
{
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
var owner = context.GetState<SelfState>().GetValue();
|
||||
var target = context.GetState<TargetEntityState>().GetValue();
|
||||
|
||||
if (target == null ||
|
||||
!target.HasComponent<ItemComponent>() ||
|
||||
!owner.TryGetComponent(out HandsComponent handsComponent))
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
return handsComponent.IsHolding(target) ? 1.0f : 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ using Content.Server.GameObjects.Components;
|
||||
|
||||
namespace Content.Server.AI.Utility.Considerations.Inventory
|
||||
{
|
||||
public class CanPutTargetInHandsCon : Consideration
|
||||
public class CanPutTargetInInventoryCon : Consideration
|
||||
{
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.AI.WorldState.States.Inventory;
|
||||
using Content.Server.GameObjects;
|
||||
using Content.Server.GameObjects.Components;
|
||||
|
||||
namespace Content.Server.AI.Utility.Considerations.Inventory
|
||||
|
||||
@@ -3,7 +3,7 @@ using Content.Server.AI.WorldState.States;
|
||||
|
||||
namespace Content.Server.AI.Utility.Considerations.Movement
|
||||
{
|
||||
public sealed class DistanceCon : Consideration
|
||||
public sealed class TargetDistanceCon : Consideration
|
||||
{
|
||||
protected override float GetScore(Blackboard context)
|
||||
{
|
||||
@@ -14,8 +14,8 @@ namespace Content.Server.AI.Utility.Considerations.Movement
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
// Kind of just pulled a max distance out of nowhere. Add 0.01 just in case it's reaally far and we have no choice so it'll still be considered at least.
|
||||
return (target.Transform.GridPosition.Position - self.Transform.GridPosition.Position).Length / 100 + 0.01f;
|
||||
// Anything further than 100 tiles gets clamped
|
||||
return (target.Transform.GridPosition.Position - self.Transform.GridPosition.Position).Length / 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,14 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.AI.Utility.Actions;
|
||||
using Content.Server.AI.Utility.Actions.Clothing.Gloves;
|
||||
using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Clothing;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.AI.WorldState.States.Inventory;
|
||||
using Content.Server.GameObjects;
|
||||
using Content.Server.GameObjects.Components.Movement;
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.AI.Utility.ExpandableActions.Clothing.Gloves
|
||||
{
|
||||
@@ -18,6 +20,17 @@ namespace Content.Server.AI.Utility.ExpandableActions.Clothing.Gloves
|
||||
{
|
||||
public override float Bonus => UtilityAction.NormalBonus;
|
||||
|
||||
protected override IEnumerable<Func<float>> GetCommonConsiderations(Blackboard context)
|
||||
{
|
||||
var considerationsManager = IoCManager.Resolve<ConsiderationsManager>();
|
||||
|
||||
return new []
|
||||
{
|
||||
considerationsManager.Get<ClothingInSlotCon>().Slot(EquipmentSlotDefines.Slots.GLOVES, context)
|
||||
.InverseBoolCurve(context),
|
||||
};
|
||||
}
|
||||
|
||||
public override IEnumerable<UtilityAction> GetActions(Blackboard context)
|
||||
{
|
||||
var owner = context.GetState<SelfState>().GetValue();
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.AI.Utility.Actions;
|
||||
using Content.Server.AI.Utility.Actions.Clothing.Gloves;
|
||||
using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Clothing;
|
||||
using Content.Server.AI.Utility.Considerations.Inventory;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.AI.WorldState.States.Clothing;
|
||||
using Content.Server.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.AI.Utility.ExpandableActions.Clothing.Gloves
|
||||
{
|
||||
@@ -13,9 +18,22 @@ namespace Content.Server.AI.Utility.ExpandableActions.Clothing.Gloves
|
||||
{
|
||||
public override float Bonus => UtilityAction.NormalBonus;
|
||||
|
||||
protected override IEnumerable<Func<float>> GetCommonConsiderations(Blackboard context)
|
||||
{
|
||||
var considerationsManager = IoCManager.Resolve<ConsiderationsManager>();
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<ClothingInSlotCon>().Slot(EquipmentSlotDefines.Slots.GLOVES, context)
|
||||
.InverseBoolCurve(context),
|
||||
considerationsManager.Get<ClothingInInventoryCon>().Slot(EquipmentSlotDefines.SlotFlags.GLOVES, context)
|
||||
.InverseBoolCurve(context),
|
||||
};
|
||||
}
|
||||
|
||||
public override IEnumerable<UtilityAction> GetActions(Blackboard context)
|
||||
{
|
||||
var owner = context.GetState<SelfState>().GetValue();
|
||||
|
||||
foreach (var entity in context.GetState<NearbyClothingState>().GetValue())
|
||||
{
|
||||
if (entity.TryGetComponent(out ClothingComponent clothing) &&
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.AI.Utility.Actions;
|
||||
using Content.Server.AI.Utility.Actions.Clothing.Head;
|
||||
using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Clothing;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.AI.WorldState.States.Inventory;
|
||||
using Content.Server.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.AI.Utility.ExpandableActions.Clothing.Head
|
||||
{
|
||||
@@ -16,6 +20,16 @@ namespace Content.Server.AI.Utility.ExpandableActions.Clothing.Head
|
||||
{
|
||||
public override float Bonus => UtilityAction.NormalBonus;
|
||||
|
||||
protected override IEnumerable<Func<float>> GetCommonConsiderations(Blackboard context)
|
||||
{
|
||||
var considerationsManager = IoCManager.Resolve<ConsiderationsManager>();
|
||||
|
||||
return new[] {
|
||||
considerationsManager.Get<ClothingInSlotCon>().Slot(EquipmentSlotDefines.Slots.HEAD, context)
|
||||
.InverseBoolCurve(context),
|
||||
};
|
||||
}
|
||||
|
||||
public override IEnumerable<UtilityAction> GetActions(Blackboard context)
|
||||
{
|
||||
var owner = context.GetState<SelfState>().GetValue();
|
||||
|
||||
@@ -2,12 +2,15 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.AI.Utility.Actions;
|
||||
using Content.Server.AI.Utility.Actions.Clothing.Head;
|
||||
using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Clothing;
|
||||
using Content.Server.AI.Utility.Considerations.Inventory;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.AI.WorldState.States.Clothing;
|
||||
using Content.Server.GameObjects;
|
||||
using Content.Server.GameObjects.Components.Movement;
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.AI.Utility.ExpandableActions.Clothing.Head
|
||||
{
|
||||
@@ -15,6 +18,18 @@ namespace Content.Server.AI.Utility.ExpandableActions.Clothing.Head
|
||||
{
|
||||
public override float Bonus => UtilityAction.NormalBonus;
|
||||
|
||||
protected override IEnumerable<Func<float>> GetCommonConsiderations(Blackboard context)
|
||||
{
|
||||
var considerationsManager = IoCManager.Resolve<ConsiderationsManager>();
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<ClothingInSlotCon>().Slot(EquipmentSlotDefines.Slots.HEAD, context)
|
||||
.InverseBoolCurve(context),
|
||||
considerationsManager.Get<ClothingInInventoryCon>().Slot(EquipmentSlotDefines.SlotFlags.HEAD, context)
|
||||
.InverseBoolCurve(context)
|
||||
};
|
||||
}
|
||||
|
||||
public override IEnumerable<UtilityAction> GetActions(Blackboard context)
|
||||
{
|
||||
var owner = context.GetState<SelfState>().GetValue();
|
||||
|
||||
@@ -2,12 +2,14 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.AI.Utility.Actions;
|
||||
using Content.Server.AI.Utility.Actions.Clothing.OuterClothing;
|
||||
using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Clothing;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.AI.WorldState.States.Inventory;
|
||||
using Content.Server.GameObjects;
|
||||
using Content.Server.GameObjects.Components.Movement;
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.AI.Utility.ExpandableActions.Clothing.OuterClothing
|
||||
{
|
||||
@@ -18,6 +20,17 @@ namespace Content.Server.AI.Utility.ExpandableActions.Clothing.OuterClothing
|
||||
{
|
||||
public override float Bonus => UtilityAction.NormalBonus;
|
||||
|
||||
protected override IEnumerable<Func<float>> GetCommonConsiderations(Blackboard context)
|
||||
{
|
||||
var considerationsManager = IoCManager.Resolve<ConsiderationsManager>();
|
||||
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<ClothingInSlotCon>().Slot(EquipmentSlotDefines.Slots.OUTERCLOTHING, context)
|
||||
.InverseBoolCurve(context),
|
||||
};
|
||||
}
|
||||
|
||||
public override IEnumerable<UtilityAction> GetActions(Blackboard context)
|
||||
{
|
||||
var owner = context.GetState<SelfState>().GetValue();
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.AI.Utility.Actions;
|
||||
using Content.Server.AI.Utility.Actions.Clothing.OuterClothing;
|
||||
using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Clothing;
|
||||
using Content.Server.AI.Utility.Considerations.Inventory;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.AI.WorldState.States.Clothing;
|
||||
using Content.Server.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.AI.Utility.ExpandableActions.Clothing.OuterClothing
|
||||
{
|
||||
@@ -13,6 +18,19 @@ namespace Content.Server.AI.Utility.ExpandableActions.Clothing.OuterClothing
|
||||
{
|
||||
public override float Bonus => UtilityAction.NormalBonus;
|
||||
|
||||
protected override IEnumerable<Func<float>> GetCommonConsiderations(Blackboard context)
|
||||
{
|
||||
var considerationsManager = IoCManager.Resolve<ConsiderationsManager>();
|
||||
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<ClothingInSlotCon>().Slot(EquipmentSlotDefines.Slots.OUTERCLOTHING, context)
|
||||
.InverseBoolCurve(context),
|
||||
considerationsManager.Get<ClothingInInventoryCon>().Slot(EquipmentSlotDefines.SlotFlags.OUTERCLOTHING, context)
|
||||
.InverseBoolCurve(context)
|
||||
};
|
||||
}
|
||||
|
||||
public override IEnumerable<UtilityAction> GetActions(Blackboard context)
|
||||
{
|
||||
var owner = context.GetState<SelfState>().GetValue();
|
||||
|
||||
@@ -2,12 +2,14 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.AI.Utility.Actions;
|
||||
using Content.Server.AI.Utility.Actions.Clothing.Shoes;
|
||||
using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Clothing;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.AI.WorldState.States.Inventory;
|
||||
using Content.Server.GameObjects;
|
||||
using Content.Server.GameObjects.Components.Movement;
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.AI.Utility.ExpandableActions.Clothing.Shoes
|
||||
{
|
||||
@@ -18,6 +20,17 @@ namespace Content.Server.AI.Utility.ExpandableActions.Clothing.Shoes
|
||||
{
|
||||
public override float Bonus => UtilityAction.NormalBonus;
|
||||
|
||||
protected override IEnumerable<Func<float>> GetCommonConsiderations(Blackboard context)
|
||||
{
|
||||
var considerationsManager = IoCManager.Resolve<ConsiderationsManager>();
|
||||
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<ClothingInSlotCon>().Slot(EquipmentSlotDefines.Slots.SHOES, context)
|
||||
.InverseBoolCurve(context),
|
||||
};
|
||||
}
|
||||
|
||||
public override IEnumerable<UtilityAction> GetActions(Blackboard context)
|
||||
{
|
||||
var owner = context.GetState<SelfState>().GetValue();
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.AI.Utility.Actions;
|
||||
using Content.Server.AI.Utility.Actions.Clothing.Shoes;
|
||||
using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Clothing;
|
||||
using Content.Server.AI.Utility.Considerations.Inventory;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.AI.WorldState.States.Clothing;
|
||||
using Content.Server.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.AI.Utility.ExpandableActions.Clothing.Shoes
|
||||
{
|
||||
@@ -13,6 +18,19 @@ namespace Content.Server.AI.Utility.ExpandableActions.Clothing.Shoes
|
||||
{
|
||||
public override float Bonus => UtilityAction.NormalBonus;
|
||||
|
||||
protected override IEnumerable<Func<float>> GetCommonConsiderations(Blackboard context)
|
||||
{
|
||||
var considerationsManager = IoCManager.Resolve<ConsiderationsManager>();
|
||||
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<ClothingInSlotCon>().Slot(EquipmentSlotDefines.Slots.SHOES, context)
|
||||
.InverseBoolCurve(context),
|
||||
considerationsManager.Get<ClothingInInventoryCon>().Slot(EquipmentSlotDefines.SlotFlags.SHOES, context)
|
||||
.InverseBoolCurve(context)
|
||||
};
|
||||
}
|
||||
|
||||
public override IEnumerable<UtilityAction> GetActions(Blackboard context)
|
||||
{
|
||||
var owner = context.GetState<SelfState>().GetValue();
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.AI.Utility.Actions;
|
||||
using Content.Server.AI.Utility.Actions.Combat.Melee;
|
||||
using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Combat.Melee;
|
||||
using Content.Server.AI.Utility.Considerations.Inventory;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.AI.WorldState.States.Inventory;
|
||||
using Content.Server.GameObjects.Components.Weapon.Melee;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.AI.Utility.ExpandableActions.Combat.Melee
|
||||
{
|
||||
@@ -12,6 +17,17 @@ namespace Content.Server.AI.Utility.ExpandableActions.Combat.Melee
|
||||
{
|
||||
public override float Bonus => UtilityAction.CombatPrepBonus;
|
||||
|
||||
protected override IEnumerable<Func<float>> GetCommonConsiderations(Blackboard context)
|
||||
{
|
||||
var considerationsManager = IoCManager.Resolve<ConsiderationsManager>();
|
||||
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<MeleeWeaponEquippedCon>()
|
||||
.InverseBoolCurve(context),
|
||||
};
|
||||
}
|
||||
|
||||
public override IEnumerable<UtilityAction> GetActions(Blackboard context)
|
||||
{
|
||||
var owner = context.GetState<SelfState>().GetValue();
|
||||
|
||||
@@ -2,12 +2,15 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.AI.Utility.Actions;
|
||||
using Content.Server.AI.Utility.Actions.Combat.Melee;
|
||||
using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Combat.Melee;
|
||||
using Content.Server.AI.Utils;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.GameObjects;
|
||||
using Content.Server.GameObjects.Components.Movement;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.AI.Utility.ExpandableActions.Combat.Melee
|
||||
{
|
||||
@@ -15,6 +18,17 @@ namespace Content.Server.AI.Utility.ExpandableActions.Combat.Melee
|
||||
{
|
||||
public override float Bonus => UtilityAction.CombatBonus;
|
||||
|
||||
protected override IEnumerable<Func<float>> GetCommonConsiderations(Blackboard context)
|
||||
{
|
||||
var considerationsManager = IoCManager.Resolve<ConsiderationsManager>();
|
||||
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<MeleeWeaponEquippedCon>()
|
||||
.BoolCurve(context),
|
||||
};
|
||||
}
|
||||
|
||||
public override IEnumerable<UtilityAction> GetActions(Blackboard context)
|
||||
{
|
||||
var owner = context.GetState<SelfState>().GetValue();
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.AI.Utility.Actions;
|
||||
using Content.Server.AI.Utility.Actions.Combat.Melee;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.AI.WorldState.States.Mobs;
|
||||
using Content.Server.GameObjects.Components.Movement;
|
||||
|
||||
namespace Content.Server.AI.Utility.ExpandableActions.Combat.Melee
|
||||
{
|
||||
@@ -14,6 +16,7 @@ namespace Content.Server.AI.Utility.ExpandableActions.Combat.Melee
|
||||
public override IEnumerable<UtilityAction> GetActions(Blackboard context)
|
||||
{
|
||||
var owner = context.GetState<SelfState>().GetValue();
|
||||
|
||||
foreach (var entity in context.GetState<NearbySpeciesState>().GetValue())
|
||||
{
|
||||
yield return new MeleeWeaponAttackEntity(owner, entity, Bonus);
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.AI.Utility.Actions;
|
||||
using Content.Server.AI.Utility.Actions.Combat.Melee;
|
||||
using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Combat.Melee;
|
||||
using Content.Server.AI.Utility.Considerations.Hands;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.AI.WorldState.States.Combat.Nearby;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.AI.Utility.ExpandableActions.Combat.Melee
|
||||
{
|
||||
@@ -11,6 +16,19 @@ namespace Content.Server.AI.Utility.ExpandableActions.Combat.Melee
|
||||
{
|
||||
public override float Bonus => UtilityAction.CombatPrepBonus;
|
||||
|
||||
protected override IEnumerable<Func<float>> GetCommonConsiderations(Blackboard context)
|
||||
{
|
||||
var considerationsManager = IoCManager.Resolve<ConsiderationsManager>();
|
||||
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<FreeHandCon>()
|
||||
.BoolCurve(context),
|
||||
considerationsManager.Get<HasMeleeWeaponCon>()
|
||||
.InverseBoolCurve(context),
|
||||
};
|
||||
}
|
||||
|
||||
public override IEnumerable<UtilityAction> GetActions(Blackboard context)
|
||||
{
|
||||
var owner = context.GetState<SelfState>().GetValue();
|
||||
|
||||
@@ -2,12 +2,15 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.AI.Utility.Actions;
|
||||
using Content.Server.AI.Utility.Actions.Combat.Melee;
|
||||
using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Combat.Melee;
|
||||
using Content.Server.AI.Utils;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.GameObjects;
|
||||
using Content.Server.GameObjects.Components.Movement;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.AI.Utility.ExpandableActions.Combat.Melee
|
||||
{
|
||||
@@ -15,6 +18,17 @@ namespace Content.Server.AI.Utility.ExpandableActions.Combat.Melee
|
||||
{
|
||||
public override float Bonus => UtilityAction.CombatBonus;
|
||||
|
||||
protected override IEnumerable<Func<float>> GetCommonConsiderations(Blackboard context)
|
||||
{
|
||||
var considerationsManager = IoCManager.Resolve<ConsiderationsManager>();
|
||||
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<CanUnarmedCombatCon>()
|
||||
.BoolCurve(context),
|
||||
};
|
||||
}
|
||||
|
||||
public override IEnumerable<UtilityAction> GetActions(Blackboard context)
|
||||
{
|
||||
var owner = context.GetState<SelfState>().GetValue();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.AI.Utility.Actions;
|
||||
using Content.Server.AI.Utility.Actions.Nutrition.Drink;
|
||||
using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Hands;
|
||||
using Content.Server.AI.Utility.Considerations.Nutrition.Drink;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.AI.WorldState.States.Nutrition;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.AI.Utility.ExpandableActions.Nutrition
|
||||
{
|
||||
@@ -11,6 +16,16 @@ namespace Content.Server.AI.Utility.ExpandableActions.Nutrition
|
||||
{
|
||||
public override float Bonus => UtilityAction.NeedsBonus;
|
||||
|
||||
protected override IEnumerable<Func<float>> GetCommonConsiderations(Blackboard context)
|
||||
{
|
||||
var considerationsManager = IoCManager.Resolve<ConsiderationsManager>();
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<ThirstCon>().PresetCurve(context, PresetCurve.Nutrition),
|
||||
considerationsManager.Get<FreeHandCon>().BoolCurve(context),
|
||||
};
|
||||
}
|
||||
|
||||
public override IEnumerable<UtilityAction> GetActions(Blackboard context)
|
||||
{
|
||||
var owner = context.GetState<SelfState>().GetValue();
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.AI.Utility.Actions;
|
||||
using Content.Server.AI.Utility.Actions.Nutrition.Food;
|
||||
using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Hands;
|
||||
using Content.Server.AI.Utility.Considerations.Nutrition.Food;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.AI.WorldState.States.Nutrition;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.AI.Utility.ExpandableActions.Nutrition
|
||||
{
|
||||
@@ -11,6 +16,16 @@ namespace Content.Server.AI.Utility.ExpandableActions.Nutrition
|
||||
{
|
||||
public override float Bonus => UtilityAction.NeedsBonus;
|
||||
|
||||
protected override IEnumerable<Func<float>> GetCommonConsiderations(Blackboard context)
|
||||
{
|
||||
var considerationsManager = IoCManager.Resolve<ConsiderationsManager>();
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<HungerCon>().PresetCurve(context, PresetCurve.Nutrition),
|
||||
considerationsManager.Get<FreeHandCon>().BoolCurve(context),
|
||||
};
|
||||
}
|
||||
|
||||
public override IEnumerable<UtilityAction> GetActions(Blackboard context)
|
||||
{
|
||||
var owner = context.GetState<SelfState>().GetValue();
|
||||
|
||||
@@ -1,17 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.AI.Utility.Actions;
|
||||
using Content.Server.AI.Utility.Actions.Nutrition.Drink;
|
||||
using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Nutrition.Drink;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.AI.WorldState.States.Inventory;
|
||||
using Content.Server.GameObjects.Components.Nutrition;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.AI.Utility.ExpandableActions.Nutrition
|
||||
{
|
||||
public sealed class UseDrinkInHandsExp : ExpandableUtilityAction
|
||||
public sealed class UseDrinkInInventoryExp : ExpandableUtilityAction
|
||||
{
|
||||
public override float Bonus => UtilityAction.NeedsBonus;
|
||||
|
||||
protected override IEnumerable<Func<float>> GetCommonConsiderations(Blackboard context)
|
||||
{
|
||||
var considerationsManager = IoCManager.Resolve<ConsiderationsManager>();
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<ThirstCon>().PresetCurve(context, PresetCurve.Nutrition)
|
||||
};
|
||||
}
|
||||
|
||||
public override IEnumerable<UtilityAction> GetActions(Blackboard context)
|
||||
{
|
||||
var owner = context.GetState<SelfState>().GetValue();
|
||||
@@ -1,10 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.AI.Utility.Actions;
|
||||
using Content.Server.AI.Utility.Actions.Nutrition.Food;
|
||||
using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Nutrition.Food;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.AI.WorldState.States.Inventory;
|
||||
using Content.Server.GameObjects.Components.Nutrition;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.AI.Utility.ExpandableActions.Nutrition
|
||||
{
|
||||
@@ -12,6 +16,15 @@ namespace Content.Server.AI.Utility.ExpandableActions.Nutrition
|
||||
{
|
||||
public override float Bonus => UtilityAction.NeedsBonus;
|
||||
|
||||
protected override IEnumerable<Func<float>> GetCommonConsiderations(Blackboard context)
|
||||
{
|
||||
var considerationsManager = IoCManager.Resolve<ConsiderationsManager>();
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<HungerCon>().PresetCurve(context, PresetCurve.Nutrition)
|
||||
};
|
||||
}
|
||||
|
||||
public override IEnumerable<UtilityAction> GetActions(Blackboard context)
|
||||
{
|
||||
var owner = context.GetState<SelfState>().GetValue();
|
||||
|
||||
@@ -79,6 +79,11 @@ namespace Content.Server.GameObjects.EntitySystems.AI.LoadBalancer
|
||||
switch (action)
|
||||
{
|
||||
case ExpandableUtilityAction expandableUtilityAction:
|
||||
if (!expandableUtilityAction.IsValid(_request.Context))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
foreach (var expanded in expandableUtilityAction.GetActions(_request.Context))
|
||||
{
|
||||
actions.Push(expanded);
|
||||
@@ -86,7 +91,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.LoadBalancer
|
||||
break;
|
||||
case UtilityAction utilityAction:
|
||||
consideredTaskCount++;
|
||||
var bonus = (float) utilityAction.Bonus;
|
||||
var bonus = utilityAction.Bonus;
|
||||
|
||||
if (bonus < cutoff)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user