priority-based selection
This commit is contained in:
@@ -65,13 +65,9 @@ namespace OpenRa.Game
|
||||
{
|
||||
if (!(orderGenerator is PlaceBuilding))
|
||||
{
|
||||
if (dragStart != xy)
|
||||
orderGenerator = new UnitOrderGenerator(
|
||||
Game.SelectUnitsInBox(Game.CellSize * dragStart, Game.CellSize * xy));
|
||||
else
|
||||
orderGenerator = new UnitOrderGenerator(
|
||||
Game.SelectUnitOrBuilding(Game.CellSize * xy));
|
||||
|
||||
orderGenerator = new UnitOrderGenerator(
|
||||
Game.SelectActorsInBox(Game.CellSize * dragStart, Game.CellSize * xy));
|
||||
|
||||
var voicedUnit = ((UnitOrderGenerator)orderGenerator).selection
|
||||
.Select(a => a.traits.GetOrDefault<Mobile>())
|
||||
.Where(m => m != null && m.self.Owner == Game.LocalPlayer)
|
||||
@@ -114,7 +110,7 @@ namespace OpenRa.Game
|
||||
.Select(a => CursorForOrderString( a.OrderString, a.Subject, a.TargetLocation ))
|
||||
.FirstOrDefault(a => a != null) : null;
|
||||
|
||||
return c ?? (Game.SelectUnitOrBuilding(Game.CellSize * dragEnd).Any() ? Cursor.Select : Cursor.Default);
|
||||
return c ?? (Game.SelectActorsInBox(Game.CellSize * dragEnd, Game.CellSize * dragEnd).Any() ? Cursor.Select : Cursor.Default);
|
||||
}
|
||||
|
||||
Cursor CursorForOrderString( string s, Actor a, int2 location )
|
||||
|
||||
@@ -262,15 +262,14 @@ namespace OpenRa.Game
|
||||
yield return new int2(i, j);
|
||||
}
|
||||
|
||||
public static IEnumerable<Actor> SelectUnitsInBox(float2 a, float2 b)
|
||||
public static IEnumerable<Actor> SelectActorsInBox(float2 a, float2 b)
|
||||
{
|
||||
return FindUnits(a, b).Where(x => x.Owner == LocalPlayer && x.traits.Contains<Traits.Unit>());
|
||||
}
|
||||
|
||||
public static IEnumerable<Actor> SelectUnitOrBuilding(float2 a)
|
||||
{
|
||||
var q = FindUnits(a, a);
|
||||
return q.Where(x => x.traits.Contains<Traits.Unit>()).Concat(q).Take(1);
|
||||
return FindUnits(a, b)
|
||||
.GroupBy(x => (x.Owner == LocalPlayer) ? x.unitInfo.SelectionPriority : 0)
|
||||
.OrderByDescending(g => g.Key)
|
||||
.Select( g => g.AsEnumerable() )
|
||||
.DefaultIfEmpty( new Actor[] {} )
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public static int GetDistanceToBase(int2 b, Player p)
|
||||
|
||||
@@ -52,6 +52,7 @@ namespace OpenRa.Game.GameRules
|
||||
public readonly int Recoil = 0;
|
||||
public readonly string SecondaryAnim = null;
|
||||
public readonly bool MuzzleFlash = false;
|
||||
public readonly int SelectionPriority = 10;
|
||||
|
||||
public UnitInfo(string name) { Name = name; }
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace OpenRa.Game.Graphics
|
||||
lineRenderer.DrawLine(a + b + c, a + c, Color.White, Color.White);
|
||||
lineRenderer.DrawLine(a, a + c, Color.White, Color.White);
|
||||
|
||||
foreach (var u in Game.SelectUnitsInBox(selbox.Value.First, selbox.Value.Second))
|
||||
foreach (var u in Game.SelectActorsInBox(selbox.Value.First, selbox.Value.Second))
|
||||
DrawSelectionBox(u, Color.Yellow, false);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user