Improve AI squad pathing and regrouping behavior.
Ensure the target location can be pathed to by all units in the squad, so the squad won't get stuck if some units can't make it. Improve the choice of leader for the squad. We attempt to a choose a leader whose locomotor is the most restrictive in terms of passable terrain. This maximises the chance that the squad will be able to follow the leader along the path to the target. We also keep this choice of leader as the squad advances, this avoids the squad constantly switching leaders and regrouping backwards in some cases.
This commit is contained in:
@@ -95,12 +95,12 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads
|
||||
/// <summary>
|
||||
/// Checks the target is still valid, and updates the <see cref="Target"/> location if it is still valid.
|
||||
/// </summary>
|
||||
public bool IsTargetValid()
|
||||
public bool IsTargetValid(Actor squadUnit)
|
||||
{
|
||||
var valid =
|
||||
TargetActor != null &&
|
||||
TargetActor.IsInWorld &&
|
||||
TargetActor.IsTargetableBy(Units.FirstOrDefault()) &&
|
||||
Units.Any(Target.IsValidFor) &&
|
||||
!TargetActor.Info.HasTraitInfo<HuskInfo>();
|
||||
if (!valid)
|
||||
return false;
|
||||
@@ -113,7 +113,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads
|
||||
// e.g. a ship targeting a land unit, but the land unit moved north.
|
||||
// We need to update our location to move north as well.
|
||||
// If we can reach the actor directly, we'll just target it directly.
|
||||
var target = SquadManager.FindEnemies(new[] { TargetActor }, Units.First()).FirstOrDefault();
|
||||
var target = SquadManager.FindEnemies(new[] { TargetActor }, squadUnit).FirstOrDefault();
|
||||
SetActorToTarget(target);
|
||||
return target.Actor != null;
|
||||
}
|
||||
@@ -122,7 +122,16 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads
|
||||
TargetActor != null &&
|
||||
TargetActor.CanBeViewedByPlayer(Bot.Player);
|
||||
|
||||
public WPos CenterPosition { get { return Units.Select(u => u.CenterPosition).Average(); } }
|
||||
public WPos CenterPosition()
|
||||
{
|
||||
return Units.Select(a => a.CenterPosition).Average();
|
||||
}
|
||||
|
||||
public Actor CenterUnit()
|
||||
{
|
||||
var centerPosition = CenterPosition();
|
||||
return Units.MinByOrDefault(a => (a.CenterPosition - centerPosition).LengthSquared);
|
||||
}
|
||||
|
||||
public MiniYaml Serialize()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user