Allow Attack* to control a subset of armaments.

This commit is contained in:
Paul Chote
2014-03-17 11:24:31 +13:00
parent 9d1526f4e7
commit ea79eb28fc
2 changed files with 13 additions and 6 deletions

View File

@@ -20,6 +20,9 @@ namespace OpenRA.Mods.RA
{ {
public abstract class AttackBaseInfo : ITraitInfo public abstract class AttackBaseInfo : ITraitInfo
{ {
[Desc("Armament names")]
public readonly string[] Armaments = { "primary", "secondary" };
public readonly string Cursor = "attack"; public readonly string Cursor = "attack";
public readonly string OutsideRangeCursor = "attackoutsiderange"; public readonly string OutsideRangeCursor = "attackoutsiderange";
@@ -29,21 +32,24 @@ namespace OpenRA.Mods.RA
public abstract class AttackBase : IIssueOrder, IResolveOrder, IOrderVoice, ISync public abstract class AttackBase : IIssueOrder, IResolveOrder, IOrderVoice, ISync
{ {
[Sync] public bool IsAttacking { get; internal set; } [Sync] public bool IsAttacking { get; internal set; }
public IEnumerable<Armament> Armaments { get { return GetArmaments(); } }
protected Lazy<IFacing> facing;
protected Lazy<Building> building;
protected Func<IEnumerable<Armament>> GetArmaments;
readonly Actor self; readonly Actor self;
readonly AttackBaseInfo info; readonly AttackBaseInfo info;
protected Lazy<IFacing> facing;
Lazy<IEnumerable<Armament>> armaments;
protected IEnumerable<Armament> Armaments { get { return armaments.Value; } }
protected Lazy<Building> building;
public AttackBase(Actor self, AttackBaseInfo info) public AttackBase(Actor self, AttackBaseInfo info)
{ {
this.self = self; this.self = self;
this.info = info; this.info = info;
armaments = Lazy.New(() => self.TraitsImplementing<Armament>()); var armaments = Lazy.New(() => self.TraitsImplementing<Armament>()
.Where(a => info.Armaments.Contains(a.Info.Name)));
GetArmaments = () => armaments.Value;
facing = Lazy.New(() => self.TraitOrDefault<IFacing>()); facing = Lazy.New(() => self.TraitOrDefault<IFacing>());
building = Lazy.New(() => self.TraitOrDefault<Building>()); building = Lazy.New(() => self.TraitOrDefault<Building>());
} }

View File

@@ -197,6 +197,7 @@ A10:
RenderUnit: RenderUnit:
WithShadow: WithShadow:
AttackBomber: AttackBomber:
Armaments: gun, bombs
Guns: gun Guns: gun
Bombs: bombs Bombs: bombs
Armament@GUNS: Armament@GUNS: