Introduce a Targetable trait; Subs can attack bridges; May introduce subtle bugs due to previous stupid assumption that !selectable == !attackable.

This commit is contained in:
Paul Chote
2010-07-28 22:57:14 +12:00
parent f9f6720437
commit 7a4fa93ce9
15 changed files with 91 additions and 58 deletions

View File

@@ -119,8 +119,8 @@ namespace OpenRA
return null;
var underCursor = World.FindUnitsAtMouse(mi.Location)
.Where(a => a.Info.Traits.Contains<SelectableInfo>())
.OrderByDescending(a => a.Info.Traits.Get<SelectableInfo>().Priority)
//.Where(a => a.Info.Traits.Contains<SelectableInfo>())
.OrderByDescending(a => a.Info.Traits.Contains<SelectableInfo>() ? a.Info.Traits.Get<SelectableInfo>().Priority : int.MinValue)
.FirstOrDefault();
return traits.WithInterface<IIssueOrder>()

View File

@@ -228,6 +228,7 @@
<Compile Include="Widgets\ViewportScrollControllerWidget.cs" />
<Compile Include="Traits\Player\DeveloperMode.cs" />
<Compile Include="Traits\RevealsShroud.cs" />
<Compile Include="Traits\Targetable.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -22,7 +22,6 @@ namespace OpenRA.Traits
{
public readonly int HP = 0;
public readonly ArmorType Armor = ArmorType.none;
public readonly string[] TargetType = {"Ground"};
}
public class BuildingInfo : OwnedActorInfo, ITraitInfo

View File

@@ -0,0 +1,26 @@
#region Copyright & License Information
/*
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see LICENSE.
*/
#endregion
using System.Drawing;
using OpenRA.Graphics;
using System.Linq;
namespace OpenRA.Traits
{
public class TargetableInfo : TraitInfo<Targetable>
{
public readonly string[] TargetTypes = {};
}
public class Targetable
{
}
}

View File

@@ -14,6 +14,7 @@ using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Orders;
using OpenRA.Traits;
using System.Collections.Generic;
namespace OpenRA.Widgets
{
@@ -36,7 +37,7 @@ namespace OpenRA.Widgets
Game.Renderer.LineRenderer.DrawLine(a + b + c, a + c, Color.White, Color.White);
Game.Renderer.LineRenderer.DrawLine(a, a + c, Color.White, Color.White);
foreach (var u in world.SelectActorsInBox(selbox.Value.First, selbox.Value.Second))
foreach (var u in SelectActorsInBox(world, selbox.Value.First, selbox.Value.Second))
world.WorldRenderer.DrawSelectionBox(u, Color.Yellow);
Game.Renderer.LineRenderer.Flush();
@@ -60,7 +61,7 @@ namespace OpenRA.Widgets
{
if (world.OrderGenerator is UnitOrderGenerator)
{
var newSelection = Game.world.SelectActorsInBox(Game.CellSize * dragStart, Game.CellSize * xy);
var newSelection = SelectActorsInBox(world, Game.CellSize * dragStart, Game.CellSize * xy);
world.Selection.Combine(world, newSelection, mi.Modifiers.HasModifier(Modifiers.Shift), dragStart == xy);
}
@@ -170,6 +171,17 @@ namespace OpenRA.Widgets
Game.viewport.Center(world.Selection.Actors);
}
IEnumerable<Actor> SelectActorsInBox(World world, float2 a, float2 b)
{
return world.FindUnits(a, b)
.Where( x => x.traits.Contains<Selectable>() && x.IsVisible() )
.GroupBy(x => (x.Owner == world.LocalPlayer) ? x.Info.Traits.Get<SelectableInfo>().Priority : 0)
.OrderByDescending(g => g.Key)
.Select( g => g.AsEnumerable() )
.DefaultIfEmpty( new Actor[] {} )
.FirstOrDefault();
}
public override Widget Clone() { return new WorldInteractionControllerWidget(this); }
}
}

View File

@@ -81,17 +81,6 @@ namespace OpenRA
if (r * r >= (new int2(i, j) - a).LengthSquared)
yield return new int2(i, j);
}
public static IEnumerable<Actor> SelectActorsInBox(this World world, float2 a, float2 b)
{
return world.FindUnits(a, b)
.Where( x => x.traits.Contains<Selectable>() && x.IsVisible() )
.GroupBy(x => (x.Owner == world.LocalPlayer) ? x.Info.Traits.Get<SelectableInfo>().Priority : 0)
.OrderByDescending(g => g.Key)
.Select( g => g.AsEnumerable() )
.DefaultIfEmpty( new Actor[] {} )
.FirstOrDefault();
}
public static string GetTerrainType(this World world, int2 cell)
{