Unhardcode various AI squad radii
This commit is contained in:
@@ -147,6 +147,18 @@ namespace OpenRA.Mods.Common.AI
|
||||
[Desc("Radius in cells around the center of the base to expand.")]
|
||||
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?")]
|
||||
public readonly bool RestrictMCVDeploymentFallbackToBase = true;
|
||||
|
||||
|
||||
@@ -63,13 +63,14 @@ namespace OpenRA.Mods.Common.AI
|
||||
protected static CPos? FindSafePlace(Squad owner, out Actor detectedEnemyTarget, bool needTarget)
|
||||
{
|
||||
var map = owner.World.Map;
|
||||
var dangerRadius = owner.Bot.Info.DangerScanRadius;
|
||||
detectedEnemyTarget = null;
|
||||
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 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;
|
||||
|
||||
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);
|
||||
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)
|
||||
{
|
||||
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();
|
||||
|
||||
if (!unitsAroundPos.Any())
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
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();
|
||||
|
||||
if (!enemyUnits.Any())
|
||||
@@ -104,7 +104,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
}
|
||||
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>());
|
||||
var target = enemies.ClosestTo(leader.CenterPosition);
|
||||
if (target != null)
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
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();
|
||||
|
||||
if (!enemyUnits.Any())
|
||||
@@ -131,7 +131,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
}
|
||||
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>());
|
||||
var target = enemies.ClosestTo(leader.CenterPosition);
|
||||
if (target != null)
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -20,8 +20,6 @@ namespace OpenRA.Mods.Common.AI
|
||||
{
|
||||
abstract class StateBase
|
||||
{
|
||||
protected const int DangerRadius = 10;
|
||||
|
||||
protected static void GoToRandomOwnBuilding(Squad squad)
|
||||
{
|
||||
var loc = RandomBuildingLocation(squad);
|
||||
@@ -83,11 +81,15 @@ namespace OpenRA.Mods.Common.AI
|
||||
if (!squad.IsValid)
|
||||
return false;
|
||||
|
||||
var u = squad.Units.Random(squad.Random);
|
||||
var units = squad.World.FindActorsInCircle(u.CenterPosition, WDist.FromCells(DangerRadius)).ToList();
|
||||
var ownBaseBuildingAround = units.Where(unit => unit.Owner == squad.Bot.Player && unit.Info.HasTraitInfo<BuildingInfo>());
|
||||
if (ownBaseBuildingAround.Any())
|
||||
return false;
|
||||
var randomSquadUnit = squad.Units.Random(squad.Random);
|
||||
var dangerRadius = squad.Bot.Info.DangerScanRadius;
|
||||
var units = squad.World.FindActorsInCircle(randomSquadUnit.CenterPosition, WDist.FromCells(dangerRadius)).ToList();
|
||||
|
||||
// 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;
|
||||
|
||||
var enemyAroundUnit = units.Where(unit => squad.Bot.Player.Stances[unit.Owner] == Stance.Enemy && unit.Info.HasTraitInfo<AttackBaseInfo>());
|
||||
if (!enemyAroundUnit.Any())
|
||||
|
||||
Reference in New Issue
Block a user