664 fixed

This commit is contained in:
Chris Forbes
2011-04-17 18:19:14 +12:00
committed by Paul Chote
parent 5e0f57d730
commit 9541023456

View File

@@ -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<Selectable>() && world.LocalShroud.IsVisible(x) )
.GroupBy(x => (x.Owner == world.LocalPlayer) ? x.Info.Traits.Get<SelectableInfo>().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<SelectableInfo>().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();
}
}
}
}