diff --git a/OpenRA.Mods.RA/Activities/SimpleTeleport.cs b/OpenRA.Mods.RA/Activities/SimpleTeleport.cs new file mode 100755 index 0000000000..d008532eaf --- /dev/null +++ b/OpenRA.Mods.RA/Activities/SimpleTeleport.cs @@ -0,0 +1,28 @@ +#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 OpenRA.Traits; + +namespace OpenRA.Mods.RA.Activities +{ + public class SimpleTeleport : Activity + { + CPos destination; + + public SimpleTeleport(CPos destination) { this.destination = destination; } + + public override Activity Tick(Actor self) + { + self.Trait().SetPosition(self, destination); + self.Generation++; + return NextActivity; + } + } +} diff --git a/OpenRA.Mods.RA/Activities/Teleport.cs b/OpenRA.Mods.RA/Activities/Teleport.cs index ead701bf90..071e320afe 100755 --- a/OpenRA.Mods.RA/Activities/Teleport.cs +++ b/OpenRA.Mods.RA/Activities/Teleport.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.RA.Activities public class Teleport : Activity { - Actor chronosphere; + Actor teleporter; CPos destination; int? maximumDistance; bool killCargo; @@ -29,12 +29,12 @@ namespace OpenRA.Mods.RA.Activities const int maxCellSearchRange = Map.MaxTilesInCircleRange; - public Teleport(Actor chronosphere, CPos destination, int? maximumDistance, bool killCargo, bool screenFlash, string sound) + public Teleport(Actor teleporter, 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.teleporter = teleporter; this.destination = destination; this.maximumDistance = maximumDistance; this.killCargo = killCargo; @@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA.Activities public override Activity Tick(Actor self) { var pc = self.TraitOrDefault(); - if (pc != null && !pc.CanTeleport) + if (teleporter == self && pc != null && !pc.CanTeleport) return NextActivity; foreach (var condition in self.TraitsImplementing()) @@ -64,23 +64,23 @@ namespace OpenRA.Mods.RA.Activities self.Trait().SetPosition(self, destination); self.Generation++; - if (killCargo && self.HasTrait()) + if (killCargo) { - var cargo = self.Trait(); - if (chronosphere != null) + var cargo = self.TraitOrDefault(); + if (cargo != null && teleporter != null) { while (!cargo.IsEmpty(self)) { var a = cargo.Unload(self); // Kill all the units that are unloaded into the void // Kill() handles kill and death statistics - a.Kill(chronosphere); + a.Kill(teleporter); } } } // Consume teleport charges if this wasn't triggered via chronosphere - if (chronosphere == null && pc != null) + if (teleporter == self && pc != null) pc.ResetChargeTime(); // Trigger screen desaturate effect @@ -88,27 +88,34 @@ namespace OpenRA.Mods.RA.Activities foreach (var a in self.World.ActorsWithTrait()) a.Trait.Enable(); - if (chronosphere != null && !chronosphere.Destroyed && chronosphere.HasTrait()) - chronosphere.Trait().PlayCustomAnim(chronosphere, "active"); + if (teleporter != null && self != teleporter && !teleporter.Destroyed) + { + var building = teleporter.TraitOrDefault(); + if (building != null) + building.PlayCustomAnim(teleporter, "active"); + } return NextActivity; } CPos? ChooseBestDestinationCell(Actor self, CPos destination) { + if (teleporter == null) + return null; + var restrictTo = maximumDistance == null ? null : self.World.Map.FindTilesInCircle(self.Location, maximumDistance.Value); if (maximumDistance != null) destination = restrictTo.MinBy(x => (x - destination).LengthSquared); var pos = self.Trait(); - if (pos.CanEnterCell(destination) && self.Owner.Shroud.IsExplored(destination)) + if (pos.CanEnterCell(destination) && teleporter.Owner.Shroud.IsExplored(destination)) return destination; var max = maximumDistance != null ? maximumDistance.Value : maxCellSearchRange; foreach (var tile in self.World.Map.FindTilesInCircle(destination, max)) { - if (self.Owner.Shroud.IsExplored(tile) + if (teleporter.Owner.Shroud.IsExplored(tile) && (restrictTo == null || (restrictTo != null && restrictTo.Contains(tile))) && pos.CanEnterCell(tile)) return tile; @@ -117,18 +124,4 @@ namespace OpenRA.Mods.RA.Activities return null; } } - - public class SimpleTeleport : Activity - { - CPos destination; - - public SimpleTeleport(CPos destination) { this.destination = destination; } - - public override Activity Tick(Actor self) - { - self.Trait().SetPosition(self, destination); - self.Generation++; - return NextActivity; - } - } } diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 0b6a88e62b..1dcfc703c3 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -453,6 +453,7 @@ + diff --git a/OpenRA.Mods.RA/PortableChrono.cs b/OpenRA.Mods.RA/PortableChrono.cs index 8c55eef747..92438fb2c6 100644 --- a/OpenRA.Mods.RA/PortableChrono.cs +++ b/OpenRA.Mods.RA/PortableChrono.cs @@ -74,7 +74,7 @@ namespace OpenRA.Mods.RA { var maxDistance = Info.HasDistanceLimit ? Info.MaxDistance : (int?)null; self.CancelActivity(); - self.QueueActivity(new Teleport(null, order.TargetLocation, maxDistance, true, false, Info.ChronoshiftSound)); + self.QueueActivity(new Teleport(self, order.TargetLocation, maxDistance, true, false, Info.ChronoshiftSound)); } }