diff --git a/OpenRA.Mods.Common/AI/AIHarvesterManager.cs b/OpenRA.Mods.Common/AI/AIHarvesterManager.cs index 51b1701fe6..33f636af29 100644 --- a/OpenRA.Mods.Common/AI/AIHarvesterManager.cs +++ b/OpenRA.Mods.Common/AI/AIHarvesterManager.cs @@ -61,18 +61,15 @@ namespace OpenRA.Mods.Common.AI return path[0]; } - public void Tick(List activeUnits) + public void Tick(List harvesters) { if (resLayer == null || resLayer.IsResourceLayerEmpty) return; // Find idle harvesters and give them orders: - foreach (var harvester in activeUnits) + foreach (var harvester in harvesters) { - var harv = harvester.TraitOrDefault(); - if (harv == null) - continue; - + var harv = harvester.Trait(); if (!harv.IsEmpty) continue; diff --git a/OpenRA.Mods.Common/AI/HackyAI.cs b/OpenRA.Mods.Common/AI/HackyAI.cs index 5227c30a33..cb88344b72 100644 --- a/OpenRA.Mods.Common/AI/HackyAI.cs +++ b/OpenRA.Mods.Common/AI/HackyAI.cs @@ -286,6 +286,10 @@ namespace OpenRA.Mods.Common.AI // Units that the ai already knows about. Any unit not on this list needs to be given a role. List activeUnits = new List(); + // Harvesters are usually listed under ExcludeFromSquads, so they're not included in the activeUnits list, but still needed in AIHarvesterManager. + // TODO: Consider adding an explicit UnitsCommonNames.Harvester category. + List harvesters = new List(); + public const int FeedbackTime = 30; // ticks; = a bit over 1s. must be >= netlag. public readonly World World; @@ -597,6 +601,7 @@ namespace OpenRA.Mods.Common.AI activeUnits.RemoveAll(unitCannotBeOrdered); unitsHangingAroundTheBase.RemoveAll(unitCannotBeOrdered); + harvesters.RemoveAll(unitCannotBeOrdered); if (--rushTicks <= 0) { @@ -615,7 +620,7 @@ namespace OpenRA.Mods.Common.AI { assignRolesTicks = Info.AssignRolesInterval; FindNewUnits(self); - harvManager.Tick(activeUnits); + harvManager.Tick(harvesters); InitializeBase(self, true); } @@ -738,10 +743,13 @@ namespace OpenRA.Mods.Common.AI void FindNewUnits(Actor self) { var newUnits = self.World.ActorsHavingTrait() - .Where(a => a.Owner == Player && !activeUnits.Contains(a)); + .Where(a => a.Owner == Player && !activeUnits.Contains(a) && !harvesters.Contains(a)); foreach (var a in newUnits) { + if (a.Info.HasTraitInfo()) + harvesters.Add(a); + if (Info.UnitsCommonNames.Mcv.Contains(a.Info.Name) || Info.UnitsCommonNames.ExcludeFromSquads.Contains(a.Info.Name)) continue;