diff --git a/OpenRA.Mods.Common/Activities/Air/Land.cs b/OpenRA.Mods.Common/Activities/Air/Land.cs index c411b8f25f..ac54334c5e 100644 --- a/OpenRA.Mods.Common/Activities/Air/Land.cs +++ b/OpenRA.Mods.Common/Activities/Air/Land.cs @@ -226,6 +226,9 @@ namespace OpenRA.Mods.Common.Activities if (aircraft.Info.LandingSounds.Length > 0) Game.Sound.Play(SoundType.World, aircraft.Info.LandingSounds, self.World, aircraft.CenterPosition); + foreach (var notify in self.TraitsImplementing()) + notify.Landing(self); + aircraft.AddInfluence(landingCell); aircraft.EnteringCell(self); landingInitiated = true; diff --git a/OpenRA.Mods.Common/Activities/Air/TakeOff.cs b/OpenRA.Mods.Common/Activities/Air/TakeOff.cs index 3252099067..deed92cfb8 100644 --- a/OpenRA.Mods.Common/Activities/Air/TakeOff.cs +++ b/OpenRA.Mods.Common/Activities/Air/TakeOff.cs @@ -36,6 +36,9 @@ namespace OpenRA.Mods.Common.Activities if (aircraft.Info.TakeoffSounds.Length > 0) Game.Sound.Play(SoundType.World, aircraft.Info.TakeoffSounds, self.World, aircraft.CenterPosition); + + foreach (var notify in self.TraitsImplementing()) + notify.TakeOff(self); } public override bool Tick(Actor self) diff --git a/OpenRA.Mods.Common/Traits/Render/WithAircraftLandingEffect.cs b/OpenRA.Mods.Common/Traits/Render/WithAircraftLandingEffect.cs new file mode 100644 index 0000000000..d6558dd18e --- /dev/null +++ b/OpenRA.Mods.Common/Traits/Render/WithAircraftLandingEffect.cs @@ -0,0 +1,82 @@ +#region Copyright & License Information +/* + * Copyright 2007-2022 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 OpenRA.Graphics; +using OpenRA.Mods.Common.Effects; +using OpenRA.Traits; + +namespace OpenRA.Mods.Common.Traits.Render +{ + [Desc("Plays an animation on the ground position when the actor lands.")] + public class WithAircraftLandingEffectInfo : ConditionalTraitInfo + { + [FieldLoader.Require] + public readonly string Image = null; + + [SequenceReference(nameof(Image))] + public readonly string[] Sequences = { "idle" }; + + [PaletteReference] + public readonly string Palette = "effect"; + + [Desc("Should the sprite effect be visible through fog.")] + public readonly bool VisibleThroughFog = false; + + [Desc("Height at which to play the animation when descending.")] + public readonly WDist DistanceAboveTerrain = new WDist(756); + + [Desc("Only play on these terrain types.")] + public readonly HashSet TerrainTypes = new HashSet(); + + public override object Create(ActorInitializer init) { return new WithAircraftLandingEffect(this); } + } + + public class WithAircraftLandingEffect : ConditionalTrait, INotifyLanding, ITick + { + bool shouldAddEffect; + + public WithAircraftLandingEffect(WithAircraftLandingEffectInfo info) + : base(info) { } + + void AddEffect(Actor self) + { + var position = self.CenterPosition - new WVec(WDist.Zero, WDist.Zero, self.World.Map.DistanceAboveTerrain(self.CenterPosition)); + self.World.AddFrameEndTask(w => w.Add(new SpriteEffect(position, self.World, Info.Image, + Info.Sequences.Random(Game.CosmeticRandom), Info.Palette, Info.VisibleThroughFog))); + } + + bool ShouldAddEffect(Map map, CPos cell) + { + if (Info.TerrainTypes.Count == 0) + return true; + + return map.Contains(cell) && Info.TerrainTypes.Contains(map.GetTerrainInfo(cell).Type); + } + + void INotifyLanding.Landing(Actor self) + { + shouldAddEffect = ShouldAddEffect(self.World.Map, self.Location); + } + + void ITick.Tick(Actor self) + { + if (!shouldAddEffect) + return; + + if (self.World.Map.DistanceAboveTerrain(self.CenterPosition) > Info.DistanceAboveTerrain) + return; + + AddEffect(self); + shouldAddEffect = false; + } + } +} diff --git a/OpenRA.Mods.Common/TraitsInterfaces.cs b/OpenRA.Mods.Common/TraitsInterfaces.cs index 51887beb59..9e5130c71c 100644 --- a/OpenRA.Mods.Common/TraitsInterfaces.cs +++ b/OpenRA.Mods.Common/TraitsInterfaces.cs @@ -147,6 +147,11 @@ namespace OpenRA.Mods.Common.Traits void StoppingResupply(Actor self, Actor host); } + [RequireExplicitImplementation] + public interface INotifyTakeOff { void TakeOff(Actor self); } + [RequireExplicitImplementation] + public interface INotifyLanding { void Landing(Actor self); } + [RequireExplicitImplementation] public interface INotifyPowerLevelChanged { void PowerLevelChanged(Actor self); } public interface INotifySupportPower { void Charged(Actor self); void Activated(Actor self); } diff --git a/mods/ts/rules/aircraft.yaml b/mods/ts/rules/aircraft.yaml index e9d9c6761c..2d923428fb 100644 --- a/mods/ts/rules/aircraft.yaml +++ b/mods/ts/rules/aircraft.yaml @@ -290,6 +290,8 @@ ORCATRAN: SpawnActorOnDeath@EMP: Actor: ORCATRAN.Husk.EMP RequiresCondition: empdisable + WithAircraftLandingEffect: + Image: dropland TRNSPORT: Inherits: ^EMPableAircraft @@ -332,6 +334,8 @@ TRNSPORT: SpawnActorOnDeath@EMP: Actor: TRNSPORT.Husk.EMP RequiresCondition: empdisable + WithAircraftLandingEffect: + Image: caryland SCRIN: Inherits: ^EMPableAircraft diff --git a/mods/ts/sequences/misc.yaml b/mods/ts/sequences/misc.yaml index beb76f6d1e..ad1d12ba15 100644 --- a/mods/ts/sequences/misc.yaml +++ b/mods/ts/sequences/misc.yaml @@ -722,3 +722,21 @@ fire2: BlendMode: Translucent Offset: 0, -18, 18 ZOffset: 1023 + +caryland: + idle: podring + Length: * + Tick: 50 + ZOffset: -512 + ZRamp: 1 + Offset: 0, 0, 1 + BlendMode: Translucent + +dropland: + idle: podring + Length: * + Tick: 90 + ZOffset: -512 + ZRamp: 1 + Offset: 0, 0, 1 + BlendMode: Translucent