Rename and simplify MayBeFlee -> ShouldFlee.
This commit is contained in:
@@ -21,6 +21,9 @@ namespace OpenRA.Mods.RA.AI
|
|||||||
|
|
||||||
protected static int CountAntiAirUnits(IEnumerable<Actor> units)
|
protected static int CountAntiAirUnits(IEnumerable<Actor> units)
|
||||||
{
|
{
|
||||||
|
if (!units.Any())
|
||||||
|
return 0;
|
||||||
|
|
||||||
int missileUnitsCount = 0;
|
int missileUnitsCount = 0;
|
||||||
foreach (var unit in units)
|
foreach (var unit in units)
|
||||||
if (unit != null && unit.HasTrait<AttackBase>() && !unit.HasTrait<Aircraft>()
|
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
|
//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) =>
|
return base.ShouldFlee(owner, enemies => CountAntiAirUnits(enemies) * missileUnitsMultiplier > owner.units.Count);
|
||||||
{
|
|
||||||
int missileUnitsCount = 0;
|
|
||||||
if (enemyAroundUnit.Any())
|
|
||||||
missileUnitsCount = CountAntiAirUnits(enemyAroundUnit);
|
|
||||||
|
|
||||||
if (missileUnitsCount * missileUnitsMultiplier > owner.units.Count)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Actor FindDefenselessTarget(Squad owner)
|
protected static Actor FindDefenselessTarget(Squad owner)
|
||||||
@@ -154,7 +147,7 @@ namespace OpenRA.Mods.RA.AI
|
|||||||
if (!owner.IsValid)
|
if (!owner.IsValid)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (MayBeFlee(owner))
|
if (ShouldFlee(owner))
|
||||||
{
|
{
|
||||||
owner.fsm.ChangeState(owner, new AirFleeState(), true);
|
owner.fsm.ChangeState(owner, new AirFleeState(), true);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -16,10 +16,9 @@ namespace OpenRA.Mods.RA.AI
|
|||||||
{
|
{
|
||||||
abstract class GroundStateBase : StateBase
|
abstract class GroundStateBase : StateBase
|
||||||
{
|
{
|
||||||
protected virtual bool MayBeFlee(Squad owner)
|
protected virtual bool ShouldFlee(Squad owner)
|
||||||
{
|
{
|
||||||
return base.MayBeFlee(owner, enemyAroundUnit =>
|
return base.ShouldFlee(owner, enemies => !owner.attackOrFleeFuzzy.CanAttack(owner.units, enemies));
|
||||||
!owner.attackOrFleeFuzzy.CanAttack(owner.units, enemyAroundUnit));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +108,7 @@ namespace OpenRA.Mods.RA.AI
|
|||||||
owner.world.IssueOrder(new Order("AttackMove", a, false) { TargetLocation = owner.Target.Location });
|
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);
|
owner.fsm.ChangeState(owner, new GroundUnitsFleeState(), true);
|
||||||
return;
|
return;
|
||||||
@@ -139,11 +138,12 @@ namespace OpenRA.Mods.RA.AI
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var a in owner.units)
|
foreach (var a in owner.units)
|
||||||
if (!BusyAttack(a))
|
if (!BusyAttack(a))
|
||||||
owner.world.IssueOrder(new Order("Attack", a, false) { TargetActor = owner.bot.FindClosestEnemy(a.CenterPosition) });
|
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);
|
owner.fsm.ChangeState(owner, new GroundUnitsFleeState(), true);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ namespace OpenRA.Mods.RA.AI
|
|||||||
return false;
|
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)
|
if (!squad.IsValid)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user