diff --git a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs index 18b349a6b1..cf3a1da4bc 100644 --- a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs @@ -15,6 +15,7 @@ using OpenRA.FileFormats; using OpenRA.Graphics; using OpenRA.Orders; using OpenRA.Traits; +using System; namespace OpenRA.Widgets { @@ -144,11 +145,35 @@ namespace OpenRA.Widgets { return world.FindUnits(a, b) .Where( x => x.HasTrait() && world.LocalShroud.IsVisible(x) ) - .GroupBy(x => (x.Owner == world.LocalPlayer) ? x.Info.Traits.Get().Priority : 0) + .GroupBy(x => x.GetSelectionPriority()) .OrderByDescending(g => g.Key) .Select( g => g.AsEnumerable() ) .DefaultIfEmpty( NoActors ) .FirstOrDefault(); } } + + static class PriorityExts + { + const int PriorityRange = 30; + + public static int GetSelectionPriority(this Actor a) + { + var basePriority = a.Info.Traits.Get().Priority; + var lp = a.World.LocalPlayer; + + if (a.Owner == lp || lp == null) + return basePriority; + + switch (lp.Stances[a.Owner]) + { + case Stance.Ally: return basePriority - PriorityRange; + case Stance.Neutral: return basePriority - 2 * PriorityRange; + case Stance.Enemy: return basePriority - 3 * PriorityRange; + + default: + throw new InvalidOperationException(); + } + } + } } \ No newline at end of file