Files
LuaCsForBarotraumaEP/Barotrauma/BarotraumaShared/Source/Map/Gap.cs
T
Joonas Rikkonen 58a14fd054 178a853...bd9a92d
commit bd9a92df11a8d83d0d0087ce64422f2fba3f6f99
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Sat Feb 2 20:07:36 2019 +0200

    v0.8.9.2

commit 4e1d5fa3744fb8cab80cb006a433d2efe7685562
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Sat Feb 2 19:20:03 2019 +0200

    Moved humpback's cargo spawn position a bit to prevent the cargo from falling down the hatch under it.

commit f0ec5530b0c7ecbdaaf8bd266d9a57fac2c92fe9
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Sat Feb 2 19:18:41 2019 +0200

    Fixed structure BodyOffset not being taken into account when generating the collider for the sub. Caused the button outside Orca's button to be impossible to interact with.

commit 1360f5511522280d03d608c8eb6f56fb6608aab5
Author: ezjamsen <ezjames.fi@gmail.com>
Date:   Sat Feb 2 19:10:37 2019 +0200

    Halved the status effect for damage to submerged items. This might be a bit too generous, let's see.

commit 06afb668bc816a345dbd12899b819843549e908a
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Sat Feb 2 18:22:00 2019 +0200

    Changed mantis loading tip to mud raptor, fixed a glaring error in one of the npc conversations

commit d2dfa960dd5fa43426eb4dfd02de6c497ae9d838
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Sat Feb 2 18:17:17 2019 +0200

    Fixed water flow forces occasionally being way too high due to bugged force calculation logic when water is flowing from a hull to the one below it. + Added a hard cap to flow forces to prevent this from happening again. Closes #572

commit 21754b39ded247e8c9837d58c6de9658f56a9772
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Sat Feb 2 17:24:48 2019 +0200

    Entities cannot be placed in the sub editor when the cursor is on a UI element. Fixes an entity being placed when selecting an item from them menu while something else is already selected. Closes #1023

commit 97d0cf92f738a058fa0140ec841549a5d6c746a3
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Sat Feb 2 16:59:56 2019 +0200

    Fixed a typo in one of the affliction descriptions

commit ddccbdc9a438199d3cb796789dd9915cc305ec5b
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Sat Feb 2 16:59:18 2019 +0200

    Fixed sliders buttons becoming invisible when pressed

commit bc28473a1c61698c9447825b1c5a13edd6e7bf6c
Merge: 2d212802e f3dfe5990
Author: ezjamsen <ezjames.fi@gmail.com>
Date:   Sat Feb 2 16:45:33 2019 +0200

    Merge branch 'dev' of https://github.com/Regalis11/Barotrauma into dev

commit 2d212802ea945c6cbd1c889d304595b68692e05c
Author: ezjamsen <ezjames.fi@gmail.com>
Date:   Sat Feb 2 16:44:30 2019 +0200

    corrected the condition at which railgun and coilgun loaders can be repaired

commit f3dfe5990a03cb3c577635dffb25883085d919f1
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Sat Feb 2 16:41:34 2019 +0200

    Fixed second submarine overlapping with the outpost at the end of the level in combat missions.

commit 1f224e9b7cae3f94e9b6937d66c171edbd8ef523
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Sat Feb 2 15:35:22 2019 +0200

    Fixed sub/mode selection setting tickboxes

commit 0eb99486454c1bb47b51b20e4d23f42f4147dd8d
Merge: ff90fdb35 80785d627
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Sat Feb 2 15:08:18 2019 +0200

    Merge branch 'dev' of https://github.com/Regalis11/Barotrauma into dev

commit ff90fdb352af6800d0dcf224816cf9e831184f1e
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Sat Feb 2 15:08:12 2019 +0200

    Don't do chat message similarity tests on order messages (caused spam kicks way too easily when giving orders or reporting things)

commit af8a350c7998ae2c729b4354c3c02cbcf75cabde
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Sat Feb 2 15:06:42 2019 +0200

    Fixed Huskappendage.xml not being copied to the output directory

commit df3af76d909099e9c9e59f74b1f5b3b381303a99
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Sat Feb 2 14:06:19 2019 +0200

    Revert "Ignore anything but the content path when checking the filepath cases." Doesn't work correctly if there's a folder named "Content" in some subfolder (e.g. "Mods/SomeMod/Content") or if checking file paths somewhere else than the content folder (Submarines, Data, NewWorkshopItem, Mods...)

    This reverts commit 123e84ea1ac6f4392c293d0d5c64b857bfc4eb30.

