AI Reachable system (#1342)
Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using Content.Server.AI.Operators.Sequences;
|
||||
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.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
@@ -44,7 +45,9 @@ namespace Content.Server.AI.Utility.Actions.Clothing.Gloves
|
||||
considerationsManager.Get<CanPutTargetInHandsCon>()
|
||||
.BoolCurve(context),
|
||||
considerationsManager.Get<ClothingInInventoryCon>().Slot(EquipmentSlotDefines.SlotFlags.GLOVES, context)
|
||||
.InverseBoolCurve(context)
|
||||
.InverseBoolCurve(context),
|
||||
considerationsManager.Get<TargetAccessibleCon>()
|
||||
.BoolCurve(context),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using Content.Server.AI.Operators.Sequences;
|
||||
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.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
@@ -44,7 +45,9 @@ namespace Content.Server.AI.Utility.Actions.Clothing.Head
|
||||
considerationsManager.Get<CanPutTargetInHandsCon>()
|
||||
.BoolCurve(context),
|
||||
considerationsManager.Get<ClothingInInventoryCon>().Slot(EquipmentSlotDefines.SlotFlags.HEAD, context)
|
||||
.InverseBoolCurve(context)
|
||||
.InverseBoolCurve(context),
|
||||
considerationsManager.Get<TargetAccessibleCon>()
|
||||
.BoolCurve(context),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using Content.Server.AI.Operators.Sequences;
|
||||
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.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
@@ -44,7 +45,9 @@ namespace Content.Server.AI.Utility.Actions.Clothing.OuterClothing
|
||||
considerationsManager.Get<CanPutTargetInHandsCon>()
|
||||
.BoolCurve(context),
|
||||
considerationsManager.Get<ClothingInInventoryCon>().Slot(EquipmentSlotDefines.SlotFlags.OUTERCLOTHING, context)
|
||||
.InverseBoolCurve(context)
|
||||
.InverseBoolCurve(context),
|
||||
considerationsManager.Get<TargetAccessibleCon>()
|
||||
.BoolCurve(context),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using Content.Server.AI.Operators.Sequences;
|
||||
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.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
@@ -44,7 +45,9 @@ namespace Content.Server.AI.Utility.Actions.Clothing.Shoes
|
||||
considerationsManager.Get<CanPutTargetInHandsCon>()
|
||||
.BoolCurve(context),
|
||||
considerationsManager.Get<ClothingInInventoryCon>().Slot(EquipmentSlotDefines.SlotFlags.SHOES, context)
|
||||
.InverseBoolCurve(context)
|
||||
.InverseBoolCurve(context),
|
||||
considerationsManager.Get<TargetAccessibleCon>()
|
||||
.BoolCurve(context),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ using Content.Server.AI.Operators.Movement;
|
||||
using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Combat;
|
||||
using Content.Server.AI.Utility.Considerations.Combat.Melee;
|
||||
using Content.Server.AI.Utility.Considerations.Containers;
|
||||
using Content.Server.AI.Utility.Considerations.Movement;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
@@ -79,6 +80,8 @@ namespace Content.Server.AI.Utility.Actions.Combat.Melee
|
||||
.QuadraticCurve(context, 1.0f, 0.5f, 0.0f, 0.0f),
|
||||
considerationsManager.Get<MeleeWeaponDamageCon>()
|
||||
.QuadraticCurve(context, 1.0f, 0.25f, 0.0f, 0.0f),
|
||||
considerationsManager.Get<TargetAccessibleCon>()
|
||||
.BoolCurve(context),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,8 +42,6 @@ namespace Content.Server.AI.Utility.Actions.Combat.Melee
|
||||
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<TargetAccessibleCon>()
|
||||
.BoolCurve(context),
|
||||
considerationsManager.Get<FreeHandCon>()
|
||||
.BoolCurve(context),
|
||||
considerationsManager.Get<HasMeleeWeaponCon>()
|
||||
@@ -54,6 +52,8 @@ namespace Content.Server.AI.Utility.Actions.Combat.Melee
|
||||
.QuadraticCurve(context, 1.0f, 0.25f, 0.0f, 0.0f),
|
||||
considerationsManager.Get<MeleeWeaponSpeedCon>()
|
||||
.QuadraticCurve(context, -1.0f, 0.5f, 1.0f, 0.0f),
|
||||
considerationsManager.Get<TargetAccessibleCon>()
|
||||
.BoolCurve(context),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using Content.Server.AI.Operators.Movement;
|
||||
using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Combat;
|
||||
using Content.Server.AI.Utility.Considerations.Combat.Melee;
|
||||
using Content.Server.AI.Utility.Considerations.Containers;
|
||||
using Content.Server.AI.Utility.Considerations.Movement;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
@@ -73,6 +74,8 @@ namespace Content.Server.AI.Utility.Actions.Combat.Melee
|
||||
.QuadraticCurve(context, -1.0f, 1.0f, 1.02f, 0.0f),
|
||||
considerationsManager.Get<TargetHealthCon>()
|
||||
.QuadraticCurve(context, 1.0f, 0.4f, 0.0f, -0.02f),
|
||||
considerationsManager.Get<TargetAccessibleCon>()
|
||||
.BoolCurve(context),
|
||||
// TODO: Consider our Speed and Damage to compare this to using a weapon
|
||||
// Also need to unequip our weapon if we have one (xenos can't hold one so no issue for now)
|
||||
};
|
||||
|
||||
@@ -4,9 +4,11 @@ using Content.Server.AI.Operators;
|
||||
using Content.Server.AI.Operators.Inventory;
|
||||
using Content.Server.AI.Operators.Movement;
|
||||
using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.Containers;
|
||||
using Content.Server.AI.Utility.Considerations.Movement;
|
||||
using Content.Server.AI.Utility.Considerations.State;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.AI.WorldState.States;
|
||||
using Content.Server.AI.WorldState.States.Inventory;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -31,8 +33,15 @@ namespace Content.Server.AI.Utility.Actions.Idle
|
||||
new MoveToEntityOperator(Owner, lastStorage),
|
||||
new CloseLastStorageOperator(Owner),
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected override void UpdateBlackboard(Blackboard context)
|
||||
{
|
||||
base.UpdateBlackboard(context);
|
||||
var lastStorage = context.GetState<LastOpenedStorageState>();
|
||||
context.GetState<TargetEntityState>().SetValue(lastStorage.GetValue());
|
||||
}
|
||||
|
||||
protected override IReadOnlyCollection<Func<float>> GetConsiderations(Blackboard context)
|
||||
{
|
||||
var considerationsManager = IoCManager.Resolve<ConsiderationsManager>();
|
||||
@@ -43,7 +52,8 @@ namespace Content.Server.AI.Utility.Actions.Idle
|
||||
.InverseBoolCurve(context),
|
||||
considerationsManager.Get<DistanceCon>()
|
||||
.QuadraticCurve(context, 1.0f, 1.0f, 0.02f, 0.0f),
|
||||
|
||||
considerationsManager.Get<TargetAccessibleCon>()
|
||||
.BoolCurve(context),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,9 @@ using Content.Server.AI.Utility.Considerations;
|
||||
using Content.Server.AI.Utility.Considerations.ActionBlocker;
|
||||
using Content.Server.AI.Utility.Considerations.Containers;
|
||||
using Content.Server.AI.WorldState;
|
||||
using Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible;
|
||||
using Content.Server.GameObjects.EntitySystems.Pathfinding;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.Interfaces.Random;
|
||||
@@ -29,12 +32,12 @@ namespace Content.Server.AI.Utility.Actions.Idle
|
||||
|
||||
public override void SetupOperators(Blackboard context)
|
||||
{
|
||||
var randomGrid = FindRandomGrid();
|
||||
var robustRandom = IoCManager.Resolve<IRobustRandom>();
|
||||
var randomGrid = FindRandomGrid(robustRandom);
|
||||
float waitTime;
|
||||
if (randomGrid != GridCoordinates.InvalidGrid)
|
||||
{
|
||||
var random = IoCManager.Resolve<IRobustRandom>();
|
||||
waitTime = random.NextFloat() * 10;
|
||||
waitTime = robustRandom.Next(3, 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -56,32 +59,39 @@ namespace Content.Server.AI.Utility.Actions.Idle
|
||||
{
|
||||
considerationsManager.Get<CanMoveCon>()
|
||||
.BoolCurve(context),
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
private GridCoordinates FindRandomGrid()
|
||||
private GridCoordinates FindRandomGrid(IRobustRandom robustRandom)
|
||||
{
|
||||
// Very inefficient (should weight each region by its node count) but better than the old system
|
||||
var reachableSystem = EntitySystem.Get<AiReachableSystem>();
|
||||
var reachableArgs = ReachableArgs.GetArgs(Owner);
|
||||
var entityRegion = reachableSystem.GetRegion(Owner);
|
||||
var reachableRegions = reachableSystem.GetReachableRegions(reachableArgs, entityRegion);
|
||||
|
||||
// TODO: When SetupOperators can fail this should be null and fail the setup.
|
||||
if (reachableRegions.Count == 0)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
var reachableNodes = new List<PathfindingNode>();
|
||||
|
||||
foreach (var region in reachableRegions)
|
||||
{
|
||||
foreach (var node in region.Nodes)
|
||||
{
|
||||
reachableNodes.Add(node);
|
||||
}
|
||||
}
|
||||
|
||||
var targetNode = robustRandom.Pick(reachableNodes);
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
var grid = mapManager.GetGrid(Owner.Transform.GridID);
|
||||
var targetGrid = grid.GridTileToLocal(targetNode.TileRef.GridIndices);
|
||||
|
||||
// Just find a random spot in bounds
|
||||
// If the grid's a single-tile wide but really tall this won't really work but eh future problem
|
||||
var gridBounds = grid.WorldBounds;
|
||||
var robustRandom = IoCManager.Resolve<IRobustRandom>();
|
||||
var newPosition = gridBounds.BottomLeft + new Vector2(
|
||||
robustRandom.Next((int) gridBounds.Width),
|
||||
robustRandom.Next((int) gridBounds.Height));
|
||||
// Conversions blah blah
|
||||
var mapIndex = grid.WorldToTile(grid.LocalToWorld(newPosition));
|
||||
// Didn't find one? Fuck it we're not walkin' into space
|
||||
if (grid.GetTileRef(mapIndex).Tile.IsEmpty)
|
||||
{
|
||||
return GridCoordinates.InvalidGrid;
|
||||
}
|
||||
var target = grid.GridTileToLocal(mapIndex);
|
||||
|
||||
return target;
|
||||
return targetGrid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,8 +40,6 @@ namespace Content.Server.AI.Utility.Actions.Nutrition.Drink
|
||||
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<TargetAccessibleCon>()
|
||||
.BoolCurve(context),
|
||||
considerationsManager.Get<FreeHandCon>()
|
||||
.BoolCurve(context),
|
||||
considerationsManager.Get<ThirstCon>()
|
||||
@@ -50,6 +48,8 @@ namespace Content.Server.AI.Utility.Actions.Nutrition.Drink
|
||||
.QuadraticCurve(context, 1.0f, 1.0f, 0.02f, 0.0f),
|
||||
considerationsManager.Get<DrinkValueCon>()
|
||||
.QuadraticCurve(context, 1.0f, 0.4f, 0.0f, 0.0f),
|
||||
considerationsManager.Get<TargetAccessibleCon>()
|
||||
.BoolCurve(context),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -40,8 +40,6 @@ namespace Content.Server.AI.Utility.Actions.Nutrition.Food
|
||||
|
||||
return new[]
|
||||
{
|
||||
considerationsManager.Get<TargetAccessibleCon>()
|
||||
.BoolCurve(context),
|
||||
considerationsManager.Get<FreeHandCon>()
|
||||
.BoolCurve(context),
|
||||
considerationsManager.Get<HungerCon>()
|
||||
@@ -50,6 +48,8 @@ namespace Content.Server.AI.Utility.Actions.Nutrition.Food
|
||||
.QuadraticCurve(context, 1.0f, 1.0f, 0.02f, 0.0f),
|
||||
considerationsManager.Get<FoodValueCon>()
|
||||
.QuadraticCurve(context, 1.0f, 0.4f, 0.0f, 0.0f),
|
||||
considerationsManager.Get<TargetAccessibleCon>()
|
||||
.BoolCurve(context),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user