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

View File

@@ -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;
}

View File

@@ -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)
{

View File

@@ -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);
}
}
}

View File

@@ -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);
}

View File

@@ -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)

View File

@@ -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);

View File

@@ -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)
{

View File

@@ -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";

View File

@@ -106,7 +106,7 @@ namespace Barotrauma
//suit can be taken off if there character is inside a hull and there's air in the room
bool canTakeOffSuit = Character.AnimController.CurrentHull != null &&
Character.AnimController.CurrentHull.OxygenPercentage > 30.0f &&
Character.AnimController.CurrentHull.Volume < Character.AnimController.CurrentHull.FullVolume * 0.3f;
Character.AnimController.CurrentHull.WaterVolume < Character.AnimController.CurrentHull.Volume * 0.3f;
//the suit can be taken off and the character is running out of oxygen (couldn't find a tank for the suit?) or idling
//-> take the suit off

View File

@@ -215,7 +215,7 @@ namespace Barotrauma
bool shouldBeOpen = false;
if (door.LinkedGap.isHorizontal)
if (door.LinkedGap.IsHorizontal)
{
int currentDir = Math.Sign(nextNode.WorldPosition.X - door.Item.WorldPosition.X);
@@ -291,7 +291,7 @@ namespace Barotrauma
}
}
if (node.Waypoint!=null && node.Waypoint.CurrentHull!=null)
if (node.Waypoint != null && node.Waypoint.CurrentHull != null)
{
var hull = node.Waypoint.CurrentHull;
@@ -303,8 +303,8 @@ namespace Barotrauma
}
}
if (character.NeedsAir && hull.Volume / hull.Rect.Width > 100.0f) penalty += 500.0f;
if (character.PressureProtection < 10.0f && hull.Volume > hull.FullVolume) penalty += 1000.0f;
if (character.NeedsAir && hull.WaterVolume / hull.Rect.Width > 100.0f) penalty += 500.0f;
if (character.PressureProtection < 10.0f && hull.WaterVolume > hull.Volume) penalty += 1000.0f;
}
return penalty;

View File

