diff --git a/OpenRA.Mods.RA/Activities/Teleport.cs b/OpenRA.Mods.RA/Activities/Teleport.cs index 8db14a0f8d..162dd4b549 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()) @@ -67,20 +67,20 @@ namespace OpenRA.Mods.RA.Activities if (killCargo && self.HasTrait()) { var cargo = self.Trait(); - if (chronosphere != null) + if (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; 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)); } }