check shroud against the initiating owner when teleporting

fixes #6999
This commit is contained in:
Oliver Brakmann
2014-11-26 20:58:16 +01:00
committed by Matthias Mailänder
parent 253dfcac29
commit ac1e7a7352
2 changed files with 19 additions and 12 deletions

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.RA.Activities
public class Teleport : Activity public class Teleport : Activity
{ {
Actor chronosphere; Actor teleporter;
CPos destination; CPos destination;
int? maximumDistance; int? maximumDistance;
bool killCargo; bool killCargo;
@@ -29,12 +29,12 @@ namespace OpenRA.Mods.RA.Activities
const int maxCellSearchRange = Map.MaxTilesInCircleRange; 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) if (maximumDistance > maxCellSearchRange)
throw new InvalidOperationException("Teleport cannot be used with a maximum teleport distance greater than {0}.".F(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.destination = destination;
this.maximumDistance = maximumDistance; this.maximumDistance = maximumDistance;
this.killCargo = killCargo; this.killCargo = killCargo;
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA.Activities
public override Activity Tick(Actor self) public override Activity Tick(Actor self)
{ {
var pc = self.TraitOrDefault<PortableChrono>(); var pc = self.TraitOrDefault<PortableChrono>();
if (pc != null && !pc.CanTeleport) if (teleporter == self && pc != null && !pc.CanTeleport)
return NextActivity; return NextActivity;
foreach (var condition in self.TraitsImplementing<IPreventsTeleport>()) foreach (var condition in self.TraitsImplementing<IPreventsTeleport>())
@@ -67,20 +67,20 @@ namespace OpenRA.Mods.RA.Activities
if (killCargo && self.HasTrait<Cargo>()) if (killCargo && self.HasTrait<Cargo>())
{ {
var cargo = self.Trait<Cargo>(); var cargo = self.Trait<Cargo>();
if (chronosphere != null) if (teleporter != null)
{ {
while (!cargo.IsEmpty(self)) while (!cargo.IsEmpty(self))
{ {
var a = cargo.Unload(self); var a = cargo.Unload(self);
// Kill all the units that are unloaded into the void // Kill all the units that are unloaded into the void
// Kill() handles kill and death statistics // Kill() handles kill and death statistics
a.Kill(chronosphere); a.Kill(teleporter);
} }
} }
} }
// Consume teleport charges if this wasn't triggered via chronosphere // Consume teleport charges if this wasn't triggered via chronosphere
if (chronosphere == null && pc != null) if (teleporter == self && pc != null)
pc.ResetChargeTime(); pc.ResetChargeTime();
// Trigger screen desaturate effect // Trigger screen desaturate effect
@@ -88,27 +88,34 @@ namespace OpenRA.Mods.RA.Activities
foreach (var a in self.World.ActorsWithTrait<ChronoshiftPaletteEffect>()) foreach (var a in self.World.ActorsWithTrait<ChronoshiftPaletteEffect>())
a.Trait.Enable(); a.Trait.Enable();
if (chronosphere != null && !chronosphere.Destroyed && chronosphere.HasTrait<RenderBuilding>()) if (teleporter != null && self != teleporter && !teleporter.Destroyed)
chronosphere.Trait<RenderBuilding>().PlayCustomAnim(chronosphere, "active"); {
var building = teleporter.TraitOrDefault<RenderBuilding>();
if (building != null)
building.PlayCustomAnim(teleporter, "active");
}
return NextActivity; return NextActivity;
} }
CPos? ChooseBestDestinationCell(Actor self, CPos destination) CPos? ChooseBestDestinationCell(Actor self, CPos destination)
{ {
if (teleporter == null)
return null;
var restrictTo = maximumDistance == null ? null : self.World.Map.FindTilesInCircle(self.Location, maximumDistance.Value); var restrictTo = maximumDistance == null ? null : self.World.Map.FindTilesInCircle(self.Location, maximumDistance.Value);
if (maximumDistance != null) if (maximumDistance != null)
destination = restrictTo.MinBy(x => (x - destination).LengthSquared); destination = restrictTo.MinBy(x => (x - destination).LengthSquared);
var pos = self.Trait<IPositionable>(); var pos = self.Trait<IPositionable>();
if (pos.CanEnterCell(destination) && self.Owner.Shroud.IsExplored(destination)) if (pos.CanEnterCell(destination) && teleporter.Owner.Shroud.IsExplored(destination))
return destination; return destination;
var max = maximumDistance != null ? maximumDistance.Value : maxCellSearchRange; var max = maximumDistance != null ? maximumDistance.Value : maxCellSearchRange;
foreach (var tile in self.World.Map.FindTilesInCircle(destination, max)) 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))) && (restrictTo == null || (restrictTo != null && restrictTo.Contains(tile)))
&& pos.CanEnterCell(tile)) && pos.CanEnterCell(tile))
return tile; return tile;

View File

@@ -74,7 +74,7 @@ namespace OpenRA.Mods.RA
{ {
var maxDistance = Info.HasDistanceLimit ? Info.MaxDistance : (int?)null; var maxDistance = Info.HasDistanceLimit ? Info.MaxDistance : (int?)null;
self.CancelActivity(); 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));
} }
} }