Unhardcode various AI squad radii

This commit is contained in:
reaperrr
2017-12-02 04:15:16 +01:00
committed by Paul Chote
parent eefaf23885
commit 6de90b02d0
6 changed files with 33 additions and 17 deletions

View File

@@ -147,6 +147,18 @@ namespace OpenRA.Mods.Common.AI
[Desc("Radius in cells around the center of the base to expand.")] [Desc("Radius in cells around the center of the base to expand.")]
public readonly int MaxBaseRadius = 20; public readonly int MaxBaseRadius = 20;
[Desc("Radius in cells that squads should scan for enemies around their position while idle.")]
public readonly int IdleScanRadius = 10;
[Desc("Radius in cells that squads should scan for danger around their position to make flee decisions.")]
public readonly int DangerScanRadius = 10;
[Desc("Radius in cells that attack squads should scan for enemies around their position when trying to attack.")]
public readonly int AttackScanRadius = 12;
[Desc("Radius in cells that protecting squads should scan for enemies around their position.")]
public readonly int ProtectionScanRadius = 8;
[Desc("Should deployment of additional MCVs be restricted to MaxBaseRadius if explicit deploy locations are missing or occupied?")] [Desc("Should deployment of additional MCVs be restricted to MaxBaseRadius if explicit deploy locations are missing or occupied?")]
public readonly bool RestrictMCVDeploymentFallbackToBase = true; public readonly bool RestrictMCVDeploymentFallbackToBase = true;

View File