commit 80785d627c82948ce1784654070a0da8f732ca33
Author: ezjamsen <ezjames.fi@gmail.com>
Date:   Sat Feb 2 14:43:36 2019 +0200

    added better visual feedback when reactor is in poor condition

commit e450872721d8e0b47b3ae5792292ea2071a8eefe
Author: ezjamsen <ezjames.fi@gmail.com>
Date:   Sat Feb 2 14:40:42 2019 +0200

    added a small stun effect to railgun shells

commit 05792285eab781990bdc3b658a9217ff38704d1e
Author: ezjamsen <ezjames.fi@gmail.com>
Date:   Sat Feb 2 14:40:03 2019 +0200

    added a little extra fuel, moved the position of guns to hull to prevent players getting caught under them

commit 8c85c33023b6cec1c18b8743d1f05fd4fc8c2ea7
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Sat Feb 2 13:58:55 2019 +0200

    Fixed crashing when attempting to use active sonar in the sub editor. Closes #1024

commit d71225d8c58fb285cbf207549b77cabdc7e1df11
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Fri Feb 1 18:27:06 2019 +0200

    Fixed crashing when selecting an item in a fabricator that's linked to containers, but not set to display the contents of the containers

commit a6fa5d82c7b1505932b8283ccfef75798b839d92
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Fri Feb 1 18:07:40 2019 +0200

    Fixed "can't create and entity event for Hull" error messages when attempting to remove a hull with fire sources in it in MP

commit 72737c6d3eb7ca7daf5e5d84fdcbc1f060b79b10
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Fri Feb 1 18:05:04 2019 +0200

    Filename case fix part 913, fixed rewards mentioned in mission descriptions not matching the actual reward of the mission.

commit a148c7843f2805b1757d231bcf028bafdbc22187
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Fri Feb 1 17:56:18 2019 +0200

    Attempt to forward steam query port when UPnP is enabled

commit 3e73d705c221a417f60baf76c8c7d100391f7802
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Fri Feb 1 17:44:34 2019 +0200

    Removed the "training" button from the main menu (not needed, tutorial is now implemented directly in the SP campaign)

commit 1f07c3f1b4de0bb09fe11e9834faeea30e4afade
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Fri Feb 1 17:33:01 2019 +0200

    Fixed crewmanager UI elements hidden outside the extents of the crew list overlapping with other UI elements

commit aa0c5f4e90b57a8ee3f152b9aeba1e73c7c539c0
Merge: 123e84ea1 73f51a405
Author: itchyOwl <lauri.harkanen@gmail.com>
Date:   Fri Feb 1 16:21:27 2019 +0200

    Merge branch 'dev' of https://github.com/Regalis11/Barotrauma into dev

commit 123e84ea1ac6f4392c293d0d5c64b857bfc4eb30
Author: itchyOwl <lauri.harkanen@gmail.com>
Date:   Fri Feb 1 16:21:19 2019 +0200

    Ignore anything but the content path when checking the filepath cases.

commit 73f51a4055ca7fd1cd65570a51d88db1f1272d23
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Fri Feb 1 15:20:15 2019 +0200

    Don't show the "incorrect case" errors in non-linux release builds. It seems that Path.GetFullPath may return paths with an incorrect case on Windows (try changing the case of any of the game's parent folders to repro).

commit 5a598129a9d63c5185529107d469404c35be59c5
Author: ezjamsen <ezjames.fi@gmail.com>
Date:   Fri Feb 1 11:29:41 2019 +0200

    Renamed hull areas... again.
2019-03-18 21:09:32 +02:00

752 lines
27 KiB
C#

