Skip to content

Commit

Permalink
Fix McvManagerBotModule spamming deploy orders
Browse files Browse the repository at this point in the history
Removes the 'activeMCVs' list since it was not useful.
The real bugfix is not iterating over 'activeMCVs' when issueing new orders
(this was previously needed for already discovered mcvs that stopped)
but over 'newMCVs' instead.
  • Loading branch information
abcdefg30 authored and reaperrr committed Nov 20, 2019
1 parent a47f60d commit 980c1e1
Showing 1 changed file with 3 additions and 26 deletions.
29 changes: 3 additions & 26 deletions OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs
Expand Up @@ -72,9 +72,6 @@ public CPos GetRandomBaseCenter()
int scanInterval;
bool firstTick = true;

// MCVs that the bot already knows about. Any MCV not on this list needs to be given an order.
List<Actor> activeMCVs = new List<Actor>();

public McvManagerBotModule(Actor self, McvManagerBotModuleInfo info)
: base(info)
{
Expand Down Expand Up @@ -140,18 +137,10 @@ bool ShouldBuildMCV()

void DeployMcvs(IBot bot, bool chooseLocation)
{
activeMCVs.RemoveAll(unitCannotBeOrdered);

var newMCVs = world.ActorsHavingTrait<Transforms>()
.Where(a => a.Owner == player &&
a.IsIdle &&
Info.McvTypes.Contains(a.Info.Name) &&
!activeMCVs.Contains(a));

foreach (var a in newMCVs)
activeMCVs.Add(a);
.Where(a => a.Owner == player && a.IsIdle && Info.McvTypes.Contains(a.Info.Name));

foreach (var mcv in activeMCVs)
foreach (var mcv in newMCVs)
DeployMcv(bot, mcv, chooseLocation);
}

Expand Down Expand Up @@ -221,11 +210,7 @@ List<MiniYamlNode> IGameSaveTraitData.IssueTraitData(Actor self)

return new List<MiniYamlNode>()
{
new MiniYamlNode("InitialBaseCenter", FieldSaver.FormatValue(initialBaseCenter)),
new MiniYamlNode("ActiveMCVs", FieldSaver.FormatValue(activeMCVs
.Where(a => !unitCannotBeOrdered(a))
.Select(a => a.ActorID)
.ToArray()))
new MiniYamlNode("InitialBaseCenter", FieldSaver.FormatValue(initialBaseCenter))
};
}

Expand All @@ -237,14 +222,6 @@ void IGameSaveTraitData.ResolveTraitData(Actor self, List<MiniYamlNode> data)
var initialBaseCenterNode = data.FirstOrDefault(n => n.Key == "InitialBaseCenter");
if (initialBaseCenterNode != null)
initialBaseCenter = FieldLoader.GetValue<CPos>("InitialBaseCenter", initialBaseCenterNode.Value.Value);

var activeMCVsNode = data.FirstOrDefault(n => n.Key == "ActiveMCVs");
if (activeMCVsNode != null)
{
activeMCVs.Clear();
activeMCVs.AddRange(FieldLoader.GetValue<uint[]>("ActiveMCVs", activeMCVsNode.Value.Value)
.Select(a => world.GetActorById(a)).Where(a => a != null));
}
}
}
}

0 comments on commit 980c1e1

Please sign in to comment.