split Hovers from WithShadow

fixes #4508
This commit is contained in:
Matthias Mailänder
2014-11-29 22:23:19 +01:00
parent 6ecc6d67cd
commit 34bedeb71f
9 changed files with 66 additions and 28 deletions

View File

@@ -460,6 +460,7 @@
<Compile Include="UtilityCommands\Extensions.cs" />
<Compile Include="Lint\CheckMapRules.cs" />
<Compile Include="Activities\Air\HeliFlyCircle.cs" />
<Compile Include="Render\Hovers.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">

View File

@@ -0,0 +1,52 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 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 System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
[Desc("Changes the visual Z position periodically.")]
class HoversInfo : ITraitInfo, Requires<IMoveInfo>
{
[Desc("Amount of Z axis changes in world units.")]
public readonly int OffsetModifier = -43;
public object Create(ActorInitializer init) { return new Hovers(this, init.self); }
}
class Hovers : IRenderModifier
{
readonly HoversInfo info;
readonly bool aircraft;
public Hovers(HoversInfo info, Actor self)
{
this.info = info;
aircraft = self.HasTrait<Aircraft>();
}
public IEnumerable<IRenderable> ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> r)
{
if (self.World.Paused)
return r;
var visualOffset = !aircraft || self.CenterPosition.Z > 0 ? (int)Math.Abs((self.ActorID + Game.LocalTick) / 5 % 4 - 1) - 1 : 0;
var worldVisualOffset = new WVec(0, 0, info.OffsetModifier * visualOffset);
return r.Select(a => a.OffsetBy(worldVisualOffset));
}
}
}

View File

@@ -37,13 +37,6 @@ namespace OpenRA.Mods.RA.Render
public IEnumerable<IRenderable> ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> r)
{
var ios = self.Trait<IOccupySpace>();
/* rude hack */
var flying = ios.CenterPosition.Z > 0;
var visualOffset = (ios is Helicopter && flying)
? (int)Math.Abs((self.ActorID + Game.LocalTick) / 5 % 4 - 1) - 1 : 0;
// Contrails shouldn't cast shadows
var shadowSprites = r.Where(s => !s.IsDecoration)
.Select(a => a.WithPalette(wr.Palette(info.Palette))
@@ -51,11 +44,7 @@ namespace OpenRA.Mods.RA.Render
.WithZOffset(a.ZOffset + a.Pos.Z)
.AsDecoration());
var worldVisualOffset = new WVec(0,0,-43*visualOffset);
var flyingSprites = !flying ? r :
r.Select(a => a.OffsetBy(worldVisualOffset));
return shadowSprites.Concat(flyingSprites);
return shadowSprites.Concat(r);
}
}
}