Skip to content

Instantly share code, notes, and snippets.

@phrohdoh
Created September 25, 2014 20:04
Show Gist options
  • Save phrohdoh/0f71aeec557731675f48 to your computer and use it in GitHub Desktop.
Save phrohdoh/0f71aeec557731675f48 to your computer and use it in GitHub Desktop.
#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 System.Drawing;
using OpenRA.Traits;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics;
using OpenRA.Mods.RA;
namespace OpenRA.Mods.TS
{
public class CloakGeneratorInfo : ITraitInfo
{
[Desc("Range, in cells, to cloak valid actor types.", "Default is 12.")]
public readonly WRange CloakRange = WRange.FromCells(12);
public readonly string[] CloakableTypes = { };
}
public class CloakGenerator : ITick, IPostRenderSelection
{
readonly Actor self;
readonly CloakGeneratorInfo info;
public CloakGenerator(Actor self, CloakGeneratorInfo info)
{
this.self = self;
this.info = info;
}
public void Tick(Actor self)
{
var toCloak = self.World.FindActorsInCircle(self.CenterPosition, info.CloakRange)
.Where(a =>
{
var cloak = a.Info.Traits.GetOrDefault<CloakInfo>();
if (cloak == null)
return false;
return cloak.RequiresCloakGenerator && info.CloakableTypes.Intersect(cloak.CloakTypes).Any();
});
foreach (var cloaker in toCloak)
cloaker.Trait<Cloak>().ForceCloak();
}
public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr)
{
if (self.Owner != self.World.LocalPlayer)
yield break;
yield return new RangeCircleRenderable
(
self.CenterPosition,
info.CloakRange,
0,
Color.FromArgb(128, Color.LimeGreen),
Color.FromArgb(96, Color.Black)
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment