Create INotifyDamageStateChanged for nearly everything else that used INotifyDamage.

This commit is contained in:
Paul Chote
2011-04-16 11:48:28 +12:00
parent 8b00e1cfa5
commit 794dcac4d2
10 changed files with 35 additions and 46 deletions

View File

@@ -90,7 +90,6 @@ namespace OpenRA.Traits
Damage = damage,
DamageState = this.DamageState,
PreviousDamageState = oldState,
DamageStateChanged = this.DamageState != oldState,
Warhead = warhead,
};
@@ -98,6 +97,11 @@ namespace OpenRA.Traits
.Concat(self.Owner.PlayerActor.TraitsImplementing<INotifyDamage>()))
nd.Damaged(self, ai);
if (DamageState != oldState)
foreach (var nd in self.TraitsImplementing<INotifyDamageStateChanged>())
nd.DamageStateChanged(self, ai);
if (attacker != null && attacker.IsInWorld && !attacker.IsDead())
foreach (var nd in attacker.TraitsImplementing<INotifyAppliedDamage>()
.Concat(attacker.Owner.PlayerActor.TraitsImplementing<INotifyAppliedDamage>()))

View File

@@ -30,7 +30,6 @@ namespace OpenRA.Traits
public int Damage;
public DamageState DamageState;
public DamageState PreviousDamageState;
public bool DamageStateChanged;
}
public interface ITick { void Tick(Actor self); }
@@ -57,6 +56,7 @@ namespace OpenRA.Traits
public interface IOrderVoice { string VoicePhraseForOrder(Actor self, Order order); }
public interface INotifySold { void Selling(Actor self); void Sold(Actor self); }
public interface INotifyDamage { void Damaged(Actor self, AttackInfo e); }
public interface INotifyDamageStateChanged { void DamageStateChanged(Actor self, AttackInfo e); }
public interface INotifyKilled { void Killed(Actor self, AttackInfo e); }
public interface INotifyAppliedDamage { void AppliedDamage(Actor self, Actor damaged, AttackInfo e); }
public interface INotifyBuildComplete { void BuildingComplete(Actor self); }

View File

