diff --git a/OpenRA.Mods.RA/HackyAI.cs b/OpenRA.Mods.RA/HackyAI.cs index aaadc5ade1..88525a98d6 100644 --- a/OpenRA.Mods.RA/HackyAI.cs +++ b/OpenRA.Mods.RA/HackyAI.cs @@ -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. List activeUnits = new List(); - //This is purely to identify production buildings that don't have a rally point set. - List activeProductionBuildings = new List(); - bool IsHumanPlayer(Player p) { return !p.IsBot && !p.NonCombatant; } bool HasHumanPlayers() @@ -288,7 +285,6 @@ namespace OpenRA.Mods.RA activeUnits.RemoveAll(a => a.Destroyed); unitsHangingAroundTheBase.RemoveAll(a => a.Destroyed); attackForce.RemoveAll(a => a.Destroyed); - activeProductionBuildings.RemoveAll(a => a.Destroyed); // don't select harvesters. var newUnits = self.World.Queries.OwnedBy[p] @@ -318,34 +314,41 @@ namespace OpenRA.Mods.RA unitsHangingAroundTheBase.Clear(); } + } + + bool IsRallyPointValid(int2 x) + { + return world.IsCellBuildable(x, false); } void SetRallyPointsForNewProductionBuildings(Actor self) - { - var newProdBuildings = self.World.Queries.OwnedBy[p] - .Where(a => (a.TraitOrDefault() != null - && !activeProductionBuildings.Contains(a) - )).ToArray(); + { + var buildings = self.World.Queries.OwnedBy[p].WithTrait() + .Where(rp => !IsRallyPointValid(rp.Trait.rallyPoint)).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.Location); - newRallyPoint.X += 4; - newRallyPoint.Y += 4; - world.IssueOrder(new Order("SetRallyPoint", a, false) { TargetLocation = newRallyPoint }); + int2 newRallyPoint = ChooseRallyLocationNear(a.Actor.Location); + world.IssueOrder(new Order("SetRallyPoint", a.Actor, false) { TargetLocation = newRallyPoint }); } } //won't work for shipyards... int2 ChooseRallyLocationNear(int2 startPos) - { - Random r = new Random(); - foreach (var t in world.FindTilesInCircle(startPos, 8)) - if (world.IsCellBuildable(t, false) && t != startPos && r.Next(64) == 0) - return t; - - return startPos; // i don't know where to put it. + { + var possibleRallyPoints = world.FindTilesInCircle(startPos, 8).Where(x => world.IsCellBuildable(x, false)).ToArray(); + if (possibleRallyPoints.Length == 0) + { + Game.Debug("Bot Bug: No possible rallypoint near {0}", startPos); + return startPos; + } + + return possibleRallyPoints.Random(random); } int2? ChooseDestinationNear(Actor a, int2 desiredMoveTarget) diff --git a/mods/ra/rules/system.yaml b/mods/ra/rules/system.yaml index 4122af73d1..a4fbce3cc6 100644 --- a/mods/ra/rules/system.yaml +++ b/mods/ra/rules/system.yaml @@ -67,17 +67,18 @@ Player: BuildingFractions: proc: 30% tent: 1% + barr: 1% weap: 1% pbox: 5% gun: 15% ftur: 10% - tsla: 15% + tsla: 10% + fix: 0.1% dome: 1% agun: 5% sam: 1% atek: 1% stek: 1% - fix: 0.1% UnitsToBuild: 1tnk: 0% 2tnk: 0%