hackyai should only attack humans

This commit is contained in:
Chris Forbes
2010-10-06 20:04:36 +13:00
parent cfc74a6dee
commit 7ec9958d47

View File

@@ -223,7 +223,29 @@ namespace OpenRA.Mods.RA
//This is purely to identify production buildings that don't have a rally point set. //This is purely to identify production buildings that don't have a rally point set.
List<Actor> activeProductionBuildings = new List<Actor>(); List<Actor> activeProductionBuildings = new List<Actor>();
private void AssignRolesToIdleUnits(Actor self) bool IsHumanPlayer(Player p)
{
/* hack hack: this actually detects 'is not HackyAI' -- possibly actually a good thing. */
var hackyAI = p.PlayerActor.Trait<HackyAI>();
return !hackyAI.enabled;
}
int2? ChooseEnemyTarget()
{
// Criteria for picking an enemy:
// 1. not ourself.
// 2. human.
// 3. not dead.
var possibleTargets = Game.world.WorldActor.Trait<MPStartLocations>().Start
.Where(kv => kv.Key != p && IsHumanPlayer(kv.Key)
&& p.WinState == WinState.Undefined)
.Select(kv => kv.Value);
return possibleTargets.Any() ? possibleTargets.Random(random) : (int2?) null;
}
void AssignRolesToIdleUnits(Actor self)
{ {
//HACK: trim these lists -- we really shouldn't be hanging onto all this state //HACK: trim these lists -- we really shouldn't be hanging onto all this state
//when it's invalidated so easily, but that's Matthew/Alli's problem. //when it's invalidated so easily, but that's Matthew/Alli's problem.
@@ -249,14 +271,15 @@ namespace OpenRA.Mods.RA
if (unitsHangingAroundTheBase.Count > 8) if (unitsHangingAroundTheBase.Count > 8)
{ {
Game.Debug("Launch an attack."); Game.Debug("Launch an attack.");
int2 attackTarget = Game.world.WorldActor.Trait<MPStartLocations>().Start var attackTarget = ChooseEnemyTarget();
.Where(kv => kv.Key != p) if (attackTarget == null)
.Select(kv => kv.Value) return;
.Random(random);
foreach (var a in unitsHangingAroundTheBase) foreach (var a in unitsHangingAroundTheBase)
if (TryToMove(a, attackTarget)) if (TryToMove(a, attackTarget.Value))
attackForce.Add(a); attackForce.Add(a);
unitsHangingAroundTheBase.Clear(); unitsHangingAroundTheBase.Clear();
} }
} }