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

@@ -11,6 +11,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using OpenRA.Effects; using OpenRA.Effects;
using OpenRA.FileFormats; using OpenRA.FileFormats;
using OpenRA.Traits;
namespace OpenRA.GameRules namespace OpenRA.GameRules
{ {
@@ -55,7 +56,7 @@ namespace OpenRA.GameRules
public int2 src; public int2 src;
public int srcAltitude; public int srcAltitude;
public int facing; public int facing;
public Actor target; public Target target;
public int2 dest; public int2 dest;
public int destAltitude; public int destAltitude;
} }

View File

@@ -36,11 +36,10 @@ namespace OpenRA.Mods.Aftermath
var unit = self.traits.GetOrDefault<Unit>(); var unit = self.traits.GetOrDefault<Unit>();
var info = self.Info.Traits.Get<AttackBaseInfo>(); var info = self.Info.Traits.Get<AttackBaseInfo>();
var altitude = unit != null ? unit.Altitude : 0; var altitude = unit != null ? unit.Altitude : 0;
int2 detonateLocation = self.CenterLocation.ToInt2();
self.World.AddFrameEndTask( w => self.World.AddFrameEndTask( w =>
{ {
Combat.DoExplosion(self, info.PrimaryWeapon, detonateLocation, altitude); Combat.DoExplosion(self, info.PrimaryWeapon, Target.FromActor(self), altitude);
var report = self.GetPrimaryWeapon().Report; var report = self.GetPrimaryWeapon().Report;
if (report != null) if (report != null)
Sound.Play(report + ".aud", self.CenterLocation); Sound.Play(report + ".aud", self.CenterLocation);

View File

@@ -18,14 +18,14 @@ namespace OpenRA.Mods.Cnc.Effects
{ {
class IonCannon : IEffect class IonCannon : IEffect
{ {
int2 Target; Target target;
Animation anim; Animation anim;
Actor firedBy; Actor firedBy;
public IonCannon(Actor firedBy, World world, int2 location) public IonCannon(Actor firedBy, World world, int2 location)
{ {
this.firedBy = firedBy; this.firedBy = firedBy;
Target = location; target = Target.FromPos(OpenRA.Traits.Util.CenterOfCell(location));
anim = new Animation("ionsfx"); anim = new Animation("ionsfx");
anim.PlayThen("idle", () => Finish(world)); anim.PlayThen("idle", () => Finish(world));
} }
@@ -35,14 +35,14 @@ namespace OpenRA.Mods.Cnc.Effects
public IEnumerable<Renderable> Render() public IEnumerable<Renderable> Render()
{ {
yield return new Renderable(anim.Image, yield return new Renderable(anim.Image,
Traits.Util.CenterOfCell(Target) - new float2(.5f * anim.Image.size.X, anim.Image.size.Y - Game.CellSize), target.CenterLocation - new float2(.5f * anim.Image.size.X, anim.Image.size.Y - Game.CellSize),
"effect"); "effect");
} }
void Finish( World world ) void Finish( World world )
{ {
world.AddFrameEndTask(w => w.Remove(this)); world.AddFrameEndTask(w => w.Remove(this));
Combat.DoExplosion(firedBy, "IonCannon", Target, 0); Combat.DoExplosion(firedBy, "IonCannon", target, 0);
} }
} }
} }

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Cnc
destAltitude = 0, destAltitude = 0,
facing = 0, facing = 0,
firedBy = self, firedBy = self,
target = self, target = Target.FromActor(self),
weapon = Rules.Weapons[info.Weapon.ToLowerInvariant()] weapon = Rules.Weapons[info.Weapon.ToLowerInvariant()]
}); });

View File

@@ -30,7 +30,8 @@ namespace OpenRA.Mods.RA
if (self.GetCurrentActivity() is Leap) return; if (self.GetCurrentActivity() is Leap) return;
var weapon = self.GetPrimaryWeapon(); 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.CancelActivity();
self.QueueActivity(new Leap(self, target)); 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 var args = new ProjectileArgs
{ {
src = location, src = Util.CellContaining(_target.CenterLocation),
dest = location, dest = Util.CellContaining(_target.CenterLocation),
srcAltitude = altitude, srcAltitude = altitude,
destAltitude = altitude, destAltitude = altitude,
firedBy = attacker, firedBy = attacker,
target = null, target = _target,
weapon = Rules.Weapons[ weapontype.ToLowerInvariant() ], weapon = Rules.Weapons[ weapontype.ToLowerInvariant() ],
facing = 0 facing = 0
}; };

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA
public override void Activate(Actor collector) 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); base.Activate(collector);
} }
} }

View File

@@ -75,8 +75,9 @@ namespace OpenRA.Mods.RA.Effects
var targetPosition = Args.target.CenterLocation + offset; var targetPosition = Args.target.CenterLocation + offset;
var targetUnit = Args.target.traits.GetOrDefault<Unit>(); var targetAltitude = 0;
var targetAltitude = targetUnit != null ? targetUnit.Altitude : 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); Altitude += Math.Sign(targetAltitude - Altitude);
Traits.Util.TickFacing(ref Facing, Traits.Util.TickFacing(ref Facing,
@@ -86,7 +87,7 @@ namespace OpenRA.Mods.RA.Effects
anim.Tick(); anim.Tick();
var dist = targetPosition - Pos; var dist = targetPosition - Pos;
if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough || Args.target.IsDead) if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough || !Args.target.IsValid )
Explode(world); Explode(world);
var speed = Scale * Info.Speed * ((targetAltitude > 0 && Info.TurboBoost) ? 1.5f : 1f); 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) void Explode(World world)
{ {
world.AddFrameEndTask(w => w.Remove(this)); 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); 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 unit = self.traits.GetOrDefault<Unit>();
var altitude = unit != null ? unit.Altitude : 0; var altitude = unit != null ? unit.Altitude : 0;
Combat.DoExplosion(e.Attacker, weapon, Combat.DoExplosion(e.Attacker, weapon, Target.FromActor(self), altitude);
self.CenterLocation.ToInt2(), altitude);
} }
} }
} }

View File

@@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA
return; return;
var info = self.Info.Traits.Get<MineInfo>(); 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()); self.QueueActivity(new RemoveSelf());
} }