fix off-by-one in IsInRange. use CenterLocation in combat code where appropriate

This commit is contained in:
Bob
2010-11-04 01:20:40 +13:00
committed by Chris Forbes
parent 5c0cd50797
commit 80caf1818b
4 changed files with 7 additions and 8 deletions

View File

@@ -216,8 +216,7 @@ namespace OpenRA.Mods.RA
var attack = self.Trait<AttackBase>();
var range = attack.GetMaximumRange();
if (!attack.target.IsValid ||
(Util.CellContaining(attack.target.CenterLocation) - self.Location).LengthSquared > range * range)
if (!attack.target.IsValid || !Combat.IsInRange( self.CenterLocation, range, attack.target ))
AttackTarget(self, ChooseTarget(self, range), allowMovement);
var info = self.Info.Traits.Get<AttackBaseInfo>();
@@ -235,7 +234,7 @@ namespace OpenRA.Mods.RA
.Where(a => a.Owner != null && self.Owner.Stances[a.Owner] == Stance.Enemy)
.Where(a => attack.HasAnyValidWeapons(Target.FromActor(a)))
.Where(a => !a.HasTrait<Cloak>() || a.Trait<Cloak>().IsVisible(a, self.Owner))
.OrderBy(a => (a.Location - self.Location).LengthSquared)
.OrderBy(a => (a.CenterLocation - self.CenterLocation).LengthSquared)
.FirstOrDefault();
}

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA
if (!attack.target.IsValid)
return true; // he's dead.
if ((attack.target.CenterLocation - self.Location).LengthSquared > range * range + 2)
if( !Combat.IsInRange( self.CenterLocation, range, attack.target ) )
return true; // wandered off faster than we could follow
if (attack.target.IsActor
@@ -64,7 +64,7 @@ namespace OpenRA.Mods.RA
.Where(a => a.IsInWorld && !a.IsDead())
.Where(a => a.HasTrait<Health>() && a.GetDamageState() > DamageState.Undamaged)
.Where(a => attack.HasAnyValidWeapons(Target.FromActor(a)))
.OrderBy(a => (a.Location - self.Location).LengthSquared)
.OrderBy(a => (a.CenterLocation - self.CenterLocation).LengthSquared)
.FirstOrDefault();
}
}

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA
{
var info = self.Info.Traits.Get<CarpetBombInfo>();
if ((self.Location - Target).LengthSquared > info.Range * info.Range)
if( !Combat.IsInRange( self.CenterLocation, info.Range, Target ) )
return;
var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();

View File

@@ -224,7 +224,7 @@ namespace OpenRA.Mods.RA
{
var rsq = range * range * Game.CellSize * Game.CellSize;
foreach( var cell in target.Trait<ITargetable>().TargetableCells( target ) )
if( ( attackOrigin - cell * Game.CellSize ).LengthSquared < rsq )
if( ( attackOrigin - cell * Game.CellSize ).LengthSquared <= rsq )
return true;
return false;
}
@@ -232,7 +232,7 @@ namespace OpenRA.Mods.RA
public static bool IsInRange( float2 attackOrigin, float range, float2 targetLocation )
{
var rsq = range * range * Game.CellSize * Game.CellSize;
return ( attackOrigin - targetLocation ).LengthSquared < rsq;
return ( attackOrigin - targetLocation ).LengthSquared <= rsq;
}
public static bool IsInRange( float2 attackOrigin, float range, Target target )