Cloak trait now implements IRenderModifier, so we can compose cloaking with pretty much anything.
This commit is contained in:
@@ -73,7 +73,9 @@ namespace OpenRa.Game
|
||||
|
||||
public IEnumerable<Tuple<Sprite, float2, int>> Render()
|
||||
{
|
||||
return traits.WithInterface<IRender>().SelectMany( x => x.Render( this ) );
|
||||
var mods = traits.WithInterface<IRenderModifier>();
|
||||
var sprites = traits.WithInterface<IRender>().SelectMany(x => x.Render(this));
|
||||
return mods.Aggregate(sprites, (m, p) => p.ModifyRender(this, m));
|
||||
}
|
||||
|
||||
public Order Order( int2 xy, MouseInput mi )
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace OpenRa.Game
|
||||
{
|
||||
var projectile = Rules.ProjectileInfo[weapon.Projectile];
|
||||
|
||||
if (projectile.ASW && target.traits.Contains<RenderSubmarine>()) return true;
|
||||
if (projectile.ASW && target.traits.Contains<Cloak>()) return true;
|
||||
if (projectile.AA && target.traits.Contains<Helicopter>()) return true;
|
||||
if (projectile.UnderWater && !target.Info.WaterBound) return false;
|
||||
return projectile.AG;
|
||||
|
||||
@@ -175,7 +175,7 @@
|
||||
<Compile Include="Traits\RenderBuildingTurreted.cs" />
|
||||
<Compile Include="Traits\RenderBuildingWarFactory.cs" />
|
||||
<Compile Include="Traits\RenderSimple.cs" />
|
||||
<Compile Include="Traits\RenderSubmarine.cs" />
|
||||
<Compile Include="Traits\Cloak.cs" />
|
||||
<Compile Include="Traits\RenderUnit.cs" />
|
||||
<Compile Include="Traits\RenderUnitMuzzleFlash.cs" />
|
||||
<Compile Include="Traits\RenderUnitReload.cs" />
|
||||
|
||||
50
OpenRa.Game/Traits/Cloak.cs
Normal file
50
OpenRa.Game/Traits/Cloak.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRa.Game.Graphics;
|
||||
|
||||
namespace OpenRa.Game.Traits
|
||||
{
|
||||
class Cloak : IRenderModifier, INotifyAttack, ITick
|
||||
{
|
||||
int remainingSurfaceTime = 2; /* setup for initial dive */
|
||||
|
||||
public Cloak(Actor self) {}
|
||||
|
||||
public void Attacking(Actor self)
|
||||
{
|
||||
if (remainingSurfaceTime <= 0)
|
||||
OnSurface();
|
||||
|
||||
remainingSurfaceTime = (int)(Rules.General.SubmergeDelay * 60 * 25);
|
||||
}
|
||||
|
||||
public IEnumerable<Tuple<Sprite, float2, int>>
|
||||
ModifyRender(Actor self, IEnumerable<Tuple<Sprite, float2, int>> rs)
|
||||
{
|
||||
if (remainingSurfaceTime > 0)
|
||||
return rs;
|
||||
|
||||
if (self.Owner == Game.LocalPlayer)
|
||||
return rs.Select(a => Tuple.New(a.a, a.b, 8));
|
||||
else
|
||||
return new Tuple<Sprite, float2, int>[] { };
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (remainingSurfaceTime > 0)
|
||||
if (--remainingSurfaceTime <= 0)
|
||||
OnDive();
|
||||
}
|
||||
|
||||
void OnSurface()
|
||||
{
|
||||
Sound.Play("subshow1.aud");
|
||||
}
|
||||
|
||||
void OnDive()
|
||||
{
|
||||
Sound.Play("subshow1.aud"); /* is this the right sound?? */
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using OpenRa.Game.Graphics;
|
||||
|
||||
namespace OpenRa.Game.Traits
|
||||
{
|
||||
class RenderSubmarine : RenderSimple, INotifyAttack, ITick
|
||||
{
|
||||
int remainingSurfaceTime = 2; /* setup for initial dive */
|
||||
|
||||
public RenderSubmarine(Actor self)
|
||||
: base(self)
|
||||
{
|
||||
anim.PlayFacing("idle", () => self.traits.Get<Unit>().Facing);
|
||||
}
|
||||
|
||||
public void Attacking(Actor self)
|
||||
{
|
||||
if (remainingSurfaceTime <= 0)
|
||||
OnSurface();
|
||||
|
||||
remainingSurfaceTime = (int)(Rules.General.SubmergeDelay * 60 * 25);
|
||||
}
|
||||
|
||||
public override IEnumerable<Tuple<Sprite, float2, int>> Render(Actor self)
|
||||
{
|
||||
var s = Util.Centered(self, anim.Image, self.CenterLocation);
|
||||
if (remainingSurfaceTime <= 0)
|
||||
{
|
||||
s.c = 8; /* shadow only palette */
|
||||
if (self.Owner != Game.LocalPlayer)
|
||||
yield break; /* can't see someone else's submerged subs */
|
||||
}
|
||||
yield return s;
|
||||
}
|
||||
|
||||
public override void Tick(Actor self)
|
||||
{
|
||||
base.Tick(self);
|
||||
if (remainingSurfaceTime > 0)
|
||||
if (--remainingSurfaceTime <= 0)
|
||||
OnDive();
|
||||
}
|
||||
|
||||
void OnSurface()
|
||||
{
|
||||
Sound.Play("subshow1.aud");
|
||||
}
|
||||
|
||||
void OnDive()
|
||||
{
|
||||
Sound.Play("subshow1.aud"); /* is this the right sound?? */
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ namespace OpenRa.Game.Traits
|
||||
interface ITick { void Tick(Actor self); }
|
||||
interface IRender { IEnumerable<Tuple<Sprite, float2, int>> Render(Actor self); }
|
||||
interface INotifyDamage { void Damaged(Actor self, DamageState ds); }
|
||||
interface INotifyDamageEx : INotifyDamage { void Damaged(Actor self, int damage, WarheadInfo warhead); }
|
||||
interface INotifyDamageEx { void Damaged(Actor self, int damage, WarheadInfo warhead); }
|
||||
interface INotifyBuildComplete { void BuildingComplete (Actor self); }
|
||||
interface IOrder
|
||||
{
|
||||
@@ -19,4 +19,6 @@ namespace OpenRa.Game.Traits
|
||||
interface IProducer { bool Produce( Actor self, UnitInfo producee ); }
|
||||
interface IOccupySpace { IEnumerable<int2> OccupiedCells(); }
|
||||
interface INotifyAttack { void Attacking(Actor self); }
|
||||
interface IRenderModifier { IEnumerable<Tuple<Sprite, float2, int>>
|
||||
ModifyRender( Actor self, IEnumerable<Tuple<Sprite, float2, int>> r ); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user