diff --git a/OpenRA.Mods.Common/Activities/Air/FallToEarth.cs b/OpenRA.Mods.Common/Activities/Air/FallToEarth.cs index 07fc6ae2ee..e7b368d7ec 100644 --- a/OpenRA.Mods.Common/Activities/Air/FallToEarth.cs +++ b/OpenRA.Mods.Common/Activities/Air/FallToEarth.cs @@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Activities info.ExplosionWeapon.Impact(Target.FromPos(self.CenterPosition), self, Enumerable.Empty()); } - self.Dispose(); + self.Kill(self); return null; } diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index fddf393d21..733ba6259f 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -787,6 +787,7 @@ + diff --git a/OpenRA.Mods.Common/Traits/RevealOnDeath.cs b/OpenRA.Mods.Common/Traits/RevealOnDeath.cs new file mode 100644 index 0000000000..61b1fb2c8f --- /dev/null +++ b/OpenRA.Mods.Common/Traits/RevealOnDeath.cs @@ -0,0 +1,78 @@ +#region Copyright & License Information +/* + * Copyright 2007-2017 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System.Collections.Generic; +using System.Linq; +using OpenRA.Mods.Common.Effects; +using OpenRA.Traits; + +namespace OpenRA.Mods.Common.Traits +{ + [Desc("Reveal this actor's last position when killed.")] + public class RevealOnDeathInfo : ConditionalTraitInfo + { + [Desc("Stances relative to the actors' owner that shroud will be revealed for.")] + public readonly Stance RevealForStances = Stance.Ally; + + [Desc("Duration of the reveal.")] + public readonly int Duration = 25; + + [Desc("Radius of the reveal around this actor.")] + public readonly WDist Radius = new WDist(1536); + + [Desc("Can this actor be revealed through shroud generated by the GeneratesShroud trait?")] + public readonly bool RevealGeneratedShroud = true; + + [Desc("DeathTypes for which shroud will be revealed.", + "Use an empty list (the default) to allow all DeathTypes.")] + public readonly HashSet DeathTypes = new HashSet(); + + public override object Create(ActorInitializer init) { return new RevealOnDeath(init.Self, this); } + } + + public class RevealOnDeath : ConditionalTrait, INotifyKilled + { + readonly RevealOnDeathInfo info; + + public RevealOnDeath(Actor self, RevealOnDeathInfo info) + : base(info) + { + this.info = info; + } + + void INotifyKilled.Killed(Actor self, AttackInfo attack) + { + if (IsTraitDisabled) + return; + + if (!self.IsInWorld) + return; + + if (info.DeathTypes.Count > 0 && !attack.Damage.DamageTypes.Overlaps(info.DeathTypes)) + return; + + var owner = self.Owner; + if (owner != null && owner.WinState == WinState.Undefined) + { + self.World.AddFrameEndTask(w => + { + // Actor has been disposed by something else before its death (for example `Enter`). + if (self.Disposed) + return; + + w.Add(new RevealShroudEffect(self.CenterPosition, info.Radius, + info.RevealGeneratedShroud ? Shroud.SourceType.Visibility : Shroud.SourceType.PassiveVisibility, + owner, info.RevealForStances, duration: info.Duration)); + }); + } + } + } +} diff --git a/mods/d2k/rules/defaults.yaml b/mods/d2k/rules/defaults.yaml index 15bbb25084..8271ca745c 100644 --- a/mods/d2k/rules/defaults.yaml +++ b/mods/d2k/rules/defaults.yaml @@ -170,6 +170,9 @@ Offset: -12, -12 RequiresCondition: carryall-reserved RevealOnFire: + RevealOnDeath: + Duration: 100 + Radius: 2c512 ^Tank: Inherits: ^Vehicle @@ -298,6 +301,8 @@ Voiced: VoiceSet: InfantryVoice RevealOnFire: + RevealOnDeath: + Duration: 100 ^Plane: Inherits@1: ^ExistsInWorld @@ -372,6 +377,9 @@ Pieces: 2, 5 Range: 1c512, 4c0 WithMakeAnimation: + RevealOnDeath: + Duration: 100 + Radius: 4c768 ^Defense: Inherits: ^Building diff --git a/mods/d2k/rules/structures.yaml b/mods/d2k/rules/structures.yaml index 163a28219b..501a10b91c 100644 --- a/mods/d2k/rules/structures.yaml +++ b/mods/d2k/rules/structures.yaml @@ -111,6 +111,8 @@ construction_yard: ReferencePoint: Top ZOffset: 256 RequiresCondition: primary + RevealOnDeath: + Radius: 5c768 wind_trap: Inherits: ^Building @@ -149,6 +151,8 @@ wind_trap: Amount: 200 ScalePowerWithHealth: ProvidesPrerequisite@buildingname: + RevealOnDeath: + Radius: 3c768 barracks: Inherits: ^Building @@ -223,6 +227,8 @@ barracks: ReferencePoint: Top ZOffset: 256 RequiresCondition: primary + RevealOnDeath: + Radius: 3c768 refinery: Inherits: ^Building @@ -325,6 +331,8 @@ silo: Weapons: Debris, Debris2, Debris3, Debris4 Pieces: 3, 5 Range: 2c0, 5c0 + RevealOnDeath: + Radius: 2c768 light_factory: Inherits: ^Building @@ -742,6 +750,8 @@ large_gun_turret: Amount: -60 SelectionDecorations: VisualBounds: 32,40,0,-8 + RevealOnDeath: + Radius: 5c768 repair_pad: Inherits: ^Building