Vertical docking port, docking sounds, water flows properly between horizontally docked hulls, falseoutput of signal check components can be changed, lighting and FOW works between hulls (todo: some logic for determining when to update light.HullsInRange when two subs are moving relative to each other)

This commit is contained in:
Regalis
2016-06-27 17:48:20 +03:00
parent b04e204dc3
commit 38c5251005
19 changed files with 291 additions and 116 deletions
+29 -15
View File
@@ -173,8 +173,6 @@ namespace Barotrauma
{
Vector2 center = new Vector2(WorldRect.X + rect.Width / 2.0f, -(WorldRect.Y - rect.Height/ 2.0f));
GUI.DrawLine(sb, center, center + new Vector2(flowForce.X, -flowForce.Y)/10.0f, Color.Red);
GUI.DrawLine(sb, center + Vector2.One * 5.0f, center + new Vector2(lerpedFlowForce.X, -lerpedFlowForce.Y) / 10.0f + Vector2.One * 5.0f, Color.Orange);
@@ -329,6 +327,18 @@ namespace Barotrauma
if (linkedTo.Count < 2) return;
Hull hull1 = (Hull)linkedTo[0];
Hull hull2 = (Hull)linkedTo[1];
Vector2 subOffset = Vector2.Zero;
if (hull1.Submarine != Submarine)
{
subOffset =Submarine.Position - hull1.Submarine.Position;
}
else if (hull2.Submarine != Submarine)
{
subOffset = hull2.Submarine.Position - Submarine.Position;
}
if (hull1.Volume == 0.0 && hull2.Volume == 0.0) return;
@@ -341,13 +351,14 @@ namespace Barotrauma
//horizontal gap (such as a regular door)
if (isHorizontal)
{
higherSurface = Math.Max(hull1.Surface,hull2.Surface);
float delta=0.0f;
higherSurface = Math.Max(hull1.Surface, hull2.Surface + subOffset.Y);
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+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) ? 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)
@@ -360,38 +371,42 @@ namespace Barotrauma
flowTargetHull = hull1;
//make sure not to move more than what the room contains
delta = Math.Min((hull2.Pressure - 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.Volume, hull2.FullVolume));
//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)
hull1.Pressure = Math.Max(hull1.Pressure, (hull1.Pressure + hull2.Pressure) / 2);
{
hull1.Pressure = Math.Max(hull1.Pressure, (hull1.Pressure + hull2.Pressure+subOffset.Y) / 2);
}
flowForce = new Vector2(-delta, 0.0f);
}
else if (dir == 1)
{
if (!(hull1.Volume > 0.0f)) return;
lowerSurface = hull2.Surface - hull2.WaveY[1];
//lowerSurface = hull2.Surface - hull2.WaveY[1];
flowTargetHull = hull2;
//make sure not to move more than what the room contains
delta = Math.Min((hull1.Pressure - hull2.Pressure) * 5.0f * sizeModifier, Math.Min(hull1.Volume, hull1.FullVolume));
delta = Math.Min((hull1.Pressure - (hull2.Pressure + subOffset.Y)) * 5.0f * sizeModifier, Math.Min(hull1.Volume, hull1.FullVolume));
//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)
hull2.Pressure = Math.Max(hull2.Pressure, (hull1.Pressure + hull2.Pressure) / 2);
{
hull2.Pressure = Math.Max(hull2.Pressure, ((hull1.Pressure-subOffset.Y) + hull2.Pressure) / 2);
}
flowForce = new Vector2(delta, 0.0f);
}
if (delta>100.0f)
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;
@@ -625,10 +640,9 @@ namespace Barotrauma
GapList.Remove(this);
foreach (MapEntity entity in linkedTo)
foreach (Hull hull in Hull.hullList)
{
var hull = entity as Hull;
if (hull.ConnectedGaps.Contains(this)) hull.ConnectedGaps.Remove(this);
hull.ConnectedGaps.Remove(this);
}
}
+25 -1
View File
@@ -53,6 +53,7 @@ namespace Barotrauma
private bool update;
private Sound currentFlowSound;
private int soundIndex;
private float soundVolume;
@@ -392,12 +393,24 @@ namespace Barotrauma
foreach (Gap gap in ConnectedGaps)
{
float gapFlow = gap.LerpedFlowForce.Length();
#if DEBUG
var asd = MapEntity.FindEntityByID(gap.ID);
if (asd != gap)
{
int adslkmfdlasfk = 9;
}
#endif
if (gapFlow > strongestFlow)
{
strongestFlow = gapFlow;
}
}
if (strongestFlow>0.1f)
{
soundVolume = soundVolume + ((strongestFlow < 100.0f) ? -deltaTime * 0.5f : deltaTime * 0.5f);
@@ -406,13 +419,24 @@ namespace Barotrauma
int index = (int)Math.Floor(strongestFlow / 100.0f);
index = Math.Min(index, 2);
soundIndex = SoundPlayer.flowSounds[index].Loop(soundIndex, soundVolume, WorldPosition, 2000.0f);
var flowSound = SoundPlayer.flowSounds[index];
if (flowSound != currentFlowSound && soundIndex > -1)
{
Sounds.SoundManager.Stop(soundIndex);
currentFlowSound = null;
soundIndex = -1;
}
currentFlowSound = flowSound;
soundIndex = currentFlowSound.Loop(soundIndex, soundVolume, WorldPosition, 2000.0f);
}
else
{
if (soundIndex > -1)
{
Sounds.SoundManager.Stop(soundIndex);
currentFlowSound = null;
soundIndex = -1;
}
}
+12 -1
View File
@@ -375,7 +375,18 @@ namespace Barotrauma.Lights
Vector2 lightSourcePos = light.Position;
if (light.Submarine==null && parentEntity != null && parentEntity.Submarine != null) lightSourcePos -= parentEntity.Submarine.Position;
if (parentEntity != null && parentEntity.Submarine != null)
{
if (light.Submarine == null)
{
lightSourcePos -= parentEntity.Submarine.Position;
}
else if (light.Submarine != parentEntity.Submarine)
{
lightSourcePos += (light.Submarine.Position-parentEntity.Submarine.Position);
}
}
CachedShadow cachedShadow = null;
if (!cachedShadows.TryGetValue(light, out cachedShadow) ||
@@ -95,6 +95,7 @@ namespace Barotrauma.Lights
foreach (LightSource light in lights)
{
if (light.Color.A < 0.01f || light.Range < 1.0f) continue;
//!!!!!!!!!!!!!!!!
if (light.hullsInRange == null) light.UpdateHullsInRange();
if (!light.hullsInRange.Any() || !MathUtils.CircleIntersectsRectangle(light.WorldPosition, light.Range, viewRect)) continue;
+12 -6
View File
@@ -86,7 +86,7 @@ namespace Barotrauma.Lights
{
range = MathHelper.Clamp(value, 0.0f, 2048.0f);
if (Math.Abs(prevHullUpdateRange - range) < 5.0f) return;
if (Math.Abs(prevHullUpdateRange - range) < 10.0f) return;
UpdateHullsInRange();
prevHullUpdateRange = range;
@@ -143,18 +143,24 @@ namespace Barotrauma.Lights
foreach (ConvexHull ch in ConvexHull.list)
{
if (Submarine == null && ch.ParentEntity.Submarine != null)
Vector2 lightPos = position;
if (Submarine==null)
{
if (MathUtils.CircleIntersectsRectangle(position - ch.ParentEntity.Submarine.Position, range, ch.BoundingBox))
if (ch.ParentEntity.Submarine != null)
{
hullsInRange.Add(ch);
lightPos -= ch.ParentEntity.Submarine.Position;
}
}
else if (MathUtils.CircleIntersectsRectangle(position, range, ch.BoundingBox))
else if (ch.ParentEntity.Submarine != null && ch.ParentEntity.Submarine != Submarine)
{
lightPos -= (ch.ParentEntity.Submarine.Position - Submarine.Position);
}
if (MathUtils.CircleIntersectsRectangle(lightPos, range, ch.BoundingBox))
{
hullsInRange.Add(ch);
}
}
}
+8
View File
@@ -349,6 +349,14 @@ namespace Barotrauma
GameMain.World.RemoveBody(b);
}
foreach (WallSection s in sections)
{
if (s.gap != null)
{
s.gap.Remove();
s.gap = null;
}
}
if (convexHulls != null) convexHulls.ForEach(x => x.Remove());
}