From cf8fff2b99a2d4618409e0290931be534cc746bd Mon Sep 17 00:00:00 2001 From: Zimmermann Gyula Date: Fri, 24 Jun 2016 13:18:15 +0200 Subject: [PATCH] Remove passing the warheads from DamageWarhead to AttackInfo. Added a Damage class to pass damage value and damage(types) instead. This removes a great amount of overhead and longterm opens possibilities to have damagetypes without warheads. --- OpenRA.Game/Actor.cs | 4 +-- OpenRA.Game/Traits/TraitsInterfaces.cs | 25 ++++++++++++++++--- OpenRA.Mods.Cnc/Traits/AttackPopupTurreted.cs | 2 +- OpenRA.Mods.Common/Activities/CaptureActor.cs | 2 +- OpenRA.Mods.Common/Activities/Repair.cs | 2 +- .../Activities/RepairBuilding.cs | 2 +- .../Scripting/Properties/HealthProperties.cs | 4 +-- OpenRA.Mods.Common/Traits/AutoTarget.cs | 2 +- OpenRA.Mods.Common/Traits/Buildings/Bridge.cs | 2 +- .../Traits/Buildings/RepairableBuilding.cs | 2 +- OpenRA.Mods.Common/Traits/Burns.cs | 2 +- .../Traits/CombatDebugOverlay.cs | 4 +-- .../Traits/Crates/HealUnitsCrateAction.cs | 3 ++- OpenRA.Mods.Common/Traits/DamagedByTerrain.cs | 2 +- OpenRA.Mods.Common/Traits/Explodes.cs | 3 +-- OpenRA.Mods.Common/Traits/GivesBounty.cs | 3 +-- OpenRA.Mods.Common/Traits/Health.cs | 16 ++++++------ .../Traits/Infantry/ScaredyCat.cs | 2 +- .../Traits/Infantry/TakeCover.cs | 10 +++----- .../Traits/Infantry/TerrainModifiesDamage.cs | 5 ++-- .../Traits/Multipliers/DamageMultiplier.cs | 2 +- .../Traits/Player/BaseAttackNotifier.cs | 4 +-- .../Traits/Render/WithDamageOverlay.cs | 5 ++-- .../Traits/Render/WithDeathAnimation.cs | 5 ++-- OpenRA.Mods.Common/Traits/SelfHealing.cs | 4 +-- .../Traits/Sound/DeathSounds.cs | 7 ++---- .../Traits/SpawnActorOnDeath.cs | 3 +-- OpenRA.Mods.Common/Warheads/DamageWarhead.cs | 2 +- .../Warheads/HealthPercentageDamageWarhead.cs | 2 +- OpenRA.Mods.RA/Traits/Chronoshiftable.cs | 2 +- 30 files changed, 69 insertions(+), 64 deletions(-) diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index 8c64efe563..26f53aac3a 100644 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -317,12 +317,12 @@ namespace OpenRA return (health == null) ? DamageState.Undamaged : health.DamageState; } - public void InflictDamage(Actor attacker, int damage, IWarhead warhead) + public void InflictDamage(Actor attacker, Damage damage) { if (Disposed || health == null) return; - health.InflictDamage(this, attacker, damage, warhead, false); + health.InflictDamage(this, attacker, damage, false); } public void Kill(Actor attacker) diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 6b649f28c7..50db274031 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -41,7 +41,7 @@ namespace OpenRA.Traits int DisplayHP { get; } bool IsDead { get; } - void InflictDamage(Actor self, Actor attacker, int damage, IWarhead warhead, bool ignoreModifiers); + void InflictDamage(Actor self, Actor attacker, Damage damage, bool ignoreModifiers); void Kill(Actor self, Actor attacker); } @@ -82,13 +82,30 @@ namespace OpenRA.Traits public class AttackInfo { - public int Damage; + public Damage Damage; public Actor Attacker; - public IWarhead Warhead; public DamageState DamageState; public DamageState PreviousDamageState; } + public class Damage + { + public readonly int Value; + public readonly HashSet DamageTypes; + + public Damage(int damage, HashSet damageTypes) + { + Value = damage; + DamageTypes = damageTypes; + } + + public Damage(int damage) + { + Value = damage; + DamageTypes = new HashSet(); + } + } + public interface ITick { void Tick(Actor self); } public interface ITickRender { void TickRender(WorldRenderer wr, Actor self); } public interface IRender { IEnumerable Render(Actor self, WorldRenderer wr); } @@ -249,7 +266,7 @@ namespace OpenRA.Traits } public interface IRenderModifier { IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r); } - public interface IDamageModifier { int GetDamageModifier(Actor attacker, IWarhead warhead); } + public interface IDamageModifier { int GetDamageModifier(Actor attacker, Damage damage); } public interface ISpeedModifier { int GetSpeedModifier(); } public interface IFirepowerModifier { int GetFirepowerModifier(); } public interface IReloadModifier { int GetReloadModifier(); } diff --git a/OpenRA.Mods.Cnc/Traits/AttackPopupTurreted.cs b/OpenRA.Mods.Cnc/Traits/AttackPopupTurreted.cs index 737c996833..c2d8808af4 100644 --- a/OpenRA.Mods.Cnc/Traits/AttackPopupTurreted.cs +++ b/OpenRA.Mods.Cnc/Traits/AttackPopupTurreted.cs @@ -112,7 +112,7 @@ namespace OpenRA.Mods.Cnc.Traits } } - public int GetDamageModifier(Actor attacker, IWarhead warhead) + public int GetDamageModifier(Actor attacker, Damage damage) { return state == PopupState.Closed ? info.ClosedDamageMultiplier : 100; } diff --git a/OpenRA.Mods.Common/Activities/CaptureActor.cs b/OpenRA.Mods.Common/Activities/CaptureActor.cs index 507b8cb0f7..b0351f5103 100644 --- a/OpenRA.Mods.Common/Activities/CaptureActor.cs +++ b/OpenRA.Mods.Common/Activities/CaptureActor.cs @@ -69,7 +69,7 @@ namespace OpenRA.Mods.Common.Activities else { var damage = health.MaxHP * capturesInfo.SabotageHPRemoval / 100; - actor.InflictDamage(self, damage, null); + actor.InflictDamage(self, new Damage(damage)); } self.Dispose(); diff --git a/OpenRA.Mods.Common/Activities/Repair.cs b/OpenRA.Mods.Common/Activities/Repair.cs index cecd60b66a..ff3f06fb2f 100644 --- a/OpenRA.Mods.Common/Activities/Repair.cs +++ b/OpenRA.Mods.Common/Activities/Repair.cs @@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Activities return this; } - self.InflictDamage(self, -hpToRepair, null); + self.InflictDamage(self, new Damage(-hpToRepair)); foreach (var depot in host.TraitsImplementing()) depot.Repairing(host, self); diff --git a/OpenRA.Mods.Common/Activities/RepairBuilding.cs b/OpenRA.Mods.Common/Activities/RepairBuilding.cs index 18cb27d8b1..8c49fdfba0 100644 --- a/OpenRA.Mods.Common/Activities/RepairBuilding.cs +++ b/OpenRA.Mods.Common/Activities/RepairBuilding.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Activities if (health.DamageState == DamageState.Undamaged) return; - target.InflictDamage(self, -health.MaxHP, null); + target.InflictDamage(self, new Damage(-health.MaxHP)); } } } diff --git a/OpenRA.Mods.Common/Scripting/Properties/HealthProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/HealthProperties.cs index 09da17a22b..2889b1eaf5 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/HealthProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/HealthProperties.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Scripting public int Health { get { return health.HP; } - set { health.InflictDamage(Self, Self, health.HP - value, null, true); } + set { health.InflictDamage(Self, Self, new Damage(health.HP - value), true); } } [Desc("Maximum health of the actor.")] @@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Scripting [Desc("Kill the actor.")] public void Kill() { - health.InflictDamage(Self, Self, health.MaxHP, null, true); + health.InflictDamage(Self, Self, new Damage(health.MaxHP), true); } } } diff --git a/OpenRA.Mods.Common/Traits/AutoTarget.cs b/OpenRA.Mods.Common/Traits/AutoTarget.cs index 1ec70432ed..7f9e5b99e4 100644 --- a/OpenRA.Mods.Common/Traits/AutoTarget.cs +++ b/OpenRA.Mods.Common/Traits/AutoTarget.cs @@ -113,7 +113,7 @@ namespace OpenRA.Mods.Common.Traits return; // don't retaliate against healers - if (e.Damage < 0) + if (e.Damage.Value < 0) return; Aggressor = attacker; diff --git a/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs b/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs index 46cbdfa0a6..241e7656b9 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs @@ -292,7 +292,7 @@ namespace OpenRA.Mods.Common.Traits KillUnitsOnBridge(); } else - health.InflictDamage(self, repairer, -health.MaxHP, null, true); + health.InflictDamage(self, repairer, new Damage(-health.MaxHP), true); if (direction < 0 ? neighbours[0] == null && neighbours[1] == null : Hut != null || neighbours[direction] == null) onComplete(); // Done if single or reached other hut }); diff --git a/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs b/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs index ea2d860345..a3831788bf 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs @@ -129,7 +129,7 @@ namespace OpenRA.Mods.Common.Traits // activePlayers won't cause IndexOutOfRange because we capped the max amount of players // to the length of the array - self.InflictDamage(self, -(hpToRepair * Info.RepairBonuses[activePlayers - 1] / 100), null); + self.InflictDamage(self, new Damage(-(hpToRepair * Info.RepairBonuses[activePlayers - 1] / 100))); if (health.DamageState == DamageState.Undamaged) { diff --git a/OpenRA.Mods.Common/Traits/Burns.cs b/OpenRA.Mods.Common/Traits/Burns.cs index b56b23773a..4713af4216 100644 --- a/OpenRA.Mods.Common/Traits/Burns.cs +++ b/OpenRA.Mods.Common/Traits/Burns.cs @@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Traits { if (--ticks <= 0) { - self.InflictDamage(self, info.Damage, null); + self.InflictDamage(self, new Damage(info.Damage)); ticks = info.Interval; } } diff --git a/OpenRA.Mods.Common/Traits/CombatDebugOverlay.cs b/OpenRA.Mods.Common/Traits/CombatDebugOverlay.cs index e8b02a42e7..08eb6b1ab9 100644 --- a/OpenRA.Mods.Common/Traits/CombatDebugOverlay.cs +++ b/OpenRA.Mods.Common/Traits/CombatDebugOverlay.cs @@ -116,14 +116,14 @@ namespace OpenRA.Mods.Common.Traits public void Damaged(Actor self, AttackInfo e) { - if (devMode == null || !devMode.ShowCombatGeometry || e.Damage == 0) + if (devMode == null || !devMode.ShowCombatGeometry || e.Damage.Value == 0) return; if (healthInfo == null) return; var maxHP = healthInfo.HP > 0 ? healthInfo.HP : 1; - var damageText = "{0} ({1}%)".F(-e.Damage, e.Damage * 100 / maxHP); + var damageText = "{0} ({1}%)".F(-e.Damage.Value, e.Damage.Value * 100 / maxHP); self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, e.Attacker.Owner.Color.RGB, damageText, 30))); } diff --git a/OpenRA.Mods.Common/Traits/Crates/HealUnitsCrateAction.cs b/OpenRA.Mods.Common/Traits/Crates/HealUnitsCrateAction.cs index ccf388d5e5..680c272a36 100644 --- a/OpenRA.Mods.Common/Traits/Crates/HealUnitsCrateAction.cs +++ b/OpenRA.Mods.Common/Traits/Crates/HealUnitsCrateAction.cs @@ -10,6 +10,7 @@ #endregion using System.Linq; +using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { @@ -28,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits { foreach (var healable in collector.World.ActorsWithTrait().Where(tp => tp.Actor.Owner == collector.Owner)) if (!healable.Trait.IsDead) - healable.Trait.InflictDamage(healable.Actor, healable.Actor, -(healable.Trait.MaxHP - healable.Trait.HP), null, true); + healable.Trait.InflictDamage(healable.Actor, healable.Actor, new Damage(-(healable.Trait.MaxHP - healable.Trait.HP)), true); base.Activate(collector); } diff --git a/OpenRA.Mods.Common/Traits/DamagedByTerrain.cs b/OpenRA.Mods.Common/Traits/DamagedByTerrain.cs index 9106d4ef9f..e1781161eb 100644 --- a/OpenRA.Mods.Common/Traits/DamagedByTerrain.cs +++ b/OpenRA.Mods.Common/Traits/DamagedByTerrain.cs @@ -67,7 +67,7 @@ namespace OpenRA.Mods.Common.Traits // Actors start with maximum damage applied var delta = health.HP - damageThreshold; if (delta > 0) - health.InflictDamage(self, self.World.WorldActor, delta, null, false); + health.InflictDamage(self, self.World.WorldActor, new Damage(delta), false); } public void Tick(Actor self) diff --git a/OpenRA.Mods.Common/Traits/Explodes.cs b/OpenRA.Mods.Common/Traits/Explodes.cs index 88299d8a4d..b73eca9587 100644 --- a/OpenRA.Mods.Common/Traits/Explodes.cs +++ b/OpenRA.Mods.Common/Traits/Explodes.cs @@ -69,8 +69,7 @@ namespace OpenRA.Mods.Common.Traits if (self.World.SharedRandom.Next(100) > info.Chance) return; - var warhead = e.Warhead as DamageWarhead; - if (info.DeathTypes.Count > 0 && warhead != null && !warhead.DamageTypes.Overlaps(info.DeathTypes)) + if (info.DeathTypes.Count > 0 && !e.Damage.DamageTypes.Overlaps(info.DeathTypes)) return; var weapon = ChooseWeaponForExplosion(self); diff --git a/OpenRA.Mods.Common/Traits/GivesBounty.cs b/OpenRA.Mods.Common/Traits/GivesBounty.cs index c397852c80..d3ed043cf8 100644 --- a/OpenRA.Mods.Common/Traits/GivesBounty.cs +++ b/OpenRA.Mods.Common/Traits/GivesBounty.cs @@ -66,8 +66,7 @@ namespace OpenRA.Mods.Common.Traits if (!info.ValidStances.HasStance(e.Attacker.Owner.Stances[self.Owner])) return; - var warhead = e.Warhead as DamageWarhead; - if (info.DeathTypes.Count > 0 && warhead != null && !warhead.DamageTypes.Overlaps(info.DeathTypes)) + if (info.DeathTypes.Count > 0 && !e.Damage.DamageTypes.Overlaps(info.DeathTypes)) return; var cost = self.GetSellValue(); diff --git a/OpenRA.Mods.Common/Traits/Health.cs b/OpenRA.Mods.Common/Traits/Health.cs index 576be316fb..0993e61a8c 100644 --- a/OpenRA.Mods.Common/Traits/Health.cs +++ b/OpenRA.Mods.Common/Traits/Health.cs @@ -112,10 +112,9 @@ namespace OpenRA.Mods.Common.Traits var ai = new AttackInfo { Attacker = repairer, - Damage = -MaxHP, + Damage = new Damage(-MaxHP), DamageState = DamageState, PreviousDamageState = DamageState.Dead, - Warhead = null, }; foreach (var nd in self.TraitsImplementing() @@ -131,7 +130,7 @@ namespace OpenRA.Mods.Common.Traits nd.AppliedDamage(repairer, self, ai); } - public void InflictDamage(Actor self, Actor attacker, int damage, IWarhead warhead, bool ignoreModifiers) + public void InflictDamage(Actor self, Actor attacker, Damage damage, bool ignoreModifiers) { // Overkill! Don't count extra hits as more kills! if (IsDead) @@ -140,16 +139,16 @@ namespace OpenRA.Mods.Common.Traits var oldState = DamageState; // Apply any damage modifiers - if (!ignoreModifiers && damage > 0) + if (!ignoreModifiers && damage.Value > 0) { var modifiers = self.TraitsImplementing() .Concat(self.Owner.PlayerActor.TraitsImplementing()) - .Select(t => t.GetDamageModifier(attacker, warhead)); + .Select(t => t.GetDamageModifier(attacker, damage)); - damage = Util.ApplyPercentageModifiers(damage, modifiers); + damage = new Damage(Util.ApplyPercentageModifiers(damage.Value, modifiers), damage.DamageTypes); } - hp = (hp - damage).Clamp(0, MaxHP); + hp = (hp - damage.Value).Clamp(0, MaxHP); var ai = new AttackInfo { @@ -157,7 +156,6 @@ namespace OpenRA.Mods.Common.Traits Damage = damage, DamageState = DamageState, PreviousDamageState = oldState, - Warhead = warhead, }; foreach (var nd in self.TraitsImplementing() @@ -191,7 +189,7 @@ namespace OpenRA.Mods.Common.Traits public void Kill(Actor self, Actor attacker) { - InflictDamage(self, attacker, MaxHP, null, true); + InflictDamage(self, attacker, new Damage(MaxHP), true); } public void Tick(Actor self) diff --git a/OpenRA.Mods.Common/Traits/Infantry/ScaredyCat.cs b/OpenRA.Mods.Common/Traits/Infantry/ScaredyCat.cs index 11907d83ef..612c71fd5a 100644 --- a/OpenRA.Mods.Common/Traits/Infantry/ScaredyCat.cs +++ b/OpenRA.Mods.Common/Traits/Infantry/ScaredyCat.cs @@ -78,7 +78,7 @@ namespace OpenRA.Mods.Common.Traits public void Damaged(Actor self, AttackInfo e) { - if (e.Damage > 0) + if (e.Damage.Value > 0) Panic(); } diff --git a/OpenRA.Mods.Common/Traits/Infantry/TakeCover.cs b/OpenRA.Mods.Common/Traits/Infantry/TakeCover.cs index 14d0e343bf..b47204eab6 100644 --- a/OpenRA.Mods.Common/Traits/Infantry/TakeCover.cs +++ b/OpenRA.Mods.Common/Traits/Infantry/TakeCover.cs @@ -56,8 +56,7 @@ namespace OpenRA.Mods.Common.Traits public void Damaged(Actor self, AttackInfo e) { - var warhead = e.Warhead as DamageWarhead; - if (e.Damage <= 0 || warhead == null || !warhead.DamageTypes.Overlaps(info.DamageTriggers)) + if (e.Damage.Value <= 0 || !e.Damage.DamageTypes.Overlaps(info.DamageTriggers)) return; if (!IsProne) @@ -79,16 +78,15 @@ namespace OpenRA.Mods.Common.Traits get { return true; } } - public int GetDamageModifier(Actor attacker, IWarhead warhead) + public int GetDamageModifier(Actor attacker, Damage damage) { if (!IsProne) return 100; - var damageWh = warhead as DamageWarhead; - if (damageWh == null) + if (damage.DamageTypes.Count == 0) return 100; - var modifierPercentages = info.DamageModifiers.Where(x => damageWh.DamageTypes.Contains(x.Key)).Select(x => x.Value); + var modifierPercentages = info.DamageModifiers.Where(x => damage.DamageTypes.Contains(x.Key)).Select(x => x.Value); return Util.ApplyPercentageModifiers(100, modifierPercentages); } diff --git a/OpenRA.Mods.Common/Traits/Infantry/TerrainModifiesDamage.cs b/OpenRA.Mods.Common/Traits/Infantry/TerrainModifiesDamage.cs index 2eb3efa893..c06d4a2262 100644 --- a/OpenRA.Mods.Common/Traits/Infantry/TerrainModifiesDamage.cs +++ b/OpenRA.Mods.Common/Traits/Infantry/TerrainModifiesDamage.cs @@ -41,10 +41,9 @@ namespace OpenRA.Mods.Common.Traits this.self = self; } - public int GetDamageModifier(Actor attacker, IWarhead warhead) + public int GetDamageModifier(Actor attacker, Damage damage) { - var damageWh = warhead as DamageWarhead; - if (attacker.Owner.IsAlliedWith(self.Owner) && (damageWh != null && damageWh.Damage < 0) && !Info.ModifyHealing) + if (attacker.Owner.IsAlliedWith(self.Owner) && damage.Value < 0 && !Info.ModifyHealing) return FullDamage; var world = self.World; diff --git a/OpenRA.Mods.Common/Traits/Multipliers/DamageMultiplier.cs b/OpenRA.Mods.Common/Traits/Multipliers/DamageMultiplier.cs index cde386ff60..87b107fe06 100644 --- a/OpenRA.Mods.Common/Traits/Multipliers/DamageMultiplier.cs +++ b/OpenRA.Mods.Common/Traits/Multipliers/DamageMultiplier.cs @@ -26,6 +26,6 @@ namespace OpenRA.Mods.Common.Traits public DamageMultiplier(DamageMultiplierInfo info, string actorType) : base(info, "DamageMultiplier", actorType) { } - public int GetDamageModifier(Actor attacker, IWarhead warhead) { return GetModifier(); } + public int GetDamageModifier(Actor attacker, Damage damage) { return GetModifier(); } } } diff --git a/OpenRA.Mods.Common/Traits/Player/BaseAttackNotifier.cs b/OpenRA.Mods.Common/Traits/Player/BaseAttackNotifier.cs index f07e850c95..2de92ec291 100644 --- a/OpenRA.Mods.Common/Traits/Player/BaseAttackNotifier.cs +++ b/OpenRA.Mods.Common/Traits/Player/BaseAttackNotifier.cs @@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Traits if (!self.Info.HasTraitInfo()) return; - if (e.Attacker.Owner.IsAlliedWith(self.Owner) && e.Damage <= 0) + if (e.Attacker.Owner.IsAlliedWith(self.Owner) && e.Damage.Value <= 0) return; if (self.World.WorldTick - lastAttackTime > info.NotifyInterval * 25) @@ -85,4 +85,4 @@ namespace OpenRA.Mods.Common.Traits lastAttackTime = self.World.WorldTick; } } -} \ No newline at end of file +} diff --git a/OpenRA.Mods.Common/Traits/Render/WithDamageOverlay.cs b/OpenRA.Mods.Common/Traits/Render/WithDamageOverlay.cs index ddb8f23695..45cedbf134 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithDamageOverlay.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithDamageOverlay.cs @@ -55,12 +55,11 @@ namespace OpenRA.Mods.Common.Traits.Render public void Damaged(Actor self, AttackInfo e) { - var warhead = e.Warhead as DamageWarhead; - if (info.DamageTypes.Count > 0 && (warhead != null && !warhead.DamageTypes.Overlaps(info.DamageTypes))) + if (info.DamageTypes.Count > 0 && !e.Damage.DamageTypes.Overlaps(info.DamageTypes)) return; if (isSmoking) return; - if (e.Damage < 0) return; /* getting healed */ + if (e.Damage.Value < 0) return; /* getting healed */ if (e.DamageState < info.MinimumDamageState) return; if (e.DamageState > info.MaximumDamageState) return; diff --git a/OpenRA.Mods.Common/Traits/Render/WithDeathAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithDeathAnimation.cs index dc434caad0..89c9a9f186 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithDeathAnimation.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithDeathAnimation.cs @@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Traits.Render palette += self.Owner.InternalName; // Killed by some non-standard means - if (e.Warhead == null || !(e.Warhead is DamageWarhead)) + if (e.Damage.DamageTypes.Count == 0) { if (Info.FallbackSequence != null) SpawnDeathAnimation(self, self.CenterPosition, rs.GetImage(self), Info.FallbackSequence, palette); @@ -95,8 +95,7 @@ namespace OpenRA.Mods.Common.Traits.Render var sequence = Info.DeathSequence; if (Info.UseDeathTypeSuffix) { - var warhead = e.Warhead as DamageWarhead; - var damageType = Info.DeathTypes.Keys.FirstOrDefault(warhead.DamageTypes.Contains); + var damageType = Info.DeathTypes.Keys.FirstOrDefault(e.Damage.DamageTypes.Contains); if (damageType == null) return; diff --git a/OpenRA.Mods.Common/Traits/SelfHealing.cs b/OpenRA.Mods.Common/Traits/SelfHealing.cs index 98a782b613..0b17489789 100644 --- a/OpenRA.Mods.Common/Traits/SelfHealing.cs +++ b/OpenRA.Mods.Common/Traits/SelfHealing.cs @@ -55,13 +55,13 @@ namespace OpenRA.Mods.Common.Traits if (--ticks <= 0) { ticks = Info.Delay; - self.InflictDamage(self, -Info.Step, null); + self.InflictDamage(self, new Damage(-Info.Step)); } } public void Damaged(Actor self, AttackInfo e) { - if (e.Damage > 0) + if (e.Damage.Value > 0) damageTicks = Info.DamageCooldown; } } diff --git a/OpenRA.Mods.Common/Traits/Sound/DeathSounds.cs b/OpenRA.Mods.Common/Traits/Sound/DeathSounds.cs index 42ee6d52d7..ffe3bca609 100644 --- a/OpenRA.Mods.Common/Traits/Sound/DeathSounds.cs +++ b/OpenRA.Mods.Common/Traits/Sound/DeathSounds.cs @@ -39,11 +39,8 @@ namespace OpenRA.Mods.Common.Traits.Sound public void Killed(Actor self, AttackInfo e) { - var warhead = e.Warhead as DamageWarhead; - - // If the warhead is null, the actor was killed by some non-standard means - if (info.DeathTypes.Count == 0 || (warhead != null && warhead.DamageTypes.Overlaps(info.DeathTypes))) + if (info.DeathTypes.Count == 0 || e.Damage.DamageTypes.Overlaps(info.DeathTypes)) self.PlayVoiceLocal(info.Voice, info.VolumeMultiplier); } } -} \ No newline at end of file +} diff --git a/OpenRA.Mods.Common/Traits/SpawnActorOnDeath.cs b/OpenRA.Mods.Common/Traits/SpawnActorOnDeath.cs index 411687848b..a041825e2e 100644 --- a/OpenRA.Mods.Common/Traits/SpawnActorOnDeath.cs +++ b/OpenRA.Mods.Common/Traits/SpawnActorOnDeath.cs @@ -72,8 +72,7 @@ namespace OpenRA.Mods.Common.Traits if (self.World.SharedRandom.Next(100) > info.Probability) return; - var warhead = e.Warhead as DamageWarhead; - if (info.DeathType != null && (warhead == null || !warhead.DamageTypes.Contains(info.DeathType))) + if (info.DeathType != null && !e.Damage.DamageTypes.Contains(info.DeathType)) return; self.World.AddFrameEndTask(w => diff --git a/OpenRA.Mods.Common/Warheads/DamageWarhead.cs b/OpenRA.Mods.Common/Warheads/DamageWarhead.cs index 9779991190..f0090efdff 100644 --- a/OpenRA.Mods.Common/Warheads/DamageWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/DamageWarhead.cs @@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Warheads return; var damage = Util.ApplyPercentageModifiers(Damage, damageModifiers.Append(DamageVersus(victim))); - victim.InflictDamage(firedBy, damage, this); + victim.InflictDamage(firedBy, new Damage(damage, DamageTypes)); } } } diff --git a/OpenRA.Mods.Common/Warheads/HealthPercentageDamageWarhead.cs b/OpenRA.Mods.Common/Warheads/HealthPercentageDamageWarhead.cs index 1874cbb458..34f34f8008 100644 --- a/OpenRA.Mods.Common/Warheads/HealthPercentageDamageWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/HealthPercentageDamageWarhead.cs @@ -52,7 +52,7 @@ namespace OpenRA.Mods.Common.Warheads // Damage is measured as a percentage of the target health var damage = Util.ApplyPercentageModifiers(healthInfo.HP, damageModifiers.Append(Damage, DamageVersus(victim))); - victim.InflictDamage(firedBy, damage, this); + victim.InflictDamage(firedBy, new Damage(damage, DamageTypes)); } } } diff --git a/OpenRA.Mods.RA/Traits/Chronoshiftable.cs b/OpenRA.Mods.RA/Traits/Chronoshiftable.cs index 33cdfeb211..8835ba97f0 100644 --- a/OpenRA.Mods.RA/Traits/Chronoshiftable.cs +++ b/OpenRA.Mods.RA/Traits/Chronoshiftable.cs @@ -95,7 +95,7 @@ namespace OpenRA.Mods.RA.Traits { // Damage is inflicted by the chronosphere if (!self.Disposed) - self.InflictDamage(chronosphere, int.MaxValue, null); + self.InflictDamage(chronosphere, new Damage(int.MaxValue)); }); return true; }