Combat.DoExplosion now takes a Target

(needs more refactoring)
This commit is contained in:
alzeih
2010-07-22 16:00:14 +12:00
parent 4e22e37192
commit 6be4e5c266
11 changed files with 22 additions and 21 deletions

View File

@@ -30,7 +30,8 @@ namespace OpenRA.Mods.RA
if (self.GetCurrentActivity() is Leap) return;
var weapon = self.GetPrimaryWeapon();
if (weapon.Range * weapon.Range < (target.CenterLocation - self.Location).LengthSquared) return;
if (weapon.Range * Game.CellSize * weapon.Range * Game.CellSize
< (target.CenterLocation - self.CenterLocation).LengthSquared) return;
self.CancelActivity();
self.QueueActivity(new Leap(self, target));

View File

@@ -113,16 +113,16 @@ namespace OpenRA.Mods.RA
}
}
public static void DoExplosion(Actor attacker, string weapontype, int2 location, int altitude)
public static void DoExplosion(Actor attacker, string weapontype, Target _target, int altitude)
{
var args = new ProjectileArgs
{
src = location,
dest = location,
src = Util.CellContaining(_target.CenterLocation),
dest = Util.CellContaining(_target.CenterLocation),
srcAltitude = altitude,
destAltitude = altitude,
firedBy = attacker,
target = null,
target = _target,
weapon = Rules.Weapons[ weapontype.ToLowerInvariant() ],
facing = 0
};

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA
public override void Activate(Actor collector)
{
Combat.DoExplosion(self, (info as ExplodeCrateActionInfo).Weapon, collector.CenterLocation.ToInt2(), 0);
Combat.DoExplosion(self, (info as ExplodeCrateActionInfo).Weapon, Target.FromActor(collector), 0);
base.Activate(collector);
}
}

View File

@@ -75,8 +75,9 @@ namespace OpenRA.Mods.RA.Effects
var targetPosition = Args.target.CenterLocation + offset;
var targetUnit = Args.target.traits.GetOrDefault<Unit>();
var targetAltitude = targetUnit != null ? targetUnit.Altitude : 0;
var targetAltitude = 0;
if (Args.target.IsActor && Args.target.Actor.traits.GetOrDefault<Unit>() != null)
targetAltitude = Args.target.Actor.traits.GetOrDefault<Unit>().Altitude;
Altitude += Math.Sign(targetAltitude - Altitude);
Traits.Util.TickFacing(ref Facing,
@@ -86,7 +87,7 @@ namespace OpenRA.Mods.RA.Effects
anim.Tick();
var dist = targetPosition - Pos;
if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough || Args.target.IsDead)
if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough || !Args.target.IsValid )
Explode(world);
var speed = Scale * Info.Speed * ((targetAltitude > 0 && Info.TurboBoost) ? 1.5f : 1f);

View File

@@ -76,7 +76,7 @@ namespace OpenRA.Mods.RA.Effects
void Explode(World world)
{
world.AddFrameEndTask(w => w.Remove(this));
Combat.DoExplosion(silo.Owner.PlayerActor, weapon, pos.ToInt2(), 0);
Combat.DoExplosion(silo.Owner.PlayerActor, weapon, Target.FromPos(pos), 0);
world.WorldActor.traits.Get<ScreenShaker>().AddEffect(20, pos, 5);
}

View File

@@ -32,8 +32,7 @@ namespace OpenRA.Mods.RA
{
var unit = self.traits.GetOrDefault<Unit>();
var altitude = unit != null ? unit.Altitude : 0;
Combat.DoExplosion(e.Attacker, weapon,
self.CenterLocation.ToInt2(), altitude);
Combat.DoExplosion(e.Attacker, weapon, Target.FromActor(self), altitude);
}
}
}

View File

@@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA
return;
var info = self.Info.Traits.Get<MineInfo>();
Combat.DoExplosion(self, info.Weapon, crusher.CenterLocation.ToInt2(), 0);
Combat.DoExplosion(self, info.Weapon, Target.FromActor(crusher), 0);
self.QueueActivity(new RemoveSelf());
}