Add VTOL landing exhaust animation.
This commit is contained in:
committed by
Gustas
parent
1073a7124f
commit
aa14c9c570
@@ -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<INotifyLanding>())
|
||||
notify.Landing(self);
|
||||
|
||||
aircraft.AddInfluence(landingCell);
|
||||
aircraft.EnteringCell(self);
|
||||
landingInitiated = true;
|
||||
|
||||
@@ -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<INotifyTakeOff>())
|
||||
notify.TakeOff(self);
|
||||
}
|
||||
|
||||
public override bool Tick(Actor self)
|
||||
|
||||
@@ -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<string> TerrainTypes = new HashSet<string>();
|
||||
|
||||
public override object Create(ActorInitializer init) { return new WithAircraftLandingEffect(this); }
|
||||
}
|
||||
|
||||
public class WithAircraftLandingEffect : ConditionalTrait<WithAircraftLandingEffectInfo>, 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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); }
|
||||
|
||||
Reference in New Issue
Block a user