diff --git a/OpenRA.Mods.Common/Traits/BotModules/Squads/States/GroundStates.cs b/OpenRA.Mods.Common/Traits/BotModules/Squads/States/GroundStates.cs index 500f5cb7f1..ff3c22a3e8 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/Squads/States/GroundStates.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/Squads/States/GroundStates.cs @@ -53,8 +53,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads if (AttackOrFleeFuzzy.Default.CanAttack(owner.Units, enemyUnits)) { - foreach (var u in owner.Units) - owner.Bot.QueueOrder(new Order("AttackMove", u, Target.FromCell(owner.World, owner.TargetActor.Location), false)); + owner.Bot.QueueOrder(new Order("AttackMove", null, Target.FromCell(owner.World, owner.TargetActor.Location), false, groupedActors: owner.Units.ToArray())); // We have gathered sufficient units. Attack the nearest enemy unit. owner.FuzzyStateMachine.ChangeState(owner, new GroundUnitsAttackMoveState(), true); @@ -124,8 +123,9 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads // Since units have different movement speeds, they get separated while approaching the target. // Let them regroup into tighter formation. owner.Bot.QueueOrder(new Order("Stop", leader, false)); - foreach (var unit in owner.Units.Where(a => !ownUnits.Contains(a))) - owner.Bot.QueueOrder(new Order("AttackMove", unit, Target.FromCell(owner.World, leader.Location), false)); + + var units = owner.Units.Where(a => !ownUnits.Contains(a)).ToArray(); + owner.Bot.QueueOrder(new Order("AttackMove", null, Target.FromCell(owner.World, leader.Location), false, groupedActors: units)); } else { @@ -138,8 +138,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads owner.FuzzyStateMachine.ChangeState(owner, new GroundUnitsAttackState(), true); } else - foreach (var a in owner.Units) - owner.Bot.QueueOrder(new Order("AttackMove", a, Target.FromCell(owner.World, owner.TargetActor.Location), false)); + owner.Bot.QueueOrder(new Order("AttackMove", null, Target.FromCell(owner.World, owner.TargetActor.Location), false, groupedActors: owner.Units.ToArray())); } if (ShouldFlee(owner)) diff --git a/OpenRA.Mods.Common/Traits/BotModules/Squads/States/NavyStates.cs b/OpenRA.Mods.Common/Traits/BotModules/Squads/States/NavyStates.cs index bee0d32e12..64a19a95d6 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/Squads/States/NavyStates.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/Squads/States/NavyStates.cs @@ -78,8 +78,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads if (AttackOrFleeFuzzy.Default.CanAttack(owner.Units, enemyUnits)) { - foreach (var u in owner.Units) - owner.Bot.QueueOrder(new Order("AttackMove", u, Target.FromCell(owner.World, owner.TargetActor.Location), false)); + owner.Bot.QueueOrder(new Order("AttackMove", null, Target.FromCell(owner.World, owner.TargetActor.Location), false, groupedActors: owner.Units.ToArray())); // We have gathered sufficient units. Attack the nearest enemy unit. owner.FuzzyStateMachine.ChangeState(owner, new NavyUnitsAttackMoveState(), true); @@ -149,8 +148,9 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads // Since units have different movement speeds, they get separated while approaching the target. // Let them regroup into tighter formation. owner.Bot.QueueOrder(new Order("Stop", leader, false)); - foreach (var unit in owner.Units.Where(a => !ownUnits.Contains(a))) - owner.Bot.QueueOrder(new Order("AttackMove", unit, Target.FromCell(owner.World, leader.Location), false)); + + var units = owner.Units.Where(a => !ownUnits.Contains(a)).ToArray(); + owner.Bot.QueueOrder(new Order("AttackMove", null, Target.FromCell(owner.World, leader.Location), false, groupedActors: units)); } else { @@ -163,8 +163,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads owner.FuzzyStateMachine.ChangeState(owner, new NavyUnitsAttackState(), true); } else - foreach (var a in owner.Units) - owner.Bot.QueueOrder(new Order("AttackMove", a, Target.FromCell(owner.World, owner.TargetActor.Location), false)); + owner.Bot.QueueOrder(new Order("AttackMove", null, Target.FromCell(owner.World, owner.TargetActor.Location), false, groupedActors: owner.Units.ToArray())); } if (ShouldFlee(owner)) diff --git a/OpenRA.Mods.Common/Traits/BotModules/Squads/States/ProtectionStates.cs b/OpenRA.Mods.Common/Traits/BotModules/Squads/States/ProtectionStates.cs index ef6e896575..3d889818f3 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/Squads/States/ProtectionStates.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/Squads/States/ProtectionStates.cs @@ -55,10 +55,7 @@ namespace OpenRA.Mods.Common.Traits.BotModules.Squads Backoff--; } else - { - foreach (var a in owner.Units) - owner.Bot.QueueOrder(new Order("AttackMove", a, Target.FromCell(owner.World, owner.TargetActor.Location), false)); - } + owner.Bot.QueueOrder(new Order("AttackMove", null, Target.FromCell(owner.World, owner.TargetActor.Location), false, groupedActors: owner.Units.ToArray())); } public void Deactivate(Squad owner) { }