Added Chrono Tank to Allies

This commit is contained in:
Curtis Shmyr
2012-10-11 21:30:18 -06:00
committed by Chris Forbes
parent f337c7fb40
commit 83fc70f415
8 changed files with 152 additions and 77 deletions

View File

@@ -8,23 +8,34 @@
*/
#endregion
using System.Drawing;
using System.Collections.Generic;
using OpenRA.Effects;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Orders;
using OpenRA.Traits;
using OpenRA.Graphics;
namespace OpenRA.Mods.RA
{
class ChronoshiftDeployInfo : TraitInfo<ChronoshiftDeploy>
class ChronoshiftDeployInfo : ITraitInfo
{
public readonly int ChargeTime = 120; // Seconds
public readonly int ChargeTime = 60; // seconds
public readonly int JumpDistance = 10;
public object Create(ActorInitializer init) { return new ChronoshiftDeploy(init.self, this); }
}
class ChronoshiftDeploy : IIssueOrder, IResolveOrder, ITick, IPips, IOrderVoice, ISync
{
// Recharge logic
[Sync] int chargeTick = 0; // How long until we can chronoshift again?
[Sync] int chargeTick = 0;
public readonly ChronoshiftDeployInfo Info;
readonly Actor self;
public ChronoshiftDeploy(Actor self, ChronoshiftDeployInfo info)
{
this.self = self;
this.Info = info;
}
public void Tick(Actor self)
{
@@ -34,29 +45,28 @@ namespace OpenRA.Mods.RA
public IEnumerable<IOrderTargeter> Orders
{
get { yield return new DeployOrderTargeter( "ChronoshiftDeploy", 5, () => chargeTick <= 0 ); }
get { yield return new DeployOrderTargeter("ChronoshiftJump", 5, () => chargeTick <= 0); }
}
public Order IssueOrder( Actor self, IOrderTargeter order, Target target, bool queued )
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
{
if( order.OrderID == "ChronoshiftDeploy" )
if (chargeTick <= 0)
self.World.OrderGenerator = new SetChronoTankDestination( self );
if (order.OrderID == "ChronoshiftJump" && chargeTick <= 0)
self.World.OrderGenerator = new ChronoTankOrderGenerator(self);
return null;
return new Order("ChronoshiftJump", self, false); // Hack until we can return null
}
public void ResolveOrder(Actor self, Order order)
{
var movement = self.TraitOrDefault<IMove>();
if (order.OrderString == "ChronoshiftSelf" && movement.CanEnterCell(order.TargetLocation))
if (order.OrderString == "ChronoshiftJump")
{
if (self.Owner == self.World.LocalPlayer)
self.World.CancelInputMode();
self.CancelActivity();
self.QueueActivity(new Teleport(null, order.TargetLocation, true));
chargeTick = 25 * self.Info.Traits.Get<ChronoshiftDeployInfo>().ChargeTime;
if (CanJumpTo(order.TargetLocation))
{
self.CancelActivity();
self.QueueActivity(new Teleport(null, order.TargetLocation, true));
chargeTick = 25 * Info.ChargeTime;
}
}
}
@@ -71,7 +81,7 @@ namespace OpenRA.Mods.RA
const int numPips = 5;
for (int i = 0; i < numPips; i++)
{
if ((1 - chargeTick * 1.0f / (25 * self.Info.Traits.Get<ChronoshiftDeployInfo>().ChargeTime)) * numPips < i + 1)
if ((1 - chargeTick * 1.0f / (25 * Info.ChargeTime)) * numPips < i + 1)
{
yield return PipType.Transparent;
continue;
@@ -93,5 +103,61 @@ namespace OpenRA.Mods.RA
}
}
}
public bool CanJumpTo(CPos xy)
{
var movement = self.TraitOrDefault<IMove>();
if (chargeTick <= 0 // Can jump
&& self.World.LocalPlayer.Shroud.IsExplored(xy) // Not in shroud
&& movement.CanEnterCell(xy) // Can enter cell
&& (self.Location - xy).Length <= Info.JumpDistance) // Within jump range
return true;
else
return false;
}
}
class ChronoTankOrderGenerator : IOrderGenerator
{
readonly Actor self;
public ChronoTankOrderGenerator(Actor self) { this.self = self; }
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
{
if (mi.Button == MouseButton.Left)
{
world.CancelInputMode();
yield break;
}
var queued = mi.Modifiers.HasModifier(Modifiers.Shift);
var cinfo = self.Trait<ChronoshiftDeploy>();
if (cinfo.CanJumpTo(xy))
{
self.World.CancelInputMode();
yield return new Order("ChronoshiftJump", self, queued) { TargetLocation = xy };
}
}
public string GetCursor(World world, CPos xy, MouseInput mi)
{
var cinfo = self.Trait<ChronoshiftDeploy>();
if (cinfo.CanJumpTo(xy))
return "chrono-target";
else
return "move-blocked";
}
public void Tick(World world) { }
public void RenderAfterWorld(WorldRenderer wr, World world) { }
public void RenderBeforeWorld(WorldRenderer wr, World world)
{
wr.DrawRangeCircle(
Color.FromArgb(128, Color.Magenta),
self.CenterLocation.ToFloat2(), (int)self.Trait<ChronoshiftDeploy>().Info.JumpDistance);
}
}
}