@@ -137,7 +137,7 @@ namespace Barotrauma
if (currentHull == null) return true;
//there's lots of water in the room -> get a suit
if (currentHull.Volume / currentHull.FullVolume > 0.5f) return true;
if (currentHull.WaterVolume / currentHull.Volume > 0.5f) return true;
if (currentHull.OxygenPercentage < 30.0f) return true;
@@ -185,7 +185,7 @@ namespace Barotrauma
{
if (hull == null) return 0.0f;
float waterPercentage = (hull.Volume / hull.FullVolume) * 100.0f;
float waterPercentage = (hull.WaterVolume / hull.Volume) * 100.0f;
float fireAmount = 0.0f;
var nearbyHulls = hull.GetConnectedHulls(3);

View File

@@ -24,7 +24,7 @@ namespace Barotrauma
{
if (leak.Open == 0.0f) return 0.0f;
float leakSize = (leak.isHorizontal ? leak.Rect.Height : leak.Rect.Width) * Math.Max(leak.Open, 0.1f);
float leakSize = (leak.IsHorizontal ? leak.Rect.Height : leak.Rect.Width) * Math.Max(leak.Open, 0.1f);
float dist = Vector2.DistanceSquared(character.SimPosition, leak.SimPosition);
dist = Math.Max(dist/100.0f, 1.0f);
@@ -80,7 +80,7 @@ namespace Barotrauma
if (hull == null) return standPos;
if (leak.isHorizontal)
if (leak.IsHorizontal)
{
standPos += Vector2.UnitX * Math.Sign(hull.Position.X - leak.Position.X) * leak.Rect.Width;
}

View File

@@ -81,7 +81,7 @@ namespace Barotrauma
if (gap == null) return 0.0f;
//larger gap -> higher priority
float gapPriority = (gap.isHorizontal ? gap.Rect.Width : gap.Rect.Height) * gap.Open;
float gapPriority = (gap.IsHorizontal ? gap.Rect.Width : gap.Rect.Height) * gap.Open;
//prioritize gaps that are close
gapPriority /= Math.Max(Vector2.Distance(character.WorldPosition, gap.WorldPosition), 1.0f);

View File

@@ -132,7 +132,7 @@ namespace Barotrauma
{
List<Hull> targetHulls = new List<Hull>(Hull.hullList);
//ignore all hulls with fires or water in them
targetHulls.RemoveAll(h => h.FireSources.Any() || (h.Volume/h.FullVolume)>0.1f);
targetHulls.RemoveAll(h => h.FireSources.Any() || h.WaterVolume / h.Volume > 0.1f);
if (!targetHulls.Any()) return null;
return targetHulls[Rand.Range(0, targetHulls.Count)].AiTarget;

View File

@@ -816,7 +816,7 @@ namespace Barotrauma
headInWater = false;
inWater = false;
if (currentHull.Volume > currentHull.FullVolume * 0.95f)
if (currentHull.WaterVolume > currentHull.Volume * 0.95f)
{
inWater = true;
}
@@ -836,7 +836,7 @@ namespace Barotrauma
}
if (currentHull == null ||
currentHull.Volume > currentHull.FullVolume * 0.95f ||
currentHull.WaterVolume > currentHull.Volume * 0.95f ||
ConvertUnits.ToSimUnits(currentHull.Surface) > Collider.SimPosition.Y)
{
Collider.ApplyWaterForces();
@@ -858,7 +858,7 @@ namespace Barotrauma
limb.inWater = true;
if (limb.type == LimbType.Head) headInWater = true;
}
else if (limbHull.Volume > 0.0f && Submarine.RectContains(limbHull.Rect, limb.Position))
else if (limbHull.WaterVolume > 0.0f && Submarine.RectContains(limbHull.Rect, limb.Position))
{
if (limb.Position.Y < limbHull.Surface)
{

View File

@@ -250,7 +250,7 @@ namespace Barotrauma.Items.Components
//steer closer if almost in range
if (dist > range)
{
Vector2 standPos = leak.isHorizontal ?
Vector2 standPos = leak.IsHorizontal ?
new Vector2(Math.Sign(item.WorldPosition.X - leak.WorldPosition.X), 0.0f)
: new Vector2(0.0f, Math.Sign(item.WorldPosition.Y - leak.WorldPosition.Y));

View File

@@ -104,7 +104,7 @@ namespace Barotrauma.Items.Components
}
else
{
hullData.Water = Math.Min(senderHull.Volume / senderHull.FullVolume, 1.0f);
hullData.Water = Math.Min(senderHull.WaterVolume / senderHull.Volume, 1.0f);
}
break;
case "oxygen_data_in":

View File

@@ -90,17 +90,12 @@ namespace Barotrauma.Items.Components
Vent vent = linkedItem.GetComponent<Vent>();
if (vent == null) continue;
ventList.Add(vent);
if (linkedItem.CurrentHull!=null) totalHullVolume += linkedItem.CurrentHull.FullVolume;
if (linkedItem.CurrentHull != null) totalHullVolume += linkedItem.CurrentHull.Volume;
}
}
//public override void OnMapLoaded()
//{
// GetVents();
//}
private void UpdateVents(float deltaOxygen)
{
if (ventList == null)
@@ -109,13 +104,13 @@ namespace Barotrauma.Items.Components
GetVents();
}
if (!ventList.Any() || totalHullVolume == 0.0f) return;
if (!ventList.Any() || totalHullVolume <= 0.0f) return;
foreach (Vent v in ventList)
{
if (v.Item.CurrentHull == null) continue;
v.OxygenFlow = deltaOxygen * (v.Item.CurrentHull.FullVolume / totalHullVolume);
v.OxygenFlow = deltaOxygen * (v.Item.CurrentHull.Volume / totalHullVolume);
v.IsActive = true;
}
}

View File

@@ -89,7 +89,7 @@ namespace Barotrauma.Items.Components
if (targetLevel != null)
{
float hullPercentage = 0.0f;
if (hull1 != null) hullPercentage = (hull1.Volume / hull1.FullVolume) * 100.0f;
if (hull1 != null) hullPercentage = (hull1.WaterVolume / hull1.Volume) * 100.0f;
FlowPercentage = ((float)targetLevel - hullPercentage) * 10.0f;
}
@@ -100,21 +100,14 @@ namespace Barotrauma.Items.Components
ApplyStatusEffects(ActionType.OnActive, deltaTime, null);
if (hull1 == null) return;
float powerFactor = currPowerConsumption <= 0.0f ? 1.0f : voltage;
currFlow = flowPercentage / 100.0f * maxFlow * powerFactor;
hull1.WaterVolume += currFlow;
if (hull1.WaterVolume > hull1.Volume) hull1.Pressure += 0.5f;
float powerFactor = (currPowerConsumption==0.0f) ? 1.0f : voltage;
//flowPercentage = maxFlow * powerFactor;
currFlow = (flowPercentage / 100.0f) * maxFlow * powerFactor;
hull1.Volume += currFlow;
if (hull1.Volume > hull1.FullVolume) hull1.Pressure += 0.5f;
//if (hull2 != null)
//{
// hull2.Volume -= currFlow;
// if (hull2.Volume > hull1.FullVolume) hull2.Pressure += 0.5f;
//}
voltage = 0.0f;
}

View File