@@ -19,9 +19,11 @@ namespace OpenRA.Mods.RA.Render
public override object Create(ActorInitializer init) { return new RenderGunboat(init.self); }
}
class RenderGunboat : RenderSimple, INotifyDamage
class RenderGunboat : RenderSimple, INotifyDamage, INotifyDamageStateChanged
{
IFacing facing;
bool isSmoking = false;
public RenderGunboat(Actor self)
: base(self, () => self.HasTrait<Turreted>() ? self.Trait<Turreted>().turretFacing : 0)
{
@@ -49,21 +51,19 @@ namespace OpenRA.Mods.RA.Render
base.Tick(self);
}
bool isSmoking;
public void DamageStateChanged(Actor self, AttackInfo e)
{
if (e.DamageState >= DamageState.Critical)
lastDamage = "-critical";
else if (e.DamageState >= DamageState.Heavy)
lastDamage = "-damaged";
else if (e.DamageState < DamageState.Heavy)
lastDamage = "";
anim.ReplaceAnim(lastDir+lastDamage);
}
public void Damaged(Actor self, AttackInfo e)
{
// Damagestate
if (e.DamageStateChanged)
{
if (e.DamageState >= DamageState.Critical)
lastDamage = "-critical";
else if (e.DamageState >= DamageState.Heavy)
lastDamage = "-damaged";
else if (e.DamageState < DamageState.Heavy)
lastDamage = "";
anim.ReplaceAnim(lastDir+lastDamage);
}
// Smoking
if (e.DamageState < DamageState.Heavy) return;
if (isSmoking) return;

View File

@@ -62,7 +62,7 @@ namespace OpenRA.Mods.RA
}
}
class Bridge: IRenderAsTerrain, INotifyDamage
class Bridge: IRenderAsTerrain, INotifyDamageStateChanged
{
static string cachedTileset;
static Cache<TileReference<ushort,byte>, Sprite> sprites;
@@ -192,14 +192,11 @@ namespace OpenRA.Mods.RA
self.World.Map.CustomTerrain[c.X, c.Y] = GetTerrainType(c);
}
public void Damaged(Actor self, AttackInfo e)
public void DamageStateChanged(Actor self, AttackInfo e)
{
if (e.DamageStateChanged)
{
UpdateState();
if (northNeighbour != null) northNeighbour.UpdateState();
if (southNeighbour != null) southNeighbour.UpdateState();
}
UpdateState();
if (northNeighbour != null) northNeighbour.UpdateState();
if (southNeighbour != null) southNeighbour.UpdateState();
}
}
}

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Render
public object Create(ActorInitializer init) { return new SoundOnDamageTransition(this);}
}
public class SoundOnDamageTransition : INotifyDamage
public class SoundOnDamageTransition : INotifyDamageStateChanged
{
readonly SoundOnDamageTransitionInfo Info;
public SoundOnDamageTransition( SoundOnDamageTransitionInfo info )
@@ -34,11 +34,8 @@ namespace OpenRA.Mods.RA.Render
Info = info;
}
public virtual void Damaged(Actor self, AttackInfo e)
public void DamageStateChanged(Actor self, AttackInfo e)
{
if (!e.DamageStateChanged)
return;
if (e.DamageState == DamageState.Dead)
Sound.Play(Info.DestroyedSound, self.CenterLocation);
else if (e.DamageState >= DamageState.Heavy && e.PreviousDamageState < DamageState.Heavy)

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Mods.RA
public object Create(ActorInitializer init) { return new Cloak(init.self, this); }
}
public class Cloak : IRenderModifier, INotifyDamage, INotifyAttack, ITick, IVisibilityModifier, IRadarColorModifier, ISync
public class Cloak : IRenderModifier, INotifyDamageStateChanged, INotifyAttack, ITick, IVisibilityModifier, IRadarColorModifier, ISync
{
[Sync]
int remainingTime;
@@ -63,7 +63,7 @@ namespace OpenRA.Mods.RA
}
public void Attacking(Actor self, Target target) { DoUncloak(); }
public void Damaged(Actor self, AttackInfo e)
public void DamageStateChanged(Actor self, AttackInfo e)
{
canCloak = (e.DamageState < DamageState.Critical);
if (Cloaked && !canCloak)

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA.Render
}
}
public class RenderBuilding : RenderSimple, INotifyDamage, IRenderModifier
public class RenderBuilding : RenderSimple, INotifyDamageStateChanged, IRenderModifier
{
readonly RenderBuildingInfo Info;
@@ -96,11 +96,8 @@ namespace OpenRA.Mods.RA.Render
anim.PlayRepeating( NormalizeSequence(self, "idle") );
}
public virtual void Damaged(Actor self, AttackInfo e)
public virtual void DamageStateChanged(Actor self, AttackInfo e)
{
if (!e.DamageStateChanged)
return;
if (e.DamageState == DamageState.Dead)
foreach (var t in FootprintUtils.UnpathableTiles( self.Info.Name, self.Info.Traits.Get<BuildingInfo>(), self.Location ))
{

View File

@@ -28,10 +28,8 @@ namespace OpenRA.Mods.RA.Render
anim.Play( "idle" );
}
public override void Damaged(Actor self, AttackInfo e)
public override void DamageStateChanged(Actor self, AttackInfo e)
{
if (!e.DamageStateChanged) return;
if (e.DamageState >= DamageState.Heavy && e.PreviousDamageState < DamageState.Heavy)
anim.ReplaceAnim("damaged-idle");
else if (e.DamageState < DamageState.Heavy)

View File

@@ -35,10 +35,8 @@ namespace OpenRA.Mods.RA.Render
anim.PlayFetchIndex(seqName, () => adjacentWalls);
}
public override void Damaged(Actor self, AttackInfo e)
public override void DamageStateChanged(Actor self, AttackInfo e)
{
if (!e.DamageStateChanged) return;
if (e.DamageState == DamageState.Medium && anim.HasSequence("scratched-idle"))
seqName = "scratched-idle";
else if (e.DamageState <= DamageState.Medium)

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Mods.RA.Render
}
}
class RenderWarFactory : RenderBuilding, INotifyBuildComplete, INotifyDamage, ITick, INotifyProduction, INotifySold, ISync
class RenderWarFactory : RenderBuilding, INotifyBuildComplete, ITick, INotifyProduction, INotifySold, ISync
{
public Animation roof;
[Sync]
@@ -69,10 +69,8 @@ namespace OpenRA.Mods.RA.Render
}
}
public override void Damaged(Actor self, AttackInfo e)
public override void DamageStateChanged(Actor self, AttackInfo e)
{
if (!e.DamageStateChanged) return;
if (roof.CurrentSequence != null)
{
if (e.DamageState >= DamageState.Heavy)