From 6594a169d83db59cc374144412cb43c572c3e18e Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sun, 6 Dec 2009 20:00:04 +1300 Subject: [PATCH] factoring various junk out of Bullet.Tick in prep for homing bullets --- OpenRa.Game/Bullet.cs | 70 +++++++++++++++++-------------------------- OpenRa.Game/Smudge.cs | 17 +++++++++++ 2 files changed, 45 insertions(+), 42 deletions(-) diff --git a/OpenRa.Game/Bullet.cs b/OpenRa.Game/Bullet.cs index 2b93c522a0..f3827a7bce 100644 --- a/OpenRa.Game/Bullet.cs +++ b/OpenRa.Game/Bullet.cs @@ -60,51 +60,37 @@ namespace OpenRa.Game if (t > TotalTime()) /* remove finished bullets */ { - Game.world.AddFrameEndTask(w => - { - w.Remove(this); - - var targetTile = ((1f / Game.CellSize) * Dest.ToFloat2()).ToInt2(); - - var isWater = Game.IsWater(targetTile); - var hitWater = Game.IsCellBuildable(targetTile, UnitMovementType.Float); - - if (Warhead.Explosion != 0) - w.Add(new Explosion(VisualDest, Warhead.Explosion, hitWater)); - - var impact = Warhead.ImpactSound; - if (hitWater && Warhead.WaterImpactSound != null) - impact = Warhead.WaterImpactSound; - - if (impact != null) - Sound.Play(impact+ ".aud"); - - if (!isWater) - switch( Warhead.Explosion ) /* todo: push the scorch/crater behavior into data */ - { - case 4: - case 5: - Smudge.AddSmudge(true, targetTile.X, targetTile.Y); - break; - - case 3: - case 6: - Smudge.AddSmudge(false, targetTile.X, targetTile.Y); - break; - } - - if (Warhead.Ore) - Ore.Destroy(targetTile.X, targetTile.Y); - }); - - var maxSpread = GetMaximumSpread(); - var hitActors = Game.FindUnitsInCircle(Dest, GetMaximumSpread()); - - foreach (var victim in hitActors) - victim.InflictDamage(FiredBy, this, (int)GetDamageToInflict(victim)); + Game.world.AddFrameEndTask(w => w.Remove(this)); + DoImpact(); } } + void DoImpact() + { + var targetTile = ((1f / Game.CellSize) * Dest.ToFloat2()).ToInt2(); + + var isWater = Game.IsWater(targetTile); + var hitWater = Game.IsCellBuildable(targetTile, UnitMovementType.Float); + + if (Warhead.Explosion != 0) + Game.world.AddFrameEndTask( + w => w.Add(new Explosion(VisualDest, Warhead.Explosion, hitWater))); + + var impactSound = Warhead.ImpactSound; + if (hitWater && Warhead.WaterImpactSound != null) + impactSound = Warhead.WaterImpactSound; + if (impactSound != null) Sound.Play(impactSound + ".aud"); + + if (!isWater) Smudge.AddSmudge(targetTile, Warhead); + if (Warhead.Ore) Ore.Destroy(targetTile.X, targetTile.Y); + + var maxSpread = GetMaximumSpread(); + var hitActors = Game.FindUnitsInCircle(Dest, GetMaximumSpread()); + + foreach (var victim in hitActors) + victim.InflictDamage(FiredBy, this, (int)GetDamageToInflict(victim)); + } + const float height = .1f; public IEnumerable> Render() diff --git a/OpenRa.Game/Smudge.cs b/OpenRa.Game/Smudge.cs index cebd3c2c47..ae76b4ab47 100644 --- a/OpenRa.Game/Smudge.cs +++ b/OpenRa.Game/Smudge.cs @@ -1,4 +1,5 @@  +using OpenRa.Game.GameRules; namespace OpenRa.Game { static class Smudge @@ -23,6 +24,22 @@ namespace OpenRa.Game Rules.Map.MapTiles[x, y].smudge++; } + public static void AddSmudge(int2 targetTile, WarheadInfo warhead) + { + switch (warhead.Explosion) /* todo: push the scorch/crater behavior into data */ + { + case 4: + case 5: + Smudge.AddSmudge(true, targetTile.X, targetTile.Y); + break; + + case 3: + case 6: + Smudge.AddSmudge(false, targetTile.X, targetTile.Y); + break; + } + } + static int lastSmudge = 0; static int ChooseSmudge() { lastSmudge = (lastSmudge + 1) % 6; return lastSmudge; } }