Fix AI idle harvester management

This was broken because our default mods now list `harv` under `ExcludeFromSquads`, which prevents them from being added to `activeUnits`.
This commit is contained in:
reaperrr
2018-07-31 23:20:18 +02:00
committed by reaperrr
parent 35600d9291
commit 6c401f0f9a
2 changed files with 13 additions and 8 deletions

View File

@@ -61,18 +61,15 @@ namespace OpenRA.Mods.Common.AI
return path[0]; return path[0];
} }
public void Tick(List<Actor> activeUnits) public void Tick(List<Actor> harvesters)
{ {
if (resLayer == null || resLayer.IsResourceLayerEmpty) if (resLayer == null || resLayer.IsResourceLayerEmpty)
return; return;
// Find idle harvesters and give them orders: // Find idle harvesters and give them orders:
foreach (var harvester in activeUnits) foreach (var harvester in harvesters)
{ {
var harv = harvester.TraitOrDefault<Harvester>(); var harv = harvester.Trait<Harvester>();
if (harv == null)
continue;
if (!harv.IsEmpty) if (!harv.IsEmpty)
continue; continue;

View File

@@ -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. // 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>();
// 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<Actor> harvesters = new List<Actor>();
public const int FeedbackTime = 30; // ticks; = a bit over 1s. must be >= netlag. public const int FeedbackTime = 30; // ticks; = a bit over 1s. must be >= netlag.
public readonly World World; public readonly World World;
@@ -597,6 +601,7 @@ namespace OpenRA.Mods.Common.AI
activeUnits.RemoveAll(unitCannotBeOrdered); activeUnits.RemoveAll(unitCannotBeOrdered);
unitsHangingAroundTheBase.RemoveAll(unitCannotBeOrdered); unitsHangingAroundTheBase.RemoveAll(unitCannotBeOrdered);
harvesters.RemoveAll(unitCannotBeOrdered);
if (--rushTicks <= 0) if (--rushTicks <= 0)
{ {
@@ -615,7 +620,7 @@ namespace OpenRA.Mods.Common.AI
{ {
assignRolesTicks = Info.AssignRolesInterval; assignRolesTicks = Info.AssignRolesInterval;
FindNewUnits(self); FindNewUnits(self);
harvManager.Tick(activeUnits); harvManager.Tick(harvesters);
InitializeBase(self, true); InitializeBase(self, true);
} }
@@ -738,10 +743,13 @@ namespace OpenRA.Mods.Common.AI
void FindNewUnits(Actor self) void FindNewUnits(Actor self)
{ {
var newUnits = self.World.ActorsHavingTrait<IPositionable>() var newUnits = self.World.ActorsHavingTrait<IPositionable>()
.Where(a => a.Owner == Player && !activeUnits.Contains(a)); .Where(a => a.Owner == Player && !activeUnits.Contains(a) && !harvesters.Contains(a));
foreach (var a in newUnits) foreach (var a in newUnits)
{ {
if (a.Info.HasTraitInfo<HarvesterInfo>())
harvesters.Add(a);
if (Info.UnitsCommonNames.Mcv.Contains(a.Info.Name) || Info.UnitsCommonNames.ExcludeFromSquads.Contains(a.Info.Name)) if (Info.UnitsCommonNames.Mcv.Contains(a.Info.Name) || Info.UnitsCommonNames.ExcludeFromSquads.Contains(a.Info.Name))
continue; continue;