From 6073de52ca0a5265706fbcfc74dc88c47bcd8eb6 Mon Sep 17 00:00:00 2001 From: Mustafa Alperen Seki Date: Thu, 28 Jun 2018 14:40:07 +0300 Subject: [PATCH] Add DamageSource to Explodes --- OpenRA.Mods.Common/Traits/Explodes.cs | 16 ++++++++++++---- mods/ra/rules/vehicles.yaml | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Explodes.cs b/OpenRA.Mods.Common/Traits/Explodes.cs index 234d51e910..79e54d43c4 100644 --- a/OpenRA.Mods.Common/Traits/Explodes.cs +++ b/OpenRA.Mods.Common/Traits/Explodes.cs @@ -19,6 +19,8 @@ namespace OpenRA.Mods.Common.Traits { public enum ExplosionType { Footprint, CenterPosition } + public enum DamageSource { Self, Killer } + [Desc("This actor explodes when killed.")] public class ExplodesInfo : ConditionalTraitInfo, Requires { @@ -40,6 +42,10 @@ namespace OpenRA.Mods.Common.Traits [Desc("DeathType(s) that trigger the explosion. Leave empty to always trigger an explosion.")] public readonly HashSet DeathTypes = new HashSet(); + [Desc("Who is counted as source of damage for explosion.", + "Possible values are Self and Killer.")] + public readonly DamageSource DamageSource = DamageSource.Self; + [Desc("Possible values are CenterPosition (explosion at the actors' center) and ", "Footprint (explosion on each occupied cell).")] public readonly ExplosionType Type = ExplosionType.CenterPosition; @@ -103,20 +109,21 @@ namespace OpenRA.Mods.Common.Traits if (weapon == null) return; + var source = Info.DamageSource == DamageSource.Self ? self : e.Attacker; if (weapon.Report != null && weapon.Report.Any()) - Game.Sound.Play(SoundType.World, weapon.Report.Random(e.Attacker.World.SharedRandom), self.CenterPosition); + Game.Sound.Play(SoundType.World, weapon.Report.Random(source.World.SharedRandom), self.CenterPosition); if (Info.Type == ExplosionType.Footprint && buildingInfo != null) { var cells = buildingInfo.UnpathableTiles(self.Location); foreach (var c in cells) - weapon.Impact(Target.FromPos(self.World.Map.CenterOfCell(c)), e.Attacker, Enumerable.Empty()); + weapon.Impact(Target.FromPos(self.World.Map.CenterOfCell(c)), source, Enumerable.Empty()); return; } // Use .FromPos since this actor is killed. Cannot use Target.FromActor - weapon.Impact(Target.FromPos(self.CenterPosition), e.Attacker, Enumerable.Empty()); + weapon.Impact(Target.FromPos(self.CenterPosition), source, Enumerable.Empty()); } WeaponInfo ChooseWeaponForExplosion(Actor self) @@ -135,8 +142,9 @@ namespace OpenRA.Mods.Common.Traits return; // Cast to long to avoid overflow when multiplying by the health + var source = Info.DamageSource == DamageSource.Self ? self : e.Attacker; if (health.HP * 100L < Info.DamageThreshold * (long)health.MaxHP) - self.World.AddFrameEndTask(w => self.Kill(e.Attacker)); + self.World.AddFrameEndTask(w => self.Kill(source)); } } } diff --git a/mods/ra/rules/vehicles.yaml b/mods/ra/rules/vehicles.yaml index 0c5e28b8ff..0b82bf4bf2 100644 --- a/mods/ra/rules/vehicles.yaml +++ b/mods/ra/rules/vehicles.yaml @@ -700,6 +700,7 @@ DTRK: Explodes: Weapon: MiniNuke EmptyWeapon: MiniNuke + DamageSource: Killer AttackSuicides: -DamageMultiplier@IRONCURTAIN: KillsSelf: