Move Parachute, Parachutable and ParaDrop to Mods.Common
This commit is contained in:
@@ -1,115 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Effects;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.RA.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Effects
|
||||
{
|
||||
public class Parachute : IEffect
|
||||
{
|
||||
readonly ParachutableInfo parachutableInfo;
|
||||
readonly Animation parachute;
|
||||
readonly Animation shadow;
|
||||
readonly WVec parachuteOffset;
|
||||
readonly Actor cargo;
|
||||
WPos pos;
|
||||
WVec fallVector;
|
||||
|
||||
public Parachute(Actor cargo, WPos dropPosition)
|
||||
{
|
||||
this.cargo = cargo;
|
||||
|
||||
parachutableInfo = cargo.Info.Traits.GetOrDefault<ParachutableInfo>();
|
||||
|
||||
if (parachutableInfo != null)
|
||||
fallVector = new WVec(0, 0, parachutableInfo.FallRate);
|
||||
|
||||
var parachuteSprite = parachutableInfo != null ? parachutableInfo.ParachuteSequence : null;
|
||||
if (parachuteSprite != null)
|
||||
{
|
||||
parachute = new Animation(cargo.World, parachuteSprite);
|
||||
parachute.PlayThen("open", () => parachute.PlayRepeating("idle"));
|
||||
}
|
||||
|
||||
var shadowSprite = parachutableInfo != null ? parachutableInfo.ShadowSequence : null;
|
||||
if (shadowSprite != null)
|
||||
{
|
||||
shadow = new Animation(cargo.World, shadowSprite);
|
||||
shadow.PlayRepeating("idle");
|
||||
}
|
||||
|
||||
if (parachutableInfo != null)
|
||||
parachuteOffset = parachutableInfo.ParachuteOffset;
|
||||
|
||||
// Adjust x,y to match the target subcell
|
||||
cargo.Trait<IPositionable>().SetPosition(cargo, cargo.World.Map.CellContaining(dropPosition));
|
||||
var cp = cargo.CenterPosition;
|
||||
pos = new WPos(cp.X, cp.Y, dropPosition.Z);
|
||||
}
|
||||
|
||||
public void Tick(World world)
|
||||
{
|
||||
if (parachute != null)
|
||||
parachute.Tick();
|
||||
|
||||
if (shadow != null)
|
||||
shadow.Tick();
|
||||
|
||||
pos -= fallVector;
|
||||
|
||||
if (pos.Z <= 0)
|
||||
{
|
||||
world.AddFrameEndTask(w =>
|
||||
{
|
||||
w.Remove(this);
|
||||
cargo.CancelActivity();
|
||||
w.Add(cargo);
|
||||
|
||||
foreach (var npl in cargo.TraitsImplementing<INotifyParachuteLanded>())
|
||||
npl.OnLanded();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr)
|
||||
{
|
||||
var rc = cargo.Render(wr);
|
||||
|
||||
// Don't render anything if the cargo is invisible (e.g. under fog)
|
||||
if (!rc.Any())
|
||||
yield break;
|
||||
|
||||
var parachuteShadowPalette = wr.Palette(parachutableInfo.ParachuteShadowPalette);
|
||||
foreach (var c in rc)
|
||||
{
|
||||
if (!c.IsDecoration && shadow == null)
|
||||
yield return c.WithPalette(parachuteShadowPalette).WithZOffset(c.ZOffset - 1).AsDecoration();
|
||||
|
||||
yield return c.OffsetBy(pos - c.Pos);
|
||||
}
|
||||
|
||||
var shadowPalette = !string.IsNullOrEmpty(parachutableInfo.ShadowPalette) ? wr.Palette(parachutableInfo.ShadowPalette) : rc.First().Palette;
|
||||
if (shadow != null)
|
||||
foreach (var r in shadow.Render(pos - new WVec(0, 0, pos.Z), WVec.Zero, 1, shadowPalette, 1f))
|
||||
yield return r;
|
||||
|
||||
var parachutePalette = !string.IsNullOrEmpty(parachutableInfo.ParachutePalette) ? wr.Palette(parachutableInfo.ParachutePalette) : rc.First().Palette;
|
||||
if (parachute != null)
|
||||
foreach (var r in parachute.Render(pos, parachuteOffset, 1, parachutePalette, 1f))
|
||||
yield return r;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,11 +110,9 @@
|
||||
<Compile Include="Traits\Crates\SupportPowerCrateAction.cs" />
|
||||
<Compile Include="Traits\DemoTruck.cs" />
|
||||
<Compile Include="Effects\GpsDot.cs" />
|
||||
<Compile Include="Effects\Parachute.cs" />
|
||||
<Compile Include="Traits\MadTank.cs" />
|
||||
<Compile Include="Traits\Mine.cs" />
|
||||
<Compile Include="Traits\Minelayer.cs" />
|
||||
<Compile Include="Traits\ParaDrop.cs" />
|
||||
<Compile Include="Traits\PortableChrono.cs" />
|
||||
<Compile Include="Traits\Render\RenderJammerCircle.cs" />
|
||||
<Compile Include="Traits\Render\RenderHarvester.cs" />
|
||||
@@ -173,7 +171,6 @@
|
||||
<Compile Include="Traits\Attack\AttackGarrisoned.cs" />
|
||||
<Compile Include="Widgets\Logic\ControlGroupLogic.cs" />
|
||||
<Compile Include="Scripting\Properties\ChronosphereProperties.cs" />
|
||||
<Compile Include="Traits\Parachutable.cs" />
|
||||
<Compile Include="Widgets\Logic\InstallFromCDLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\InstallMusicLogic.cs" />
|
||||
<Compile Include="Traits\Buildings\ClonesProducedUnits.cs" />
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Mods.Common.Effects;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.RA.Effects;
|
||||
using OpenRA.Primitives;
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Mods.RA.Effects;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
[Desc("This unit can spawn and eject other actors while flying.")]
|
||||
public class ParaDropInfo : ITraitInfo, Requires<CargoInfo>
|
||||
{
|
||||
[Desc("Distance around the drop-point to unload troops.")]
|
||||
public readonly WRange DropRange = WRange.FromCells(4);
|
||||
|
||||
[Desc("Sound to play when dropping.")]
|
||||
public readonly string ChuteSound = "chute1.aud";
|
||||
|
||||
public object Create(ActorInitializer init) { return new ParaDrop(init.Self, this); }
|
||||
}
|
||||
|
||||
public class ParaDrop : ITick, INotifyRemovedFromWorld
|
||||
{
|
||||
readonly ParaDropInfo info;
|
||||
readonly Actor self;
|
||||
readonly Cargo cargo;
|
||||
readonly HashSet<CPos> droppedAt = new HashSet<CPos>();
|
||||
|
||||
public event Action<Actor> OnRemovedFromWorld = self => { };
|
||||
public event Action<Actor> OnEnteredDropRange = self => { };
|
||||
public event Action<Actor> OnExitedDropRange = self => { };
|
||||
|
||||
[Sync] bool inDropRange;
|
||||
[Sync] Target target;
|
||||
|
||||
bool checkForSuitableCell;
|
||||
|
||||
public ParaDrop(Actor self, ParaDropInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
this.self = self;
|
||||
cargo = self.Trait<Cargo>();
|
||||
}
|
||||
|
||||
public void SetLZ(CPos lz, bool checkLandingCell)
|
||||
{
|
||||
droppedAt.Clear();
|
||||
target = Target.FromCell(self.World, lz);
|
||||
checkForSuitableCell = checkLandingCell;
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
var wasInDropRange = inDropRange;
|
||||
inDropRange = target.IsInRange(self.CenterPosition, info.DropRange);
|
||||
|
||||
if (inDropRange && !wasInDropRange)
|
||||
OnEnteredDropRange(self);
|
||||
|
||||
if (!inDropRange && wasInDropRange)
|
||||
OnExitedDropRange(self);
|
||||
|
||||
// Are we able to drop the next trooper?
|
||||
if (!inDropRange || cargo.IsEmpty(self))
|
||||
return;
|
||||
|
||||
if (droppedAt.Contains(self.Location) || (checkForSuitableCell && !IsSuitableCell(cargo.Peek(self), self.Location)))
|
||||
return;
|
||||
|
||||
if (!self.World.Map.Contains(self.Location))
|
||||
return;
|
||||
|
||||
// unload a dude here
|
||||
droppedAt.Add(self.Location);
|
||||
|
||||
var a = cargo.Unload(self);
|
||||
self.World.AddFrameEndTask(w => w.Add(new Parachute(a, self.CenterPosition)));
|
||||
Sound.Play(info.ChuteSound, self.CenterPosition);
|
||||
}
|
||||
|
||||
static bool IsSuitableCell(Actor actorToDrop, CPos p)
|
||||
{
|
||||
return actorToDrop.Trait<IPositionable>().CanEnterCell(p);
|
||||
}
|
||||
|
||||
public void RemovedFromWorld(Actor self)
|
||||
{
|
||||
OnRemovedFromWorld(self);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Mods.Common.Effects;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
[Desc("Can be paradropped by a ParaDrop actor.")]
|
||||
class ParachutableInfo : ITraitInfo
|
||||
{
|
||||
[Desc("If we land on invalid terrain for my actor type should we be killed?")]
|
||||
public readonly bool KilledOnImpassableTerrain = true;
|
||||
|
||||
public readonly string GroundImpactSound = null;
|
||||
public readonly string GroundCorpseSequence = "corpse";
|
||||
public readonly string GroundCorpsePalette = "effect";
|
||||
|
||||
public readonly string WaterImpactSound = null;
|
||||
public readonly string WaterCorpseSequence = "small_splash";
|
||||
public readonly string WaterCorpsePalette = "effect";
|
||||
|
||||
[Desc("Requires the sub-sequences \"open\" and \"idle\".")]
|
||||
public readonly string ParachuteSequence = null;
|
||||
|
||||
[Desc("Optional, otherwise defaults to the palette the actor is using.")]
|
||||
public readonly string ParachutePalette = null;
|
||||
|
||||
[Desc("Used to clone the actor with this palette and render it with a visual offset below.")]
|
||||
public readonly string ParachuteShadowPalette = "shadow";
|
||||
|
||||
public readonly WVec ParachuteOffset = WVec.Zero;
|
||||
|
||||
public readonly int FallRate = 13;
|
||||
|
||||
[Desc("Alternative to ParachuteShadowPalette which disables it and allows to set a custom sprite sequence instead.")]
|
||||
public readonly string ShadowSequence = null;
|
||||
|
||||
[Desc("Optional, otherwise defaults to the palette the actor is using.")]
|
||||
public readonly string ShadowPalette = null;
|
||||
|
||||
public object Create(ActorInitializer init) { return new Parachutable(init, this); }
|
||||
}
|
||||
|
||||
class Parachutable : INotifyParachuteLanded
|
||||
{
|
||||
readonly Actor self;
|
||||
readonly ParachutableInfo info;
|
||||
readonly IPositionable positionable;
|
||||
|
||||
public Parachutable(ActorInitializer init, ParachutableInfo info)
|
||||
{
|
||||
this.self = init.Self;
|
||||
this.info = info;
|
||||
|
||||
positionable = self.TraitOrDefault<IPositionable>();
|
||||
}
|
||||
|
||||
public void OnLanded()
|
||||
{
|
||||
if (!info.KilledOnImpassableTerrain)
|
||||
return;
|
||||
|
||||
if (positionable.CanEnterCell(self.Location, self))
|
||||
return;
|
||||
|
||||
var terrain = self.World.Map.GetTerrainInfo(self.Location);
|
||||
|
||||
var sound = terrain.IsWater ? info.WaterImpactSound : info.GroundImpactSound;
|
||||
Sound.Play(sound, self.CenterPosition);
|
||||
|
||||
var sequence = terrain.IsWater ? info.WaterCorpseSequence : info.GroundCorpseSequence;
|
||||
var palette = terrain.IsWater ? info.WaterCorpsePalette : info.GroundCorpsePalette;
|
||||
if (sequence != null && palette != null)
|
||||
self.World.AddFrameEndTask(w => w.Add(new Explosion(w, self.OccupiesSpace.CenterPosition, sequence, palette)));
|
||||
|
||||
self.Kill(self);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user