From bb17463aae632a3a1ed9c8b577203f5647c21b40 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Wed, 27 Mar 2019 11:30:33 +0200 Subject: [PATCH] (f5be65240) Optimized explosions a bit, toned down wall damage effect when the wall has a small amount of damage. --- .../BarotraumaClient/Source/Map/Structure.cs | 3 +- .../BarotraumaShared/Source/Map/Explosion.cs | 28 ++++++++++++++----- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Map/Structure.cs b/Barotrauma/BarotraumaClient/Source/Map/Structure.cs index 7631b14c5..8adc0b920 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Structure.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Structure.cs @@ -292,8 +292,7 @@ namespace Barotrauma { if (damageEffect != null) { - float newCutoff = Sections[i].damage > 0 ? - MathHelper.Lerp(0.2f, 0.65f, Sections[i].damage / Prefab.Health) : 0.0f; + float newCutoff = MathHelper.Lerp(0.0f, 0.65f, Sections[i].damage / Prefab.Health); if (Math.Abs(newCutoff - Submarine.DamageEffectCutoff) > 0.01f || color != Submarine.DamageEffectColor) { diff --git a/Barotrauma/BarotraumaShared/Source/Map/Explosion.cs b/Barotrauma/BarotraumaShared/Source/Map/Explosion.cs index 3d7798b96..72dab9b50 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Explosion.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Explosion.cs @@ -28,8 +28,10 @@ namespace Barotrauma public Explosion(float range, float force, float damage, float structureDamage, float empStrength = 0.0f) { - attack = new Attack(damage, 0.0f, 0.0f, structureDamage, range); - attack.SeverLimbsProbability = 1.0f; + attack = new Attack(damage, 0.0f, 0.0f, structureDamage, range) + { + SeverLimbsProbability = 1.0f + }; this.force = force; this.empStrength = empStrength; sparks = true; @@ -165,10 +167,23 @@ namespace Barotrauma { if (attack.Range <= 0.0f) return; + //long range for the broad distance check, because large characters may still be in range even if their collider isn't + float broadRange = Math.Max(attack.Range * 10.0f, 10000.0f); + foreach (Character c in Character.CharacterList) { + if (!c.Enabled || + Math.Abs(c.WorldPosition.X - worldPosition.X) > broadRange || + Math.Abs(c.WorldPosition.Y - worldPosition.Y) > broadRange) + { + continue; + } + Vector2 explosionPos = worldPosition; - if (c.Submarine != null) explosionPos -= c.Submarine.Position; + if (c.Submarine != null) { explosionPos -= c.Submarine.Position; } + + Hull hull = Hull.FindHull(ConvertUnits.ToDisplayUnits(explosionPos), null, false); + bool underWater = hull == null || explosionPos.Y < hull.Surface; Hull hull = Hull.FindHull(ConvertUnits.ToDisplayUnits(explosionPos), null, false); bool underWater = hull == null || explosionPos.Y < hull.Surface; @@ -184,8 +199,8 @@ namespace Barotrauma //doesn't take the rotation of the limb into account, but should be accurate enough for this purpose float limbRadius = Math.Max(Math.Max(limb.body.width * 0.5f, limb.body.height * 0.5f), limb.body.radius); dist = Math.Max(0.0f, dist - FarseerPhysics.ConvertUnits.ToDisplayUnits(limbRadius)); - - if (dist > attack.Range) continue; + + if (dist > attack.Range) { continue; } float distFactor = 1.0f - dist / attack.Range; @@ -259,8 +274,7 @@ namespace Barotrauma float dist = 600.0f; foreach (MapEntity entity in MapEntity.mapEntityList) { - Structure structure = entity as Structure; - if (structure == null) continue; + if (!(entity is Structure structure)) { continue; } if (structure.HasBody && !structure.IsPlatform &&