Files
OpenRA/OpenRA.Mods.RA/Effects/GpsDot.cs
2011-05-04 09:21:30 +12:00

77 lines
1.8 KiB
C#

#region Copyright & License Information
/*
* Copyright 2007-2011 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.Drawing;
using OpenRA.Effects;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Effects
{
class GpsDotInfo : ITraitInfo, ITraitPrerequisite<RenderSimpleInfo>
{
public readonly string String = "Infantry";
public object Create(ActorInitializer init)
{
return new GpsDot(init, String);
}
}
class GpsDot : IEffect
{
Actor self;
GpsWatcher watcher;
RenderSimple rs;
bool show = false;
Animation anim;
public GpsDot(ActorInitializer init, string s)
{
anim = new Animation("gpsdot");
anim.PlayRepeating(s);
self = init.self;
rs = self.Trait<RenderSimple>();
self.World.AddFrameEndTask(w => w.Add(this));
if(self.World.LocalPlayer != null)
watcher = self.World.LocalPlayer.PlayerActor.Trait<GpsWatcher>();
}
public void Tick(World world)
{
show = false;
if (self.Destroyed)
world.AddFrameEndTask(w => w.Remove(this));
if (world.LocalPlayer == null)
return;
if (
self.IsInWorld
&& (watcher.Granted || watcher.GrantedAllies)
&& !self.Trait<HiddenUnderFog>().IsVisible(self)
&& (!self.HasTrait<Cloak>() || !self.Trait<Cloak>().Cloaked)
)
{
show = true;
}
}
public IEnumerable<Renderable> Render()
{
if (show && !self.Destroyed)
yield return new Renderable(anim.Image, self.CenterLocation - 0.5f * anim.Image.size, rs.Palette(self.Owner), (int)self.CenterLocation.Y)
.WithScale(1.5f);
}
}
}