Skip to content

Commit

Permalink
Add helper methods to locate actors that can be reached via a path.
Browse files Browse the repository at this point in the history
Previously, the ClosestTo and PositionClosestTo existed to perform a simple distance based check to choose the closest location from a choice of locations to a single other location. For some functions this is sufficient, but for many functions we want to then move between the locations. If the location selected is in fact unreachable (e.g. on another island) then we would not want to consider it.

We now introduce ClosestToIgnoringPath for checks where we don't care about a path existing, e.g. weapons hitting nearby targets. When we do care about paths, we introduce ClosestToWithPathFrom and ClosestToWithPathTo which will check that a path exists. The PathFrom check will make sure one of the actors from the list can make it to the single target location. The PathTo check will make sure the single actor can make it to one of the target locations. This difference allows us to specify which actor will be doing the moving. This is important as a path might exists for one actor, but not another. Consider two islands with a hovercraft on one and a tank on the other. The hovercraft can path to the tank, but the tank cannot path to the hovercraft.

We also introduce WithPathFrom and WithPathTo. These will perform filtering by checking for valid paths, but won't select the closest location.

By employing the new methods that filter for paths, we fix various behaviour that would cause actors to get confused. Imagine an islands map, by checking for paths we ensure logic will locate reachable locations on the island, rather than considering a location on a nearby island that is physically closer but unreachable. This fixes AI squad automation, and other automated behaviours such as rearming.
  • Loading branch information
RoosterDragon committed Jul 15, 2023
1 parent 659ec5e commit c011959
Show file tree
Hide file tree
Showing 26 changed files with 368 additions and 315 deletions.
5 changes: 5 additions & 0 deletions OpenRA.Game/Exts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ public static int MultiplyBySqrtTwo(short number)
return number * 46341 / 32768;
}

public static int MultiplyBySqrtTwoOverTwo(int number)
{
return (int)(number * 23170L / 32768L);
}

