better fix for chrono bug

This commit is contained in:
Chris Forbes
2011-01-08 17:30:29 +13:00
parent 07abeffc5e
commit e2ff40dc7f
3 changed files with 15 additions and 17 deletions

View File

@@ -40,14 +40,14 @@ namespace OpenRA.Mods.RA
}
}
// Can't be used in synced code
public virtual bool CanChronoshiftTo(Actor self, int2 targetLocation)
{
// Todo: Allow enemy units to be chronoshifted into bad terrain to kill them
return self.HasTrait<ITeleportable>() &&
self.Trait<ITeleportable>().CanEnterCell(targetLocation) &&
(self.World.LocalShroud.IsExplored(targetLocation));
}
// Can't be used in synced code, except with ignoreVis.
public virtual bool CanChronoshiftTo(Actor self, int2 targetLocation, bool ignoreVis)
{
// Todo: Allow enemy units to be chronoshifted into bad terrain to kill them
return self.HasTrait<ITeleportable>() &&
self.Trait<ITeleportable>().CanEnterCell(targetLocation) &&
(ignoreVis || self.World.LocalShroud.IsExplored(targetLocation));
}
public virtual bool Teleport(Actor self, int2 targetLocation, int duration, bool killCargo, Actor chronosphere)
{

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Scripting
var target = kv.First;
var targetCell = kv.Second;
var cs = target.Trait<Chronoshiftable>();
if (cs.CanChronoshiftTo(target, targetCell))
if (cs.CanChronoshiftTo(target, targetCell, true))
target.Trait<Chronoshiftable>().Teleport(target,
targetCell,
duration,

View File

@@ -51,13 +51,11 @@ namespace OpenRA.Mods.RA
{
var cs = target.Trait<Chronoshiftable>();
var targetCell = target.Location + order.TargetLocation - order.ExtraLocation;
// TODO: CanChronoshiftTo() can't be used in synced code, but not checking this here
// leaves it open to exploitation.
// if (cs.CanChronoshiftTo(target, targetCell)) ...
var cpi = Info as ChronoshiftPowerInfo;
cs.Teleport(target, targetCell,
cpi.Duration * 25, cpi.KillCargo, self);
if (cs.CanChronoshiftTo(target, targetCell, true))
cs.Teleport(target, targetCell,
cpi.Duration * 25, cpi.KillCargo, self);
}
}
@@ -217,7 +215,7 @@ namespace OpenRA.Mods.RA
foreach (var unit in power.UnitsInRange(sourceLocation))
{
var targetCell = unit.Location + xy - sourceLocation;
var canEnter = unit.Trait<Chronoshiftable>().CanChronoshiftTo(unit,targetCell);
var canEnter = unit.Trait<Chronoshiftable>().CanChronoshiftTo(unit,targetCell, false);
var tile = canEnter ? validTile : invalidTile;
tile.DrawAt( wr, Game.CellSize * targetCell, "terrain" );
}
@@ -229,7 +227,7 @@ namespace OpenRA.Mods.RA
foreach (var unit in power.UnitsInRange(sourceLocation))
{
var targetCell = unit.Location + xy - sourceLocation;
if (unit.Trait<Chronoshiftable>().CanChronoshiftTo(unit,targetCell))
if (unit.Trait<Chronoshiftable>().CanChronoshiftTo(unit,targetCell, false))
{
canTeleport = true;
break;