minor tidying

This commit is contained in:
Chris Forbes
2009-10-22 23:33:51 +13:00
parent b73e5a62bb
commit 8249951b27
2 changed files with 16 additions and 29 deletions

View File

@@ -23,7 +23,8 @@ namespace OpenRa
public int2 Sign() { return new int2(Math.Sign(X), Math.Sign(Y)); } public int2 Sign() { return new int2(Math.Sign(X), Math.Sign(Y)); }
public int2 Abs() { return new int2( Math.Abs( X ), Math.Abs( Y ) ); } public int2 Abs() { return new int2( Math.Abs( X ), Math.Abs( Y ) ); }
public int Length { get { return (int)Math.Sqrt(X * X + Y * Y); } } public int LengthSquared { get { return X * X + Y * Y; } }
public int Length { get { return (int)Math.Sqrt(LengthSquared); } }
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); } public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); }
public override bool Equals(object obj) public override bool Equals(object obj)

View File

@@ -13,49 +13,35 @@ namespace OpenRa.Game.Traits
int primaryFireDelay = 0; int primaryFireDelay = 0;
int secondaryFireDelay = 0; int secondaryFireDelay = 0;
public AttackTurreted( Actor self ) public AttackTurreted( Actor self ) { self.traits.Get<Turreted>(); }
{
self.traits.Get<Turreted>();
}
public void Tick( Actor self ) public void Tick(Actor self)
{ {
if( primaryFireDelay > 0 ) if (primaryFireDelay > 0) --primaryFireDelay;
--primaryFireDelay; if (secondaryFireDelay > 0) --secondaryFireDelay;
if( secondaryFireDelay > 0 )
--secondaryFireDelay;
if( target == null ) if (target != null && target.IsDead) target = null; /* he's dead, jim. */
return; if (target == null) return;
if (target.IsDead) /* stop firing on targets after we've killed them */
{
target = null;
return;
}
var turreted = self.traits.Get<Turreted>(); var turreted = self.traits.Get<Turreted>();
turreted.desiredFacing = Util.GetFacing( target.CenterLocation - self.CenterLocation, turreted.turretFacing ); turreted.desiredFacing = Util.GetFacing(target.CenterLocation - self.CenterLocation, turreted.turretFacing);
if( turreted.desiredFacing != turreted.turretFacing ) if (turreted.desiredFacing != turreted.turretFacing)
return; return;
if( self.unitInfo.Primary != null && CheckFire( self, self.unitInfo.Primary, ref primaryFireDelay ) ) if (self.unitInfo.Primary != null && CheckFire(self, self.unitInfo.Primary, ref primaryFireDelay))
{ {
secondaryFireDelay = Math.Max( 4, secondaryFireDelay ); secondaryFireDelay = Math.Max(4, secondaryFireDelay);
return; return;
} }
if( self.unitInfo.Secondary != null && CheckFire( self, self.unitInfo.Secondary, ref secondaryFireDelay ) ) if (self.unitInfo.Secondary != null && CheckFire(self, self.unitInfo.Secondary, ref secondaryFireDelay))
return; return;
} }
bool CheckFire( Actor self, string weaponName, ref int fireDelay ) bool CheckFire( Actor self, string weaponName, ref int fireDelay )
{ {
if( fireDelay > 0 ) if( fireDelay > 0 ) return false;
return false;
var weapon = Rules.WeaponInfo[ weaponName ]; var weapon = Rules.WeaponInfo[ weaponName ];
var d = target.Location - self.Location; if( weapon.Range * weapon.Range < (target.Location - self.Location).LengthSquared ) return false;
if( weapon.Range * weapon.Range < d.X * d.X + d.Y * d.Y )
return false;
// FIXME: rules specifies ROF in 1/15 sec units; ticks are 1/25 sec // FIXME: rules specifies ROF in 1/15 sec units; ticks are 1/25 sec
fireDelay = weapon.ROF; fireDelay = weapon.ROF;