@@ -868,7 +868,7 @@ namespace Barotrauma
if (CurrentHull != null)
{
float floor = CurrentHull.Rect.Y - CurrentHull.Rect.Height;
float waterLevel = (floor + CurrentHull.Volume / CurrentHull.Rect.Width);
float waterLevel = floor + CurrentHull.WaterVolume / CurrentHull.Rect.Width;
//forceFactor is 1.0f if the item is completely submerged,
//and goes to 0.0f as the item goes through the surface

View File

@@ -154,7 +154,7 @@ namespace Barotrauma
DamageCharacters(deltaTime);
DamageItems(deltaTime);
if (hull.Volume > 0.0f) HullWaterExtinquish(deltaTime);
if (hull.WaterVolume > 0.0f) HullWaterExtinquish(deltaTime);
hull.Oxygen -= size.X * deltaTime * OxygenConsumption;
@@ -263,7 +263,7 @@ namespace Barotrauma
size.X -= extinquishAmount;
//evaporate some of the water
hull.Volume -= extinquishAmount;
hull.WaterVolume -= extinquishAmount;
if (GameMain.Client != null) return;
@@ -299,7 +299,7 @@ namespace Barotrauma
position.X += extinquishAmount / 2.0f;
size.X -= extinquishAmount;
hull.Volume -= extinquishAmount;
hull.WaterVolume -= extinquishAmount;
if (GameMain.Client != null) return;

View File

@@ -13,10 +13,8 @@ namespace Barotrauma
public static bool ShowGaps = true;
public bool isHorizontal;
//private Sound waterSound;
public readonly bool IsHorizontal;
//a value between 0.0f-1.0f (0.0 = closed, 1.0f = open)
private float open;
@@ -27,7 +25,7 @@ namespace Barotrauma
private float higherSurface;
private float lowerSurface;
private Vector2 lerpedFlowForce;
//if set to true, hull connections of this gap won't be updated when changes are being done to hulls
@@ -110,7 +108,7 @@ namespace Barotrauma
flowForce = Vector2.Zero;
this.isHorizontal = isHorizontal;
this.IsHorizontal = isHorizontal;
open = 1.0f;
@@ -122,7 +120,7 @@ namespace Barotrauma
public override MapEntity Clone()
{
return new Gap(rect, isHorizontal, Submarine);
return new Gap(rect, IsHorizontal, Submarine);
}
public override void Move(Vector2 amount)
@@ -143,8 +141,8 @@ namespace Barotrauma
public override bool IsMouseOn(Vector2 position)
{
return (ShowGaps && Submarine.RectContains(WorldRect, position) &&
!Submarine.RectContains(MathUtils.ExpandRect(WorldRect, -5), position));
return ShowGaps && Submarine.RectContains(WorldRect, position) &&
!Submarine.RectContains(MathUtils.ExpandRect(WorldRect, -5), position);
}
private void FindHulls()
@@ -154,7 +152,7 @@ namespace Barotrauma
linkedTo.Clear();
Vector2[] searchPos = new Vector2[2];
if (isHorizontal)
if (IsHorizontal)
{
searchPos[0] = new Vector2(rect.X, rect.Y - rect.Height / 2);
searchPos[1] = new Vector2(rect.Right, rect.Y - rect.Height / 2);
@@ -170,7 +168,7 @@ namespace Barotrauma
if (hulls[0] == null && hulls[1] == null) return;
if (hulls[0]==null && hulls[1]!=null)
if (hulls[0] == null && hulls[1] != null)
{
Hull temp = hulls[0];
hulls[0] = hulls[1];
@@ -179,9 +177,9 @@ namespace Barotrauma
flowTargetHull = hulls[0];
for (int i = 0 ; i <2; i++)
for (int i = 0; i < 2; i++)
{
if (hulls[i]==null) continue;
if (hulls[i] == null) continue;
linkedTo.Add(hulls[i]);
if (!hulls[i].ConnectedGaps.Contains(this)) hulls[i].ConnectedGaps.Add(this);
}
@@ -191,7 +189,7 @@ namespace Barotrauma
{
flowForce = Vector2.Zero;
if (open == 0.0f)
if (open == 0.0f || linkedTo.Count == 0)
{
lerpedFlowForce = Vector2.Zero;
return;
@@ -210,23 +208,22 @@ namespace Barotrauma
UpdateRoomToRoom(deltaTime);
}
lerpedFlowForce = Vector2.Lerp(lerpedFlowForce, flowForce, deltaTime);
lerpedFlowForce = Vector2.Lerp(lerpedFlowForce, flowForce, deltaTime * 5.0f);
if (LerpedFlowForce.LengthSquared() > 20000.0f && flowTargetHull != null && flowTargetHull.Volume < flowTargetHull.FullVolume)
#if CLIENT
if (LerpedFlowForce.LengthSquared() > 20000.0f && flowTargetHull != null && flowTargetHull.WaterVolume < flowTargetHull.Volume)
{
//UpdateFlowForce();
Vector2 pos = Position;
if (isHorizontal)
if (IsHorizontal)
{
pos.X += Math.Sign(flowForce.X);
pos.Y = MathHelper.Clamp((higherSurface + lowerSurface) / 2.0f, rect.Y - rect.Height, rect.Y) + 10;
Vector2 velocity = new Vector2(
MathHelper.Clamp(flowForce.X, -5000.0f, 5000.0f) * Rand.Range(0.5f, 0.7f),
flowForce.Y * Rand.Range(0.5f, 0.7f));
#if CLIENT
var particle = GameMain.ParticleManager.CreateParticle(
"watersplash",
(Submarine == null ? pos : pos + Submarine.Position) - Vector2.UnitY * Rand.Range(0.0f, 10.0f),
@@ -236,19 +233,16 @@ namespace Barotrauma
{
particle.Size = particle.Size * Math.Min(Math.Abs(flowForce.X / 1000.0f), 5.0f);
}
#endif
if (Math.Abs(flowForce.X) > 300.0f)
{
pos.X += Math.Sign(flowForce.X) * 10.0f;
pos.Y = Rand.Range(lowerSurface, rect.Y - rect.Height);
#if CLIENT
GameMain.ParticleManager.CreateParticle(
"bubbles",
Submarine == null ? pos : pos + Submarine.Position,
flowForce / 10.0f, 0, flowTargetHull);
#endif
}
}
else
@@ -264,7 +258,6 @@ namespace Barotrauma
lerpedFlowForce.X * Rand.Range(0.5f, 0.7f),
Math.Max(lerpedFlowForce.Y, -100.0f) * Rand.Range(0.5f, 0.7f));
#if CLIENT
var splash = GameMain.ParticleManager.CreateParticle(
"watersplash",
Submarine == null ? pos : pos + Submarine.Position,
@@ -276,18 +269,21 @@ namespace Barotrauma
"bubbles",
Submarine == null ? pos : pos + Submarine.Position,
flowForce / 2.0f, 0, FlowTargetHull);
#endif
}
}
}
#endif
if (flowTargetHull != null && lerpedFlowForce != Vector2.Zero)
{
foreach (Character character in Character.CharacterList)
{
if (character.AnimController.CurrentHull != flowTargetHull) continue;
if (character.CurrentHull == null) continue;
if (character.CurrentHull != linkedTo[0] as Hull &&
(linkedTo.Count < 2 || character.CurrentHull != linkedTo[1] as Hull))
{
continue;
}
foreach (Limb limb in character.AnimController.Limbs)
{
@@ -296,12 +292,21 @@ namespace Barotrauma
float dist = Vector2.Distance(limb.WorldPosition, WorldPosition);
if (dist > lerpedFlowForce.Length()) continue;
limb.body.ApplyForce(lerpedFlowForce / dist/10.0f);
Vector2 force = lerpedFlowForce / (float)Math.Max(Math.Sqrt(dist), 20.0f) * 0.025f;
//vertical gaps only apply forces if the character is roughly above/below the gap
if (!IsHorizontal)
{
float xDist = Math.Abs(limb.WorldPosition.X - WorldPosition.X);
if (xDist > rect.Width || rect.Width == 0) return;
force *= 1.0f - xDist / rect.Width;
}
character.AnimController.Collider.ApplyForce(force * limb.body.Mass);
}
}
}
}
void UpdateRoomToRoom(float deltaTime)
@@ -322,30 +327,30 @@ namespace Barotrauma
}
if (hull1.Volume == 0.0 && hull2.Volume == 0.0) return;
if (hull1.WaterVolume <= 0.0 && hull2.WaterVolume <= 0.0) return;
float size = (isHorizontal) ? rect.Height : rect.Width;
float size = IsHorizontal ? rect.Height : rect.Width;
//a variable affecting the water flow through the gap
//the larger the gap is, the faster the water flows
float sizeModifier = size / 100.0f * open;
//horizontal gap (such as a regular door)
if (isHorizontal)
if (IsHorizontal)
{
higherSurface = Math.Max(hull1.Surface, hull2.Surface + subOffset.Y);
float delta=0.0f;
float delta = 0.0f;
//water level is above the lower boundary of the gap
if (Math.Max(hull1.Surface+hull1.WaveY[hull1.WaveY.Length - 1], hull2.Surface + subOffset.Y +hull2.WaveY[0]) > rect.Y - size)
if (Math.Max(hull1.Surface + hull1.WaveY[hull1.WaveY.Length - 1], hull2.Surface + subOffset.Y + hull2.WaveY[0]) > rect.Y - size)
{
int dir = (hull1.Pressure > hull2.Pressure+subOffset.Y) ? 1 : -1;
int dir = (hull1.Pressure > hull2.Pressure + subOffset.Y) ? 1 : -1;
//water flowing from the righthand room to the lefthand room
if (dir == -1)
{
if (!(hull2.Volume > 0.0f)) return;
if (!(hull2.WaterVolume > 0.0f)) return;
lowerSurface = hull1.Surface - hull1.WaveY[hull1.WaveY.Length - 1];
//delta = Math.Min((room2.water.pressure - room1.water.pressure) * sizeModifier, Math.Min(room2.water.Volume, room2.Volume));
//delta = Math.Min(delta, room1.Volume - room1.water.Volume + Water.MaxCompress);
@@ -353,13 +358,13 @@ namespace Barotrauma
flowTargetHull = hull1;
//make sure not to move more than what the room contains
delta = Math.Min(((hull2.Pressure + subOffset.Y) - hull1.Pressure) * 5.0f * sizeModifier, Math.Min(hull2.Volume, hull2.FullVolume));
delta = Math.Min(((hull2.Pressure + subOffset.Y) - hull1.Pressure) * 5.0f * sizeModifier, Math.Min(hull2.WaterVolume, hull2.Volume));
//make sure not to place more water to the target room than it can hold
delta = Math.Min(delta, hull1.FullVolume + Hull.MaxCompress - (hull1.Volume));
hull1.Volume += delta;
hull2.Volume -= delta;
if (hull1.Volume > hull1.FullVolume)
delta = Math.Min(delta, hull1.Volume + Hull.MaxCompress - (hull1.WaterVolume));
hull1.WaterVolume += delta;
hull2.WaterVolume -= delta;
if (hull1.WaterVolume > hull1.Volume)
{
hull1.Pressure = Math.Max(hull1.Pressure, (hull1.Pressure + hull2.Pressure+subOffset.Y) / 2);
}
@@ -368,19 +373,19 @@ namespace Barotrauma
}
else if (dir == 1)
{
if (!(hull1.Volume > 0.0f)) return;
if (!(hull1.WaterVolume > 0.0f)) return;
lowerSurface = hull2.Surface - hull2.WaveY[hull2.WaveY.Length - 1];
flowTargetHull = hull2;
//make sure not to move more than what the room contains
delta = Math.Min((hull1.Pressure - (hull2.Pressure + subOffset.Y)) * 5.0f * sizeModifier, Math.Min(hull1.Volume, hull1.FullVolume));
delta = Math.Min((hull1.Pressure - (hull2.Pressure + subOffset.Y)) * 5.0f * sizeModifier, Math.Min(hull1.WaterVolume, hull1.Volume));
//make sure not to place more water to the target room than it can hold
delta = Math.Min(delta, hull2.FullVolume + Hull.MaxCompress - (hull2.Volume));
hull1.Volume -= delta;
hull2.Volume += delta;
if (hull2.Volume > hull2.FullVolume)
delta = Math.Min(delta, hull2.Volume + Hull.MaxCompress - (hull2.WaterVolume));
hull1.WaterVolume -= delta;
hull2.WaterVolume += delta;
if (hull2.WaterVolume > hull2.Volume)
{
hull2.Pressure = Math.Max(hull2.Pressure, ((hull1.Pressure-subOffset.Y) + hull2.Pressure) / 2);
}
@@ -388,92 +393,86 @@ namespace Barotrauma
flowForce = new Vector2(delta, 0.0f);
}
if (delta>100.0f && subOffset == Vector2.Zero)
if (delta > 100.0f && subOffset == Vector2.Zero)
{
float avg = (hull1.Surface + hull2.Surface) / 2.0f;
//float avgVel = (hull2.WaveVel[1] + hull1.WaveVel[hull1.WaveY.Length - 2]) / 2.0f;
if (hull1.Volume < hull1.FullVolume - Hull.MaxCompress &&
if (hull1.WaterVolume < hull1.Volume - Hull.MaxCompress &&
hull1.Surface + hull1.WaveY[hull1.WaveY.Length - 1] < rect.Y)
{
hull1.WaveVel[hull1.WaveY.Length - 1] = (avg-(hull1.Surface + hull1.WaveY[hull1.WaveY.Length - 1]))*0.1f;
hull1.WaveVel[hull1.WaveY.Length - 1] = (avg - (hull1.Surface + hull1.WaveY[hull1.WaveY.Length - 1])) * 0.1f;
hull1.WaveVel[hull1.WaveY.Length - 2] = hull1.WaveVel[hull1.WaveY.Length - 1];
}
if (hull2.Volume < hull2.FullVolume - Hull.MaxCompress &&
if (hull2.WaterVolume < hull2.Volume - Hull.MaxCompress &&
hull2.Surface + hull2.WaveY[0] < rect.Y)
{
hull2.WaveVel[0] = (avg - (hull2.Surface + hull2.WaveY[0])) * 0.1f;
hull2.WaveVel[1] = hull2.WaveVel[0];
hull2.WaveVel[1] = hull2.WaveVel[0];
}
}
}
}
else
{
//lower room is full of water
if ((hull2.Pressure + subOffset.Y) > hull1.Pressure)
if (hull2.Pressure + subOffset.Y > hull1.Pressure)
{
float delta = Math.Min(hull2.Volume - hull2.FullVolume + Hull.MaxCompress / 2.0f, deltaTime * 8000.0f * sizeModifier);
float delta = Math.Min(hull2.WaterVolume - hull2.Volume + Hull.MaxCompress, deltaTime * 8000.0f * sizeModifier);
flowForce = new Vector2(0.0f, Math.Min((hull2.Pressure + subOffset.Y) - hull1.Pressure, 500.0f));
//make sure not to place more water to the target room than it can hold
if (hull1.WaterVolume + delta > hull1.Volume + Hull.MaxCompress)
{
delta -= (hull1.WaterVolume + delta) - (hull1.Volume + Hull.MaxCompress);
}
delta = Math.Max(delta, 0.0f);
hull1.Volume += delta;
hull2.Volume -= delta;
hull1.WaterVolume += delta;
hull2.WaterVolume -= delta;
flowForce = new Vector2(
0.0f,
Math.Min(Math.Min((hull2.Pressure + subOffset.Y) - hull1.Pressure, 200.0f), delta));
flowTargetHull = hull1;
if (hull1.Volume > hull1.FullVolume)
if (hull1.WaterVolume > hull1.Volume)
{
hull1.Pressure = Math.Max(hull1.Pressure, (hull1.Pressure + (hull2.Pressure + subOffset.Y)) / 2);
}
}
//there's water in the upper room, drop to lower
else if (hull1.Volume > 0)
else if (hull1.WaterVolume > 0)
{
flowTargetHull = hull2;
//make sure the amount of water moved isn't more than what the room contains
float delta = Math.Min(hull1.Volume, deltaTime * 25000f * sizeModifier);
float delta = Math.Min(hull1.WaterVolume, deltaTime * 25000f * sizeModifier);
//make sure not to place more water to the target room than it can hold
delta = Math.Min(delta, (hull2.FullVolume + Math.Max(hull1.Volume - hull1.FullVolume, 0.0f)) - hull2.Volume + Hull.MaxCompress / 4.0f);
if (hull2.WaterVolume + delta > hull2.Volume + Hull.MaxCompress)
{
delta -= (hull2.WaterVolume + delta) - (hull2.Volume + Hull.MaxCompress);
}
hull1.WaterVolume -= delta;
hull2.WaterVolume += delta;
hull1.Volume -= delta;
hull2.Volume += delta;
flowForce = new Vector2(
hull1.WaveY[hull1.GetWaveIndex(rect.X)] - hull1.WaveY[hull1.GetWaveIndex(rect.Right)],
Math.Max(Math.Max((hull2.Pressure + subOffset.Y - hull1.Pressure) * 10.0f, -200.0f), -delta));
if (hull2.Volume > hull2.FullVolume)
if (hull2.WaterVolume > hull2.Volume)
{
hull2.Pressure = Math.Max(hull2.Pressure, ((hull1.Pressure - subOffset.Y) + hull2.Pressure) / 2);
}
flowForce = new Vector2(0.0f, -delta);
flowForce.X = hull1.WaveY[hull1.GetWaveIndex(rect.X)] - hull1.WaveY[hull1.GetWaveIndex(rect.Right)] * 10.0f;
//if (water2.Volume < water2.FullVolume - Hull.MaxCompress)
//{
// int posX = (int)((rect.X + size / 2.0f - water1.Rect.X) / Hull.WaveWidth);
// //water1.WaveY[posX] = -delta;
// if (posX > -1 && posX < water2.WaveVel.Length)
// water1.WaveVel[posX] = -delta * 0.01f;
// posX = (int)((rect.X + size / 2.0f - water2.Rect.X) / Hull.WaveWidth);
// //water2.WaveY[posX] = delta;
// if (posX > -1 && posX<water2.WaveVel.Length)
// water2.WaveVel[posX] = delta * 0.01f;
//}
}
}
if (open > 0.0f)
{
if (hull1.Volume > hull1.FullVolume - Hull.MaxCompress && hull2.Volume > hull2.FullVolume - Hull.MaxCompress)
if (hull1.WaterVolume > hull1.Volume - Hull.MaxCompress && hull2.WaterVolume > hull2.Volume - Hull.MaxCompress)
{
float avgLethality = (hull1.LethalPressure + hull2.LethalPressure) / 2.0f;
hull1.LethalPressure = avgLethality;
@@ -491,7 +490,7 @@ namespace Barotrauma
{
if (linkedTo.Count != 1) return;
float size = (isHorizontal) ? rect.Height : rect.Width;
float size = (IsHorizontal) ? rect.Height : rect.Width;
Hull hull1 = (Hull)linkedTo[0];
@@ -502,14 +501,14 @@ namespace Barotrauma
float delta = Hull.MaxCompress * sizeModifier * deltaTime;
//make sure not to place more water to the target room than it can hold
delta = Math.Min(delta, hull1.FullVolume + Hull.MaxCompress - hull1.Volume);
hull1.Volume += delta;
delta = Math.Min(delta, hull1.Volume + Hull.MaxCompress - hull1.WaterVolume);
hull1.WaterVolume += delta;
if (hull1.Volume > hull1.FullVolume) hull1.Pressure += 0.5f;
if (hull1.WaterVolume > hull1.Volume) hull1.Pressure += 0.5f;
flowTargetHull = hull1;
if (isHorizontal)
if (IsHorizontal)
{
//water flowing from right to left
if (rect.X > hull1.Rect.X + hull1.Rect.Width / 2.0f)
@@ -525,7 +524,7 @@ namespace Barotrauma
higherSurface = hull1.Surface;
lowerSurface = rect.Y;
if (hull1.Volume < hull1.FullVolume - Hull.MaxCompress &&
if (hull1.WaterVolume < hull1.Volume - Hull.MaxCompress &&
hull1.Surface < rect.Y)
{
if (rect.X > hull1.Rect.X + hull1.Rect.Width / 2.0f)
@@ -560,7 +559,7 @@ namespace Barotrauma
{
flowForce = new Vector2(0.0f, delta);
}
if (hull1.Volume >= hull1.FullVolume - Hull.MaxCompress)
if (hull1.WaterVolume >= hull1.Volume - Hull.MaxCompress)
{
hull1.LethalPressure += (Submarine != null && Submarine.AtDamageDepth) ? 100.0f * deltaTime : 10.0f * deltaTime;
}
@@ -574,15 +573,15 @@ namespace Barotrauma
Hull hull1 = (Hull)linkedTo[0];
Hull hull2 = (Hull)linkedTo[1];
if (isHorizontal)
if (IsHorizontal)
{
if (Math.Max(hull1.Surface + hull1.WaveY[hull1.WaveY.Length - 1], hull2.Surface + hull2.WaveY[0]) > rect.Y) return;
}
float totalOxygen = hull1.Oxygen + hull2.Oxygen;
float totalVolume = (hull1.FullVolume + hull2.FullVolume);
float totalVolume = (hull1.Volume + hull2.Volume);
float deltaOxygen = (totalOxygen * hull1.FullVolume / totalVolume) - hull1.Oxygen;
float deltaOxygen = (totalOxygen * hull1.Volume / totalVolume) - hull1.Oxygen;
deltaOxygen = MathHelper.Clamp(deltaOxygen, -Hull.OxygenDistributionSpeed, Hull.OxygenDistributionSpeed);
hull1.Oxygen += deltaOxygen;
@@ -601,7 +600,7 @@ namespace Barotrauma
if (sectionIndex > -1 && !gap.ConnectedWall.SectionBodyDisabled(sectionIndex)) continue;
}
if (gap.isHorizontal)
if (gap.IsHorizontal)
{
if (worldPos.Y < gap.WorldRect.Y && worldPos.Y > gap.WorldRect.Y - gap.WorldRect.Height &&
Math.Abs(gap.WorldRect.Center.X - worldPos.X) < allowedOrthogonalDist)
@@ -693,7 +692,7 @@ namespace Barotrauma
element.Add(
new XAttribute("ID", ID),
new XAttribute("horizontal", isHorizontal ? "true" : "false"));
new XAttribute("horizontal", IsHorizontal ? "true" : "false"));
element.Add(new XAttribute("rect",
(int)(rect.X - Submarine.HiddenSubPosition.X) + "," +

View File

@@ -49,7 +49,7 @@ namespace Barotrauma
private float lethalPressure;
private float surface;
private float volume;
private float waterVolume;
private float pressure;
private float oxygen;
@@ -93,7 +93,7 @@ namespace Barotrauma
Gap.UpdateHulls();
}
surface = rect.Y - rect.Height + Volume / rect.Width;
surface = rect.Y - rect.Height + WaterVolume / rect.Width;
Pressure = surface;
}
}
@@ -127,15 +127,15 @@ namespace Barotrauma
get { return surface; }
}
public float Volume
public float WaterVolume
{
get { return volume; }
get { return waterVolume; }
set
{
if (!MathUtils.IsValid(value)) return;
volume = MathHelper.Clamp(value, 0.0f, FullVolume + MaxCompress);
if (volume < FullVolume) Pressure = rect.Y - rect.Height + volume / rect.Width;
if (volume > 0.0f) update = true;
waterVolume = MathHelper.Clamp(value, 0.0f, Volume + MaxCompress);
if (waterVolume < Volume) Pressure = rect.Y - rect.Height + waterVolume / rect.Width;
if (waterVolume > 0.0f) update = true;
}
}
@@ -146,19 +146,19 @@ namespace Barotrauma
set
{
if (!MathUtils.IsValid(value)) return;
oxygen = MathHelper.Clamp(value, 0.0f, FullVolume);
oxygen = MathHelper.Clamp(value, 0.0f, Volume);
}
}
public float OxygenPercentage
{
get { return oxygen / FullVolume * 100.0f; }
set { Oxygen = (value / 100.0f) * FullVolume; }
get { return oxygen / Volume * 100.0f; }
set { Oxygen = (value / 100.0f) * Volume; }
}
public float FullVolume
public float Volume
{
get { return (rect.Width * rect.Height); }
get { return rect.Width * rect.Height; }
}
public float Pressure
@@ -213,14 +213,14 @@ namespace Barotrauma
hullList.Add(this);
ConnectedGaps = new List<Gap>();
if (submarine==null || !submarine.Loading)
if (submarine == null || !submarine.Loading)
{
Item.UpdateHulls();
Gap.UpdateHulls();
}
Volume = 0.0f;
WaterVolume = 0.0f;
InsertToList();
}
@@ -309,7 +309,7 @@ namespace Barotrauma
Gap.UpdateHulls();
}
surface = rect.Y - rect.Height + Volume / rect.Width;
surface = rect.Y - rect.Height + WaterVolume / rect.Width;
Pressure = surface;
}
@@ -403,7 +403,7 @@ namespace Barotrauma
//update client hulls if the amount of water has changed by >10%
//or if oxygen percentage has changed by 5%
if (Math.Abs(lastSentVolume - volume) > FullVolume * 0.1f ||
if (Math.Abs(lastSentVolume - waterVolume) > Volume * 0.1f ||
Math.Abs(lastSentOxygen - OxygenPercentage) > 5f)
{
if (GameMain.Server != null)
@@ -412,7 +412,7 @@ namespace Barotrauma
if (sendUpdateTimer < 0.0f)
{
GameMain.Server.CreateEntityEvent(this);
lastSentVolume = volume;
lastSentVolume = waterVolume;
lastSentOxygen = OxygenPercentage;
sendUpdateTimer = NetworkUpdateInterval;
}
@@ -425,7 +425,7 @@ namespace Barotrauma
return;
}
float surfaceY = rect.Y - rect.Height + Volume / rect.Width;
float surfaceY = rect.Y - rect.Height + WaterVolume / rect.Width;
for (int i = 0; i < waveY.Length; i++)
{
waveY[i] = waveY[i] + waveVel[i];
@@ -467,10 +467,10 @@ namespace Barotrauma
//interpolate the position of the rendered surface towards the "target surface"
surface = Math.Max(MathHelper.Lerp(surface, surfaceY, deltaTime*10.0f), rect.Y - rect.Height);
if (volume < FullVolume)
if (waterVolume < Volume)
{
LethalPressure -= 10.0f * deltaTime;
if (Volume == 0.0f)
if (WaterVolume <= 0.0f)
{
//wait for the surface to be lerped back to bottom and the waves to settle until disabling update
if (surface > rect.Y - rect.Height + 1) return;
@@ -611,10 +611,10 @@ namespace Barotrauma
}
}
private bool CanSeeOther(Hull other,bool allowIndirect=true)
private bool CanSeeOther(Hull other, bool allowIndirect = true)
{
if (other == this) return true;
if (other != null && other.Submarine==Submarine)
{
bool retVal = false;
@@ -641,7 +641,7 @@ namespace Barotrauma
public void ServerWrite(NetBuffer message, Client c, object[] extraData = null)
{
message.WriteRangedSingle(MathHelper.Clamp(volume / FullVolume, 0.0f, 1.5f), 0.0f, 1.5f, 8);
message.WriteRangedSingle(MathHelper.Clamp(waterVolume / Volume, 0.0f, 1.5f), 0.0f, 1.5f, 8);
message.WriteRangedSingle(MathHelper.Clamp(OxygenPercentage, 0.0f, 100.0f), 0.0f, 100.0f, 8);
message.Write(fireSources.Count > 0);
@@ -664,7 +664,7 @@ namespace Barotrauma
public void ClientRead(ServerNetObject type, NetBuffer message, float sendingTime)
{
Volume = message.ReadRangedSingle(0.0f, 1.5f, 8) * FullVolume;
WaterVolume = message.ReadRangedSingle(0.0f, 1.5f, 8) * Volume;
OxygenPercentage = message.ReadRangedSingle(0.0f, 100.0f, 8);
bool hasFireSources = message.ReadBoolean();
@@ -731,7 +731,7 @@ namespace Barotrauma
Hull h = new Hull(MapEntityPrefab.list.Find(m => m.Name == "Hull"), rect, submarine);
h.volume = element.GetAttributeFloat("pressure", 0.0f);
h.waterVolume = element.GetAttributeFloat("pressure", 0.0f);
h.ID = (ushort)int.Parse(element.Attribute("ID").Value);
}
@@ -747,7 +747,7 @@ namespace Barotrauma
(int)(rect.X - Submarine.HiddenSubPosition.X) + "," +
(int)(rect.Y - Submarine.HiddenSubPosition.Y) + "," +
rect.Width + "," + rect.Height),
new XAttribute("water", volume)
new XAttribute("water", waterVolume)
);
parentElement.Add(element);

View File

@@ -315,11 +315,11 @@ namespace Barotrauma
{
if (hull.Submarine != submarine) continue;
waterVolume += hull.Volume;
volume += hull.FullVolume;
waterVolume += hull.WaterVolume;
volume += hull.Volume;
}
float waterPercentage = volume==0.0f ? 0.0f : waterVolume / volume;
float waterPercentage = volume <= 0.0f ? 0.0f : waterVolume / volume;
float neutralPercentage = 0.07f;

View File

@@ -356,7 +356,7 @@ namespace Barotrauma
foreach (Gap gap in Gap.GapList)
{
if (!gap.isHorizontal) continue;
if (!gap.IsHorizontal) continue;
//too small to walk through
if (gap.Rect.Height < 150.0f) continue;
@@ -381,7 +381,7 @@ namespace Barotrauma
foreach (Gap gap in Gap.GapList)
{
if (gap.isHorizontal || gap.IsRoomToRoom) continue;
if (gap.IsHorizontal || gap.IsRoomToRoom) continue;
//too small to walk through
if (gap.Rect.Width < 100.0f) continue;

View File

@@ -365,7 +365,7 @@ namespace Barotrauma.Networking
if (hull.Submarine != respawnShuttle) continue;
hull.OxygenPercentage = 100.0f;
hull.Volume = 0.0f;
hull.WaterVolume = 0.0f;
}
foreach (Character c in Character.CharacterList)