using Barotrauma.Items.Components;
using FarseerPhysics;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Xml.Linq;
namespace Barotrauma
{
partial class Gap : MapEntity
{
public static List<Gap> GapList = new List<Gap>();
const float MaxFlowForce = 500.0f;
public static bool ShowGaps = true;
const float OutsideColliderRaycastInterval = 0.1f;
public bool IsHorizontal
{
get;
private set;
}
//a value between 0.0f-1.0f (0.0 = closed, 1.0f = open)
private float open;
//the force of the water flow which is exerted on physics bodies
private Vector2 flowForce;
private Hull flowTargetHull;
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
public bool DisableHullRechecks;
//can ambient light get through the gap even if it's not open
public bool PassAmbientLight;
//position of a collider outside the gap (for example an ice wall next to the sub)
//used by ragdolls to prevent them from ending up inside colliders when teleporting out of the sub
private Vector2? outsideColliderPos;
private Vector2? outsideColliderNormal;
private float outsideColliderRaycastTimer;
public float Open
{
get { return open; }
set { open = MathHelper.Clamp(value, 0.0f, 1.0f); }
}
public Door ConnectedDoor;
public Structure ConnectedWall;
public Vector2 LerpedFlowForce
{
get { return lerpedFlowForce; }
}
public Hull FlowTargetHull
{
get { return flowTargetHull; }
}
public bool IsRoomToRoom
{
get
{
return linkedTo.Count == 2;
}
}
public override Rectangle Rect
{
get
{
return base.Rect;
}
set
{
base.Rect = value;
FindHulls();
}
}
public override string Name
{
get
{
return "Gap";
}
}
public Gap(MapEntityPrefab prefab, Rectangle rectangle)
: this (rectangle, Submarine.MainSub)
{ }
public Gap(Rectangle newRect, Submarine submarine)
: this(newRect, newRect.Width < newRect.Height, submarine)
{ }
public Gap(Rectangle newRect, bool isHorizontal, Submarine submarine)
: base (MapEntityPrefab.Find(null, "gap"), submarine)
{
rect = newRect;
linkedTo = new ObservableCollection<MapEntity>();
flowForce = Vector2.Zero;
this.IsHorizontal = isHorizontal;
open = 1.0f;
FindHulls();
GapList.Add(this);
InsertToList();
}
public override MapEntity Clone()
{
return new Gap(rect, IsHorizontal, Submarine);
}
public override void Move(Vector2 amount)
{
base.Move(amount);
if (!DisableHullRechecks) FindHulls();
}
public static void UpdateHulls()
{
foreach (Gap g in GapList)
{
for (int i = g.linkedTo.Count - 1; i >= 0; i--)
{
if (g.linkedTo[i].Removed)
{
g.linkedTo.RemoveAt(i);
}
}
if (g.DisableHullRechecks) continue;
g.FindHulls();
}
}
public override bool IsMouseOn(Vector2 position)
{
return ShowGaps && Submarine.RectContains(WorldRect, position) &&
!Submarine.RectContains(MathUtils.ExpandRect(WorldRect, -5), position);
}
public void AutoOrient()
{
Vector2 searchPosLeft = new Vector2(rect.X, rect.Y - rect.Height / 2);
Hull hullLeft = Hull.FindHullOld(searchPosLeft, null, false);
Vector2 searchPosRight = new Vector2(rect.Right, rect.Y - rect.Height / 2);
Hull hullRight = Hull.FindHullOld(searchPosRight, null, false);
if (hullLeft != null && hullRight != null && hullLeft != hullRight)
{
IsHorizontal = true;
return;
}
Vector2 searchPosTop = new Vector2(rect.Center.X, rect.Y);
Hull hullTop = Hull.FindHullOld(searchPosTop, null, false);
Vector2 searchPosBottom = new Vector2(rect.Center.X, rect.Y - rect.Height);
Hull hullBottom = Hull.FindHullOld(searchPosBottom, null, false);
if (hullTop != null && hullBottom != null && hullTop != hullBottom)
{
IsHorizontal = false;
return;
}
if ((hullLeft == null) != (hullRight == null))
{
IsHorizontal = true;
}
else if ((hullTop == null) != (hullBottom == null))
{
IsHorizontal = false;
}
}
private void FindHulls()
{
Hull[] hulls = new Hull[2];
linkedTo.Clear();
Vector2[] searchPos = new Vector2[2];
if (IsHorizontal)
{
searchPos[0] = new Vector2(rect.X, rect.Y - rect.Height / 2);
searchPos[1] = new Vector2(rect.Right, rect.Y - rect.Height / 2);
}
else
{
searchPos[0] = new Vector2(rect.Center.X, rect.Y);
searchPos[1] = new Vector2(rect.Center.X, rect.Y - rect.Height);
}
for (int i = 0; i < 2; i++)
{
hulls[i] = Hull.FindHullOld(searchPos[i], null, false);
if (hulls[i] == null) hulls[i] = Hull.FindHullOld(searchPos[i], null, false, true);
}
if (hulls[0] == null && hulls[1] == null) return;
if (hulls[0] == null && hulls[1] != null)
{
Hull temp = hulls[0];
hulls[0] = hulls[1];
hulls[1] = temp;
}
flowTargetHull = hulls[0];
for (int i = 0; i < 2; i++)
{
if (hulls[i] == null) continue;
linkedTo.Add(hulls[i]);
if (!hulls[i].ConnectedGaps.Contains(this)) hulls[i].ConnectedGaps.Add(this);
}
}
public override void Update(float deltaTime, Camera cam)
{
flowForce = Vector2.Zero;
outsideColliderRaycastTimer -= deltaTime;
if (open == 0.0f || linkedTo.Count == 0)
{
lerpedFlowForce = Vector2.Zero;
return;
}
UpdateOxygen();
if (linkedTo.Count == 1)
{
//gap leading from a room to outside
UpdateRoomToOut(deltaTime);
}
else
{
//gap leading from a room to another
UpdateRoomToRoom(deltaTime);
}
flowForce.X = MathHelper.Clamp(flowForce.X, -MaxFlowForce, MaxFlowForce);
flowForce.Y = MathHelper.Clamp(flowForce.Y, -MaxFlowForce, MaxFlowForce);
lerpedFlowForce = Vector2.Lerp(lerpedFlowForce, flowForce, deltaTime * 5.0f);
EmitParticles(deltaTime);
if (flowTargetHull != null && lerpedFlowForce.LengthSquared() > 0.0001f)
{
foreach (Character character in Character.CharacterList)
{
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)
{
if (!limb.inWater) continue;
float dist = Vector2.Distance(limb.WorldPosition, WorldPosition);
if (dist > lerpedFlowForce.Length()) continue;
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) break;
force *= 1.0f - xDist / rect.Width;
}
if (!MathUtils.IsValid(force))
{
string errorMsg = "Attempted to apply invalid flow force to the character \"" + character.Name +
"\", gap pos: " + WorldPosition +
", limb pos: " + limb.WorldPosition +
", flowforce: " + flowForce + ", lerpedFlowForce:" + lerpedFlowForce +
", dist: " + dist;
DebugConsole.Log(errorMsg);
GameAnalyticsManager.AddErrorEventOnce("Gap.Update:InvalidFlowForce:" + character.Name,
GameAnalyticsSDK.Net.EGAErrorSeverity.Error,
errorMsg);
continue;
}
character.AnimController.Collider.ApplyForce(force * limb.body.Mass);
}
}
}
}
partial void EmitParticles(float deltaTime);
void UpdateRoomToRoom(float deltaTime)
{
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.WaterVolume <= 0.0 && hull2.WaterVolume <= 0.0) return;
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)
{
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 + subOffset.Y + hull2.WaveY[0]) > rect.Y - size)
{
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.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);
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.WaterVolume, hull2.Volume));
//make sure not to place more water to the target room than it can hold
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);
}
flowForce = new Vector2(-delta, 0.0f);
}
else if (dir == 1)
{
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.WaterVolume, hull1.Volume));
//make sure not to place more water to the target room than it can hold
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);
}
flowForce = new Vector2(delta, 0.0f);
}
if (delta > 100.0f && subOffset == Vector2.Zero)
{
float avg = (hull1.Surface + hull2.Surface) / 2.0f;
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 - 2] = hull1.WaveVel[hull1.WaveY.Length - 1];
}
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];
}
}
}
}
else
{
//lower room is full of water
if (hull2.Pressure + subOffset.Y > hull1.Pressure && hull2.WaterVolume > 0.0f)
{
float delta = Math.Min(hull2.WaterVolume - hull2.Volume + Hull.MaxCompress, deltaTime * 8000.0f * sizeModifier);
//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.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.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.WaterVolume > 0)
{
flowTargetHull = hull2;
//make sure the amount of water moved isn't more than what the room contains
float delta = Math.Min(hull1.WaterVolume, deltaTime * 25000f * sizeModifier);
//make sure not to place more water to the target room than it can hold
if (hull2.WaterVolume + delta > hull2.Volume + Hull.MaxCompress)
{
delta -= (hull2.WaterVolume + delta) - (hull2.Volume + Hull.MaxCompress);
}
hull1.WaterVolume -= delta;
hull2.WaterVolume += delta;
flowForce = new Vector2(
hull1.WaveY[hull1.GetWaveIndex(rect.X)] - hull1.WaveY[hull1.GetWaveIndex(rect.Right)],
MathHelper.Clamp(-delta, -200.0f, 0.0f));
if (hull2.WaterVolume > hull2.Volume)
{
hull2.Pressure = Math.Max(hull2.Pressure, ((hull1.Pressure - subOffset.Y) + hull2.Pressure) / 2);
}
}
}
if (open > 0.0f)
{
if (hull1.WaterVolume > hull1.Volume - Hull.MaxCompress && hull2.WaterVolume > hull2.Volume - Hull.MaxCompress)
{
float avgLethality = (hull1.LethalPressure + hull2.LethalPressure) / 2.0f;
hull1.LethalPressure = avgLethality;
hull2.LethalPressure = avgLethality;
}
else
{
hull1.LethalPressure = 0.0f;
hull2.LethalPressure = 0.0f;
}
}
}
void UpdateRoomToOut(float deltaTime)
{
if (linkedTo.Count != 1) return;
float size = (IsHorizontal) ? rect.Height : rect.Width;
Hull hull1 = (Hull)linkedTo[0];
//a variable affecting the water flow through the gap
//the larger the gap is, the faster the water flows
float sizeModifier = size * open * open;
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.Volume + Hull.MaxCompress - hull1.WaterVolume);
hull1.WaterVolume += delta;
if (hull1.WaterVolume > hull1.Volume) hull1.Pressure += 0.5f;
flowTargetHull = hull1;
if (IsHorizontal)
{
//water flowing from right to left
if (rect.X > hull1.Rect.X + hull1.Rect.Width / 2.0f)
{
flowForce = new Vector2(-delta, 0.0f);
}
else
{
flowForce = new Vector2(delta, 0.0f);
}
higherSurface = hull1.Surface;
lowerSurface = rect.Y;
if (hull1.WaterVolume < hull1.Volume - Hull.MaxCompress &&
hull1.Surface < rect.Y)
{
if (rect.X > hull1.Rect.X + hull1.Rect.Width / 2.0f)
{
float vel = ((rect.Y - rect.Height / 2) - (hull1.Surface + hull1.WaveY[hull1.WaveY.Length - 1])) * 0.1f;
vel *= Math.Min(Math.Abs(flowForce.X) / 200.0f, 1.0f);
hull1.WaveVel[hull1.WaveY.Length - 1] += vel;
hull1.WaveVel[hull1.WaveY.Length - 2] += vel;
}
else
{
float vel = ((rect.Y - rect.Height / 2) - (hull1.Surface + hull1.WaveY[0])) * 0.1f;
vel *= Math.Min(Math.Abs(flowForce.X) / 200.0f, 1.0f);
hull1.WaveVel[0] += vel;
hull1.WaveVel[1] += vel;
}
}
else
{
hull1.LethalPressure += (Submarine != null && Submarine.AtDamageDepth) ? 100.0f * deltaTime : 10.0f * deltaTime;
}
}
else
{
if (rect.Y > hull1.Rect.Y - hull1.Rect.Height / 2.0f)
{
flowForce = new Vector2(0.0f, -delta);
}
else
{
flowForce = new Vector2(0.0f, delta);
}
if (hull1.WaterVolume >= hull1.Volume - Hull.MaxCompress)
{
hull1.LethalPressure += (Submarine != null && Submarine.AtDamageDepth) ? 100.0f * deltaTime : 10.0f * deltaTime;
}
}
}
public bool GetOutsideCollider(out Vector2? simPosition, out Vector2? normal)
{
simPosition = null;
normal = null;
if (IsRoomToRoom || Submarine == null || open <= 0.0f || linkedTo.Count == 0 || !(linkedTo[0] is Hull)) return false;
if (outsideColliderRaycastTimer <= 0.0f)
{
UpdateOutsideColliderPos((Hull)linkedTo[0]);
outsideColliderRaycastTimer = OutsideColliderRaycastInterval;
}
simPosition = outsideColliderPos;
normal = outsideColliderNormal;
return simPosition != null;
}
private void UpdateOutsideColliderPos(Hull hull)
{
outsideColliderNormal = null;
outsideColliderPos = null;
if (Submarine == null) return;
Vector2 rayDir;
if (IsHorizontal)
{
rayDir = new Vector2(Math.Sign(rect.Center.X - hull.Rect.Center.X), 0);
}
else
{
rayDir = new Vector2(0, Math.Sign((rect.Y - rect.Height / 2) - (hull.Rect.Y - hull.Rect.Height / 2)));
}
Vector2 rayStart = ConvertUnits.ToSimUnits(WorldPosition);
Vector2 rayEnd = rayStart + rayDir * 500.0f;
if (Submarine.CheckVisibility(rayStart, rayEnd) != null)
{
outsideColliderNormal = -rayDir;
outsideColliderPos = Submarine.LastPickedPosition;
}
}
private void UpdateOxygen()
{
if (linkedTo.Count < 2) return;
Hull hull1 = (Hull)linkedTo[0];
Hull hull2 = (Hull)linkedTo[1];
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.Volume + hull2.Volume);
float deltaOxygen = (totalOxygen * hull1.Volume / totalVolume) - hull1.Oxygen;
deltaOxygen = MathHelper.Clamp(deltaOxygen, -Hull.OxygenDistributionSpeed, Hull.OxygenDistributionSpeed);
hull1.Oxygen += deltaOxygen;
hull2.Oxygen -= deltaOxygen;
}
public static Gap FindAdjacent(IEnumerable<Gap> gaps, Vector2 worldPos, float allowedOrthogonalDist)
{
foreach (Gap gap in gaps)
{
if (gap.Open == 0.0f || gap.IsRoomToRoom) continue;
if (gap.ConnectedWall != null)
{
int sectionIndex = gap.ConnectedWall.FindSectionIndex(gap.Position);
if (sectionIndex > -1 && !gap.ConnectedWall.SectionBodyDisabled(sectionIndex)) continue;
}
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)
{
return gap;
}
}
else
{
if (worldPos.X > gap.WorldRect.X && worldPos.X < gap.WorldRect.Right &&
Math.Abs(gap.WorldRect.Y - gap.WorldRect.Height / 2 - worldPos.Y) < allowedOrthogonalDist)
{
return gap;
}
}
}
return null;
}
public override void ShallowRemove()
{
base.ShallowRemove();
GapList.Remove(this);
foreach (Hull hull in Hull.hullList)
{
hull.ConnectedGaps.Remove(this);
}
}
public override void Remove()
{
base.Remove();
GapList.Remove(this);
foreach (Hull hull in Hull.hullList)
{
hull.ConnectedGaps.Remove(this);
}
}
public override void OnMapLoaded()
{
if (!DisableHullRechecks) FindHulls();
}
public static Gap Load(XElement element, Submarine submarine)
{
Rectangle rect = Rectangle.Empty;
if (element.Attribute("rect") != null)
{
rect = element.GetAttributeRect("rect", Rectangle.Empty);
}
else
{
//backwards compatibility
rect = new Rectangle(
int.Parse(element.Attribute("x").Value),
int.Parse(element.Attribute("y").Value),
int.Parse(element.Attribute("width").Value),
int.Parse(element.Attribute("height").Value));
}
bool isHorizontal = rect.Height > rect.Width;
var horizontalAttribute = element.Attribute("horizontal");
if (horizontalAttribute != null)
{
isHorizontal = horizontalAttribute.Value.ToString() == "true";
}
Gap g = new Gap(rect, isHorizontal, submarine);
g.ID = (ushort)int.Parse(element.Attribute("ID").Value);
g.linkedToID = new List<ushort>();
return g;
}
public override XElement Save(XElement parentElement)
{
XElement element = new XElement("Gap");
element.Add(
new XAttribute("ID", ID),
new XAttribute("horizontal", IsHorizontal ? "true" : "false"));
element.Add(new XAttribute("rect",
(int)(rect.X - Submarine.HiddenSubPosition.X) + "," +
(int)(rect.Y - Submarine.HiddenSubPosition.Y) + "," +
rect.Width + "," + rect.Height));
parentElement.Add(element);
return element;
}
}
}