52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
#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 System.Linq;
|
|
using OpenRA.Graphics;
|
|
using OpenRA.Mods.Common.Activities;
|
|
using OpenRA.Traits;
|
|
|
|
namespace OpenRA.Mods.Common.Traits
|
|
{
|
|
[Desc("Changes the visual Z position periodically.")]
|
|
public 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); }
|
|
}
|
|
|
|
public class Hovers : IRenderModifier
|
|
{
|
|
readonly HoversInfo info;
|
|
readonly bool aircraft;
|
|
|
|
public Hovers(HoversInfo info, Actor self)
|
|
{
|
|
this.info = info;
|
|
aircraft = self.Info.HasTraitInfo<AircraftInfo>();
|
|
}
|
|
|
|
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));
|
|
}
|
|
}
|
|
}
|