diff --git a/OpenRA.Mods.RA/AI/HackyAI.cs b/OpenRA.Mods.RA/AI/HackyAI.cs index 93df902f2c..21ebf35f50 100644 --- a/OpenRA.Mods.RA/AI/HackyAI.cs +++ b/OpenRA.Mods.RA/AI/HackyAI.cs @@ -76,7 +76,7 @@ namespace OpenRA.Mods.RA.AI XRandom random = new XRandom(); //we do not use the synced random number generator. BaseBuilder[] builders; - const int MaxBaseDistance = 15; + const int MaxBaseDistance = 20; public const int feedbackTime = 30; // ticks; = a bit over 1s. must be >= netlag. public World world { get { return p.PlayerActor.World; } } @@ -221,18 +221,27 @@ namespace OpenRA.Mods.RA.AI var enemy = leastLikedEnemies != null ? leastLikedEnemies.Random(random) : null; + /* pick something worth attacking owned by that player */ + var targets = world.Actors + .Where(a => a.Owner == enemy && a.HasTrait()); + Actor target=null; + + if (targets.Count()>0) + target = targets.Random(random); + + if (target == null) + { + /* Assume that "enemy" has nothing. Cool off on attacks. */ + aggro[enemy].Aggro = aggro[enemy].Aggro / 2 - 1; + Log.Write("debug", "Bot {0} couldn't find target for player {1}", this.p.ClientIndex, enemy.ClientIndex); + + return null; + } + /* bump the aggro slightly to avoid changing our mind */ if (leastLikedEnemies.Count() > 1) aggro[enemy].Aggro++; - /* pick something worth attacking owned by that player */ - var target = world.Actors - .Where(a => a.Owner == enemy && a.HasTrait()) - .Random(random); - - if (target == null) - return null; - return target.Location; }