From 11121baf23b07ff8885ce8d7526f17cdbbe0b879 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Thu, 1 Apr 2010 18:06:58 +1300 Subject: [PATCH] bullet/lobbed sortof work now --- OpenRA.Game/Effects/Bullet.cs | 80 ++++++++------------- OpenRA.Game/Traits/Explodes.cs | 9 +-- OpenRA.Mods.Aftermath/DemoTruck.cs | 4 +- OpenRA.Mods.RA/Crates/ExplodeCrateAction.cs | 8 +-- 4 files changed, 42 insertions(+), 59 deletions(-) diff --git a/OpenRA.Game/Effects/Bullet.cs b/OpenRA.Game/Effects/Bullet.cs index c66d998f38..a0d6851cc4 100755 --- a/OpenRA.Game/Effects/Bullet.cs +++ b/OpenRA.Game/Effects/Bullet.cs @@ -25,7 +25,7 @@ using OpenRA.Traits; namespace OpenRA.Effects { - class BulletInfo : IProjectileInfo + public class BulletInfo : IProjectileInfo { public readonly int Speed = 1; public readonly bool AA = false; @@ -42,56 +42,37 @@ namespace OpenRA.Effects public readonly bool Shadow = false; public readonly bool Proximity = false; - public IEffect Create(ProjectileArgs args) { return null; } + public IEffect Create(ProjectileArgs args) { return new Bullet( this, args ); } } public class Bullet : IEffect { - readonly Player Owner; - readonly Actor FiredBy; - readonly WeaponInfo Weapon; - readonly ProjectileInfo Projectile; - readonly WarheadInfo Warhead; - readonly int2 Src; - readonly int2 Dest; + readonly BulletInfo Info; + readonly ProjectileArgs Args; readonly int2 VisualDest; - readonly int SrcAltitude; - readonly int DestAltitude; - + int t = 0; Animation anim; const int BaseBulletSpeed = 100; /* pixels / 40ms frame */ - public Bullet(string weapon, Player owner, Actor firedBy, - int2 src, int2 dest, int srcAltitude, int destAltitude) - : this(Rules.WeaponInfo[weapon], owner, firedBy, src, dest, srcAltitude, destAltitude) { } - - /* src, dest are *pixel* coords */ - public Bullet(WeaponInfo weapon, Player owner, Actor firedBy, - int2 src, int2 dest, int srcAltitude, int destAltitude) + public Bullet(BulletInfo info, ProjectileArgs args) { - Owner = owner; - FiredBy = firedBy; - Src = src; - Dest = dest; - SrcAltitude = srcAltitude; - DestAltitude = destAltitude; - VisualDest = Dest + new int2( - firedBy.World.CosmeticRandom.Next(-10, 10), - firedBy.World.CosmeticRandom.Next(-10, 10)); - Weapon = weapon; - Projectile = Rules.ProjectileInfo[Weapon.Projectile]; - Warhead = Rules.WarheadInfo[Weapon.Warhead]; + Info = info; + Args = args; - if (Projectile.Image != null && Projectile.Image != "none") + VisualDest = args.dest + new int2( + args.firedBy.World.CosmeticRandom.Next(-10, 10), + args.firedBy.World.CosmeticRandom.Next(-10, 10)); + + if (Info.Image != null) { - anim = new Animation(Projectile.Image, () => Traits.Util.GetFacing((dest - src).ToFloat2(), 0)); + anim = new Animation(Info.Image, () => Traits.Util.GetFacing(Args.dest - Args.src, 0)); anim.PlayRepeating("idle"); } } - int TotalTime() { return (Dest - Src).Length * BaseBulletSpeed / Weapon.Speed; } + int TotalTime() { return (Args.dest - Args.src).Length * BaseBulletSpeed / Info.Speed; } public void Tick( World world ) { @@ -100,23 +81,23 @@ namespace OpenRA.Effects if (t > TotalTime()) /* remove finished bullets */ { world.AddFrameEndTask(w => w.Remove(this)); - Combat.DoImpact(Dest, VisualDest - new int2( 0, DestAltitude ), - Weapon, Projectile, Warhead, FiredBy); + //Combat.DoImpact(Args.dest, VisualDest - new int2( 0, Args.destAltitude ), + // Weapon, Projectile, Warhead, FiredBy); } - if (Projectile.Trail != null) + if (Info.Trail != null) { var at = (float)t / TotalTime(); - var altitude = float2.Lerp(SrcAltitude, DestAltitude, at); - var pos = float2.Lerp(Src.ToFloat2(), VisualDest.ToFloat2(), at) + var altitude = float2.Lerp(Args.srcAltitude, Args.destAltitude, at); + var pos = float2.Lerp(Args.src, VisualDest, at) - 0.5f * anim.Image.size - new float2(0, altitude); - var highPos = (Projectile.High || Projectile.Arcing) - ? (pos - new float2(0, (VisualDest - Src).Length * height * 4 * at * (1 - at))) + var highPos = (Info.High || Info.Arcing) + ? (pos - new float2(0, (VisualDest - Args.src).Length * height * 4 * at * (1 - at))) : pos; world.AddFrameEndTask(w => w.Add( - new Smoke(w, highPos.ToInt2(), Projectile.Trail))); + new Smoke(w, highPos.ToInt2(), Info.Trail))); } } @@ -128,21 +109,22 @@ namespace OpenRA.Effects { var at = (float)t / TotalTime(); - var altitude = float2.Lerp(SrcAltitude, DestAltitude, at); - var pos = float2.Lerp( Src.ToFloat2(), VisualDest.ToFloat2(), at) + var altitude = float2.Lerp(Args.srcAltitude, Args.destAltitude, at); + var pos = float2.Lerp( Args.src, VisualDest, at) - 0.5f * anim.Image.size - new float2( 0, altitude ); - if (Projectile.High || Projectile.Arcing) + if (Info.High || Info.Arcing) { - if (Projectile.Shadow) + if (Info.Shadow) yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, "shadow"); - var highPos = pos - new float2(0, (VisualDest - Src).Length * height * 4 * at * (1 - at)); + var highPos = pos - new float2(0, (VisualDest - Args.src).Length * height * 4 * at * (1 - at)); - yield return new Renderable(anim.Image, highPos - .5f * anim.Image.size, Owner.Palette); + yield return new Renderable(anim.Image, highPos - .5f * anim.Image.size, Args.firedBy.Owner.Palette); } else - yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, Projectile.UnderWater ? "shadow" : Owner.Palette); + yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, + Info.UnderWater ? "shadow" : Args.firedBy.Owner.Palette); } } } diff --git a/OpenRA.Game/Traits/Explodes.cs b/OpenRA.Game/Traits/Explodes.cs index 061ba4d82d..9243389881 100644 --- a/OpenRA.Game/Traits/Explodes.cs +++ b/OpenRA.Game/Traits/Explodes.cs @@ -33,10 +33,11 @@ namespace OpenRA.Traits var unit = self.traits.GetOrDefault(); var altitude = unit != null ? unit.Altitude : 0; - self.World.AddFrameEndTask( - w => w.Add(new Bullet("UnitExplode", e.Attacker.Owner, e.Attacker, - self.CenterLocation.ToInt2(), self.CenterLocation.ToInt2(), - altitude, altitude))); +// self.World.AddFrameEndTask( +// w => w.Add(new Bullet( +// "UnitExplode", e.Attacker.Owner, e.Attacker, +// self.CenterLocation.ToInt2(), self.CenterLocation.ToInt2(), +// altitude, altitude))); } } } diff --git a/OpenRA.Mods.Aftermath/DemoTruck.cs b/OpenRA.Mods.Aftermath/DemoTruck.cs index d4876dbad5..4c994911bd 100644 --- a/OpenRA.Mods.Aftermath/DemoTruck.cs +++ b/OpenRA.Mods.Aftermath/DemoTruck.cs @@ -56,8 +56,8 @@ namespace OpenRA.Mods.Aftermath self.World.AddFrameEndTask( w => { // Fire weapon - w.Add(new Bullet(info.PrimaryWeapon, detonatedBy.Owner, detonatedBy, - detonateLocation, detonateLocation, altitude, altitude)); + //w.Add(new Bullet(info.PrimaryWeapon, detonatedBy.Owner, detonatedBy, + // detonateLocation, detonateLocation, altitude, altitude)); var weapon = Rules.WeaponInfo[info.PrimaryWeapon]; if (!string.IsNullOrEmpty(weapon.Report)) diff --git a/OpenRA.Mods.RA/Crates/ExplodeCrateAction.cs b/OpenRA.Mods.RA/Crates/ExplodeCrateAction.cs index 7037290bc1..721b95efb9 100644 --- a/OpenRA.Mods.RA/Crates/ExplodeCrateAction.cs +++ b/OpenRA.Mods.RA/Crates/ExplodeCrateAction.cs @@ -20,10 +20,10 @@ namespace OpenRA.Mods.RA public override void Activate(Actor collector) { - self.World.AddFrameEndTask( - w => w.Add(new Bullet((info as ExplodeCrateActionInfo).Weapon, self.Owner, - self, self.CenterLocation.ToInt2(), self.CenterLocation.ToInt2(), - 0, 0))); + //self.World.AddFrameEndTask( + // w => w.Add(new Bullet((info as ExplodeCrateActionInfo).Weapon, self.Owner, + // self, self.CenterLocation.ToInt2(), self.CenterLocation.ToInt2(), + // 0, 0))); base.Activate(collector); } }