From b34bd7c188ee404a7945ce001cfb50dce0893489 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Wed, 12 Aug 2020 06:01:55 +1000 Subject: [PATCH] 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 --- .../Actions/Clothing/Gloves/EquipGloves.cs | 6 +- .../Actions/Clothing/Gloves/PickUpGloves.cs | 11 ++- .../Actions/Clothing/Head/EquipHead.cs | 4 +- .../Actions/Clothing/Head/PickUpHead.cs | 11 ++- .../OuterClothing/EquipOuterClothing.cs | 4 +- .../OuterClothing/PickUpOuterClothing.cs | 9 +-- .../Actions/Clothing/Shoes/EquipShoes.cs | 4 +- .../Actions/Clothing/Shoes/PickUpShoes.cs | 9 +-- .../Actions/Combat/Melee/EquipMelee.cs | 4 +- .../Combat/Melee/MeleeWeaponAttackEntity.cs | 8 +- .../Actions/Combat/Melee/PickUpMeleeWeapon.cs | 8 +- .../Combat/Melee/UnarmedAttackEntity.cs | 10 +-- .../Actions/Idle/CloseLastEntityStorage.cs | 10 +-- .../Actions/Nutrition/Drink/PickUpDrink.cs | 6 +- .../Nutrition/Drink/UseDrinkInInventory.cs | 6 +- .../Actions/Nutrition/Food/PickUpFood.cs | 9 +-- .../Nutrition/Food/UseFoodInInventory.cs | 8 +- .../AI/Utility/Actions/UtilityAction.cs | 1 - .../Utility/BehaviorSets/ThirstBehaviorSet.cs | 2 +- .../Utility/Considerations/Consideration.cs | 77 +++++++++++++++++-- .../Hands/TargetInOurHandsCon.cs | 28 ------- ...dsCon.cs => CanPutTargetInInventoryCon.cs} | 2 +- .../Inventory/TargetInOurInventoryCon.cs | 1 + .../{DistanceCon.cs => TargetDistanceCon.cs} | 6 +- .../Clothing/Gloves/EquipAnyGlovesExp.cs | 15 +++- .../Gloves/PickUpAnyNearbyGlovesExp.cs | 18 +++++ .../Clothing/Head/EquipAnyHeadExp.cs | 14 ++++ .../Clothing/Head/PickUpAnyNearbyHeadExp.cs | 17 +++- .../OuterClothing/EquipAnyOuterClothingExp.cs | 15 +++- .../PickUpAnyNearbyOuterClothingExp.cs | 18 +++++ .../Clothing/Shoes/EquipAnyShoesExp.cs | 15 +++- .../Clothing/Shoes/PickUpAnyNearbyShoesExp.cs | 18 +++++ .../Combat/Melee/EquipMeleeExp.cs | 16 ++++ .../Melee/MeleeAttackNearbyPlayerExp.cs | 14 ++++ .../Melee/MeleeAttackNearbySpeciesExp.cs | 3 + .../Combat/Melee/PickUpMeleeWeaponExp.cs | 18 +++++ .../Melee/UnarmedAttackNearbyPlayerExp.cs | 14 ++++ .../ExpandableUtilityAction.cs | 32 ++++++++ .../Nutrition/PickUpNearbyDrinkExp.cs | 15 ++++ .../Nutrition/PickUpNearbyFoodExp.cs | 15 ++++ ...nHandsExp.cs => UseDrinkInInventoryExp.cs} | 15 +++- .../Nutrition/UseFoodInInventoryExp.cs | 13 ++++ .../AI/LoadBalancer/AiActionRequestJob.cs | 7 +- 43 files changed, 409 insertions(+), 127 deletions(-) delete mode 100644 Content.Server/AI/Utility/Considerations/Hands/TargetInOurHandsCon.cs rename Content.Server/AI/Utility/Considerations/Inventory/{CanPutTargetInHandsCon.cs => CanPutTargetInInventoryCon.cs} (94%) rename Content.Server/AI/Utility/Considerations/Movement/{DistanceCon.cs => TargetDistanceCon.cs} (68%) rename Content.Server/AI/Utility/ExpandableActions/Nutrition/{UseDrinkInHandsExp.cs => UseDrinkInInventoryExp.cs} (62%) diff --git a/Content.Server/AI/Utility/Actions/Clothing/Gloves/EquipGloves.cs b/Content.Server/AI/Utility/Actions/Clothing/Gloves/EquipGloves.cs index 96317b6ad2..fcd63a2da6 100644 --- a/Content.Server/AI/Utility/Actions/Clothing/Gloves/EquipGloves.cs +++ b/Content.Server/AI/Utility/Actions/Clothing/Gloves/EquipGloves.cs @@ -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().Slot(EquipmentSlotDefines.Slots.GLOVES, context) - .InverseBoolCurve(context), - considerationsManager.Get() + considerationsManager.Get() .BoolCurve(context), }; } diff --git a/Content.Server/AI/Utility/Actions/Clothing/Gloves/PickUpGloves.cs b/Content.Server/AI/Utility/Actions/Clothing/Gloves/PickUpGloves.cs index 736db66a7f..85df65dbfc 100644 --- a/Content.Server/AI/Utility/Actions/Clothing/Gloves/PickUpGloves.cs +++ b/Content.Server/AI/Utility/Actions/Clothing/Gloves/PickUpGloves.cs @@ -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().Slot(EquipmentSlotDefines.Slots.GLOVES, context) - .InverseBoolCurve(context), - considerationsManager.Get() + considerationsManager.Get() .BoolCurve(context), - considerationsManager.Get().Slot(EquipmentSlotDefines.SlotFlags.GLOVES, context) - .InverseBoolCurve(context), - considerationsManager.Get() + considerationsManager.Get() + .PresetCurve(context, PresetCurve.Distance), + considerationsManager.Get() .BoolCurve(context), }; } diff --git a/Content.Server/AI/Utility/Actions/Clothing/Head/EquipHead.cs b/Content.Server/AI/Utility/Actions/Clothing/Head/EquipHead.cs index 1935416dc7..7bffe3d92d 100644 --- a/Content.Server/AI/Utility/Actions/Clothing/Head/EquipHead.cs +++ b/Content.Server/AI/Utility/Actions/Clothing/Head/EquipHead.cs @@ -44,9 +44,7 @@ namespace Content.Server.AI.Utility.Actions.Clothing.Head return new[] { - considerationsManager.Get().Slot(EquipmentSlotDefines.Slots.HEAD, context) - .InverseBoolCurve(context), - considerationsManager.Get() + considerationsManager.Get() .BoolCurve(context), }; diff --git a/Content.Server/AI/Utility/Actions/Clothing/Head/PickUpHead.cs b/Content.Server/AI/Utility/Actions/Clothing/Head/PickUpHead.cs index 038dd54a6b..ba91121254 100644 --- a/Content.Server/AI/Utility/Actions/Clothing/Head/PickUpHead.cs +++ b/Content.Server/AI/Utility/Actions/Clothing/Head/PickUpHead.cs @@ -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().Slot(EquipmentSlotDefines.Slots.HEAD, context) - .InverseBoolCurve(context), - considerationsManager.Get() + considerationsManager.Get() .BoolCurve(context), - considerationsManager.Get().Slot(EquipmentSlotDefines.SlotFlags.HEAD, context) - .InverseBoolCurve(context), - considerationsManager.Get() + considerationsManager.Get() + .PresetCurve(context, PresetCurve.Distance), + considerationsManager.Get() .BoolCurve(context), }; } diff --git a/Content.Server/AI/Utility/Actions/Clothing/OuterClothing/EquipOuterClothing.cs b/Content.Server/AI/Utility/Actions/Clothing/OuterClothing/EquipOuterClothing.cs index e593098cf5..9955cc49aa 100644 --- a/Content.Server/AI/Utility/Actions/Clothing/OuterClothing/EquipOuterClothing.cs +++ b/Content.Server/AI/Utility/Actions/Clothing/OuterClothing/EquipOuterClothing.cs @@ -44,9 +44,7 @@ namespace Content.Server.AI.Utility.Actions.Clothing.OuterClothing return new[] { - considerationsManager.Get().Slot(EquipmentSlotDefines.Slots.OUTERCLOTHING, context) - .InverseBoolCurve(context), - considerationsManager.Get() + considerationsManager.Get() .BoolCurve(context), }; } diff --git a/Content.Server/AI/Utility/Actions/Clothing/OuterClothing/PickUpOuterClothing.cs b/Content.Server/AI/Utility/Actions/Clothing/OuterClothing/PickUpOuterClothing.cs index 0eb4ff1cbe..22730f3659 100644 --- a/Content.Server/AI/Utility/Actions/Clothing/OuterClothing/PickUpOuterClothing.cs +++ b/Content.Server/AI/Utility/Actions/Clothing/OuterClothing/PickUpOuterClothing.cs @@ -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().Slot(EquipmentSlotDefines.Slots.OUTERCLOTHING, context) - .InverseBoolCurve(context), - considerationsManager.Get() + considerationsManager.Get() .BoolCurve(context), - considerationsManager.Get().Slot(EquipmentSlotDefines.SlotFlags.OUTERCLOTHING, context) - .InverseBoolCurve(context), + considerationsManager.Get() + .PresetCurve(context, PresetCurve.Distance), considerationsManager.Get() .BoolCurve(context), }; diff --git a/Content.Server/AI/Utility/Actions/Clothing/Shoes/EquipShoes.cs b/Content.Server/AI/Utility/Actions/Clothing/Shoes/EquipShoes.cs index fdbc2c78e7..218e218c35 100644 --- a/Content.Server/AI/Utility/Actions/Clothing/Shoes/EquipShoes.cs +++ b/Content.Server/AI/Utility/Actions/Clothing/Shoes/EquipShoes.cs @@ -44,9 +44,7 @@ namespace Content.Server.AI.Utility.Actions.Clothing.Shoes return new[] { - considerationsManager.Get().Slot(EquipmentSlotDefines.Slots.SHOES, context) - .InverseBoolCurve(context), - considerationsManager.Get() + considerationsManager.Get() .BoolCurve(context), }; } diff --git a/Content.Server/AI/Utility/Actions/Clothing/Shoes/PickUpShoes.cs b/Content.Server/AI/Utility/Actions/Clothing/Shoes/PickUpShoes.cs index 94dd05efd4..00cd4b1cd9 100644 --- a/Content.Server/AI/Utility/Actions/Clothing/Shoes/PickUpShoes.cs +++ b/Content.Server/AI/Utility/Actions/Clothing/Shoes/PickUpShoes.cs @@ -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().Slot(EquipmentSlotDefines.Slots.SHOES, context) - .InverseBoolCurve(context), - considerationsManager.Get() + considerationsManager.Get() .BoolCurve(context), - considerationsManager.Get().Slot(EquipmentSlotDefines.SlotFlags.SHOES, context) - .InverseBoolCurve(context), + considerationsManager.Get() + .PresetCurve(context, PresetCurve.Distance), considerationsManager.Get() .BoolCurve(context), }; diff --git a/Content.Server/AI/Utility/Actions/Combat/Melee/EquipMelee.cs b/Content.Server/AI/Utility/Actions/Combat/Melee/EquipMelee.cs index 29bdea8394..ce42bfd6dd 100644 --- a/Content.Server/AI/Utility/Actions/Combat/Melee/EquipMelee.cs +++ b/Content.Server/AI/Utility/Actions/Combat/Melee/EquipMelee.cs @@ -44,9 +44,7 @@ namespace Content.Server.AI.Utility.Actions.Combat.Melee return new[] { - considerationsManager.Get() - .InverseBoolCurve(context), - considerationsManager.Get() + considerationsManager.Get() .BoolCurve(context), considerationsManager.Get() .QuadraticCurve(context, 1.0f, 0.5f, 0.0f, 0.0f), diff --git a/Content.Server/AI/Utility/Actions/Combat/Melee/MeleeWeaponAttackEntity.cs b/Content.Server/AI/Utility/Actions/Combat/Melee/MeleeWeaponAttackEntity.cs index 5b9ce74248..28335ace75 100644 --- a/Content.Server/AI/Utility/Actions/Combat/Melee/MeleeWeaponAttackEntity.cs +++ b/Content.Server/AI/Utility/Actions/Combat/Melee/MeleeWeaponAttackEntity.cs @@ -66,16 +66,14 @@ namespace Content.Server.AI.Utility.Actions.Combat.Melee return new[] { - considerationsManager.Get() - .BoolCurve(context), considerationsManager.Get() .InverseBoolCurve(context), considerationsManager.Get() .QuadraticCurve(context, -0.8f, 1.0f, 1.0f, 0.0f), - considerationsManager.Get() - .QuadraticCurve(context, 1.0f, 1.0f, 0.02f, 0.0f), + considerationsManager.Get() + .PresetCurve(context, PresetCurve.Distance), considerationsManager.Get() - .QuadraticCurve(context, 1.0f, 0.4f, 0.0f, -0.02f), + .PresetCurve(context, PresetCurve.TargetHealth), considerationsManager.Get() .QuadraticCurve(context, 1.0f, 0.5f, 0.0f, 0.0f), considerationsManager.Get() diff --git a/Content.Server/AI/Utility/Actions/Combat/Melee/PickUpMeleeWeapon.cs b/Content.Server/AI/Utility/Actions/Combat/Melee/PickUpMeleeWeapon.cs index 12b502b4dd..708afc240e 100644 --- a/Content.Server/AI/Utility/Actions/Combat/Melee/PickUpMeleeWeapon.cs +++ b/Content.Server/AI/Utility/Actions/Combat/Melee/PickUpMeleeWeapon.cs @@ -42,12 +42,8 @@ namespace Content.Server.AI.Utility.Actions.Combat.Melee return new[] { - considerationsManager.Get() - .BoolCurve(context), - considerationsManager.Get() - .InverseBoolCurve(context), - considerationsManager.Get() - .QuadraticCurve(context, 1.0f, 1.0f, 0.02f, 0.0f), + considerationsManager.Get() + .PresetCurve(context, PresetCurve.Distance), considerationsManager.Get() .QuadraticCurve(context, 1.0f, 0.25f, 0.0f, 0.0f), considerationsManager.Get() diff --git a/Content.Server/AI/Utility/Actions/Combat/Melee/UnarmedAttackEntity.cs b/Content.Server/AI/Utility/Actions/Combat/Melee/UnarmedAttackEntity.cs index d3593cc982..5735b884e7 100644 --- a/Content.Server/AI/Utility/Actions/Combat/Melee/UnarmedAttackEntity.cs +++ b/Content.Server/AI/Utility/Actions/Combat/Melee/UnarmedAttackEntity.cs @@ -64,16 +64,14 @@ namespace Content.Server.AI.Utility.Actions.Combat.Melee return new[] { - considerationsManager.Get() - .BoolCurve(context), considerationsManager.Get() .InverseBoolCurve(context), considerationsManager.Get() .QuadraticCurve(context, -0.8f, 1.0f, 1.0f, 0.0f), - considerationsManager.Get() - .QuadraticCurve(context, -1.0f, 1.0f, 1.02f, 0.0f), + considerationsManager.Get() + .PresetCurve(context, PresetCurve.Distance), considerationsManager.Get() - .QuadraticCurve(context, 1.0f, 0.4f, 0.0f, -0.02f), + .PresetCurve(context, PresetCurve.TargetHealth), considerationsManager.Get() .BoolCurve(context), // TODO: Consider our Speed and Damage to compare this to using a weapon @@ -81,4 +79,4 @@ namespace Content.Server.AI.Utility.Actions.Combat.Melee }; } } -} \ No newline at end of file +} diff --git a/Content.Server/AI/Utility/Actions/Idle/CloseLastEntityStorage.cs b/Content.Server/AI/Utility/Actions/Idle/CloseLastEntityStorage.cs index 4d9fa36f8a..f1ab155f00 100644 --- a/Content.Server/AI/Utility/Actions/Idle/CloseLastEntityStorage.cs +++ b/Content.Server/AI/Utility/Actions/Idle/CloseLastEntityStorage.cs @@ -20,7 +20,7 @@ namespace Content.Server.AI.Utility.Actions.Idle /// 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,12 +50,12 @@ namespace Content.Server.AI.Utility.Actions.Idle { considerationsManager.Get().Set(typeof(LastOpenedStorageState), context) .InverseBoolCurve(context), - considerationsManager.Get() - .QuadraticCurve(context, 1.0f, 1.0f, 0.02f, 0.0f), - considerationsManager.Get() + considerationsManager.Get() + .PresetCurve(context, PresetCurve.Distance), + considerationsManager.Get() .BoolCurve(context), }; } } -} \ No newline at end of file +} diff --git a/Content.Server/AI/Utility/Actions/Nutrition/Drink/PickUpDrink.cs b/Content.Server/AI/Utility/Actions/Nutrition/Drink/PickUpDrink.cs index a7680e6eb8..0549fc1ed7 100644 --- a/Content.Server/AI/Utility/Actions/Nutrition/Drink/PickUpDrink.cs +++ b/Content.Server/AI/Utility/Actions/Nutrition/Drink/PickUpDrink.cs @@ -43,9 +43,9 @@ namespace Content.Server.AI.Utility.Actions.Nutrition.Drink considerationsManager.Get() .BoolCurve(context), considerationsManager.Get() - .LogisticCurve(context, 1000f, 1.3f, -1.0f, 0.5f), - considerationsManager.Get() - .QuadraticCurve(context, 1.0f, 1.0f, 0.02f, 0.0f), + .PresetCurve(context, PresetCurve.Nutrition), + considerationsManager.Get() + .PresetCurve(context, PresetCurve.Distance), considerationsManager.Get() .QuadraticCurve(context, 1.0f, 0.4f, 0.0f, 0.0f), considerationsManager.Get() diff --git a/Content.Server/AI/Utility/Actions/Nutrition/Drink/UseDrinkInInventory.cs b/Content.Server/AI/Utility/Actions/Nutrition/Drink/UseDrinkInInventory.cs index 408addf0d1..f05838ce22 100644 --- a/Content.Server/AI/Utility/Actions/Nutrition/Drink/UseDrinkInInventory.cs +++ b/Content.Server/AI/Utility/Actions/Nutrition/Drink/UseDrinkInInventory.cs @@ -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() + considerationsManager.Get() .BoolCurve(context), - considerationsManager.Get() - .LogisticCurve(context, 1000f, 1.3f, -0.3f, 0.5f), considerationsManager.Get() .QuadraticCurve(context, 1.0f, 0.4f, 0.0f, 0.0f), }; diff --git a/Content.Server/AI/Utility/Actions/Nutrition/Food/PickUpFood.cs b/Content.Server/AI/Utility/Actions/Nutrition/Food/PickUpFood.cs index 840d9c3cab..4c4dd08cfa 100644 --- a/Content.Server/AI/Utility/Actions/Nutrition/Food/PickUpFood.cs +++ b/Content.Server/AI/Utility/Actions/Nutrition/Food/PickUpFood.cs @@ -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() - .BoolCurve(context), - considerationsManager.Get() - .LogisticCurve(context, 1000f, 1.3f, -1.0f, 0.5f), - considerationsManager.Get() - .QuadraticCurve(context, 1.0f, 1.0f, 0.02f, 0.0f), + considerationsManager.Get() + .PresetCurve(context, PresetCurve.Distance), considerationsManager.Get() .QuadraticCurve(context, 1.0f, 0.4f, 0.0f, 0.0f), considerationsManager.Get() diff --git a/Content.Server/AI/Utility/Actions/Nutrition/Food/UseFoodInInventory.cs b/Content.Server/AI/Utility/Actions/Nutrition/Food/UseFoodInInventory.cs index 162d69c29b..6edcbb9c43 100644 --- a/Content.Server/AI/Utility/Actions/Nutrition/Food/UseFoodInInventory.cs +++ b/Content.Server/AI/Utility/Actions/Nutrition/Food/UseFoodInInventory.cs @@ -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() + considerationsManager.Get() .BoolCurve(context), - considerationsManager.Get() - .LogisticCurve(context, 1000f, 1.3f, -0.3f, 0.5f), considerationsManager.Get() .QuadraticCurve(context, 1.0f, 0.4f, 0.0f, 0.0f), - }; } } diff --git a/Content.Server/AI/Utility/Actions/UtilityAction.cs b/Content.Server/AI/Utility/Actions/UtilityAction.cs index 2453750532..f00ee01ddf 100644 --- a/Content.Server/AI/Utility/Actions/UtilityAction.cs +++ b/Content.Server/AI/Utility/Actions/UtilityAction.cs @@ -106,7 +106,6 @@ namespace Content.Server.AI.Utility.Actions /// This is where the magic happens /// /// - /// /// /// public float GetScore(Blackboard context, float min) diff --git a/Content.Server/AI/Utility/BehaviorSets/ThirstBehaviorSet.cs b/Content.Server/AI/Utility/BehaviorSets/ThirstBehaviorSet.cs index 7274d9034f..cc38d1babb 100644 --- a/Content.Server/AI/Utility/BehaviorSets/ThirstBehaviorSet.cs +++ b/Content.Server/AI/Utility/BehaviorSets/ThirstBehaviorSet.cs @@ -11,7 +11,7 @@ namespace Content.Server.AI.Utility.BehaviorSets Actions = new IAiUtility[] { new PickUpNearbyDrinkExp(), - new UseDrinkInHandsExp(), + new UseDrinkInInventoryExp(), }; } } diff --git a/Content.Server/AI/Utility/Considerations/Consideration.cs b/Content.Server/AI/Utility/Considerations/Consideration.cs index 4e49b58cb9..f2f0a9429d 100644 --- a/Content.Server/AI/Utility/Considerations/Consideration.cs +++ b/Content.Server/AI/Utility/Considerations/Consideration.cs @@ -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 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 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 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 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; + } + + /// + /// For any curves that are re-used across actions so you only need to update it once. + /// + /// + /// + /// + /// + public Func 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; } } + + /// + /// Preset response curves for considerations + /// + public enum PresetCurve + { + Distance, + Nutrition, + TargetHealth, + } } diff --git a/Content.Server/AI/Utility/Considerations/Hands/TargetInOurHandsCon.cs b/Content.Server/AI/Utility/Considerations/Hands/TargetInOurHandsCon.cs deleted file mode 100644 index 25df8fc548..0000000000 --- a/Content.Server/AI/Utility/Considerations/Hands/TargetInOurHandsCon.cs +++ /dev/null @@ -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 -{ - /// - /// Returns 1 if in our hands else 0 - /// - public sealed class TargetInOurHandsCon : Consideration - { - protected override float GetScore(Blackboard context) - { - var owner = context.GetState().GetValue(); - var target = context.GetState().GetValue(); - - if (target == null || - !target.HasComponent() || - !owner.TryGetComponent(out HandsComponent handsComponent)) - { - return 0.0f; - } - - return handsComponent.IsHolding(target) ? 1.0f : 0.0f; - } - } -} diff --git a/Content.Server/AI/Utility/Considerations/Inventory/CanPutTargetInHandsCon.cs b/Content.Server/AI/Utility/Considerations/Inventory/CanPutTargetInInventoryCon.cs similarity index 94% rename from Content.Server/AI/Utility/Considerations/Inventory/CanPutTargetInHandsCon.cs rename to Content.Server/AI/Utility/Considerations/Inventory/CanPutTargetInInventoryCon.cs index 7a75efe411..706054cb10 100644 --- a/Content.Server/AI/Utility/Considerations/Inventory/CanPutTargetInHandsCon.cs +++ b/Content.Server/AI/Utility/Considerations/Inventory/CanPutTargetInInventoryCon.cs @@ -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) { diff --git a/Content.Server/AI/Utility/Considerations/Inventory/TargetInOurInventoryCon.cs b/Content.Server/AI/Utility/Considerations/Inventory/TargetInOurInventoryCon.cs index 4d4e1b6970..100f111a7e 100644 --- a/Content.Server/AI/Utility/Considerations/Inventory/TargetInOurInventoryCon.cs +++ b/Content.Server/AI/Utility/Considerations/Inventory/TargetInOurInventoryCon.cs @@ -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 diff --git a/Content.Server/AI/Utility/Considerations/Movement/DistanceCon.cs b/Content.Server/AI/Utility/Considerations/Movement/TargetDistanceCon.cs similarity index 68% rename from Content.Server/AI/Utility/Considerations/Movement/DistanceCon.cs rename to Content.Server/AI/Utility/Considerations/Movement/TargetDistanceCon.cs index 7b099bfcd0..ca63985179 100644 --- a/Content.Server/AI/Utility/Considerations/Movement/DistanceCon.cs +++ b/Content.Server/AI/Utility/Considerations/Movement/TargetDistanceCon.cs @@ -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; } } } diff --git a/Content.Server/AI/Utility/ExpandableActions/Clothing/Gloves/EquipAnyGlovesExp.cs b/Content.Server/AI/Utility/ExpandableActions/Clothing/Gloves/EquipAnyGlovesExp.cs index 4a8e10b0a6..a022113f1b 100644 --- a/Content.Server/AI/Utility/ExpandableActions/Clothing/Gloves/EquipAnyGlovesExp.cs +++ b/Content.Server/AI/Utility/ExpandableActions/Clothing/Gloves/EquipAnyGlovesExp.cs @@ -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> GetCommonConsiderations(Blackboard context) + { + var considerationsManager = IoCManager.Resolve(); + + return new [] + { + considerationsManager.Get().Slot(EquipmentSlotDefines.Slots.GLOVES, context) + .InverseBoolCurve(context), + }; + } + public override IEnumerable GetActions(Blackboard context) { var owner = context.GetState().GetValue(); diff --git a/Content.Server/AI/Utility/ExpandableActions/Clothing/Gloves/PickUpAnyNearbyGlovesExp.cs b/Content.Server/AI/Utility/ExpandableActions/Clothing/Gloves/PickUpAnyNearbyGlovesExp.cs index 7b3f165e4a..50d584aa69 100644 --- a/Content.Server/AI/Utility/ExpandableActions/Clothing/Gloves/PickUpAnyNearbyGlovesExp.cs +++ b/Content.Server/AI/Utility/ExpandableActions/Clothing/Gloves/PickUpAnyNearbyGlovesExp.cs @@ -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> GetCommonConsiderations(Blackboard context) + { + var considerationsManager = IoCManager.Resolve(); + return new[] + { + considerationsManager.Get().Slot(EquipmentSlotDefines.Slots.GLOVES, context) + .InverseBoolCurve(context), + considerationsManager.Get().Slot(EquipmentSlotDefines.SlotFlags.GLOVES, context) + .InverseBoolCurve(context), + }; + } + public override IEnumerable GetActions(Blackboard context) { var owner = context.GetState().GetValue(); + foreach (var entity in context.GetState().GetValue()) { if (entity.TryGetComponent(out ClothingComponent clothing) && diff --git a/Content.Server/AI/Utility/ExpandableActions/Clothing/Head/EquipAnyHeadExp.cs b/Content.Server/AI/Utility/ExpandableActions/Clothing/Head/EquipAnyHeadExp.cs index 9164111d01..a98faf0804 100644 --- a/Content.Server/AI/Utility/ExpandableActions/Clothing/Head/EquipAnyHeadExp.cs +++ b/Content.Server/AI/Utility/ExpandableActions/Clothing/Head/EquipAnyHeadExp.cs @@ -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> GetCommonConsiderations(Blackboard context) + { + var considerationsManager = IoCManager.Resolve(); + + return new[] { + considerationsManager.Get().Slot(EquipmentSlotDefines.Slots.HEAD, context) + .InverseBoolCurve(context), + }; + } + public override IEnumerable GetActions(Blackboard context) { var owner = context.GetState().GetValue(); diff --git a/Content.Server/AI/Utility/ExpandableActions/Clothing/Head/PickUpAnyNearbyHeadExp.cs b/Content.Server/AI/Utility/ExpandableActions/Clothing/Head/PickUpAnyNearbyHeadExp.cs index 85806e99ee..f1e3d0e14f 100644 --- a/Content.Server/AI/Utility/ExpandableActions/Clothing/Head/PickUpAnyNearbyHeadExp.cs +++ b/Content.Server/AI/Utility/ExpandableActions/Clothing/Head/PickUpAnyNearbyHeadExp.cs @@ -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> GetCommonConsiderations(Blackboard context) + { + var considerationsManager = IoCManager.Resolve(); + return new[] + { + considerationsManager.Get().Slot(EquipmentSlotDefines.Slots.HEAD, context) + .InverseBoolCurve(context), + considerationsManager.Get().Slot(EquipmentSlotDefines.SlotFlags.HEAD, context) + .InverseBoolCurve(context) + }; + } + public override IEnumerable GetActions(Blackboard context) { var owner = context.GetState().GetValue(); diff --git a/Content.Server/AI/Utility/ExpandableActions/Clothing/OuterClothing/EquipAnyOuterClothingExp.cs b/Content.Server/AI/Utility/ExpandableActions/Clothing/OuterClothing/EquipAnyOuterClothingExp.cs index 007b801d27..548a08f774 100644 --- a/Content.Server/AI/Utility/ExpandableActions/Clothing/OuterClothing/EquipAnyOuterClothingExp.cs +++ b/Content.Server/AI/Utility/ExpandableActions/Clothing/OuterClothing/EquipAnyOuterClothingExp.cs @@ -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> GetCommonConsiderations(Blackboard context) + { + var considerationsManager = IoCManager.Resolve(); + + return new[] + { + considerationsManager.Get().Slot(EquipmentSlotDefines.Slots.OUTERCLOTHING, context) + .InverseBoolCurve(context), + }; + } + public override IEnumerable GetActions(Blackboard context) { var owner = context.GetState().GetValue(); diff --git a/Content.Server/AI/Utility/ExpandableActions/Clothing/OuterClothing/PickUpAnyNearbyOuterClothingExp.cs b/Content.Server/AI/Utility/ExpandableActions/Clothing/OuterClothing/PickUpAnyNearbyOuterClothingExp.cs index dd1d06c0c7..29ec45a582 100644 --- a/Content.Server/AI/Utility/ExpandableActions/Clothing/OuterClothing/PickUpAnyNearbyOuterClothingExp.cs +++ b/Content.Server/AI/Utility/ExpandableActions/Clothing/OuterClothing/PickUpAnyNearbyOuterClothingExp.cs @@ -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> GetCommonConsiderations(Blackboard context) + { + var considerationsManager = IoCManager.Resolve(); + + return new[] + { + considerationsManager.Get().Slot(EquipmentSlotDefines.Slots.OUTERCLOTHING, context) + .InverseBoolCurve(context), + considerationsManager.Get().Slot(EquipmentSlotDefines.SlotFlags.OUTERCLOTHING, context) + .InverseBoolCurve(context) + }; + } + public override IEnumerable GetActions(Blackboard context) { var owner = context.GetState().GetValue(); diff --git a/Content.Server/AI/Utility/ExpandableActions/Clothing/Shoes/EquipAnyShoesExp.cs b/Content.Server/AI/Utility/ExpandableActions/Clothing/Shoes/EquipAnyShoesExp.cs index f750fba71a..f02f7abe0f 100644 --- a/Content.Server/AI/Utility/ExpandableActions/Clothing/Shoes/EquipAnyShoesExp.cs +++ b/Content.Server/AI/Utility/ExpandableActions/Clothing/Shoes/EquipAnyShoesExp.cs @@ -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> GetCommonConsiderations(Blackboard context) + { + var considerationsManager = IoCManager.Resolve(); + + return new[] + { + considerationsManager.Get().Slot(EquipmentSlotDefines.Slots.SHOES, context) + .InverseBoolCurve(context), + }; + } + public override IEnumerable GetActions(Blackboard context) { var owner = context.GetState().GetValue(); diff --git a/Content.Server/AI/Utility/ExpandableActions/Clothing/Shoes/PickUpAnyNearbyShoesExp.cs b/Content.Server/AI/Utility/ExpandableActions/Clothing/Shoes/PickUpAnyNearbyShoesExp.cs index 598d180808..8a1fa9429e 100644 --- a/Content.Server/AI/Utility/ExpandableActions/Clothing/Shoes/PickUpAnyNearbyShoesExp.cs +++ b/Content.Server/AI/Utility/ExpandableActions/Clothing/Shoes/PickUpAnyNearbyShoesExp.cs @@ -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> GetCommonConsiderations(Blackboard context) + { + var considerationsManager = IoCManager.Resolve(); + + return new[] + { + considerationsManager.Get().Slot(EquipmentSlotDefines.Slots.SHOES, context) + .InverseBoolCurve(context), + considerationsManager.Get().Slot(EquipmentSlotDefines.SlotFlags.SHOES, context) + .InverseBoolCurve(context) + }; + } + public override IEnumerable GetActions(Blackboard context) { var owner = context.GetState().GetValue(); diff --git a/Content.Server/AI/Utility/ExpandableActions/Combat/Melee/EquipMeleeExp.cs b/Content.Server/AI/Utility/ExpandableActions/Combat/Melee/EquipMeleeExp.cs index d0aade8647..1d993bec7b 100644 --- a/Content.Server/AI/Utility/ExpandableActions/Combat/Melee/EquipMeleeExp.cs +++ b/Content.Server/AI/Utility/ExpandableActions/Combat/Melee/EquipMeleeExp.cs @@ -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> GetCommonConsiderations(Blackboard context) + { + var considerationsManager = IoCManager.Resolve(); + + return new[] + { + considerationsManager.Get() + .InverseBoolCurve(context), + }; + } + public override IEnumerable GetActions(Blackboard context) { var owner = context.GetState().GetValue(); diff --git a/Content.Server/AI/Utility/ExpandableActions/Combat/Melee/MeleeAttackNearbyPlayerExp.cs b/Content.Server/AI/Utility/ExpandableActions/Combat/Melee/MeleeAttackNearbyPlayerExp.cs index adab7f24cd..a1ee5543bf 100644 --- a/Content.Server/AI/Utility/ExpandableActions/Combat/Melee/MeleeAttackNearbyPlayerExp.cs +++ b/Content.Server/AI/Utility/ExpandableActions/Combat/Melee/MeleeAttackNearbyPlayerExp.cs @@ -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> GetCommonConsiderations(Blackboard context) + { + var considerationsManager = IoCManager.Resolve(); + + return new[] + { + considerationsManager.Get() + .BoolCurve(context), + }; + } + public override IEnumerable GetActions(Blackboard context) { var owner = context.GetState().GetValue(); diff --git a/Content.Server/AI/Utility/ExpandableActions/Combat/Melee/MeleeAttackNearbySpeciesExp.cs b/Content.Server/AI/Utility/ExpandableActions/Combat/Melee/MeleeAttackNearbySpeciesExp.cs index 617252184e..b78bb2812c 100644 --- a/Content.Server/AI/Utility/ExpandableActions/Combat/Melee/MeleeAttackNearbySpeciesExp.cs +++ b/Content.Server/AI/Utility/ExpandableActions/Combat/Melee/MeleeAttackNearbySpeciesExp.cs @@ -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 GetActions(Blackboard context) { var owner = context.GetState().GetValue(); + foreach (var entity in context.GetState().GetValue()) { yield return new MeleeWeaponAttackEntity(owner, entity, Bonus); diff --git a/Content.Server/AI/Utility/ExpandableActions/Combat/Melee/PickUpMeleeWeaponExp.cs b/Content.Server/AI/Utility/ExpandableActions/Combat/Melee/PickUpMeleeWeaponExp.cs index 781a72c2a1..c91e0b065b 100644 --- a/Content.Server/AI/Utility/ExpandableActions/Combat/Melee/PickUpMeleeWeaponExp.cs +++ b/Content.Server/AI/Utility/ExpandableActions/Combat/Melee/PickUpMeleeWeaponExp.cs @@ -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> GetCommonConsiderations(Blackboard context) + { + var considerationsManager = IoCManager.Resolve(); + + return new[] + { + considerationsManager.Get() + .BoolCurve(context), + considerationsManager.Get() + .InverseBoolCurve(context), + }; + } + public override IEnumerable GetActions(Blackboard context) { var owner = context.GetState().GetValue(); diff --git a/Content.Server/AI/Utility/ExpandableActions/Combat/Melee/UnarmedAttackNearbyPlayerExp.cs b/Content.Server/AI/Utility/ExpandableActions/Combat/Melee/UnarmedAttackNearbyPlayerExp.cs index e168116431..0fc6d162b7 100644 --- a/Content.Server/AI/Utility/ExpandableActions/Combat/Melee/UnarmedAttackNearbyPlayerExp.cs +++ b/Content.Server/AI/Utility/ExpandableActions/Combat/Melee/UnarmedAttackNearbyPlayerExp.cs @@ -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> GetCommonConsiderations(Blackboard context) + { + var considerationsManager = IoCManager.Resolve(); + + return new[] + { + considerationsManager.Get() + .BoolCurve(context), + }; + } + public override IEnumerable GetActions(Blackboard context) { var owner = context.GetState().GetValue(); diff --git a/Content.Server/AI/Utility/ExpandableActions/ExpandableUtilityAction.cs b/Content.Server/AI/Utility/ExpandableActions/ExpandableUtilityAction.cs index 619fc36139..d8f291c9f8 100644 --- a/Content.Server/AI/Utility/ExpandableActions/ExpandableUtilityAction.cs +++ b/Content.Server/AI/Utility/ExpandableActions/ExpandableUtilityAction.cs @@ -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; } + /// + /// 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) + /// + /// + /// + public bool IsValid(Blackboard context) + { + foreach (var con in GetCommonConsiderations(context)) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator + if (con.Invoke() == 0.0f) return false; + } + + return true; + } + + /// + /// 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. + /// + /// 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. + /// + /// + protected virtual IEnumerable> 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 GetActions(Blackboard context); } diff --git a/Content.Server/AI/Utility/ExpandableActions/Nutrition/PickUpNearbyDrinkExp.cs b/Content.Server/AI/Utility/ExpandableActions/Nutrition/PickUpNearbyDrinkExp.cs index 87f735b7f8..c2558bcbc7 100644 --- a/Content.Server/AI/Utility/ExpandableActions/Nutrition/PickUpNearbyDrinkExp.cs +++ b/Content.Server/AI/Utility/ExpandableActions/Nutrition/PickUpNearbyDrinkExp.cs @@ -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> GetCommonConsiderations(Blackboard context) + { + var considerationsManager = IoCManager.Resolve(); + return new[] + { + considerationsManager.Get().PresetCurve(context, PresetCurve.Nutrition), + considerationsManager.Get().BoolCurve(context), + }; + } + public override IEnumerable GetActions(Blackboard context) { var owner = context.GetState().GetValue(); diff --git a/Content.Server/AI/Utility/ExpandableActions/Nutrition/PickUpNearbyFoodExp.cs b/Content.Server/AI/Utility/ExpandableActions/Nutrition/PickUpNearbyFoodExp.cs index 01affba951..e3a3409aea 100644 --- a/Content.Server/AI/Utility/ExpandableActions/Nutrition/PickUpNearbyFoodExp.cs +++ b/Content.Server/AI/Utility/ExpandableActions/Nutrition/PickUpNearbyFoodExp.cs @@ -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> GetCommonConsiderations(Blackboard context) + { + var considerationsManager = IoCManager.Resolve(); + return new[] + { + considerationsManager.Get().PresetCurve(context, PresetCurve.Nutrition), + considerationsManager.Get().BoolCurve(context), + }; + } + public override IEnumerable GetActions(Blackboard context) { var owner = context.GetState().GetValue(); diff --git a/Content.Server/AI/Utility/ExpandableActions/Nutrition/UseDrinkInHandsExp.cs b/Content.Server/AI/Utility/ExpandableActions/Nutrition/UseDrinkInInventoryExp.cs similarity index 62% rename from Content.Server/AI/Utility/ExpandableActions/Nutrition/UseDrinkInHandsExp.cs rename to Content.Server/AI/Utility/ExpandableActions/Nutrition/UseDrinkInInventoryExp.cs index fac523cd96..06574721c6 100644 --- a/Content.Server/AI/Utility/ExpandableActions/Nutrition/UseDrinkInHandsExp.cs +++ b/Content.Server/AI/Utility/ExpandableActions/Nutrition/UseDrinkInInventoryExp.cs @@ -1,16 +1,29 @@ +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> GetCommonConsiderations(Blackboard context) + { + var considerationsManager = IoCManager.Resolve(); + return new[] + { + considerationsManager.Get().PresetCurve(context, PresetCurve.Nutrition) + }; + } public override IEnumerable GetActions(Blackboard context) { diff --git a/Content.Server/AI/Utility/ExpandableActions/Nutrition/UseFoodInInventoryExp.cs b/Content.Server/AI/Utility/ExpandableActions/Nutrition/UseFoodInInventoryExp.cs index 2df0385f6f..1f919b56a3 100644 --- a/Content.Server/AI/Utility/ExpandableActions/Nutrition/UseFoodInInventoryExp.cs +++ b/Content.Server/AI/Utility/ExpandableActions/Nutrition/UseFoodInInventoryExp.cs @@ -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> GetCommonConsiderations(Blackboard context) + { + var considerationsManager = IoCManager.Resolve(); + return new[] + { + considerationsManager.Get().PresetCurve(context, PresetCurve.Nutrition) + }; + } + public override IEnumerable GetActions(Blackboard context) { var owner = context.GetState().GetValue(); diff --git a/Content.Server/GameObjects/EntitySystems/AI/LoadBalancer/AiActionRequestJob.cs b/Content.Server/GameObjects/EntitySystems/AI/LoadBalancer/AiActionRequestJob.cs index bd4041bf76..fda623d6e6 100644 --- a/Content.Server/GameObjects/EntitySystems/AI/LoadBalancer/AiActionRequestJob.cs +++ b/Content.Server/GameObjects/EntitySystems/AI/LoadBalancer/AiActionRequestJob.cs @@ -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) {