public static int IntegerDivisionRoundingAwayFromZero(int dividend, int divisor)
{
var quotient = Math.DivRem(dividend, divisor, out var remainder);
Expand Down
24 changes: 18 additions & 6 deletions OpenRA.Game/WorldUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,31 @@ namespace OpenRA
{
public static class WorldUtils
{
public static Actor ClosestTo(this IEnumerable<Actor> actors, Actor a)
/// <summary>
/// From the given <paramref name="actors"/>, select the one nearest the given <paramref name="actor"/> by
/// comparing their <see cref="Actor.CenterPosition"/>. No check is done to see if a path exists.
/// </summary>
public static Actor ClosestToIgnoringPath(this IEnumerable<Actor> actors, Actor actor)
{
return actors.ClosestTo(a.CenterPosition);
return actors.ClosestToIgnoringPath(actor.CenterPosition);
}

public static Actor ClosestTo(this IEnumerable<Actor> actors, WPos pos)
/// <summary>
/// From the given <paramref name="actors"/>, select the one nearest the given <paramref name="position"/> by
/// comparing the <see cref="Actor.CenterPosition"/>. No check is done to see if a path exists.
/// </summary>
public static Actor ClosestToIgnoringPath(this IEnumerable<Actor> actors, WPos position)
{
return actors.MinByOrDefault(a => (a.CenterPosition - pos).LengthSquared);
return actors.MinByOrDefault(a => (a.CenterPosition - position).LengthSquared);
}

public static WPos PositionClosestTo(this IEnumerable<WPos> positions, WPos pos)
/// <summary>
/// From the given <paramref name="positions"/>, select the one nearest the given <paramref name="position"/>.
/// No check is done to see if a path exists, as an actor is required for that.
/// </summary>
public static WPos ClosestToIgnoringPath(this IEnumerable<WPos> positions, WPos position)
{
return positions.MinByOrDefault(p => (p - pos).LengthSquared);
return positions.MinByOrDefault(p => (p - position).LengthSquared);
}

public static IEnumerable<Actor> FindActorsInCircle(this World world, WPos origin, WDist r)
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Cnc/Projectiles/TeslaZap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void Tick(World world)

// Zap tracks target
if (info.TrackTarget && args.GuidedTarget.IsValidFor(args.SourceActor))
target = args.Weapon.TargetActorCenter ? args.GuidedTarget.CenterPosition : args.GuidedTarget.Positions.PositionClosestTo(args.Source);
target = args.Weapon.TargetActorCenter ? args.GuidedTarget.CenterPosition : args.GuidedTarget.Positions.ClosestToIgnoringPath(args.Source);

if (damageDuration-- > 0)
args.Weapon.Impact(Target.FromPos(target), new WarheadArgs(args));
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static Actor ChooseResupplier(Actor self, bool unreservedOnly)
&& a.Owner == self.Owner
&& rearmInfo.RearmActors.Contains(a.Info.Name)
&& (!unreservedOnly || Reservable.IsAvailableFor(a, self)))
.ClosestTo(self);
.ClosestToWithPathFrom(self);
}

bool ShouldLandAtBuilding(Actor self, Actor dest)
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Activities/Enter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public override bool Tick(Actor self)
case EnterState.Entering:
{
// Check that we reached the requested position
var targetPos = target.Positions.PositionClosestTo(self.CenterPosition);
var targetPos = target.Positions.ClosestToWithPathFrom(self);
if (!IsCanceling && self.CenterPosition == targetPos && target.Type == TargetType.Actor)
OnEnterComplete(self, target.Actor);

Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Activities/Hunt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override bool Tick(Actor self)
if (IsCanceling)
return true;

var target = targets.ClosestTo(self);
var target = targets.ClosestToWithPathFrom(self);
if (target == null)
return false;

Expand Down
8 changes: 6 additions & 2 deletions OpenRA.Mods.Common/Activities/LayMines.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Collections.Generic;
using System.Linq;
using OpenRA.Activities;
using OpenRA.Mods.Common;

Check failure on line 15 in OpenRA.Mods.Common/Activities/LayMines.cs

View workflow job for this annotation

GitHub Actions / Linux (.NET 6.0)

Using directive is unnecessary.

Check failure on line 15 in OpenRA.Mods.Common/Activities/LayMines.cs

View workflow job for this annotation

GitHub Actions / Linux (.NET 6.0)

Using directive is unnecessary.

Check failure on line 15 in OpenRA.Mods.Common/Activities/LayMines.cs

View workflow job for this annotation

GitHub Actions / Windows (.NET 6.0)

Using directive is unnecessary.

Check failure on line 15 in OpenRA.Mods.Common/Activities/LayMines.cs

View workflow job for this annotation

GitHub Actions / Windows (.NET 6.0)

Using directive is unnecessary.

Check warning on line 15 in OpenRA.Mods.Common/Activities/LayMines.cs

View workflow job for this annotation

GitHub Actions / Windows (.NET 6.0)

Using directive is unnecessary.

Check warning on line 15 in OpenRA.Mods.Common/Activities/LayMines.cs

View workflow job for this annotation

GitHub Actions / Windows (.NET 6.0)

Using directive is unnecessary.
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
Expand Down Expand Up @@ -68,8 +69,11 @@ public override bool Tick(Actor self)
if (rearmableInfo != null && ammoPools.Any(p => p.Info.Name == minelayer.Info.AmmoPoolName && !p.HasAmmo))
{
// Rearm (and possibly repair) at rearm building, then back out here to refill the minefield some more
rearmTarget = self.World.Actors.Where(a => self.Owner.RelationshipWith(a.Owner) == PlayerRelationship.Ally && rearmableInfo.RearmActors.Contains(a.Info.Name))
.ClosestTo(self);
rearmTarget = self.World.Actors
.Where(a =>
self.Owner.RelationshipWith(a.Owner) == PlayerRelationship.Ally
&& rearmableInfo.RearmActors.Contains(a.Info.Name))
.ClosestToWithPathFrom(self);

if (rearmTarget == null)
return true;
Expand Down
15 changes: 9 additions & 6 deletions OpenRA.Mods.Common/Activities/Move/LocalMoveIntoTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class LocalMoveIntoTarget : Activity
readonly Target target;
readonly Color? targetLineColor;
readonly WDist targetMovementThreshold;
WPos targetStartPos;
WPos? targetStartPos;

public LocalMoveIntoTarget(Actor self, in Target target, WDist targetMovementThreshold, Color? targetLineColor = null)
{
Expand All @@ -35,7 +35,7 @@ public LocalMoveIntoTarget(Actor self, in Target target, WDist targetMovementThr

protected override void OnFirstRun(Actor self)
{
targetStartPos = target.Positions.PositionClosestTo(self.CenterPosition);
targetStartPos = target.Positions.ClosestToWithPathFrom(self);
}

public override bool Tick(Actor self)
Expand All @@ -47,14 +47,17 @@ public override bool Tick(Actor self)
return false;

var currentPos = self.CenterPosition;
var targetPos = target.Positions.PositionClosestTo(currentPos);
var targetPos = target.Positions.ClosestToWithPathFrom(self);

if (targetStartPos == null || targetPos == null)
return true;

// Give up if the target has moved too far
if (targetMovementThreshold > WDist.Zero && (targetPos - targetStartPos).LengthSquared > targetMovementThreshold.LengthSquared)
if (targetMovementThreshold > WDist.Zero && (targetPos.Value - targetStartPos.Value).LengthSquared > targetMovementThreshold.LengthSquared)
return true;

// Turn if required
var delta = targetPos - currentPos;
var delta = targetPos.Value - currentPos;
var facing = delta.HorizontalLengthSquared != 0 ? delta.Yaw : mobile.Facing;
if (facing != mobile.Facing)
{
Expand All @@ -66,7 +69,7 @@ public override bool Tick(Actor self)
var speed = mobile.MovementSpeedForCell(self.Location);
if (delta.LengthSquared <= speed * speed)
{
mobile.SetCenterPosition(self, targetPos);
mobile.SetCenterPosition(self, targetPos.Value);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Projectiles/AreaBeam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void TrackTarget()

if (args.GuidedTarget.IsValidFor(args.SourceActor))
{
var guidedTargetPos = args.Weapon.TargetActorCenter ? args.GuidedTarget.CenterPosition : args.GuidedTarget.Positions.PositionClosestTo(args.Source);
var guidedTargetPos = args.Weapon.TargetActorCenter ? args.GuidedTarget.CenterPosition : args.GuidedTarget.Positions.ClosestToIgnoringPath(args.Source);
var targetDistance = new WDist((guidedTargetPos - args.Source).Length);

// Only continue tracking target if it's within weapon range +
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Projectiles/LaserZap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void Tick(World world)

// Beam tracks target
if (info.TrackTarget && args.GuidedTarget.IsValidFor(args.SourceActor))
target = args.Weapon.TargetActorCenter ? args.GuidedTarget.CenterPosition : args.GuidedTarget.Positions.PositionClosestTo(source);
target = args.Weapon.TargetActorCenter ? args.GuidedTarget.CenterPosition : args.GuidedTarget.Positions.ClosestToIgnoringPath(source);

// Check for blocking actors
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, args.SourceActor.Owner, source, target, info.Width, out var blockedPos))
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Projectiles/Missile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ public void Tick(World world)
// Check if target position should be updated (actor visible & locked on)
var newTarPos = targetPosition;
if (args.GuidedTarget.IsValidFor(args.SourceActor) && lockOn)
newTarPos = (args.Weapon.TargetActorCenter ? args.GuidedTarget.CenterPosition : args.GuidedTarget.Positions.PositionClosestTo(args.Source))
newTarPos = (args.Weapon.TargetActorCenter ? args.GuidedTarget.CenterPosition : args.GuidedTarget.Positions.ClosestToIgnoringPath(args.Source))
+ new WVec(WDist.Zero, WDist.Zero, info.AirburstAltitude);

// Compute target's predicted velocity vector (assuming uniform circular motion)
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/Armament.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ protected virtual void FireBarrel(Actor self, IFacing facing, in Target target,
WAngle MuzzleFacing() => MuzzleOrientation(self, barrel).Yaw;
var muzzleOrientation = WRot.FromYaw(MuzzleFacing());

var passiveTarget = Weapon.TargetActorCenter ? target.CenterPosition : target.Positions.PositionClosestTo(MuzzlePosition());
var passiveTarget = Weapon.TargetActorCenter ? target.CenterPosition : target.Positions.ClosestToIgnoringPath(MuzzlePosition());
var initialOffset = Weapon.FirstBurstTargetOffset;
if (initialOffset != WVec.Zero)
{
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/Attack/AttackBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public bool HasAnyValidWeapons(in Target t, bool checkForCenterTargetingWeapons

public virtual WPos GetTargetPosition(WPos pos, in Target target)
{
return HasAnyValidWeapons(target, true) ? target.CenterPosition : target.Positions.PositionClosestTo(pos);
return HasAnyValidWeapons(target, true) ? target.CenterPosition : target.Positions.ClosestToIgnoringPath(pos);
}

public WDist GetMinimumRange()
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/AutoCarryall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static bool IsBestAutoCarryallForCargo(Actor self, Actor candidateCargo)
var carriers = self.World.ActorsHavingTrait<AutoCarryall>(c => !c.busy)
.Where(a => a.Owner == self.Owner && a.IsInWorld);

return carriers.ClosestTo(candidateCargo) == self;
return carriers.ClosestToWithPathTo(candidateCargo) == self;
}

void FindCarryableForTransport(Actor self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,9 @@ ActorInfo ChooseBuildingToBuild(ProductionQueue queue)
case BuildingType.Defense:

// Build near the closest enemy structure
var closestEnemy = world.ActorsHavingTrait<Building>().Where(a => !a.Disposed && player.RelationshipWith(a.Owner) == PlayerRelationship.Enemy)
.ClosestTo(world.Map.CenterOfCell(baseBuilder.DefenseCenter));
var closestEnemy = world.ActorsHavingTrait<Building>()
.Where(a => !a.Disposed && player.RelationshipWith(a.Owner) == PlayerRelationship.Enemy)
.ClosestToIgnoringPath(world.Map.CenterOfCell(baseBuilder.DefenseCenter));

var targetCell = closestEnemy != null ? closestEnemy.Location : baseCenter;

Expand Down
12 changes: 1 addition & 11 deletions OpenRA.Mods.Common/Traits/BotModules/CaptureManagerBotModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,6 @@ void IBotTick.BotTick(IBot bot)
}
}

internal Actor FindClosestEnemy(WPos pos)
{
return world.Actors.Where(isEnemyUnit).ClosestTo(pos);
}

internal Actor FindClosestEnemy(WPos pos, WDist radius)
{
return world.FindActorsInCircle(pos, radius).Where(isEnemyUnit).ClosestTo(pos);
}

IEnumerable<Actor> GetVisibleActorsBelongingToPlayer(Player owner)
{
foreach (var actor in GetActorsThatCanBeOrderedByPlayer(owner))
Expand Down Expand Up @@ -159,7 +149,7 @@ void QueueCaptureOrders(IBot bot)

foreach (var capturer in capturers)
{
var targetActor = capturableTargetOptions.MinByOrDefault(target => (target.CenterPosition - capturer.Actor.CenterPosition).LengthSquared);
var targetActor = capturableTargetOptions.ClosestToWithPathFrom(capturer.Actor);
if (targetActor == null)
continue;

Expand Down
114 changes: 105 additions & 9 deletions OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,96 @@ void IBotTick.BotTick(IBot bot)
AssignRolesToIdleUnits(bot);
}

internal Actor FindClosestEnemy(WPos pos)
internal static Actor ClosestTo(IEnumerable<Actor> actors, Actor targetActor)
{
var units = World.Actors.Where(IsPreferredEnemyUnit);
return units.Where(IsNotHiddenUnit).ClosestTo(pos) ?? units.ClosestTo(pos);
// Return actors that can get within weapons range of the target.
// First, let's determine the max weapons range for each of the actors.
var actorsAndAttackRanges = actors
.Select(a => (Actor: a, AttackBases: a.TraitsImplementing<AttackBase>().Where(Exts.IsTraitEnabled)
.Where(ab => ab.HasAnyValidWeapons(Target.FromActor(targetActor))).ToList()))
.Where(x => x.AttackBases.Count > 0)
.Select(x => (x.Actor, Range: x.AttackBases.Max(ab => ab.GetMaximumRangeVersusTarget(Target.FromActor(x.Actor)))))
.ToDictionary(x => x.Actor, x => x.Range);

// Now determine if each actor can either path directly to the target,
// or if it can path to a nearby location at the edge of its weapon range to the target
// A thorough check would check each position within the circle, but for performance
// we'll only check 8 positions around the edge of the circle.
// We need to account for the weapons range here to account for units such as boats.
// They can't path directly to a land target,
// but might be able to get close enough to shore to attack the target from range.
return actorsAndAttackRanges.Keys
.ClosestToWithPathToAny(targetActor.World, a =>
{
var range = actorsAndAttackRanges[a].Length;
var rangeDiag = Exts.MultiplyBySqrtTwoOverTwo(range);
return new[]
{
targetActor.CenterPosition,
targetActor.CenterPosition + new WVec(range, 0, 0),
targetActor.CenterPosition + new WVec(-range, 0, 0),
targetActor.CenterPosition + new WVec(0, range, 0),
targetActor.CenterPosition + new WVec(0, -range, 0),
targetActor.CenterPosition + new WVec(rangeDiag, rangeDiag, 0),
targetActor.CenterPosition + new WVec(-rangeDiag, rangeDiag, 0),
targetActor.CenterPosition + new WVec(-rangeDiag, -rangeDiag, 0),
targetActor.CenterPosition + new WVec(rangeDiag, -rangeDiag, 0),
};
});
}

internal IEnumerable<Actor> FindEnemies(IEnumerable<Actor> enemies, Actor sourceActor)
{
// Check units are in fact enemies and not hidden.
// Then check which are in weapons range of the source.
var activeAttackBases = sourceActor.TraitsImplementing<AttackBase>().Where(Exts.IsTraitEnabled).ToArray();
var actorsAndAttackRanges = enemies
.Where(a => IsPreferredEnemyUnit(a) && IsNotHiddenUnit(a))
.Select(a => (Actor: a, AttackBases: activeAttackBases.Where(ab => ab.HasAnyValidWeapons(Target.FromActor(a))).ToList()))
.Where(x => x.AttackBases.Count > 0)
.Select(x => (x.Actor, Range: x.AttackBases.Max(ab => ab.GetMaximumRangeVersusTarget(Target.FromActor(x.Actor)))))
.ToDictionary(x => x.Actor, x => x.Range);

// Now determine if the source actor can path directly to the target,
// or if it can path to a nearby location at the edge of its weapon range to the target
// A thorough check would check each position within the circle, but for performance
// we'll only check 8 positions around the edge of the circle.
// We need to account for the weapons range here to account for units such as boats.
// They can't path directly to a land target,
// but might be able to get close enough to shore to attack the target from range.
return actorsAndAttackRanges.Keys
.WithPathFrom(sourceActor, a =>
{
var range = actorsAndAttackRanges[a].Length;
var rangeDiag = Exts.MultiplyBySqrtTwoOverTwo(range);
return new[]
{
WVec.Zero,
new WVec(range, 0, 0),
new WVec(-range, 0, 0),
new WVec(0, range, 0),
new WVec(0, -range, 0),
new WVec(rangeDiag, rangeDiag, 0),
new WVec(-rangeDiag, rangeDiag, 0),
new WVec(-rangeDiag, -rangeDiag, 0),
new WVec(rangeDiag, -rangeDiag, 0),
};
});
}

internal Actor FindClosestEnemy(Actor sourceActor)
{
return FindClosestEnemy(World.Actors, sourceActor);
}

internal Actor FindClosestEnemy(Actor sourceActor, WDist radius)
{
return FindClosestEnemy(World.FindActorsInCircle(sourceActor.CenterPosition, radius), sourceActor);
}

internal Actor FindClosestEnemy(WPos pos, WDist radius)
Actor FindClosestEnemy(IEnumerable<Actor> actors, Actor sourceActor)
{
return World.FindActorsInCircle(pos, radius).Where(a => IsPreferredEnemyUnit(a) && IsNotHiddenUnit(a)).ClosestTo(pos);
return FindEnemies(actors, sourceActor).ClosestToIgnoringPath(sourceActor);
}

void CleanSquads()
Expand Down Expand Up @@ -318,8 +399,13 @@ void TryToRushAttack(IBot bot)
var allEnemyBaseBuilder = AIUtils.FindEnemiesByCommonName(Info.ConstructionYardTypes, Player);

var ownUnits = activeUnits
.Where(unit => unit.IsIdle && unit.Info.HasTraitInfo<AttackBaseInfo>()
&& !Info.AirUnitsTypes.Contains(unit.Info.Name) && !Info.NavalUnitsTypes.Contains(unit.Info.Name) && !Info.ExcludeFromSquadsTypes.Contains(unit.Info.Name)).ToList();
.Where(unit =>
unit.IsIdle
&& unit.Info.HasTraitInfo<AttackBaseInfo>()
&& !Info.AirUnitsTypes.Contains(unit.Info.Name)
&& !Info.NavalUnitsTypes.Contains(unit.Info.Name)
&& !Info.ExcludeFromSquadsTypes.Contains(unit.Info.Name))
.ToList();

if (allEnemyBaseBuilder.Count == 0 || ownUnits.Count < Info.SquadSize)
return;
Expand All @@ -328,7 +414,13 @@ void TryToRushAttack(IBot bot)
{
// Don't rush enemy aircraft!
var enemies = World.FindActorsInCircle(b.CenterPosition, WDist.FromCells(Info.RushAttackScanRadius))
.Where(unit => IsPreferredEnemyUnit(unit) && unit.Info.HasTraitInfo<AttackBaseInfo>() && !Info.AirUnitsTypes.Contains(unit.Info.Name) && !Info.NavalUnitsTypes.Contains(unit.Info.Name)).ToList();
.Where(unit =>
IsPreferredEnemyUnit(unit) && IsNotHiddenUnit(unit)
&& unit.Info.HasTraitInfo<AttackBaseInfo>()
&& !Info.AirUnitsTypes.Contains(unit.Info.Name)
&& !Info.NavalUnitsTypes.Contains(unit.Info.Name))
.WithPathFrom(ownUnits.First())
.ToList();

if (AttackOrFleeFuzzy.Rush.CanAttack(ownUnits, enemies))
{
Expand All @@ -355,7 +447,11 @@ void ProtectOwn(IBot bot, Actor attacker)
if (!protectSq.IsValid)
{
var ownUnits = World.FindActorsInCircle(World.Map.CenterOfCell(GetRandomBaseCenter()), WDist.FromCells(Info.ProtectUnitScanRadius))
.Where(unit => unit.Owner == Player && !Info.ProtectionTypes.Contains(unit.Info.Name) && unit.Info.HasTraitInfo<AttackBaseInfo>());
.Where(unit =>
unit.Owner == Player
&& !Info.ProtectionTypes.Contains(unit.Info.Name)
&& unit.Info.HasTraitInfo<AttackBaseInfo>())
.WithPathTo(protectSq.TargetActor);

foreach (var a in ownUnits)
protectSq.Units.Add(a);
Expand Down

0 comments on commit c011959

Please sign in to comment.