New types for cell and pixel coordinate position/vectors.
This commit is contained in:
@@ -72,7 +72,7 @@ namespace OpenRA.Mods.RA.AI
|
||||
readonly HackyAIInfo Info;
|
||||
|
||||
Cache<Player,Enemy> aggro = new Cache<Player, Enemy>( _ => new Enemy() );
|
||||
int2 baseCenter;
|
||||
CPos baseCenter;
|
||||
XRandom random = new XRandom(); //we do not use the synced random number generator.
|
||||
BaseBuilder[] builders;
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace OpenRA.Mods.RA.AI
|
||||
ActorInfo ChooseRandomUnitToBuild(ProductionQueue queue)
|
||||
{
|
||||
var buildableThings = queue.BuildableItems();
|
||||
if (buildableThings.Count() == 0) return null;
|
||||
if (!buildableThings.Any()) return null;
|
||||
return buildableThings.ElementAtOrDefault(random.Next(buildableThings.Count()));
|
||||
}
|
||||
|
||||
@@ -154,13 +154,13 @@ namespace OpenRA.Mods.RA.AI
|
||||
return null;
|
||||
}
|
||||
|
||||
bool NoBuildingsUnder(IEnumerable<int2> cells)
|
||||
bool NoBuildingsUnder(IEnumerable<CPos> cells)
|
||||
{
|
||||
var bi = world.WorldActor.Trait<BuildingInfluence>();
|
||||
return cells.All(c => bi.GetBuildingAt(c) == null);
|
||||
}
|
||||
|
||||
public int2? ChooseBuildLocation(string actorType)
|
||||
public CPos? ChooseBuildLocation(string actorType)
|
||||
{
|
||||
var bi = Rules.Info[actorType].Traits.Get<BuildingInfo>();
|
||||
|
||||
@@ -200,12 +200,12 @@ namespace OpenRA.Mods.RA.AI
|
||||
//A bunch of hardcoded lists to keep track of which units are doing what.
|
||||
List<Actor> unitsHangingAroundTheBase = new List<Actor>();
|
||||
List<Actor> attackForce = new List<Actor>();
|
||||
int2? attackTarget;
|
||||
CPos? attackTarget;
|
||||
|
||||
//Units that the ai already knows about. Any unit not on this list needs to be given a role.
|
||||
List<Actor> activeUnits = new List<Actor>();
|
||||
|
||||
int2? ChooseEnemyTarget()
|
||||
CPos? ChooseEnemyTarget()
|
||||
{
|
||||
var liveEnemies = world.Players
|
||||
.Where(q => p != q && p.Stances[q] == Stance.Enemy)
|
||||
@@ -219,14 +219,14 @@ namespace OpenRA.Mods.RA.AI
|
||||
if (leastLikedEnemies == null)
|
||||
return null;
|
||||
|
||||
var enemy = leastLikedEnemies != null ? leastLikedEnemies.Random(random) : null;
|
||||
var enemy = leastLikedEnemies.Random(random);
|
||||
|
||||
/* pick something worth attacking owned by that player */
|
||||
var targets = world.Actors
|
||||
.Where(a => a.Owner == enemy && a.HasTrait<IOccupySpace>());
|
||||
Actor target=null;
|
||||
Actor target = null;
|
||||
|
||||
if (targets.Count()>0)
|
||||
if (targets.Any())
|
||||
target = targets.Random(random);
|
||||
|
||||
if (target == null)
|
||||
@@ -346,7 +346,7 @@ namespace OpenRA.Mods.RA.AI
|
||||
}
|
||||
}
|
||||
|
||||
bool IsRallyPointValid(int2 x)
|
||||
bool IsRallyPointValid(CPos x)
|
||||
{
|
||||
// this is actually WRONG as soon as HackyAI is building units with a variety of
|
||||
// movement capabilities. (has always been wrong)
|
||||
@@ -363,16 +363,15 @@ namespace OpenRA.Mods.RA.AI
|
||||
BotDebug("Bot {0} needs to find rallypoints for {1} buildings.",
|
||||
p.PlayerName, buildings.Length);
|
||||
|
||||
|
||||
foreach (var a in buildings)
|
||||
{
|
||||
int2 newRallyPoint = ChooseRallyLocationNear(a.Actor.Location);
|
||||
CPos newRallyPoint = ChooseRallyLocationNear(a.Actor.Location);
|
||||
world.IssueOrder(new Order("SetRallyPoint", a.Actor, false) { TargetLocation = newRallyPoint });
|
||||
}
|
||||
}
|
||||
|
||||
//won't work for shipyards...
|
||||
int2 ChooseRallyLocationNear(int2 startPos)
|
||||
CPos ChooseRallyLocationNear(CPos startPos)
|
||||
{
|
||||
var possibleRallyPoints = world.FindTilesInCircle(startPos, 8).Where(IsRallyPointValid).ToArray();
|
||||
if (possibleRallyPoints.Length == 0)
|
||||
@@ -384,18 +383,18 @@ namespace OpenRA.Mods.RA.AI
|
||||
return possibleRallyPoints.Random(random);
|
||||
}
|
||||
|
||||
int2? ChooseDestinationNear(Actor a, int2 desiredMoveTarget)
|
||||
CPos? ChooseDestinationNear(Actor a, CPos desiredMoveTarget)
|
||||
{
|
||||
var move = a.TraitOrDefault<IMove>();
|
||||
if (move == null) return null;
|
||||
|
||||
int2 xy;
|
||||
CPos xy;
|
||||
int loopCount = 0; //avoid infinite loops.
|
||||
int range = 2;
|
||||
do
|
||||
{
|
||||
//loop until we find a valid move location
|
||||
xy = new int2(desiredMoveTarget.X + random.Next(-range, range), desiredMoveTarget.Y + random.Next(-range, range));
|
||||
xy = new CPos(desiredMoveTarget.X + random.Next(-range, range), desiredMoveTarget.Y + random.Next(-range, range));
|
||||
loopCount++;
|
||||
range = Math.Max(range, loopCount / 2);
|
||||
if (loopCount > 10) return null;
|
||||
@@ -406,7 +405,7 @@ namespace OpenRA.Mods.RA.AI
|
||||
|
||||
//try very hard to find a valid move destination near the target.
|
||||
//(Don't accept a move onto the subject's current position. maybe this is already not allowed? )
|
||||
bool TryToMove(Actor a, int2 desiredMoveTarget, bool attackMove)
|
||||
bool TryToMove(Actor a, CPos desiredMoveTarget, bool attackMove)
|
||||
{
|
||||
var xy = ChooseDestinationNear(a, desiredMoveTarget);
|
||||
if (xy == null)
|
||||
|
||||
Reference in New Issue
Block a user