Water flow logic tweaking:

- Less fluctuation, water doesn't constantly flow back and forth through gaps.
- Flowing water pushes characters around much more heavily, and the force is applied to the collider in addition to the limbs.
- Vertical gaps don't push characters up/down unless the character is roughly above/below the gap.

+ Renamed some fields in the hull and gap classes (Volume -> WaterVolume, FullVolume -> Volume, public fields start with a capital letter)
This commit is contained in:
Joonas Rikkonen
2017-10-10 00:34:54 +03:00
parent c444186426
commit f46dc5da28
26 changed files with 190 additions and 203 deletions
@@ -370,7 +370,7 @@ namespace Barotrauma.Tutorials
(commandDoor1.IsOpen || (commandDoor2.IsOpen || commandDoor3.IsOpen)))
{
//prevent the hull from filling up completely and crushing the player
steering.Item.CurrentHull.Volume = Math.Min(steering.Item.CurrentHull.Volume, steering.Item.CurrentHull.FullVolume * 0.9f);
steering.Item.CurrentHull.WaterVolume = Math.Min(steering.Item.CurrentHull.WaterVolume, steering.Item.CurrentHull.Volume * 0.9f);
yield return CoroutineStatus.Running;
}
@@ -589,7 +589,7 @@ namespace Barotrauma.Tutorials
infoBox = CreateInfoFrame("The pump is up and running. Wait for the water to be drained out.");
while (pump.Item.CurrentHull.Volume > 1000.0f)
while (pump.Item.CurrentHull.WaterVolume > 1000.0f)
{
yield return CoroutineStatus.Running;
}
@@ -79,7 +79,7 @@ namespace Barotrauma.Items.Components
{
waterAmount = hullData != null && hullData.Water != null ?
(float)hullData.Water :
Math.Min(hull.Volume / hull.FullVolume, 1.0f);
Math.Min(hull.WaterVolume / hull.Volume, 1.0f);
if (hullRect.Height * waterAmount > 3.0f)
{
@@ -62,7 +62,7 @@ namespace Barotrauma
//make some of the particles create another firesource when they enter another hull
if (Rand.Int(20) == 1) particle.OnChangeHull = OnChangeHull;
particle.Size *= MathHelper.Clamp(size.X / 60.0f * Math.Max(hull.Oxygen / hull.FullVolume, 0.4f), 0.5f, 1.0f);
particle.Size *= MathHelper.Clamp(size.X / 60.0f * Math.Max(hull.Oxygen / hull.Volume, 0.4f), 0.5f, 1.0f);
if (Rand.Int(5) == 1)
{
@@ -71,7 +71,7 @@ namespace Barotrauma
if (smokeParticle != null)
{
smokeParticle.Size *= MathHelper.Clamp(size.X / 100.0f * Math.Max(hull.Oxygen / hull.FullVolume, 0.4f), 0.5f, 1.0f);
smokeParticle.Size *= MathHelper.Clamp(size.X / 100.0f * Math.Max(hull.Oxygen / hull.Volume, 0.4f), 0.5f, 1.0f);
}
}
}
@@ -32,7 +32,7 @@ namespace Barotrauma
for (int i = 0; i < linkedTo.Count; i++)
{
Vector2 dir = isHorizontal ?
Vector2 dir = IsHorizontal ?
new Vector2(Math.Sign(linkedTo[i].Rect.Center.X - rect.Center.X), 0.0f)
: new Vector2(0.0f, Math.Sign((linkedTo[i].Rect.Y - linkedTo[i].Rect.Height / 2.0f) - (rect.Y - rect.Height / 2.0f)));
@@ -42,7 +42,7 @@ namespace Barotrauma
GUI.Arrow.Draw(sb,
arrowPos, clr * 0.8f,
GUI.Arrow.Origin, MathUtils.VectorToAngle(dir) + MathHelper.PiOver2,
isHorizontal ? new Vector2(rect.Height / 16.0f, 1.0f) : new Vector2(rect.Width / 16.0f, 1.0f),
IsHorizontal ? new Vector2(rect.Height / 16.0f, 1.0f) : new Vector2(rect.Width / 16.0f, 1.0f),
SpriteEffects.None, depth);
}
@@ -66,12 +66,11 @@ namespace Barotrauma
{
if (PlayerInput.LeftButtonHeld())
{
//waveY[GetWaveIndex(position.X - rect.X - Submarine.Position.X) / WaveWidth] = 100.0f;
Volume = Volume + 1500.0f;
WaterVolume += 1500.0f;
}
else if (PlayerInput.RightButtonHeld())
{
Volume = Volume - 1500.0f;
WaterVolume -= 1500.0f;
}
}
}
@@ -209,12 +208,14 @@ namespace Barotrauma
{
GUI.SmallFont.DrawString(spriteBatch, "Pressure: " + ((int)pressure - rect.Y).ToString() +
" - Oxygen: " + ((int)OxygenPercentage), new Vector2(drawRect.X + 5, -drawRect.Y + 5), Color.White);
GUI.SmallFont.DrawString(spriteBatch, volume + " / " + FullVolume, new Vector2(drawRect.X + 5, -drawRect.Y + 20), Color.White);
GUI.SmallFont.DrawString(spriteBatch, waterVolume + " / " + Volume, new Vector2(drawRect.X + 5, -drawRect.Y + 20), Color.White);
foreach (FireSource fs in fireSources)
GUI.DrawRectangle(spriteBatch, new Rectangle(drawRect.Center.X, -drawRect.Y + drawRect.Height / 2, 10, (int)(100 * Math.Min(waterVolume / Volume, 1.0f))), Color.Cyan, true);
if (WaterVolume > Volume)
{
GUI.DrawRectangle(spriteBatch, new Rectangle((int)fs.WorldPosition.X, (int)-fs.WorldPosition.Y, (int)fs.Size.X, (int)fs.Size.Y), Color.Orange, false);
GUI.DrawRectangle(spriteBatch, new Rectangle(drawRect.Center.X, -drawRect.Y + drawRect.Height / 2, 10, (int)(100 * (waterVolume - Volume) / MaxCompress)), Color.Red, true);
}
GUI.DrawRectangle(spriteBatch, new Rectangle(drawRect.Center.X, -drawRect.Y + drawRect.Height / 2, 10, 100), Color.Black);
}
if ((IsSelected || isHighlighted) && editing)
@@ -229,9 +229,9 @@ namespace Barotrauma.Particles
bool gapFound = false;
foreach (Gap gap in hullGaps)
{
if (gap.isHorizontal != (collisionNormal.X != 0.0f)) continue;
if (gap.IsHorizontal != (collisionNormal.X != 0.0f)) continue;
if (gap.isHorizontal)
if (gap.IsHorizontal)
{
if (gap.WorldRect.Y < position.Y || gap.WorldRect.Y - gap.WorldRect.Height > position.Y) continue;
int gapDir = Math.Sign(gap.WorldRect.Center.X - currentHull.WorldRect.Center.X);
@@ -69,9 +69,7 @@ namespace Barotrauma
private string GetTotalHullVolume()
{
float totalVol = 0.0f;
Hull.hullList.ForEach(h => { totalVol += h.FullVolume; });
return "Total Hull Volume:\n" + totalVol;
return "Total Hull Volume:\n" + Hull.hullList.Sum(h => h.Volume);
}
private string GetSelectedHullVolume()
@@ -79,16 +77,17 @@ namespace Barotrauma
float buoyancyVol = 0.0f;
float selectedVol = 0.0f;
float neutralPercentage = 0.07f;
Hull.hullList.ForEach(h => {
buoyancyVol += h.FullVolume;
Hull.hullList.ForEach(h =>
{
buoyancyVol += h.Volume;
if (h.IsSelected)
{
selectedVol += h.FullVolume;
selectedVol += h.Volume;
}
});
buoyancyVol *= neutralPercentage;
string retVal = "Selected Hull Volume:\n" + selectedVol;
if (selectedVol>0.0f && buoyancyVol>0.0f)
if (selectedVol > 0.0f && buoyancyVol > 0.0f)
{
if (buoyancyVol / selectedVol < 1.0f)
{
@@ -396,8 +396,8 @@ namespace Barotrauma
foreach (Hull hull in Hull.hullList)
{
if (hull.Submarine != targetSubmarine) continue;
floodedArea += hull.Volume;
totalArea += hull.FullVolume;
floodedArea += hull.WaterVolume;
totalArea += hull.Volume;
}
if (totalArea > 0.0f && floodedArea / totalArea > 0.25f) return "repair";