From 0b603ba10b7ffdfba5e7eda8da7a122dde3a8d90 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Tue, 5 Dec 2017 22:30:24 +0200 Subject: [PATCH] Fixed particles in water being drawn under ruin structures (making it seem like plasma cutters aren't working), fixed all structures having the default health of 100 because of mismatching parameter name (Health vs MaxHealth) --- .../BarotraumaClient/Source/Map/Structure.cs | 2 +- .../Source/Screens/GameScreen.cs | 80 +++++++------------ .../BarotraumaShared/Source/Map/Structure.cs | 12 +-- .../Source/Map/StructurePrefab.cs | 8 +- 4 files changed, 40 insertions(+), 62 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Map/Structure.cs b/Barotrauma/BarotraumaClient/Source/Map/Structure.cs index fa02a23be..5f7989073 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Structure.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Structure.cs @@ -147,7 +147,7 @@ namespace Barotrauma { if (damageEffect != null) { - float newCutoff = Math.Min((sections[i].damage / prefab.MaxHealth), 0.65f); + float newCutoff = Math.Min((sections[i].damage / prefab.Health), 0.65f); if (Math.Abs(newCutoff - Submarine.DamageEffectCutoff) > 0.01f) { diff --git a/Barotrauma/BarotraumaClient/Source/Screens/GameScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/GameScreen.cs index 3499f9589..eb1e61524 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/GameScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/GameScreen.cs @@ -128,34 +128,28 @@ namespace Barotrauma Level.Loaded.DrawBack(graphics, spriteBatch, cam); } + //draw structures that are in water and not part of any sub (e.g. ruins) + spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, cam.Transform); + Submarine.DrawBack(spriteBatch, false, s => s is Structure && s.Submarine == null); + spriteBatch.End(); + + //draw alpha blended particles that are in water and behind subs #if LINUX - spriteBatch.Begin(SpriteSortMode.Deferred, - BlendState.NonPremultiplied, - null, DepthStencilState.DepthRead, null, null, - cam.Transform); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, DepthStencilState.DepthRead, null, null, cam.Transform); #else - spriteBatch.Begin(SpriteSortMode.Deferred, - BlendState.AlphaBlend, - null, DepthStencilState.DepthRead, null, null, - cam.Transform); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, DepthStencilState.DepthRead, null, null, cam.Transform); #endif GameMain.ParticleManager.Draw(spriteBatch, true, false, Particles.ParticleBlendState.AlphaBlend); spriteBatch.End(); - spriteBatch.Begin(SpriteSortMode.Deferred, - BlendState.Additive, - null, DepthStencilState.Default, null, null, - cam.Transform); + //draw additive particles that are in water and behind subs + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, null, DepthStencilState.Default, null, null, cam.Transform); GameMain.ParticleManager.Draw(spriteBatch, true, false, Particles.ParticleBlendState.Additive); spriteBatch.End(); - - spriteBatch.Begin(SpriteSortMode.BackToFront, - BlendState.AlphaBlend, - null, null, null, null, - cam.Transform); - - Submarine.DrawBack(spriteBatch, false, s => s is Structure); - + + //draw submarine structures that are behind water + spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, cam.Transform); + Submarine.DrawBack(spriteBatch, false, s => s is Structure && s.Submarine != null); spriteBatch.End(); graphics.SetRenderTarget(renderTarget); @@ -180,29 +174,21 @@ namespace Barotrauma //draw the rendertarget and particles that are only supposed to be drawn in water into renderTargetWater graphics.SetRenderTarget(renderTargetWater); - spriteBatch.Begin(SpriteSortMode.Deferred, - BlendState.Opaque); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque); spriteBatch.Draw(renderTarget, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), waterColor); spriteBatch.End(); + //draw alpha blended particles that are inside a sub #if LINUX - spriteBatch.Begin(SpriteSortMode.Deferred, - BlendState.NonPremultiplied, - null, DepthStencilState.DepthRead, null, null, - cam.Transform); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, DepthStencilState.DepthRead, null, null, cam.Transform); #else - spriteBatch.Begin(SpriteSortMode.Deferred, - BlendState.AlphaBlend, - null, DepthStencilState.DepthRead, null, null, - cam.Transform); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, DepthStencilState.DepthRead, null, null, cam.Transform); #endif GameMain.ParticleManager.Draw(spriteBatch, true, true, Particles.ParticleBlendState.AlphaBlend); spriteBatch.End(); - spriteBatch.Begin(SpriteSortMode.Deferred, - BlendState.Additive, - null, DepthStencilState.Default, null, null, - cam.Transform); + //draw additive particles that are inside a sub + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, null, DepthStencilState.Default, null, null, cam.Transform); GameMain.ParticleManager.Draw(spriteBatch, true, true, Particles.ParticleBlendState.Additive); spriteBatch.End(); @@ -210,29 +196,21 @@ namespace Barotrauma //draw the rendertarget and particles that are only supposed to be drawn in air into renderTargetAir graphics.SetRenderTarget(renderTargetAir); - spriteBatch.Begin(SpriteSortMode.Deferred, - BlendState.Opaque); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque); spriteBatch.Draw(renderTarget, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White); spriteBatch.End(); -#if LINUX - spriteBatch.Begin(SpriteSortMode.Deferred, - BlendState.NonPremultiplied, - null, DepthStencilState.DepthRead, null, null, - cam.Transform); -#else - spriteBatch.Begin(SpriteSortMode.Deferred, - BlendState.AlphaBlend, - null, DepthStencilState.DepthRead, null, null, - cam.Transform); -#endif + //draw alpha blended particles that are not in water +#if LINUX + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, DepthStencilState.DepthRead, null, null, cam.Transform); +#else + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, DepthStencilState.DepthRead, null, null, cam.Transform); +#endif GameMain.ParticleManager.Draw(spriteBatch, false, null, Particles.ParticleBlendState.AlphaBlend); spriteBatch.End(); - spriteBatch.Begin(SpriteSortMode.Deferred, - BlendState.Additive, - null, DepthStencilState.DepthRead, null, null, - cam.Transform); + //draw additive particles that are not in water + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, null, DepthStencilState.DepthRead, null, null, cam.Transform); GameMain.ParticleManager.Draw(spriteBatch, false, null, Particles.ParticleBlendState.Additive); spriteBatch.End(); diff --git a/Barotrauma/BarotraumaShared/Source/Map/Structure.cs b/Barotrauma/BarotraumaShared/Source/Map/Structure.cs index eef7eccd7..c7501b38d 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Structure.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Structure.cs @@ -106,7 +106,7 @@ namespace Barotrauma public float Health { - get { return prefab.MaxHealth; } + get { return prefab.Health; } } public override bool DrawBelowWater @@ -535,7 +535,7 @@ namespace Barotrauma { if (sectionIndex < 0 || sectionIndex >= sections.Length) return false; - return (sections[sectionIndex].damage>=prefab.MaxHealth); + return (sections[sectionIndex].damage>=prefab.Health); } /// @@ -545,7 +545,7 @@ namespace Barotrauma { if (sectionIndex < 0 || sectionIndex >= sections.Length) return false; - return (sections[sectionIndex].damage >= prefab.MaxHealth*0.5f); + return (sections[sectionIndex].damage >= prefab.Health*0.5f); } public int SectionLength(int sectionIndex) @@ -686,7 +686,7 @@ namespace Barotrauma } AdjustKarma(attacker, damageDiff); - if (damage < prefab.MaxHealth*0.5f) + if (damage < prefab.Health*0.5f) { if (sections[sectionIndex].gap != null) { @@ -715,11 +715,11 @@ namespace Barotrauma #endif } - sections[sectionIndex].gap.Open = (damage / prefab.MaxHealth - 0.5f) * 2.0f; + sections[sectionIndex].gap.Open = (damage / prefab.Health - 0.5f) * 2.0f; } bool hadHole = SectionBodyDisabled(sectionIndex); - sections[sectionIndex].damage = MathHelper.Clamp(damage, 0.0f, prefab.MaxHealth); + sections[sectionIndex].damage = MathHelper.Clamp(damage, 0.0f, prefab.Health); bool hasHole = SectionBodyDisabled(sectionIndex); diff --git a/Barotrauma/BarotraumaShared/Source/Map/StructurePrefab.cs b/Barotrauma/BarotraumaShared/Source/Map/StructurePrefab.cs index 5f6b28715..cdd954390 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/StructurePrefab.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/StructurePrefab.cs @@ -10,7 +10,7 @@ namespace Barotrauma { private bool canSpriteFlipX; - private float maxHealth; + private float health; //default size private Vector2 size; @@ -31,10 +31,10 @@ namespace Barotrauma } [Serialize(100.0f, false)] - public float MaxHealth + public float Health { - get { return maxHealth; } - set { maxHealth = Math.Max(value, 0.0f); } + get { return health; } + set { health = Math.Max(value, 0.0f); } } [Serialize(false, false)]