fix bots getting stuck in ra

This commit is contained in:
Chris Forbes
2011-03-05 13:10:43 +13:00
parent a1f1b5882e
commit d9881885aa
2 changed files with 28 additions and 24 deletions

View File

@@ -256,9 +256,6 @@ namespace OpenRA.Mods.RA
//Units that the ai already knows about. Any unit not on this list needs to be given a role. //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>(); List<Actor> activeUnits = new List<Actor>();
//This is purely to identify production buildings that don't have a rally point set.
List<Actor> activeProductionBuildings = new List<Actor>();
bool IsHumanPlayer(Player p) { return !p.IsBot && !p.NonCombatant; } bool IsHumanPlayer(Player p) { return !p.IsBot && !p.NonCombatant; }
bool HasHumanPlayers() bool HasHumanPlayers()
@@ -288,7 +285,6 @@ namespace OpenRA.Mods.RA
activeUnits.RemoveAll(a => a.Destroyed); activeUnits.RemoveAll(a => a.Destroyed);
unitsHangingAroundTheBase.RemoveAll(a => a.Destroyed); unitsHangingAroundTheBase.RemoveAll(a => a.Destroyed);
attackForce.RemoveAll(a => a.Destroyed); attackForce.RemoveAll(a => a.Destroyed);
activeProductionBuildings.RemoveAll(a => a.Destroyed);
// don't select harvesters. // don't select harvesters.
var newUnits = self.World.Queries.OwnedBy[p] var newUnits = self.World.Queries.OwnedBy[p]
@@ -318,34 +314,41 @@ namespace OpenRA.Mods.RA
unitsHangingAroundTheBase.Clear(); unitsHangingAroundTheBase.Clear();
} }
}
bool IsRallyPointValid(int2 x)
{
return world.IsCellBuildable(x, false);
} }
void SetRallyPointsForNewProductionBuildings(Actor self) void SetRallyPointsForNewProductionBuildings(Actor self)
{ {
var newProdBuildings = self.World.Queries.OwnedBy[p] var buildings = self.World.Queries.OwnedBy[p].WithTrait<RallyPoint>()
.Where(a => (a.TraitOrDefault<RallyPoint>() != null .Where(rp => !IsRallyPointValid(rp.Trait.rallyPoint)).ToArray();
&& !activeProductionBuildings.Contains(a)
)).ToArray(); if (buildings.Length > 0)
BotDebug("Bot {0} needs to find rallypoints for {1} buildings.",
p.PlayerName, buildings.Length);
foreach (var a in newProdBuildings)
foreach (var a in buildings)
{ {
activeProductionBuildings.Add(a); int2 newRallyPoint = ChooseRallyLocationNear(a.Actor.Location);
int2 newRallyPoint = ChooseRallyLocationNear(a.Location); world.IssueOrder(new Order("SetRallyPoint", a.Actor, false) { TargetLocation = newRallyPoint });
newRallyPoint.X += 4;
newRallyPoint.Y += 4;
world.IssueOrder(new Order("SetRallyPoint", a, false) { TargetLocation = newRallyPoint });
} }
} }
//won't work for shipyards... //won't work for shipyards...
int2 ChooseRallyLocationNear(int2 startPos) int2 ChooseRallyLocationNear(int2 startPos)
{ {
Random r = new Random(); var possibleRallyPoints = world.FindTilesInCircle(startPos, 8).Where(x => world.IsCellBuildable(x, false)).ToArray();
foreach (var t in world.FindTilesInCircle(startPos, 8)) if (possibleRallyPoints.Length == 0)
if (world.IsCellBuildable(t, false) && t != startPos && r.Next(64) == 0) {
return t; Game.Debug("Bot Bug: No possible rallypoint near {0}", startPos);
return startPos;
return startPos; // i don't know where to put it. }
return possibleRallyPoints.Random(random);
} }
int2? ChooseDestinationNear(Actor a, int2 desiredMoveTarget) int2? ChooseDestinationNear(Actor a, int2 desiredMoveTarget)

View File

@@ -67,17 +67,18 @@ Player:
BuildingFractions: BuildingFractions:
proc: 30% proc: 30%
tent: 1% tent: 1%
barr: 1%
weap: 1% weap: 1%
pbox: 5% pbox: 5%
gun: 15% gun: 15%
ftur: 10% ftur: 10%
tsla: 15% tsla: 10%
fix: 0.1%
dome: 1% dome: 1%
agun: 5% agun: 5%
sam: 1% sam: 1%
atek: 1% atek: 1%
stek: 1% stek: 1%
fix: 0.1%
UnitsToBuild: UnitsToBuild:
1tnk: 0% 1tnk: 0%
2tnk: 0% 2tnk: 0%