Move various RA-specific traits to the new folder/namespace structure
This commit is contained in:
122
OpenRA.Mods.RA/Traits/Chronoshiftable.cs
Normal file
122
OpenRA.Mods.RA/Traits/Chronoshiftable.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
#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.Drawing;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
[Desc("Can be teleported via Chronoshift power.")]
|
||||
public class ChronoshiftableInfo : ITraitInfo
|
||||
{
|
||||
public readonly bool ExplodeInstead = false;
|
||||
public readonly string ChronoshiftSound = "chrono2.aud";
|
||||
|
||||
public object Create(ActorInitializer init) { return new Chronoshiftable(init, this); }
|
||||
}
|
||||
|
||||
public class Chronoshiftable : ITick, ISync, ISelectionBar
|
||||
{
|
||||
readonly ChronoshiftableInfo info;
|
||||
Actor chronosphere;
|
||||
bool killCargo;
|
||||
int duration;
|
||||
|
||||
// Return-to-sender logic
|
||||
[Sync] public CPos Origin;
|
||||
[Sync] public int ReturnTicks = 0;
|
||||
|
||||
public Chronoshiftable(ActorInitializer init, ChronoshiftableInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
|
||||
if (init.Contains<ChronoshiftReturnInit>())
|
||||
ReturnTicks = init.Get<ChronoshiftReturnInit, int>();
|
||||
|
||||
if (init.Contains<ChronoshiftOriginInit>())
|
||||
Origin = init.Get<ChronoshiftOriginInit, CPos>();
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (ReturnTicks <= 0)
|
||||
return;
|
||||
|
||||
// Return to original location
|
||||
if (--ReturnTicks == 0)
|
||||
{
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new Teleport(chronosphere, Origin, null, killCargo, true, info.ChronoshiftSound));
|
||||
}
|
||||
}
|
||||
|
||||
// Can't be used in synced code, except with ignoreVis.
|
||||
public virtual bool CanChronoshiftTo(Actor self, CPos targetLocation)
|
||||
{
|
||||
// TODO: Allow enemy units to be chronoshifted into bad terrain to kill them
|
||||
return self.HasTrait<IPositionable>() && self.Trait<IPositionable>().CanEnterCell(targetLocation);
|
||||
}
|
||||
|
||||
public virtual bool Teleport(Actor self, CPos targetLocation, int duration, bool killCargo, Actor chronosphere)
|
||||
{
|
||||
// some things appear chronoshiftable, but instead they just die.
|
||||
if (info.ExplodeInstead)
|
||||
{
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
// damage is inflicted by the chronosphere
|
||||
if (!self.Destroyed)
|
||||
self.InflictDamage(chronosphere, int.MaxValue, null);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Set up return-to-sender info
|
||||
Origin = self.Location;
|
||||
ReturnTicks = duration;
|
||||
this.duration = duration;
|
||||
this.chronosphere = chronosphere;
|
||||
this.killCargo = killCargo;
|
||||
|
||||
// Set up the teleport
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new Teleport(chronosphere, targetLocation, null, killCargo, true, info.ChronoshiftSound));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Show the remaining time as a bar
|
||||
public float GetValue()
|
||||
{
|
||||
if (ReturnTicks == 0) // otherwise an empty bar is rendered all the time
|
||||
return 0f;
|
||||
|
||||
return (float)ReturnTicks / duration;
|
||||
}
|
||||
|
||||
public Color GetColor() { return Color.White; }
|
||||
}
|
||||
|
||||
public class ChronoshiftReturnInit : IActorInit<int>
|
||||
{
|
||||
[FieldFromYamlKey] readonly int value = 0;
|
||||
public ChronoshiftReturnInit() { }
|
||||
public ChronoshiftReturnInit(int init) { value = init; }
|
||||
public int Value(World world) { return value; }
|
||||
}
|
||||
|
||||
public class ChronoshiftOriginInit : IActorInit<CPos>
|
||||
{
|
||||
[FieldFromYamlKey] readonly CPos value;
|
||||
public ChronoshiftOriginInit(CPos init) { value = init; }
|
||||
public CPos Value(World world) { return value; }
|
||||
}
|
||||
}
|
||||
75
OpenRA.Mods.RA/Traits/DemoTruck.cs
Normal file
75
OpenRA.Mods.RA/Traits/DemoTruck.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
#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.Drawing;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Mods.Common.Orders;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Mods.RA.Orders;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
class DemoTruckInfo : TraitInfo<DemoTruck>, Requires<ExplodesInfo> { }
|
||||
|
||||
class DemoTruck : IIssueOrder, IResolveOrder, IOrderVoice
|
||||
{
|
||||
static void Explode(Actor self)
|
||||
{
|
||||
self.World.AddFrameEndTask(w => self.InflictDamage(self, int.MaxValue, null));
|
||||
}
|
||||
|
||||
public IEnumerable<IOrderTargeter> Orders
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new TargetTypeOrderTargeter(new[] { "DetonateAttack" }, "DetonateAttack", 5, "attack", true, false) { ForceAttack = false };
|
||||
yield return new DeployOrderTargeter("Detonate", 5);
|
||||
}
|
||||
}
|
||||
|
||||
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
|
||||
{
|
||||
if (order.OrderID != "DetonateAttack" && order.OrderID != "Detonate")
|
||||
return null;
|
||||
|
||||
if (target.Type == TargetType.FrozenActor)
|
||||
return new Order(order.OrderID, self, queued) { ExtraData = target.FrozenActor.ID };
|
||||
|
||||
return new Order(order.OrderID, self, queued) { TargetActor = target.Actor };
|
||||
}
|
||||
|
||||
public string VoicePhraseForOrder(Actor self, Order order)
|
||||
{
|
||||
return "Attack";
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "DetonateAttack")
|
||||
{
|
||||
var target = self.ResolveFrozenActorOrder(order, Color.Red);
|
||||
if (target.Type != TargetType.Actor)
|
||||
return;
|
||||
|
||||
if (!order.Queued)
|
||||
self.CancelActivity();
|
||||
|
||||
self.SetTargetLine(target, Color.Red);
|
||||
self.QueueActivity(new MoveAdjacentTo(self, target));
|
||||
self.QueueActivity(new CallFunc(() => Explode(self)));
|
||||
}
|
||||
|
||||
else if (order.OrderString == "Detonate")
|
||||
Explode(self);
|
||||
}
|
||||
}
|
||||
}
|
||||
175
OpenRA.Mods.RA/Traits/MadTank.cs
Normal file
175
OpenRA.Mods.RA/Traits/MadTank.cs
Normal file
@@ -0,0 +1,175 @@
|
||||
#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.Linq;
|
||||
using System.Drawing;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Mods.Common.Orders;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Primitives;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
class MadTankInfo : ITraitInfo, Requires<ExplodesInfo>, Requires<RenderUnitInfo>
|
||||
{
|
||||
public readonly string ThumpSequence = "piston";
|
||||
public readonly int ThumpInterval = 8;
|
||||
[WeaponReference]
|
||||
public readonly string ThumpDamageWeapon = "MADTankThump";
|
||||
public readonly int ThumpShakeIntensity = 3;
|
||||
public readonly float2 ThumpShakeMultiplier = new float2(1, 0);
|
||||
public readonly int ThumpShakeTime = 10;
|
||||
|
||||
public readonly int ChargeDelay = 96;
|
||||
public readonly string ChargeSound = "madchrg2.aud";
|
||||
|
||||
public readonly int DetonationDelay = 42;
|
||||
public readonly string DetonationSound = "madexplo.aud";
|
||||
[WeaponReference]
|
||||
public readonly string DetonationWeapon = "MADTankDetonate";
|
||||
|
||||
[ActorReference]
|
||||
public readonly string DriverActor = "e1";
|
||||
|
||||
public object Create(ActorInitializer init) { return new MadTank(init.self, this); }
|
||||
}
|
||||
|
||||
class MadTank : IIssueOrder, IResolveOrder, IOrderVoice, ITick, IPreventsTeleport
|
||||
{
|
||||
readonly Actor self;
|
||||
readonly MadTankInfo info;
|
||||
readonly RenderUnit renderUnit;
|
||||
readonly ScreenShaker screenShaker;
|
||||
bool deployed;
|
||||
int tick;
|
||||
|
||||
public MadTank(Actor self, MadTankInfo info)
|
||||
{
|
||||
this.self = self;
|
||||
this.info = info;
|
||||
renderUnit = self.Trait<RenderUnit>();
|
||||
screenShaker = self.World.WorldActor.Trait<ScreenShaker>();
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (!deployed)
|
||||
return;
|
||||
|
||||
if (++tick >= info.ThumpInterval)
|
||||
{
|
||||
if (info.ThumpDamageWeapon != null)
|
||||
{
|
||||
var weapon = self.World.Map.Rules.Weapons[info.ThumpDamageWeapon.ToLowerInvariant()];
|
||||
// Use .FromPos since this weapon needs to affect more than just the MadTank actor
|
||||
weapon.Impact(Target.FromPos(self.CenterPosition), self, Enumerable.Empty<int>());
|
||||
}
|
||||
screenShaker.AddEffect(info.ThumpShakeTime, self.CenterPosition, info.ThumpShakeIntensity, info.ThumpShakeMultiplier);
|
||||
tick = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<IOrderTargeter> Orders
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new TargetTypeOrderTargeter(new[] { "DetonateAttack" }, "DetonateAttack", 5, "attack", true, false) { ForceAttack = false };
|
||||
yield return new DeployOrderTargeter("Detonate", 5);
|
||||
}
|
||||
}
|
||||
|
||||
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
|
||||
{
|
||||
if (order.OrderID != "DetonateAttack" && order.OrderID != "Detonate")
|
||||
return null;
|
||||
|
||||
if (target.Type == TargetType.FrozenActor)
|
||||
return new Order(order.OrderID, self, queued) { ExtraData = target.FrozenActor.ID };
|
||||
|
||||
return new Order(order.OrderID, self, queued) { TargetActor = target.Actor };
|
||||
}
|
||||
|
||||
public string VoicePhraseForOrder(Actor self, Order order)
|
||||
{
|
||||
return "Attack";
|
||||
}
|
||||
|
||||
void Detonate()
|
||||
{
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
if (info.DetonationWeapon != null)
|
||||
{
|
||||
var weapon = self.World.Map.Rules.Weapons[info.DetonationWeapon.ToLowerInvariant()];
|
||||
// Use .FromPos since this actor is killed. Cannot use Target.FromActor
|
||||
weapon.Impact(Target.FromPos(self.CenterPosition), self, Enumerable.Empty<int>());
|
||||
}
|
||||
self.Kill(self);
|
||||
});
|
||||
}
|
||||
|
||||
void EjectDriver()
|
||||
{
|
||||
var driver = self.World.CreateActor(info.DriverActor.ToLowerInvariant(), new TypeDictionary
|
||||
{
|
||||
new LocationInit(self.Location),
|
||||
new OwnerInit(self.Owner)
|
||||
});
|
||||
var driverMobile = driver.TraitOrDefault<Mobile>();
|
||||
if (driverMobile != null)
|
||||
driverMobile.Nudge(driver, driver, true);
|
||||
}
|
||||
|
||||
public bool PreventsTeleport(Actor self) { return deployed; }
|
||||
|
||||
void StartDetonationSequence()
|
||||
{
|
||||
if (deployed)
|
||||
return;
|
||||
|
||||
self.World.AddFrameEndTask(w => EjectDriver());
|
||||
if (info.ThumpSequence != null)
|
||||
renderUnit.PlayCustomAnimRepeating(self, info.ThumpSequence);
|
||||
deployed = true;
|
||||
self.QueueActivity(new Wait(info.ChargeDelay, false));
|
||||
self.QueueActivity(new CallFunc(() => Sound.Play(info.ChargeSound, self.CenterPosition)));
|
||||
self.QueueActivity(new Wait(info.DetonationDelay, false));
|
||||
self.QueueActivity(new CallFunc(() => Sound.Play(info.DetonationSound, self.CenterPosition)));
|
||||
self.QueueActivity(new CallFunc(Detonate));
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "DetonateAttack")
|
||||
{
|
||||
var target = self.ResolveFrozenActorOrder(order, Color.Red);
|
||||
if (target.Type != TargetType.Actor)
|
||||
return;
|
||||
|
||||
if (!order.Queued)
|
||||
self.CancelActivity();
|
||||
|
||||
self.SetTargetLine(target, Color.Red);
|
||||
self.QueueActivity(new MoveAdjacentTo(self, target));
|
||||
self.QueueActivity(new CallFunc(StartDetonationSequence));
|
||||
}
|
||||
|
||||
else if (order.OrderString == "Detonate")
|
||||
{
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new CallFunc(StartDetonationSequence));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
#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.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
[Desc("Apply palette full screen rotations during chronoshifts. Add this to the world actor.")]
|
||||
class ChronoshiftPaletteEffectInfo : TraitInfo<ChronoshiftPaletteEffect> { }
|
||||
|
||||
public class ChronoshiftPaletteEffect : IPaletteModifier, ITick
|
||||
{
|
||||
const int chronoEffectLength = 60;
|
||||
int remainingFrames;
|
||||
|
||||
public void Enable()
|
||||
{
|
||||
remainingFrames = chronoEffectLength;
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (remainingFrames > 0)
|
||||
remainingFrames--;
|
||||
}
|
||||
|
||||
public void AdjustPalette(IReadOnlyDictionary<string, MutablePalette> palettes)
|
||||
{
|
||||
if (remainingFrames == 0)
|
||||
return;
|
||||
|
||||
var frac = (float)remainingFrames / chronoEffectLength;
|
||||
|
||||
foreach (var pal in palettes)
|
||||
{
|
||||
for (var x = 0; x < Palette.Size; x++)
|
||||
{
|
||||
var orig = pal.Value.GetColor(x);
|
||||
var lum = (int)(255 * orig.GetBrightness());
|
||||
var desat = Color.FromArgb(orig.A, lum, lum, lum);
|
||||
pal.Value.SetColor(x, Exts.ColorLerp(frac, orig, desat));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
202
OpenRA.Mods.RA/Traits/PortableChrono.cs
Normal file
202
OpenRA.Mods.RA/Traits/PortableChrono.cs
Normal file
@@ -0,0 +1,202 @@
|
||||
#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.Drawing;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Graphics;
|
||||
using OpenRA.Mods.Common.Orders;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
class PortableChronoInfo : ITraitInfo
|
||||
{
|
||||
[Desc("Cooldown in seconds until the unit can teleport.")]
|
||||
public readonly int ChargeTime = 20;
|
||||
[Desc("Can the unit teleport only a certain distance?")]
|
||||
public readonly bool HasDistanceLimit = true;
|
||||
[Desc("The maximum distance in cells this unit can teleport (only used if HasDistanceLimit = true).")]
|
||||
public readonly int MaxDistance = 12;
|
||||
[Desc("Sound to play when teleporting.")]
|
||||
public readonly string ChronoshiftSound = "chrotnk1.aud";
|
||||
|
||||
public object Create(ActorInitializer init) { return new PortableChrono(this); }
|
||||
}
|
||||
|
||||
class PortableChrono : IIssueOrder, IResolveOrder, ITick, IPips, IOrderVoice, ISync
|
||||
{
|
||||
[Sync] int chargeTick = 0;
|
||||
public readonly PortableChronoInfo Info;
|
||||
|
||||
public PortableChrono(PortableChronoInfo info)
|
||||
{
|
||||
this.Info = info;
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (chargeTick > 0)
|
||||
chargeTick--;
|
||||
}
|
||||
|
||||
public IEnumerable<IOrderTargeter> Orders
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new PortableChronoOrderTargeter();
|
||||
yield return new DeployOrderTargeter("PortableChronoDeploy", 5, () => CanTeleport);
|
||||
}
|
||||
}
|
||||
|
||||
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
|
||||
{
|
||||
if (order.OrderID == "PortableChronoDeploy" && CanTeleport)
|
||||
self.World.OrderGenerator = new PortableChronoOrderGenerator(self);
|
||||
|
||||
if (order.OrderID == "PortableChronoTeleport")
|
||||
return new Order(order.OrderID, self, queued) { TargetLocation = self.World.Map.CellContaining(target.CenterPosition) };
|
||||
|
||||
return new Order(order.OrderID, self, queued) { TargetActor = target.Actor };
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "PortableChronoTeleport" && CanTeleport)
|
||||
{
|
||||
var maxDistance = Info.HasDistanceLimit ? Info.MaxDistance : (int?)null;
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new Teleport(self, order.TargetLocation, maxDistance, true, false, Info.ChronoshiftSound));
|
||||
}
|
||||
}
|
||||
|
||||
public string VoicePhraseForOrder(Actor self, Order order)
|
||||
{
|
||||
return order.OrderString == "PortableChronoTeleport" && CanTeleport ? "Move" : null;
|
||||
}
|
||||
|
||||
public void ResetChargeTime()
|
||||
{
|
||||
chargeTick = 25 * Info.ChargeTime;
|
||||
}
|
||||
|
||||
public bool CanTeleport
|
||||
{
|
||||
get { return chargeTick <= 0; }
|
||||
}
|
||||
|
||||
// Display 2 pips indicating the current charge status
|
||||
public IEnumerable<PipType> GetPips(Actor self)
|
||||
{
|
||||
const int numPips = 2;
|
||||
for (var i = 0; i < numPips; i++)
|
||||
{
|
||||
if ((1 - chargeTick * 1.0f / (25 * Info.ChargeTime)) * numPips < i + 1)
|
||||
{
|
||||
yield return PipType.Transparent;
|
||||
continue;
|
||||
}
|
||||
|
||||
yield return PipType.Blue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PortableChronoOrderTargeter : IOrderTargeter
|
||||
{
|
||||
public string OrderID { get { return "PortableChronoTeleport"; } }
|
||||
public int OrderPriority { get { return 5; } }
|
||||
public bool IsQueued { get; protected set; }
|
||||
|
||||
public bool CanTarget(Actor self, Target target, List<Actor> othersAtTarget, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
// TODO: When target modifiers are configurable this needs to be revisited
|
||||
if (modifiers.HasModifier(TargetModifiers.ForceMove) || modifiers.HasModifier(TargetModifiers.ForceQueue))
|
||||
{
|
||||
var xy = self.World.Map.CellContaining(target.CenterPosition);
|
||||
|
||||
IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue);
|
||||
|
||||
if (self.IsInWorld && self.Owner.Shroud.IsExplored(xy))
|
||||
{
|
||||
cursor = "chrono-target";
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class PortableChronoOrderGenerator : IOrderGenerator
|
||||
{
|
||||
readonly Actor self;
|
||||
|
||||
public PortableChronoOrderGenerator(Actor self)
|
||||
{
|
||||
this.self = self;
|
||||
}
|
||||
|
||||
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
|
||||
{
|
||||
if (mi.Button == MouseButton.Left)
|
||||
{
|
||||
world.CancelInputMode();
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (self.IsInWorld && self.Location != xy
|
||||
&& self.Trait<PortableChrono>().CanTeleport && self.Owner.Shroud.IsExplored(xy))
|
||||
{
|
||||
world.CancelInputMode();
|
||||
yield return new Order("PortableChronoTeleport", self, mi.Modifiers.HasModifier(Modifiers.Shift)) { TargetLocation = xy };
|
||||
}
|
||||
}
|
||||
|
||||
public void Tick(World world)
|
||||
{
|
||||
if (!self.IsInWorld || self.IsDead)
|
||||
world.CancelInputMode();
|
||||
}
|
||||
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr, World world)
|
||||
{
|
||||
if (!self.IsInWorld || self.Owner != self.World.LocalPlayer)
|
||||
yield break;
|
||||
|
||||
if (!self.Trait<PortableChrono>().Info.HasDistanceLimit)
|
||||
yield break;
|
||||
|
||||
yield return new RangeCircleRenderable(
|
||||
self.CenterPosition,
|
||||
WRange.FromCells(self.Trait<PortableChrono>().Info.MaxDistance),
|
||||
0,
|
||||
Color.FromArgb(128, Color.LawnGreen),
|
||||
Color.FromArgb(96, Color.Black)
|
||||
);
|
||||
}
|
||||
|
||||
public string GetCursor(World world, CPos xy, MouseInput mi)
|
||||
{
|
||||
if (self.IsInWorld && self.Location != xy
|
||||
&& self.Trait<PortableChrono>().CanTeleport && self.Owner.Shroud.IsExplored(xy))
|
||||
return "chrono-target";
|
||||
else
|
||||
return "move-blocked";
|
||||
}
|
||||
}
|
||||
}
|
||||
280
OpenRA.Mods.RA/Traits/SupportPowers/ChronoshiftPower.cs
Normal file
280
OpenRA.Mods.RA/Traits/SupportPowers/ChronoshiftPower.cs
Normal file
@@ -0,0 +1,280 @@
|
||||
#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.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
class ChronoshiftPowerInfo : SupportPowerInfo
|
||||
{
|
||||
[Desc("Cells")]
|
||||
public readonly int Range = 1;
|
||||
[Desc("Seconds")]
|
||||
public readonly int Duration = 30;
|
||||
public readonly bool KillCargo = true;
|
||||
|
||||
public override object Create(ActorInitializer init) { return new ChronoshiftPower(init.self,this); }
|
||||
}
|
||||
|
||||
class ChronoshiftPower : SupportPower
|
||||
{
|
||||
public ChronoshiftPower(Actor self, ChronoshiftPowerInfo info) : base(self, info) { }
|
||||
|
||||
public override IOrderGenerator OrderGenerator(string order, SupportPowerManager manager)
|
||||
{
|
||||
Sound.PlayToPlayer(manager.self.Owner, Info.SelectTargetSound);
|
||||
return new SelectTarget(self.World, order, manager, this);
|
||||
}
|
||||
|
||||
public override void Activate(Actor self, Order order, SupportPowerManager manager)
|
||||
{
|
||||
base.Activate(self, order, manager);
|
||||
|
||||
foreach (var target in UnitsInRange(order.ExtraLocation))
|
||||
{
|
||||
var cs = target.Trait<Chronoshiftable>();
|
||||
var targetCell = target.Location + (order.TargetLocation - order.ExtraLocation);
|
||||
var cpi = Info as ChronoshiftPowerInfo;
|
||||
|
||||
if (self.Owner.Shroud.IsExplored(targetCell) && cs.CanChronoshiftTo(target, targetCell))
|
||||
cs.Teleport(target, targetCell, cpi.Duration * 25, cpi.KillCargo, self);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Actor> UnitsInRange(CPos xy)
|
||||
{
|
||||
var range = ((ChronoshiftPowerInfo)Info).Range;
|
||||
var tiles = self.World.Map.FindTilesInCircle(xy, range);
|
||||
var units = new List<Actor>();
|
||||
foreach (var t in tiles)
|
||||
units.AddRange(self.World.ActorMap.GetUnitsAt(t));
|
||||
|
||||
return units.Distinct().Where(a => a.HasTrait<Chronoshiftable>() &&
|
||||
!a.TraitsImplementing<IPreventsTeleport>().Any(condition => condition.PreventsTeleport(a)));
|
||||
}
|
||||
|
||||
public bool SimilarTerrain(CPos xy, CPos sourceLocation)
|
||||
{
|
||||
if (!self.Owner.Shroud.IsExplored(xy))
|
||||
return false;
|
||||
|
||||
var range = ((ChronoshiftPowerInfo)Info).Range;
|
||||
var sourceTiles = self.World.Map.FindTilesInCircle(xy, range);
|
||||
var destTiles = self.World.Map.FindTilesInCircle(sourceLocation, range);
|
||||
|
||||
using (var se = sourceTiles.GetEnumerator())
|
||||
using (var de = destTiles.GetEnumerator())
|
||||
while (se.MoveNext() && de.MoveNext())
|
||||
{
|
||||
var a = se.Current;
|
||||
var b = de.Current;
|
||||
|
||||
if (!self.Owner.Shroud.IsExplored(a) || !self.Owner.Shroud.IsExplored(b))
|
||||
return false;
|
||||
|
||||
if (self.World.Map.GetTerrainIndex(a) != self.World.Map.GetTerrainIndex(b))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
class SelectTarget : IOrderGenerator
|
||||
{
|
||||
readonly ChronoshiftPower power;
|
||||
readonly int range;
|
||||
readonly Sprite tile;
|
||||
readonly SupportPowerManager manager;
|
||||
readonly string order;
|
||||
|
||||
public SelectTarget(World world, string order, SupportPowerManager manager, ChronoshiftPower power)
|
||||
{
|
||||
this.manager = manager;
|
||||
this.order = order;
|
||||
this.power = power;
|
||||
this.range = ((ChronoshiftPowerInfo)power.Info).Range;
|
||||
tile = world.Map.SequenceProvider.GetSequence("overlay", "target-select").GetSprite(0);
|
||||
}
|
||||
|
||||
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
|
||||
{
|
||||
world.CancelInputMode();
|
||||
if (mi.Button == MouseButton.Left)
|
||||
world.OrderGenerator = new SelectDestination(world, order, manager, power, xy);
|
||||
|
||||
yield break;
|
||||
}
|
||||
|
||||
public void Tick(World world)
|
||||
{
|
||||
// Cancel the OG if we can't use the power
|
||||
if (!manager.Powers.ContainsKey(order))
|
||||
world.CancelInputMode();
|
||||
}
|
||||
|
||||
public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr, World world)
|
||||
{
|
||||
var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
|
||||
var targetUnits = power.UnitsInRange(xy).Where(a => !world.FogObscures(a));
|
||||
|
||||
foreach (var unit in targetUnits)
|
||||
if (manager.self.Owner.Shroud.IsTargetable(unit))
|
||||
yield return new SelectionBoxRenderable(unit, Color.Red);
|
||||
}
|
||||
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world)
|
||||
{
|
||||
var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
|
||||
var tiles = world.Map.FindTilesInCircle(xy, range);
|
||||
var pal = wr.Palette("terrain");
|
||||
foreach (var t in tiles)
|
||||
yield return new SpriteRenderable(tile, wr.world.Map.CenterOfCell(t), WVec.Zero, -511, pal, 1f, true);
|
||||
}
|
||||
|
||||
public string GetCursor(World world, CPos xy, MouseInput mi)
|
||||
{
|
||||
return "chrono-select";
|
||||
}
|
||||
}
|
||||
|
||||
class SelectDestination : IOrderGenerator
|
||||
{
|
||||
readonly ChronoshiftPower power;
|
||||
readonly CPos sourceLocation;
|
||||
readonly int range;
|
||||
readonly Sprite validTile, invalidTile, sourceTile;
|
||||
readonly SupportPowerManager manager;
|
||||
readonly string order;
|
||||
|
||||
public SelectDestination(World world, string order, SupportPowerManager manager, ChronoshiftPower power, CPos sourceLocation)
|
||||
{
|
||||
this.manager = manager;
|
||||
this.order = order;
|
||||
this.power = power;
|
||||
this.sourceLocation = sourceLocation;
|
||||
this.range = ((ChronoshiftPowerInfo)power.Info).Range;
|
||||
|
||||
var tileset = manager.self.World.TileSet.Id.ToLowerInvariant();
|
||||
validTile = world.Map.SequenceProvider.GetSequence("overlay", "target-valid-{0}".F(tileset)).GetSprite(0);
|
||||
invalidTile = world.Map.SequenceProvider.GetSequence("overlay", "target-invalid").GetSprite(0);
|
||||
sourceTile = world.Map.SequenceProvider.GetSequence("overlay", "target-select").GetSprite(0);
|
||||
}
|
||||
|
||||
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
|
||||
{
|
||||
if (mi.Button == MouseButton.Right)
|
||||
{
|
||||
world.CancelInputMode();
|
||||
yield break;
|
||||
}
|
||||
|
||||
var ret = OrderInner(xy).FirstOrDefault();
|
||||
if (ret == null)
|
||||
yield break;
|
||||
|
||||
world.CancelInputMode();
|
||||
yield return ret;
|
||||
}
|
||||
|
||||
IEnumerable<Order> OrderInner(CPos xy)
|
||||
{
|
||||
// Cannot chronoshift into unexplored location
|
||||
if (IsValidTarget(xy))
|
||||
yield return new Order(order, manager.self, false)
|
||||
{
|
||||
TargetLocation = xy,
|
||||
ExtraLocation = sourceLocation,
|
||||
SuppressVisualFeedback = true
|
||||
};
|
||||
}
|
||||
|
||||
public void Tick(World world)
|
||||
{
|
||||
// Cancel the OG if we can't use the power
|
||||
if (!manager.Powers.ContainsKey(order))
|
||||
world.CancelInputMode();
|
||||
}
|
||||
|
||||
public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr, World world)
|
||||
{
|
||||
foreach (var unit in power.UnitsInRange(sourceLocation))
|
||||
if (manager.self.Owner.Shroud.IsTargetable(unit))
|
||||
yield return new SelectionBoxRenderable(unit, Color.Red);
|
||||
}
|
||||
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world)
|
||||
{
|
||||
var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
|
||||
var pal = wr.Palette("terrain");
|
||||
|
||||
// Source tiles
|
||||
foreach (var t in world.Map.FindTilesInCircle(sourceLocation, range))
|
||||
yield return new SpriteRenderable(sourceTile, wr.world.Map.CenterOfCell(t), WVec.Zero, -511, pal, 1f, true);
|
||||
|
||||
// Destination tiles
|
||||
foreach (var t in world.Map.FindTilesInCircle(xy, range))
|
||||
yield return new SpriteRenderable(sourceTile, wr.world.Map.CenterOfCell(t), WVec.Zero, -511, pal, 1f, true);
|
||||
|
||||
// Unit previews
|
||||
foreach (var unit in power.UnitsInRange(sourceLocation))
|
||||
{
|
||||
var offset = world.Map.CenterOfCell(xy) - world.Map.CenterOfCell(sourceLocation);
|
||||
if (manager.self.Owner.Shroud.IsTargetable(unit))
|
||||
foreach (var r in unit.Render(wr))
|
||||
yield return r.OffsetBy(offset);
|
||||
}
|
||||
|
||||
// Unit tiles
|
||||
foreach (var unit in power.UnitsInRange(sourceLocation))
|
||||
{
|
||||
if (manager.self.Owner.Shroud.IsTargetable(unit))
|
||||
{
|
||||
var targetCell = unit.Location + (xy - sourceLocation);
|
||||
var canEnter = manager.self.Owner.Shroud.IsExplored(targetCell) &&
|
||||
unit.Trait<Chronoshiftable>().CanChronoshiftTo(unit, targetCell);
|
||||
var tile = canEnter ? validTile : invalidTile;
|
||||
yield return new SpriteRenderable(tile, wr.world.Map.CenterOfCell(targetCell), WVec.Zero, -511, pal, 1f, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool IsValidTarget(CPos xy)
|
||||
{
|
||||
var canTeleport = false;
|
||||
foreach (var unit in power.UnitsInRange(sourceLocation))
|
||||
{
|
||||
var targetCell = unit.Location + (xy - sourceLocation);
|
||||
if (manager.self.Owner.Shroud.IsExplored(targetCell) && unit.Trait<Chronoshiftable>().CanChronoshiftTo(unit,targetCell))
|
||||
{
|
||||
canTeleport = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!canTeleport)
|
||||
{
|
||||
// Check the terrain types. This will allow chronoshifts to occur on empty terrain to terrain of
|
||||
// a similar type. This also keeps the cursor from changing in non-visible property, alerting the
|
||||
// chronoshifter of enemy unit presence
|
||||
canTeleport = power.SimilarTerrain(sourceLocation,xy);
|
||||
}
|
||||
return canTeleport;
|
||||
}
|
||||
|
||||
public string GetCursor(World world, CPos xy, MouseInput mi)
|
||||
{
|
||||
return IsValidTarget(xy) ? "chrono-target" : "move-blocked";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
143
OpenRA.Mods.RA/Traits/SupportPowers/GpsPower.cs
Normal file
143
OpenRA.Mods.RA/Traits/SupportPowers/GpsPower.cs
Normal file
@@ -0,0 +1,143 @@
|
||||
#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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Effects;
|
||||
using OpenRA.Mods.RA.Effects;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
[Desc("Required for GpsPower. Attach this to the player actor.")]
|
||||
class GpsWatcherInfo : ITraitInfo
|
||||
{
|
||||
public object Create (ActorInitializer init) { return new GpsWatcher(init.self.Owner); }
|
||||
}
|
||||
|
||||
class GpsWatcher : ISync, IFogVisibilityModifier
|
||||
{
|
||||
[Sync] bool Launched = false;
|
||||
[Sync] public bool GrantedAllies = false;
|
||||
[Sync] public bool Granted = false;
|
||||
Player owner;
|
||||
|
||||
List<Actor> actors = new List<Actor> { };
|
||||
|
||||
public GpsWatcher(Player owner) { this.owner = owner; }
|
||||
|
||||
public void GpsRem(Actor atek)
|
||||
{
|
||||
actors.Remove(atek);
|
||||
RefreshGps(atek);
|
||||
}
|
||||
|
||||
public void GpsAdd(Actor atek)
|
||||
{
|
||||
actors.Add(atek);
|
||||
RefreshGps(atek);
|
||||
}
|
||||
|
||||
public void Launch(Actor atek, SupportPowerInfo info)
|
||||
{
|
||||
atek.World.Add(new DelayedAction(((GpsPowerInfo)info).RevealDelay * 25,
|
||||
() =>
|
||||
{
|
||||
Launched = true;
|
||||
RefreshGps(atek);
|
||||
}));
|
||||
}
|
||||
|
||||
public void RefreshGps(Actor atek)
|
||||
{
|
||||
RefreshGranted();
|
||||
|
||||
foreach (var i in atek.World.ActorsWithTrait<GpsWatcher>())
|
||||
i.Trait.RefreshGranted();
|
||||
|
||||
if ((Granted || GrantedAllies) && atek.Owner.IsAlliedWith(atek.World.RenderPlayer))
|
||||
atek.Owner.Shroud.ExploreAll(atek.World);
|
||||
}
|
||||
|
||||
void RefreshGranted()
|
||||
{
|
||||
Granted = (actors.Count > 0 && Launched);
|
||||
GrantedAllies = owner.World.ActorsWithTrait<GpsWatcher>().Any(p => p.Actor.Owner.IsAlliedWith(owner) && p.Trait.Granted);
|
||||
|
||||
if (Granted || GrantedAllies)
|
||||
owner.Shroud.ExploreAll(owner.World);
|
||||
}
|
||||
|
||||
public bool HasFogVisibility(Player byPlayer)
|
||||
{
|
||||
return Granted || GrantedAllies;
|
||||
}
|
||||
}
|
||||
|
||||
class GpsPowerInfo : SupportPowerInfo
|
||||
{
|
||||
public readonly int RevealDelay = 0;
|
||||
|
||||
public override object Create(ActorInitializer init) { return new GpsPower(init.self, this); }
|
||||
}
|
||||
|
||||
class GpsPower : SupportPower, INotifyKilled, INotifyStanceChanged, INotifySold, INotifyOwnerChanged
|
||||
{
|
||||
GpsWatcher owner;
|
||||
|
||||
public GpsPower(Actor self, GpsPowerInfo info) : base(self, info)
|
||||
{
|
||||
owner = self.Owner.PlayerActor.Trait<GpsWatcher>();
|
||||
owner.GpsAdd(self);
|
||||
}
|
||||
|
||||
public override void Charged(Actor self, string key)
|
||||
{
|
||||
self.Owner.PlayerActor.Trait<SupportPowerManager>().Powers[key].Activate(new Order());
|
||||
}
|
||||
|
||||
public override void Activate(Actor self, Order order, SupportPowerManager manager)
|
||||
{
|
||||
base.Activate(self, order, manager);
|
||||
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
Sound.PlayToPlayer(self.Owner, Info.LaunchSound);
|
||||
|
||||
w.Add(new SatelliteLaunch(self));
|
||||
|
||||
owner.Launch(self, Info);
|
||||
});
|
||||
}
|
||||
|
||||
public void Killed(Actor self, AttackInfo e) { RemoveGps(self); }
|
||||
|
||||
public void Selling(Actor self) {}
|
||||
public void Sold(Actor self) { RemoveGps(self); }
|
||||
|
||||
void RemoveGps(Actor self)
|
||||
{
|
||||
// Extra function just in case something needs to be added later
|
||||
owner.GpsRem(self);
|
||||
}
|
||||
|
||||
public void StanceChanged(Actor self, Player a, Player b, Stance oldStance, Stance newStance)
|
||||
{
|
||||
owner.RefreshGps(self);
|
||||
}
|
||||
|
||||
public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
||||
{
|
||||
RemoveGps(self);
|
||||
owner = newOwner.PlayerActor.Trait<GpsWatcher>();
|
||||
owner.GpsAdd(self);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user