@@ -63,13 +63,14 @@ namespace OpenRA.Mods.Common.AI
protected static CPos? FindSafePlace(Squad owner, out Actor detectedEnemyTarget, bool needTarget) protected static CPos? FindSafePlace(Squad owner, out Actor detectedEnemyTarget, bool needTarget)
{ {
var map = owner.World.Map; var map = owner.World.Map;
var dangerRadius = owner.Bot.Info.DangerScanRadius;
detectedEnemyTarget = null; detectedEnemyTarget = null;
var x = (map.MapSize.X % DangerRadius) == 0 ? map.MapSize.X : map.MapSize.X + DangerRadius; var x = (map.MapSize.X % dangerRadius) == 0 ? map.MapSize.X : map.MapSize.X + dangerRadius;
var y = (map.MapSize.Y % DangerRadius) == 0 ? map.MapSize.Y : map.MapSize.Y + DangerRadius; var y = (map.MapSize.Y % dangerRadius) == 0 ? map.MapSize.Y : map.MapSize.Y + dangerRadius;
for (var i = 0; i < x; i += DangerRadius * 2) for (var i = 0; i < x; i += dangerRadius * 2)
{ {
for (var j = 0; j < y; j += DangerRadius * 2) for (var j = 0; j < y; j += dangerRadius * 2)
{ {
var pos = new CPos(i, j); var pos = new CPos(i, j);
if (NearToPosSafely(owner, map.CenterOfCell(pos), out detectedEnemyTarget)) if (NearToPosSafely(owner, map.CenterOfCell(pos), out detectedEnemyTarget))
@@ -94,7 +95,8 @@ namespace OpenRA.Mods.Common.AI
protected static bool NearToPosSafely(Squad owner, WPos loc, out Actor detectedEnemyTarget) protected static bool NearToPosSafely(Squad owner, WPos loc, out Actor detectedEnemyTarget)
{ {
detectedEnemyTarget = null; detectedEnemyTarget = null;
var unitsAroundPos = owner.World.FindActorsInCircle(loc, WDist.FromCells(DangerRadius)) var dangerRadius = owner.Bot.Info.DangerScanRadius;
var unitsAroundPos = owner.World.FindActorsInCircle(loc, WDist.FromCells(dangerRadius))
.Where(unit => owner.Bot.Player.Stances[unit.Owner] == Stance.Enemy).ToList(); .Where(unit => owner.Bot.Player.Stances[unit.Owner] == Stance.Enemy).ToList();
if (!unitsAroundPos.Any()) if (!unitsAroundPos.Any())

View File

@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.AI
owner.TargetActor = closestEnemy; owner.TargetActor = closestEnemy;
} }
var enemyUnits = owner.World.FindActorsInCircle(owner.TargetActor.CenterPosition, WDist.FromCells(10)) var enemyUnits = owner.World.FindActorsInCircle(owner.TargetActor.CenterPosition, WDist.FromCells(owner.Bot.Info.IdleScanRadius))
.Where(unit => owner.Bot.Player.Stances[unit.Owner] == Stance.Enemy).ToList(); .Where(unit => owner.Bot.Player.Stances[unit.Owner] == Stance.Enemy).ToList();
if (!enemyUnits.Any()) if (!enemyUnits.Any())
@@ -104,7 +104,7 @@ namespace OpenRA.Mods.Common.AI
} }
else else
{ {
var enemies = owner.World.FindActorsInCircle(leader.CenterPosition, WDist.FromCells(12)) var enemies = owner.World.FindActorsInCircle(leader.CenterPosition, WDist.FromCells(owner.Bot.Info.AttackScanRadius))
.Where(a => !a.IsDead && leader.Owner.Stances[a.Owner] == Stance.Enemy && a.Info.HasTraitInfo<ITargetableInfo>()); .Where(a => !a.IsDead && leader.Owner.Stances[a.Owner] == Stance.Enemy && a.Info.HasTraitInfo<ITargetableInfo>());
var target = enemies.ClosestTo(leader.CenterPosition); var target = enemies.ClosestTo(leader.CenterPosition);
if (target != null) if (target != null)

View File

@@ -72,7 +72,7 @@ namespace OpenRA.Mods.Common.AI
owner.TargetActor = closestEnemy; owner.TargetActor = closestEnemy;
} }
var enemyUnits = owner.World.FindActorsInCircle(owner.TargetActor.CenterPosition, WDist.FromCells(10)) var enemyUnits = owner.World.FindActorsInCircle(owner.TargetActor.CenterPosition, WDist.FromCells(owner.Bot.Info.IdleScanRadius))
.Where(unit => owner.Bot.Player.Stances[unit.Owner] == Stance.Enemy).ToList(); .Where(unit => owner.Bot.Player.Stances[unit.Owner] == Stance.Enemy).ToList();
if (!enemyUnits.Any()) if (!enemyUnits.Any())
@@ -131,7 +131,7 @@ namespace OpenRA.Mods.Common.AI
} }
else else
{ {
var enemies = owner.World.FindActorsInCircle(leader.CenterPosition, WDist.FromCells(12)) var enemies = owner.World.FindActorsInCircle(leader.CenterPosition, WDist.FromCells(owner.Bot.Info.AttackScanRadius))
.Where(a => !a.IsDead && leader.Owner.Stances[a.Owner] == Stance.Enemy && a.Info.HasTraitInfo<ITargetableInfo>()); .Where(a => !a.IsDead && leader.Owner.Stances[a.Owner] == Stance.Enemy && a.Info.HasTraitInfo<ITargetableInfo>());
var target = enemies.ClosestTo(leader.CenterPosition); var target = enemies.ClosestTo(leader.CenterPosition);
if (target != null) if (target != null)

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.AI
if (!owner.IsTargetValid) if (!owner.IsTargetValid)
{ {
owner.TargetActor = owner.Bot.FindClosestEnemy(owner.CenterPosition, WDist.FromCells(8)); owner.TargetActor = owner.Bot.FindClosestEnemy(owner.CenterPosition, WDist.FromCells(owner.Bot.Info.ProtectionScanRadius));
if (owner.TargetActor == null) if (owner.TargetActor == null)
{ {

View File

@@ -20,8 +20,6 @@ namespace OpenRA.Mods.Common.AI
{ {
abstract class StateBase abstract class StateBase
{ {
protected const int DangerRadius = 10;
protected static void GoToRandomOwnBuilding(Squad squad) protected static void GoToRandomOwnBuilding(Squad squad)
{ {
var loc = RandomBuildingLocation(squad); var loc = RandomBuildingLocation(squad);
@@ -83,10 +81,14 @@ namespace OpenRA.Mods.Common.AI
if (!squad.IsValid) if (!squad.IsValid)
return false; return false;
var u = squad.Units.Random(squad.Random); var randomSquadUnit = squad.Units.Random(squad.Random);
var units = squad.World.FindActorsInCircle(u.CenterPosition, WDist.FromCells(DangerRadius)).ToList(); var dangerRadius = squad.Bot.Info.DangerScanRadius;
var ownBaseBuildingAround = units.Where(unit => unit.Owner == squad.Bot.Player && unit.Info.HasTraitInfo<BuildingInfo>()); var units = squad.World.FindActorsInCircle(randomSquadUnit.CenterPosition, WDist.FromCells(dangerRadius)).ToList();
if (ownBaseBuildingAround.Any())
// If there are any own buildings within the DangerRadius, don't flee
// PERF: Avoid LINQ
foreach (var u in units)
if (u.Owner == squad.Bot.Player && u.Info.HasTraitInfo<BuildingInfo>())
return false; return false;
var enemyAroundUnit = units.Where(unit => squad.Bot.Player.Stances[unit.Owner] == Stance.Enemy && unit.Info.HasTraitInfo<AttackBaseInfo>()); var enemyAroundUnit = units.Where(unit => squad.Bot.Player.Stances[unit.Owner] == Stance.Enemy && unit.Info.HasTraitInfo<AttackBaseInfo>());