using StatelessTraitInfo<> for some things

This commit is contained in:
Chris Forbes
2010-01-10 14:15:45 +13:00
parent 79ce6b70b6
commit be9fd1e277
18 changed files with 20 additions and 89 deletions

View File

@@ -198,7 +198,7 @@ namespace OpenRa.Game
{
var hasRadar = Game.world.Actors.Any(a => a.Owner == Game.LocalPlayer
&& a.traits.Contains<ProvidesRadar>()
&& a.traits.Get<ProvidesRadar>().IsActive());
&& a.traits.Get<ProvidesRadar>().IsActive(a));
if (hasRadar != hadRadar)
Sound.Play((hasRadar) ? "radaron2.aud" : "radardn1.aud");

View File

@@ -1,20 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq;
using OpenRa.Game.Traits.Activities;
namespace OpenRa.Game.Traits
{
class PassengerInfo : ITraitInfo
{
public object Create(Actor self) { return new Passenger(self); }
}
class PassengerInfo : StatelessTraitInfo<Passenger> {}
class Passenger : IIssueOrder, IResolveOrder
{
public Passenger(Actor self) { }
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
{
if (mi.Button != MouseButton.Right)

View File

@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRa.Game.Traits.Activities;
namespace OpenRa.Game.Traits

View File

@@ -1,6 +1,6 @@
using OpenRa.Game.GameRules;
using System.Collections.Generic;
using System.Linq;
using System.Collections.Generic;
using OpenRa.Game.GameRules;
namespace OpenRa.Game.Traits
{

View File

@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq;
using OpenRa.Game.GameRules;
namespace OpenRa.Game.Traits

View File

@@ -1,24 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OpenRa.Game.Traits
{
class ProvidesRadarInfo : ITraitInfo
{
public object Create(Actor self) { return new ProvidesRadar(self); }
}
class ProvidesRadarInfo : StatelessTraitInfo<ProvidesRadar> {}
class ProvidesRadar
{
Actor self;
public ProvidesRadar(Actor self)
{
this.self = self;
}
public bool IsActive()
public bool IsActive(Actor self)
{
// TODO: Check for nearby MRJ

View File

@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using OpenRa.Game.Graphics;
using OpenRa.Game.Effects;
namespace OpenRa.Game.Traits

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OpenRa.Game.Traits
{
class RenderBuildingChargeInfo : RenderBuildingInfo

View File

@@ -1,5 +1,4 @@
using System;

namespace OpenRa.Game.Traits
{
class RenderBuildingOreInfo : RenderBuildingInfo

View File

@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRa.Game.Graphics;
using OpenRa.Game.GameRules;
using OpenRa.Game.Effects;
using OpenRa.Game.Effects;
namespace OpenRa.Game.Traits
{

View File

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using IjwFramework.Collections;
using OpenRa.Game.Graphics;
namespace OpenRa.Game.Traits

View File

@@ -10,14 +10,12 @@ namespace OpenRa.Game.Traits
class RenderUnitSpinner : RenderUnit
{
public Animation spinnerAnim;
public RenderUnitSpinner( Actor self )
: base(self)
{
var unit = self.traits.Get<Unit>();
spinnerAnim = new Animation( self.Info.Name );
var spinnerAnim = new Animation( self.Info.Name );
spinnerAnim.PlayRepeating( "spinner" );
anims.Add( "spinner", new AnimationWithOffset(
spinnerAnim,

View File

@@ -11,8 +11,6 @@ namespace OpenRa.Game.Traits
class RenderUnitTurreted : RenderUnit
{
public Animation muzzleFlash;
public RenderUnitTurreted(Actor self)
: base(self)
{
@@ -37,7 +35,7 @@ namespace OpenRa.Game.Traits
if( self.Info.MuzzleFlash )
{
muzzleFlash = new Animation( self.Info.Name );
var muzzleFlash = new Animation( self.Info.Name );
muzzleFlash.PlayFetchIndex( "muzzle",
() => ( Util.QuantizeFacing( self.traits.Get<Turreted>().turretFacing, 8 ) ) * 6
+ (int)( attack.primaryRecoil * 5.9f ) ); /* hack: recoil can be 1.0f, but don't overflow into next anim */

View File

@@ -1,15 +1,10 @@

namespace OpenRa.Game.Traits
{
class SeedsOreInfo : ITraitInfo
{
public object Create(Actor self) { return new SeedsOre(self); }
}
class SeedsOreInfo : StatelessTraitInfo<SeedsOre> {}
class SeedsOre : ITick
{
public SeedsOre( Actor self ) {}
const double OreSeedProbability = .05; // todo: push this out into rules
public void Tick(Actor self)

View File

@@ -5,17 +5,12 @@ using System.Text;
namespace OpenRa.Game.Traits
{
class SelectableInfo : ITraitInfo
class SelectableInfo : StatelessTraitInfo<Selectable>
{
public readonly int Priority = 10;
public readonly int[] Bounds = null;
public readonly string Voice = "GenericVoice";
public object Create(Actor self) { return new Selectable(self); }
}
class Selectable
{
public Selectable( Actor self ) { }
}
class Selectable {}
}

View File

@@ -3,18 +3,14 @@ using System;
using OpenRa.Game.GameRules;
namespace OpenRa.Game.Traits
{
class StoresOreInfo : ITraitInfo
class StoresOreInfo : StatelessTraitInfo<StoresOre>
{
public readonly int Pips = 0;
public readonly int Capacity = 0;
public object Create(Actor self) { return new StoresOre(self); }
}
class StoresOre : IPips, IAcceptThief
{
public StoresOre(Actor self) {}
public void OnSteal(Actor self, Actor thief)
{
// Steal half the ore the building holds

View File

@@ -3,15 +3,10 @@ using System.Collections.Generic;
using System.Linq;
namespace OpenRa.Game.Traits
{
class ThiefInfo : ITraitInfo
{
public object Create(Actor self) { return new Thief(self); }
}
class ThiefInfo : StatelessTraitInfo<Thief> { }
class Thief : IIssueOrder, IResolveOrder
{
public Thief(Actor self) { }
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
{
if (mi.Button != MouseButton.Right) return null;

View File

@@ -6,15 +6,10 @@ using OpenRa.Game.Graphics;
namespace OpenRa.Game.Traits
{
class WithShadowInfo : ITraitInfo
{
public object Create(Actor self) { return new WithShadow(self); }
}
class WithShadowInfo : StatelessTraitInfo<WithShadow> {}
class WithShadow : IRenderModifier
{
public WithShadow(Actor self) {}
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
{
var unit = self.traits.Get<Unit>();