diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj
index 903659b412..6f34e6745e 100755
--- a/OpenRA.Game/OpenRA.Game.csproj
+++ b/OpenRA.Game/OpenRA.Game.csproj
@@ -192,7 +192,6 @@
-
@@ -259,4 +258,4 @@
-->
-
+
\ No newline at end of file
diff --git a/OpenRA.Game/Orders/UnitOrderGenerator.cs b/OpenRA.Game/Orders/UnitOrderGenerator.cs
index 368d514146..cf99c259b9 100644
--- a/OpenRA.Game/Orders/UnitOrderGenerator.cs
+++ b/OpenRA.Game/Orders/UnitOrderGenerator.cs
@@ -30,7 +30,7 @@ namespace OpenRA.Orders
else
{
var underCursor = world.FindUnitsAtMouse(mi.Location)
- .Where(a => a.Info.Traits.Contains())
+ .Where(a => a.HasTrait())
.OrderByDescending(
a =>
a.Info.Traits.Contains()
@@ -106,7 +106,7 @@ namespace OpenRA.Orders
}
var underCursor = world.FindUnitsAtMouse(mi.Location)
- .Where(a => a.Info.Traits.Contains())
+ .Where(a => a.HasTrait())
.OrderByDescending(a => a.Info.Traits.Contains() ? a.Info.Traits.Get().Priority : int.MinValue)
.FirstOrDefault();
diff --git a/OpenRA.Game/Traits/Targetable.cs b/OpenRA.Game/Traits/Targetable.cs
deleted file mode 100644
index 05e0d682bf..0000000000
--- a/OpenRA.Game/Traits/Targetable.cs
+++ /dev/null
@@ -1,42 +0,0 @@
-#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;
-using System.Collections.Generic;
-
-namespace OpenRA.Traits
-{
- public class TargetableInfo : ITraitInfo
- {
- public readonly string[] TargetTypes = {};
- public virtual object Create( ActorInitializer init ) { return new Targetable(this); }
- }
-
- public class Targetable
- {
- protected TargetableInfo Info;
- public Targetable(TargetableInfo info)
- {
- Info = info;
- }
-
- public virtual string[] TargetTypes
- {
- get { return Info.TargetTypes;}
- }
-
- public virtual IEnumerable TargetableSquares( Actor self )
- {
- yield return self.Location;
- }
- }
-}
diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs
index cf19ea561f..0cc587b62b 100755
--- a/OpenRA.Game/Traits/TraitsInterfaces.cs
+++ b/OpenRA.Game/Traits/TraitsInterfaces.cs
@@ -237,4 +237,10 @@ namespace OpenRA.Traits
public Actor Actor { get { return IsActor ? actor : null; } }
public bool IsActor { get { return actor != null && !actor.Destroyed; } }
}
+
+ public interface ITargetable
+ {
+ string[] TargetTypes { get; }
+ IEnumerable TargetableSquares( Actor self );
+ }
}
diff --git a/OpenRA.Mods.RA/Combat.cs b/OpenRA.Mods.RA/Combat.cs
index 45be4ac4d5..35723a7dcf 100755
--- a/OpenRA.Mods.RA/Combat.cs
+++ b/OpenRA.Mods.RA/Combat.cs
@@ -163,7 +163,7 @@ namespace OpenRA.Mods.RA
public static bool WeaponValidForTarget(WeaponInfo weapon, Actor target)
{
- var targetable = target.TraitOrDefault();
+ var targetable = target.TraitOrDefault();
if (targetable == null || !weapon.ValidTargets.Intersect(targetable.TargetTypes).Any())
return false;
@@ -223,7 +223,7 @@ namespace OpenRA.Mods.RA
public static bool IsInRange( float2 attackOrigin, float range, Actor target )
{
var rsq = range * range * Game.CellSize * Game.CellSize;
- foreach( var cell in target.Trait().TargetableSquares( target ) )
+ foreach( var cell in target.Trait().TargetableSquares( target ) )
if( ( attackOrigin - cell * Game.CellSize ).LengthSquared < rsq )
return true;
return false;
diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj
index a01a1b0406..9e3419d5fb 100644
--- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj
+++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj
@@ -222,6 +222,7 @@
+
diff --git a/OpenRA.Mods.RA/TargetableAircraft.cs b/OpenRA.Mods.RA/TargetableAircraft.cs
index 822190ca9e..2977379407 100644
--- a/OpenRA.Mods.RA/TargetableAircraft.cs
+++ b/OpenRA.Mods.RA/TargetableAircraft.cs
@@ -15,13 +15,13 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
- public class TargetableAircraftInfo : TargetableInfo, ITraitPrerequisite
+ public class TargetableAircraftInfo : TargetableUnitInfo, ITraitPrerequisite
{
public readonly string[] GroundedTargetTypes = { };
public override object Create(ActorInitializer init) { return new TargetableAircraft(init.self, this); }
}
- public class TargetableAircraft : Targetable
+ public class TargetableAircraft : TargetableUnit
{
Aircraft Aircraft;
public TargetableAircraft(Actor self, TargetableAircraftInfo info)
@@ -32,8 +32,8 @@ namespace OpenRA.Mods.RA
public override string[] TargetTypes
{
- get { return (Aircraft.Altitude > 0) ? ((TargetableAircraftInfo)Info).TargetTypes
- : ((TargetableAircraftInfo)Info).GroundedTargetTypes; }
+ get { return (Aircraft.Altitude > 0) ? info.TargetTypes
+ : info.GroundedTargetTypes; }
}
}
}
diff --git a/OpenRA.Mods.RA/TargetableBuilding.cs b/OpenRA.Mods.RA/TargetableBuilding.cs
index 6a946706fe..2ea74c6bdd 100755
--- a/OpenRA.Mods.RA/TargetableBuilding.cs
+++ b/OpenRA.Mods.RA/TargetableBuilding.cs
@@ -1,4 +1,14 @@
-using System;
+#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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -6,19 +16,23 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
- class TargetableBuildingInfo : TargetableInfo, ITraitPrerequisite
+ class TargetableBuildingInfo : ITraitInfo, ITraitPrerequisite
{
- public override object Create( ActorInitializer init ) { return new TargetableBuilding( this ); }
+ public readonly string[] TargetTypes = { };
+ public object Create( ActorInitializer init ) { return new TargetableBuilding( this ); }
}
- class TargetableBuilding : Targetable
+ class TargetableBuilding : ITargetable
{
+ readonly TargetableBuildingInfo info;
public TargetableBuilding( TargetableBuildingInfo info )
- : base( info )
{
+ this.info = info;
}
- public override IEnumerable TargetableSquares( Actor self )
+ public string[] TargetTypes { get { return info.TargetTypes; } }
+
+ public IEnumerable TargetableSquares( Actor self )
{
return self.Trait().OccupiedCells();
}
diff --git a/OpenRA.Mods.RA/TargetableCloaked.cs b/OpenRA.Mods.RA/TargetableCloaked.cs
index 5e3461e50e..bfea0e8040 100644
--- a/OpenRA.Mods.RA/TargetableCloaked.cs
+++ b/OpenRA.Mods.RA/TargetableCloaked.cs
@@ -12,13 +12,13 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
- public class TargetableCloakedInfo : TargetableInfo, ITraitPrerequisite
+ public class TargetableCloakedInfo : TargetableUnitInfo, ITraitPrerequisite
{
public readonly string[] CloakedTargetTypes = {};
public override object Create( ActorInitializer init ) { return new TargetableCloaked(init.self, this); }
}
- public class TargetableCloaked : Targetable
+ public class TargetableCloaked : TargetableUnit
{
Cloak Cloak;
public TargetableCloaked(Actor self, TargetableCloakedInfo info)
@@ -29,8 +29,8 @@ namespace OpenRA.Mods.RA
public override string[] TargetTypes
{
- get { return (Cloak.Cloaked) ? ((TargetableCloakedInfo)Info).CloakedTargetTypes
- : ((TargetableCloakedInfo)Info).TargetTypes;}
+ get { return (Cloak.Cloaked) ? info.CloakedTargetTypes
+ : info.TargetTypes;}
}
}
}
diff --git a/OpenRA.Mods.RA/TargetableUnit.cs b/OpenRA.Mods.RA/TargetableUnit.cs
new file mode 100755
index 0000000000..3e5d01dc60
--- /dev/null
+++ b/OpenRA.Mods.RA/TargetableUnit.cs
@@ -0,0 +1,41 @@
+#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;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using OpenRA.Traits;
+
+namespace OpenRA.Mods.RA
+{
+ public class TargetableUnitInfo : ITraitInfo
+ {
+ public readonly string[] TargetTypes = { };
+ public virtual object Create( ActorInitializer init ) { return new TargetableUnit( this ); }
+ }
+
+ public class TargetableUnit : ITargetable
+ where Info : TargetableUnitInfo
+ {
+ protected readonly Info info;
+ public TargetableUnit( Info info )
+ {
+ this.info = info;
+ }
+
+ public virtual string[] TargetTypes { get { return info.TargetTypes; } }
+
+ public virtual IEnumerable TargetableSquares( Actor self )
+ {
+ yield return Util.CellContaining( self.CenterLocation );
+ }
+ }
+}
diff --git a/mods/cnc/rules/defaults.yaml b/mods/cnc/rules/defaults.yaml
index 9d547cd66d..a62f258483 100644
--- a/mods/cnc/rules/defaults.yaml
+++ b/mods/cnc/rules/defaults.yaml
@@ -12,7 +12,7 @@
ROT: 5
Selectable:
Voice: VehicleVoice
- Targetable:
+ TargetableUnit:
TargetTypes: Ground
Buildable:
Queue: Vehicle
@@ -43,7 +43,7 @@
ROT: 5
Selectable:
Voice: VehicleVoice
- Targetable:
+ TargetableUnit:
TargetTypes: Ground
Buildable:
Queue: Vehicle
@@ -63,7 +63,7 @@
^Helicopter:
AppearsOnRadar:
UseLocation: yes
- Targetable:
+ TargetableUnit:
TargetTypes: Air
Selectable:
Voice: VehicleVoice
@@ -100,7 +100,7 @@
Beach: 80
Selectable:
Voice: GenericVoice
- Targetable:
+ TargetableUnit:
TargetTypes: Ground
Buildable:
Queue: Infantry
@@ -146,7 +146,7 @@
UseLocation: yes
Selectable:
Voice: GenericVoice
- Targetable:
+ TargetableUnit:
TargetTypes: Air
HiddenUnderFog:
GainsExperience:
@@ -163,7 +163,7 @@
Water: 100
Selectable:
Voice: GenericVoice
- Targetable:
+ TargetableUnit:
TargetTypes: Ground, Water
HiddenUnderFog:
GainsExperience:
@@ -177,7 +177,7 @@
AppearsOnRadar:
Selectable:
Priority: 3
- Targetable:
+ TargetableBuilding:
TargetTypes: Ground
Armor:
Type: Wood
@@ -242,7 +242,7 @@
DamagedSound: xplos.aud
DestroyedSound: xplobig4.aud
Adjacent: 7
- Targetable:
+ TargetableBuilding:
TargetTypes: Ground
Wall:
CrushClasses: wall
@@ -293,7 +293,7 @@
^Bridge:
Tooltip:
Name: Bridge
- Targetable:
+ TargetableBuilding:
TargetTypes: Ground, Water
BelowUnits:
Health:
diff --git a/mods/cnc/rules/vehicles.yaml b/mods/cnc/rules/vehicles.yaml
index 4f34d4dce8..761a97475e 100644
--- a/mods/cnc/rules/vehicles.yaml
+++ b/mods/cnc/rules/vehicles.yaml
@@ -446,6 +446,9 @@ STNK:
PrimaryWeapon: 227mm
RenderUnit:
AutoTarget:
+ -TargetableUnit:
+ TargetableCloaked:
+ CloakedTargetTypes: cloaked
TRAN:
Inherits: ^Helicopter
@@ -565,7 +568,7 @@ C17:
Passengers: 10
Invulnerable:
-Selectable:
- -Targetable:
+ -TargetableUnit:
-GainsExperience:
FlyAwayOnIdle:
diff --git a/mods/ra/rules/defaults.yaml b/mods/ra/rules/defaults.yaml
index 03ebab4158..7a274d03cb 100644
--- a/mods/ra/rules/defaults.yaml
+++ b/mods/ra/rules/defaults.yaml
@@ -11,7 +11,7 @@
ROT: 5
Selectable:
Voice: VehicleVoice
- Targetable:
+ TargetableUnit:
TargetTypes: Ground
Repairable:
Chronoshiftable:
@@ -39,7 +39,7 @@
ROT: 5
Selectable:
Voice: VehicleVoice
- Targetable:
+ TargetableUnit:
TargetTypes: Ground
Repairable:
Chronoshiftable:
@@ -71,7 +71,7 @@
Beach: 80
Selectable:
Voice: GenericVoice
- Targetable:
+ TargetableUnit:
TargetTypes: Ground
RenderInfantry:
AutoTarget:
@@ -94,7 +94,7 @@
Water: 100
Selectable:
Voice: ShipVoice
- Targetable:
+ TargetableUnit:
TargetTypes: Ground, Water
DetectCloaked:
Range: 3
@@ -157,7 +157,7 @@
Range: 8
Selectable:
Priority: 1
- Targetable:
+ TargetableBuilding:
TargetTypes: Ground
RenderBuildingWall:
HasMakeAnimation: false
@@ -208,7 +208,7 @@
Tooltip:
Name: Bridge
BelowUnits:
- Targetable:
+ TargetableBuilding:
TargetTypes: Ground, Water
Building:
Footprint: ____ ____
diff --git a/mods/ra/rules/structures.yaml b/mods/ra/rules/structures.yaml
index 4afd4bea25..ba9d739440 100755
--- a/mods/ra/rules/structures.yaml
+++ b/mods/ra/rules/structures.yaml
@@ -68,7 +68,7 @@ SPEN:
Prerequisites: @Power Plant
Owner: soviet
Hotkey: s
- Targetable:
+ TargetableBuilding:
TargetTypes: Ground, Water
Building:
Power: -30
@@ -123,7 +123,7 @@ SYRD:
Tooltip:
Name: Shipyard
Description: Produces and repairs ships
- Targetable:
+ TargetableBuilding:
TargetTypes: Ground, Water
Building:
Power: -30
@@ -964,7 +964,7 @@ SYRF:
# Description: Fake Shipyard
# LongDesc: Looks like a Shipyard
# Hotkey: z
- Targetable:
+ TargetableBuilding:
TargetTypes: Ground, Water
Building:
Power: -2
@@ -985,7 +985,7 @@ SYRF:
SPEF:
Inherits: ^Building
- Targetable:
+ TargetableBuilding:
TargetTypes: Ground, Water
Building:
Power: -2
diff --git a/mods/ra/rules/vehicles.yaml b/mods/ra/rules/vehicles.yaml
index 0c724691d0..dfefcd2d92 100644
--- a/mods/ra/rules/vehicles.yaml
+++ b/mods/ra/rules/vehicles.yaml
@@ -480,7 +480,7 @@ SS:
Speed: 5
RevealsShroud:
Range: 6
- -Targetable:
+ -TargetableUnit:
TargetableCloaked:
TargetTypes: Ground, Water
CloakedTargetTypes: Underwater
@@ -523,7 +523,7 @@ MSUB:
RevealsShroud:
Range: 6
RenderUnit:
- -Targetable:
+ -TargetableUnit:
TargetableCloaked:
TargetTypes: Ground, Water
CloakedTargetTypes: Underwater