Rename and simplify MayBeFlee -> ShouldFlee.

This commit is contained in:
Paul Chote
2013-08-24 11:25:25 +12:00
parent 7bcdf7d74b
commit d46c535850
3 changed files with 12 additions and 19 deletions

View File

@@ -21,6 +21,9 @@ namespace OpenRA.Mods.RA.AI
protected static int CountAntiAirUnits(IEnumerable<Actor> units)
{
if (!units.Any())
return 0;
int missileUnitsCount = 0;
foreach (var unit in units)
if (unit != null && unit.HasTrait<AttackBase>() && !unit.HasTrait<Aircraft>()
@@ -38,19 +41,9 @@ namespace OpenRA.Mods.RA.AI
}
//checks the number of anti air enemies around units
protected virtual bool MayBeFlee(Squad owner)
protected virtual bool ShouldFlee(Squad owner)
{
return base.MayBeFlee(owner, (enemyAroundUnit) =>
{
int missileUnitsCount = 0;
if (enemyAroundUnit.Any())
missileUnitsCount = CountAntiAirUnits(enemyAroundUnit);
if (missileUnitsCount * missileUnitsMultiplier > owner.units.Count)
return true;
return false;
});
return base.ShouldFlee(owner, enemies => CountAntiAirUnits(enemies) * missileUnitsMultiplier > owner.units.Count);
}
protected static Actor FindDefenselessTarget(Squad owner)
@@ -154,7 +147,7 @@ namespace OpenRA.Mods.RA.AI
if (!owner.IsValid)
return;
if (MayBeFlee(owner))
if (ShouldFlee(owner))
{
owner.fsm.ChangeState(owner, new AirFleeState(), true);
return;

View File

@@ -16,10 +16,9 @@ namespace OpenRA.Mods.RA.AI
{
abstract class GroundStateBase : StateBase
{
protected virtual bool MayBeFlee(Squad owner)
protected virtual bool ShouldFlee(Squad owner)
{
return base.MayBeFlee(owner, enemyAroundUnit =>
!owner.attackOrFleeFuzzy.CanAttack(owner.units, enemyAroundUnit));
return base.ShouldFlee(owner, enemies => !owner.attackOrFleeFuzzy.CanAttack(owner.units, enemies));
}
}
@@ -109,7 +108,7 @@ namespace OpenRA.Mods.RA.AI
owner.world.IssueOrder(new Order("AttackMove", a, false) { TargetLocation = owner.Target.Location });
}
if (MayBeFlee(owner))
if (ShouldFlee(owner))
{
owner.fsm.ChangeState(owner, new GroundUnitsFleeState(), true);
return;
@@ -139,11 +138,12 @@ namespace OpenRA.Mods.RA.AI
return;
}
}
foreach (var a in owner.units)
if (!BusyAttack(a))
owner.world.IssueOrder(new Order("Attack", a, false) { TargetActor = owner.bot.FindClosestEnemy(a.CenterPosition) });
if (MayBeFlee(owner))
if (ShouldFlee(owner))
{
owner.fsm.ChangeState(owner, new GroundUnitsFleeState(), true);
return;

View File

@@ -75,7 +75,7 @@ namespace OpenRA.Mods.RA.AI
return false;
}
protected virtual bool MayBeFlee(Squad squad, Func<IEnumerable<Actor>, bool> flee)
protected virtual bool ShouldFlee(Squad squad, Func<IEnumerable<Actor>, bool> flee)
{
if (!squad.IsValid)
return false;