Chronotank teleporation by holding SHIFT or ALT and issuing a move order

This commit is contained in:
Curtis Shmyr
2014-03-22 00:04:29 -06:00
parent 21544ce235
commit 6ced7b274c
10 changed files with 280 additions and 233 deletions

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* 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,
@@ -8,6 +8,9 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
using OpenRA.Mods.RA.Render;
@@ -15,21 +18,40 @@ namespace OpenRA.Mods.RA.Activities
{
public class Teleport : Activity
{
CPos destination;
bool killCargo;
Actor chronosphere;
CPos destination;
int? maximumDistance;
bool killCargo;
bool screenFlash;
string sound;
public Teleport(Actor chronosphere, CPos destination, bool killCargo, string sound)
const int maxCellSearchRange = WorldUtils.MaxRange;
public Teleport(Actor chronosphere, CPos destination, int? maximumDistance, bool killCargo, bool screenFlash, string sound)
{
if (maximumDistance > maxCellSearchRange)
throw new InvalidOperationException("Teleport cannot be used with a maximum teleport distance greater than {0}.".F(maxCellSearchRange));
this.chronosphere = chronosphere;
this.destination = destination;
this.maximumDistance = maximumDistance;
this.killCargo = killCargo;
this.screenFlash = screenFlash;
this.sound = sound;
}
public override Activity Tick(Actor self)
{
var pc = self.TraitOrDefault<PortableChrono>();
if (pc != null && !pc.CanTeleport)
return NextActivity;
var bestCell = ChooseBestDestinationCell(self, destination);
if (bestCell == null)
return NextActivity;
destination = bestCell.Value;
Sound.Play(sound, self.CenterPosition);
Sound.Play(sound, destination.CenterPosition);
@@ -51,15 +73,48 @@ namespace OpenRA.Mods.RA.Activities
}
}
// Consume teleport charges if this wasn't triggered via chronosphere
if (chronosphere == null && pc != null)
pc.ResetChargeTime();
// Trigger screen desaturate effect
foreach (var a in self.World.ActorsWithTrait<ChronoshiftPaletteEffect>())
a.Trait.Enable();
if (screenFlash)
foreach (var a in self.World.ActorsWithTrait<ChronoshiftPaletteEffect>())
a.Trait.Enable();
if (chronosphere != null && !chronosphere.Destroyed && chronosphere.HasTrait<RenderBuilding>())
chronosphere.Trait<RenderBuilding>().PlayCustomAnim(chronosphere, "active");
return NextActivity;
}
CPos? ChooseBestDestinationCell(Actor self, CPos destination)
{
var restrictTo = maximumDistance == null ? null : self.World.FindTilesInCircle(self.Location, maximumDistance.Value);
if (maximumDistance != null)
destination = restrictTo.OrderBy(x => (x - destination).Length).First();
var pos = self.Trait<IPositionable>();
if (pos.CanEnterCell(destination) && self.Owner.Shroud.IsExplored(destination))
return destination;
var searched = new List<CPos>();
for (int r = 1; r <= maxCellSearchRange || (maximumDistance != null && r <= maximumDistance); r++)
{
foreach (var tile in self.World.FindTilesInCircle(destination, r).Except(searched))
{
if (self.Owner.Shroud.IsExplored(tile)
&& (restrictTo == null || (restrictTo != null && restrictTo.Contains(tile)))
&& pos.CanEnterCell(tile))
return tile;
searched.Add(tile);
}
}
return null;
}
}
public class SimpleTeleport : Activity