Extract BaseBuilderBotModule from HackyAI

This commit is contained in:
reaperrr
2018-11-05 02:39:48 +01:00
committed by Paul Chote
parent 9f30e2ecb0
commit 04c34741c8
7 changed files with 559 additions and 323 deletions

View File

@@ -11,12 +11,15 @@
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.AI
{
public enum BuildingType { Building, Defense, Refinery }
public enum WaterCheck { NotChecked, EnoughWater, NotEnoughWater }
public class CaptureTarget<TInfoType> where TInfoType : class, ITraitInfoInterface
{
internal readonly Actor Actor;
@@ -48,6 +51,40 @@ namespace OpenRA.Mods.Common.AI
.Any(availableCells => availableCells > 0);
}
public static IEnumerable<ProductionQueue> FindQueues(Player player, string category)
{
return player.World.ActorsWithTrait<ProductionQueue>()
.Where(a => a.Actor.Owner == player && a.Trait.Info.Type == category && a.Trait.Enabled)
.Select(a => a.Trait);
}
public static IEnumerable<Actor> GetActorsWithTrait<T>(World world)
{
return world.ActorsHavingTrait<T>();
}
public static int CountActorsWithTrait<T>(string actorName, Player owner)
{
return GetActorsWithTrait<T>(owner.World).Count(a => a.Owner == owner && a.Info.Name == actorName);
}
public static int CountBuildingByCommonName(HashSet<string> buildings, Player owner)
{
return GetActorsWithTrait<Building>(owner.World)
.Count(a => a.Owner == owner && buildings.Contains(a.Info.Name));
}
public static List<Actor> FindEnemiesByCommonName(HashSet<string> commonNames, Player player)
{
return player.World.Actors.Where(a => !a.IsDead && player.Stances[a.Owner] == Stance.Enemy &&
commonNames.Contains(a.Info.Name)).ToList();
}
public static ActorInfo GetInfoByCommonName(HashSet<string> names, Player owner)
{
return owner.World.Map.Rules.Actors.Where(k => names.Contains(k.Key)).Random(owner.World.LocalRandom).Value;
}
public static void BotDebug(string s, params object[] args)
{
if (Game.Settings.Debug.BotDebug)