Unify Squad enemy unit filtering.
This commit is contained in:
@@ -91,7 +91,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public readonly World World;
|
||||
public readonly Player Player;
|
||||
|
||||
readonly Func<Actor, bool> isEnemyUnit;
|
||||
readonly Predicate<Actor> unitCannotBeOrdered;
|
||||
|
||||
public List<Squad> Squads = new List<Squad>();
|
||||
@@ -116,14 +115,16 @@ namespace OpenRA.Mods.Common.Traits
|
||||
World = self.World;
|
||||
Player = self.Owner;
|
||||
|
||||
isEnemyUnit = unit =>
|
||||
Player.Stances[unit.Owner] == Stance.Enemy
|
||||
&& !unit.Info.HasTraitInfo<HuskInfo>()
|
||||
&& unit.Info.HasTraitInfo<ITargetableInfo>();
|
||||
|
||||
unitCannotBeOrdered = a => a.Owner != Player || a.IsDead || !a.IsInWorld;
|
||||
}
|
||||
|
||||
public bool IsEnemyUnit(Actor a)
|
||||
{
|
||||
return a != null && !a.IsDead && Player.Stances[a.Owner] == Stance.Enemy
|
||||
&& !a.Info.HasTraitInfo<HuskInfo>()
|
||||
&& !a.GetEnabledTargetTypes().IsEmpty;
|
||||
}
|
||||
|
||||
protected override void TraitEnabled(Actor self)
|
||||
{
|
||||
notifyPositionsUpdated = Player.PlayerActor.TraitsImplementing<IBotPositionsUpdated>().ToArray();
|
||||
@@ -146,12 +147,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
internal Actor FindClosestEnemy(WPos pos)
|
||||
{
|
||||
return World.Actors.Where(isEnemyUnit).ClosestTo(pos);
|
||||
return World.Actors.Where(IsEnemyUnit).ClosestTo(pos);
|
||||
}
|
||||
|
||||
internal Actor FindClosestEnemy(WPos pos, WDist radius)
|
||||
{
|
||||
return World.FindActorsInCircle(pos, radius).Where(isEnemyUnit).ClosestTo(pos);
|
||||
return World.FindActorsInCircle(pos, radius).Where(IsEnemyUnit).ClosestTo(pos);
|
||||
}
|
||||
|
||||
void CleanSquads()
|
||||
@@ -280,7 +281,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
foreach (var b in allEnemyBaseBuilder)
|
||||
{
|
||||
var enemies = World.FindActorsInCircle(b.CenterPosition, WDist.FromCells(Info.RushAttackScanRadius))
|
||||
.Where(unit => Player.Stances[unit.Owner] == Stance.Enemy && unit.Info.HasTraitInfo<AttackBaseInfo>()).ToList();
|
||||
.Where(unit => IsEnemyUnit(unit) && unit.Info.HasTraitInfo<AttackBaseInfo>()).ToList();
|
||||
|
||||
if (AttackOrFleeFuzzy.Rush.CanAttack(ownUnits, enemies))
|
||||
{
|
||||
@@ -326,16 +327,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
void IBotRespondToAttack.RespondToAttack(IBot bot, Actor self, AttackInfo e)
|
||||
{
|
||||
if (e.Attacker == null)
|
||||
return;
|
||||
|
||||
if (e.Attacker.Disposed)
|
||||
return;
|
||||
|
||||
if (e.Attacker.Owner.Stances[self.Owner] != Stance.Enemy)
|
||||
return;
|
||||
|
||||
if (!e.Attacker.Info.HasTraitInfo<ITargetableInfo>())
|
||||
if (!IsEnemyUnit(e.Attacker))
|
||||
return;
|
||||
|
||||
// Protected priority assets, MCVs, harvesters and buildings
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads
|
||||
detectedEnemyTarget = null;
|
||||
var dangerRadius = owner.SquadManager.Info.DangerScanRadius;
|
||||
var unitsAroundPos = owner.World.FindActorsInCircle(loc, WDist.FromCells(dangerRadius))
|
||||
.Where(unit => owner.Bot.Player.Stances[unit.Owner] == Stance.Enemy).ToList();
|
||||
.Where(owner.SquadManager.IsEnemyUnit).ToList();
|
||||
|
||||
if (!unitsAroundPos.Any())
|
||||
return true;
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads
|
||||
}
|
||||
|
||||
var enemyUnits = owner.World.FindActorsInCircle(owner.TargetActor.CenterPosition, WDist.FromCells(owner.SquadManager.Info.IdleScanRadius))
|
||||
.Where(unit => owner.Bot.Player.Stances[unit.Owner] == Stance.Enemy).ToList();
|
||||
.Where(owner.SquadManager.IsEnemyUnit).ToList();
|
||||
|
||||
if (enemyUnits.Count == 0)
|
||||
return;
|
||||
@@ -105,7 +105,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads
|
||||
else
|
||||
{
|
||||
var enemies = owner.World.FindActorsInCircle(leader.CenterPosition, WDist.FromCells(owner.SquadManager.Info.AttackScanRadius))
|
||||
.Where(a => !a.IsDead && leader.Owner.Stances[a.Owner] == Stance.Enemy && !a.GetEnabledTargetTypes().IsEmpty);
|
||||
.Where(owner.SquadManager.IsEnemyUnit);
|
||||
var target = enemies.ClosestTo(leader.CenterPosition);
|
||||
if (target != null)
|
||||
{
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads
|
||||
}
|
||||
|
||||
var enemyUnits = owner.World.FindActorsInCircle(owner.TargetActor.CenterPosition, WDist.FromCells(owner.SquadManager.Info.IdleScanRadius))
|
||||
.Where(unit => owner.Bot.Player.Stances[unit.Owner] == Stance.Enemy).ToList();
|
||||
.Where(owner.SquadManager.IsEnemyUnit).ToList();
|
||||
|
||||
if (enemyUnits.Count == 0)
|
||||
return;
|
||||
@@ -130,7 +130,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads
|
||||
else
|
||||
{
|
||||
var enemies = owner.World.FindActorsInCircle(leader.CenterPosition, WDist.FromCells(owner.SquadManager.Info.AttackScanRadius))
|
||||
.Where(a => !a.IsDead && leader.Owner.Stances[a.Owner] == Stance.Enemy && !a.GetEnabledTargetTypes().IsEmpty);
|
||||
.Where(owner.SquadManager.IsEnemyUnit);
|
||||
var target = enemies.ClosestTo(leader.CenterPosition);
|
||||
if (target != null)
|
||||
{
|
||||
|
||||
@@ -95,7 +95,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads
|
||||
if (u.Owner == squad.Bot.Player && u.Info.HasTraitInfo<BuildingInfo>())
|
||||
return false;
|
||||
|
||||
var enemyAroundUnit = units.Where(unit => squad.Bot.Player.Stances[unit.Owner] == Stance.Enemy && unit.Info.HasTraitInfo<AttackBaseInfo>());
|
||||
var enemyAroundUnit = units.Where(unit => squad.SquadManager.IsEnemyUnit(unit) && unit.Info.HasTraitInfo<AttackBaseInfo>());
|
||||
if (!enemyAroundUnit.Any())
|
||||
return false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user