diff --git a/Subsurface/Source/Characters/AI/IndoorsSteeringManager.cs b/Subsurface/Source/Characters/AI/IndoorsSteeringManager.cs
index c1e622deb..8c1ba6307 100644
--- a/Subsurface/Source/Characters/AI/IndoorsSteeringManager.cs
+++ b/Subsurface/Source/Characters/AI/IndoorsSteeringManager.cs
@@ -78,6 +78,7 @@ namespace Barotrauma
Vector2 pos = host.SimPosition;
if (character!=null && character.Submarine==null)
{
+ //todo: take multiple subs into account
pos -= Submarine.MainSub.SimPosition;
}
@@ -107,6 +108,7 @@ namespace Barotrauma
Vector2 pos2 = host.SimPosition;
if (character != null && character.Submarine == null)
{
+ //todo: take multiple subs into account
pos2 -= Submarine.MainSub.SimPosition;
}
return currentTarget-pos2;
@@ -120,6 +122,7 @@ namespace Barotrauma
Vector2 pos = host.SimPosition;
if (character != null && character.Submarine == null)
{
+ //todo: take multiple subs into account
pos -= Submarine.MainSub.SimPosition;
}
diff --git a/Subsurface/Source/CoroutineManager.cs b/Subsurface/Source/CoroutineManager.cs
index 7d9187e9c..a6b9929d5 100644
--- a/Subsurface/Source/CoroutineManager.cs
+++ b/Subsurface/Source/CoroutineManager.cs
@@ -86,21 +86,21 @@ namespace Barotrauma
}
}
- try
- {
+ //try
+ //{
Coroutines[i].Coroutine.MoveNext();
- }
+ //}
- catch (Exception e)
- {
- DebugConsole.ThrowError("Coroutine " + Coroutines[i].Name + " threw an exception: " + e.Message);
+ //catch (Exception e)
+ //{
+ // DebugConsole.ThrowError("Coroutine " + Coroutines[i].Name + " threw an exception: " + e.Message);
-#if DEBUG
- throw e;
-#endif
+//#if DEBUG
+// throw e;
+//#endif
- Coroutines.RemoveAt(i);
- }
+// Coroutines.RemoveAt(i);
+// }
}
}
diff --git a/Subsurface/Source/GameSession/GameSession.cs b/Subsurface/Source/GameSession/GameSession.cs
index 901e59b26..d31140560 100644
--- a/Subsurface/Source/GameSession/GameSession.cs
+++ b/Subsurface/Source/GameSession/GameSession.cs
@@ -68,6 +68,8 @@ namespace Barotrauma
public GameSession(Submarine submarine, string saveFile, GameModePreset gameModePreset = null, string missionType="")
{
+ Submarine.MainSub = submarine;
+
GameMain.GameSession = this;
CrewManager = new CrewManager();
@@ -88,6 +90,8 @@ namespace Barotrauma
public GameSession(Submarine selectedSub, string saveFile, XDocument doc)
: this(selectedSub, saveFile)
{
+ Submarine.MainSub = submarine;
+
GameMain.GameSession = this;
CrewManager = new CrewManager();
diff --git a/Subsurface/Source/Items/Components/Holdable/RepairTool.cs b/Subsurface/Source/Items/Components/Holdable/RepairTool.cs
index e23911b06..b1d4037f1 100644
--- a/Subsurface/Source/Items/Components/Holdable/RepairTool.cs
+++ b/Subsurface/Source/Items/Components/Holdable/RepairTool.cs
@@ -132,80 +132,19 @@ namespace Barotrauma.Items.Components
IsActive = true;
activeTimer = 0.1f;
+ Vector2 rayStart = ConvertUnits.ToSimUnits(item.WorldPosition);
+ Vector2 rayEnd = ConvertUnits.ToSimUnits(targetPosition);
- for (int n = 0; n < 2; n++)
+ if (character.Submarine == null)
{
- Vector2 rayStart = ConvertUnits.ToSimUnits(item.WorldPosition);
- Vector2 rayEnd = ConvertUnits.ToSimUnits(targetPosition);
-
- if (n == 0)
+ foreach (Submarine sub in Submarine.Loaded)
{
- //do a raycast in "submarine coordinates"
- rayStart -= Submarine.Loaded.SimPosition;
- rayEnd -= Submarine.Loaded.SimPosition;
+ Repair(rayStart - sub.SimPosition, rayEnd - sub.SimPosition, deltaTime, character, degreeOfSuccess, ignoredBodies);
}
- else
- {
- //do a raycast outside the sub if the character is outside
- if (character.AnimController.CurrentHull != null) continue;
- }
-
- Body targetBody = Submarine.PickBody(rayStart, rayEnd, ignoredBodies);
-
- pickedPosition = Submarine.LastPickedPosition;
-
- if (ExtinquishAmount > 0.0f)
- {
- Vector2 displayPos = rayStart + (rayEnd - rayStart) * Submarine.LastPickedFraction * 0.9f;
- Hull hull = Hull.FindHull(displayPos, item.CurrentHull);
- if (hull != null) hull.Extinquish(deltaTime, ExtinquishAmount, displayPos);
- }
-
- if (targetBody == null || targetBody.UserData == null) continue;
-
- Structure targetStructure;
- Limb targetLimb;
- Item targetItem;
- if ((targetStructure = (targetBody.UserData as Structure)) != null)
- {
- if (!fixableEntities.Contains(targetStructure.Name)) continue;
-
- int sectionIndex = targetStructure.FindSectionIndex(ConvertUnits.ToDisplayUnits(pickedPosition));
- if (sectionIndex < 0) continue;
-
- targetStructure.HighLightSection(sectionIndex);
-
- targetStructure.AddDamage(sectionIndex, -StructureFixAmount * degreeOfSuccess);
-
- //if the next section is small enough, apply the effect to it as well
- //(to make it easier to fix a small "left-over" section)
- for (int i = -1; i < 2; i += 2)
- {
- int nextSectionLength = targetStructure.SectionLength(sectionIndex + i);
- if ((sectionIndex == 1 && i == -1) ||
- (sectionIndex == targetStructure.SectionCount - 2 && i == 1) ||
- (nextSectionLength > 0 && nextSectionLength < Structure.wallSectionSize * 0.3f))
- {
- targetStructure.HighLightSection(sectionIndex + i);
- targetStructure.AddDamage(sectionIndex + i, -StructureFixAmount * degreeOfSuccess);
- }
- }
-
-
- }
- else if ((targetLimb = (targetBody.UserData as Limb)) != null)
- {
- if (character.IsKeyDown(InputType.Aim))
- {
- targetLimb.character.AddDamage(CauseOfDeath.Damage, -LimbFixAmount * degreeOfSuccess, character);
- }
- }
- else if ((targetItem = (targetBody.UserData as Item)) != null)
- {
- targetItem.IsHighlighted = true;
-
- ApplyStatusEffects(ActionType.OnUse, targetItem.AllPropertyObjects, deltaTime);
- }
+ }
+ else
+ {
+ Repair(rayStart, rayEnd, deltaTime, character, degreeOfSuccess, ignoredBodies);
}
GameMain.ParticleManager.CreateParticle(particles, item.WorldPosition + TransformedBarrelPos,
@@ -214,6 +153,64 @@ namespace Barotrauma.Items.Components
return true;
}
+ private void Repair(Vector2 rayStart, Vector2 rayEnd, float deltaTime, Character user, float degreeOfSuccess, List
ignoredBodies)
+ {
+
+ Body targetBody = Submarine.PickBody(rayStart, rayEnd, ignoredBodies);
+
+ pickedPosition = Submarine.LastPickedPosition;
+
+ if (ExtinquishAmount > 0.0f)
+ {
+ Vector2 displayPos = rayStart + (rayEnd - rayStart) * Submarine.LastPickedFraction * 0.9f;
+ Hull hull = Hull.FindHull(displayPos, item.CurrentHull);
+ if (hull != null) hull.Extinquish(deltaTime, ExtinquishAmount, displayPos);
+ }
+
+ if (targetBody == null || targetBody.UserData == null) return;
+
+ Structure targetStructure;
+ Limb targetLimb;
+ Item targetItem;
+ if ((targetStructure = (targetBody.UserData as Structure)) != null)
+ {
+ if (!fixableEntities.Contains(targetStructure.Name)) return;
+
+ int sectionIndex = targetStructure.FindSectionIndex(ConvertUnits.ToDisplayUnits(pickedPosition));
+ if (sectionIndex < 0) return;
+
+ targetStructure.HighLightSection(sectionIndex);
+
+ targetStructure.AddDamage(sectionIndex, -StructureFixAmount * degreeOfSuccess);
+
+ //if the next section is small enough, apply the effect to it as well
+ //(to make it easier to fix a small "left-over" section)
+ for (int i = -1; i < 2; i += 2)
+ {
+ int nextSectionLength = targetStructure.SectionLength(sectionIndex + i);
+ if ((sectionIndex == 1 && i == -1) ||
+ (sectionIndex == targetStructure.SectionCount - 2 && i == 1) ||
+ (nextSectionLength > 0 && nextSectionLength < Structure.wallSectionSize * 0.3f))
+ {
+ targetStructure.HighLightSection(sectionIndex + i);
+ targetStructure.AddDamage(sectionIndex + i, -StructureFixAmount * degreeOfSuccess);
+ }
+ }
+
+
+ }
+ else if ((targetLimb = (targetBody.UserData as Limb)) != null)
+ {
+ targetLimb.character.AddDamage(CauseOfDeath.Damage, -LimbFixAmount * degreeOfSuccess, user);
+ }
+ else if ((targetItem = (targetBody.UserData as Item)) != null)
+ {
+ targetItem.IsHighlighted = true;
+
+ ApplyStatusEffects(ActionType.OnUse, targetItem.AllPropertyObjects, deltaTime);
+ }
+ }
+
public override bool AIOperate(float deltaTime, Character character, AIObjectiveOperateItem objective)
{
Gap leak = objective.OperateTarget as Gap;
diff --git a/Subsurface/Source/Map/EntityGrid.cs b/Subsurface/Source/Map/EntityGrid.cs
index b5b5b9d90..8641b6539 100644
--- a/Subsurface/Source/Map/EntityGrid.cs
+++ b/Subsurface/Source/Map/EntityGrid.cs
@@ -12,9 +12,12 @@ namespace Barotrauma
private float cellSize;
- public EntityGrid(Rectangle limits, float cellSize)
+ public readonly Submarine Submarine;
+
+ public EntityGrid(Submarine submarine, float cellSize)
{
- this.limits = limits;
+ this.limits = submarine.Borders;
+ this.Submarine = submarine;
this.cellSize = cellSize;
entities = new List[(int)Math.Ceiling(limits.Width / cellSize), (int)Math.Ceiling(limits.Height / cellSize)];
@@ -71,11 +74,28 @@ namespace Barotrauma
}
}
+ public static List GetEntities(List entityGrids, Vector2 position, bool useWorldCoordinates = true)
+ {
+ List entities = new List();
+ foreach (EntityGrid entityGrid in entityGrids)
+ {
+ Vector2 transformedPosition = position;
+ if (useWorldCoordinates)
+ {
+ transformedPosition -= entityGrid.Submarine.Position;
+ }
+
+ entities.AddRange(entityGrid.GetEntities(position));
+ }
+
+ return entities;
+ }
+
public List GetEntities(Vector2 position)
{
if (!MathUtils.IsValid(position)) new List();
- if (Submarine.Loaded != null) position -= Submarine.HiddenSubPosition;
+ if (Submarine != null) position -= Submarine.HiddenSubPosition;
Point indices = GetIndices(position);
diff --git a/Subsurface/Source/Map/Hull.cs b/Subsurface/Source/Map/Hull.cs
index 813119bf8..d124b5305 100644
--- a/Subsurface/Source/Map/Hull.cs
+++ b/Subsurface/Source/Map/Hull.cs
@@ -15,7 +15,7 @@ namespace Barotrauma
class Hull : MapEntity, IPropertyObject
{
public static List hullList = new List();
- private static EntityGrid entityGrid;
+ private static List entityGrids = new List();
public static bool ShowHulls = true;
@@ -248,13 +248,15 @@ namespace Barotrauma
return rect;
}
- public static void GenerateEntityGrid()
+ public static void GenerateEntityGrid(Submarine submarine)
{
- entityGrid = new EntityGrid(Submarine.Borders, 200.0f);
+ var newGrid = new EntityGrid(submarine, 200.0f);
+
+ entityGrids.Add(newGrid);
foreach (Hull hull in hullList)
{
- entityGrid.InsertEntity(hull);
+ if (hull.Submarine == submarine) newGrid.InsertEntity(hull);
}
}
@@ -313,8 +315,14 @@ namespace Barotrauma
}
//renderer.Dispose();
+ if (entityGrids != null)
+ {
+ foreach (EntityGrid entityGrid in entityGrids)
+ {
+ entityGrid.RemoveEntity(this);
+ }
+ }
- if (entityGrid != null) entityGrid.RemoveEntity(this);
hullList.Remove(this);
}
@@ -652,15 +660,14 @@ namespace Barotrauma
//returns the water block which contains the point (or null if it isn't inside any)
public static Hull FindHull(Vector2 position, Hull guess = null, bool useWorldCoordinates = true)
{
- if (entityGrid == null) return null;
+ if (entityGrids == null) return null;
if (guess != null)
{
if (Submarine.RectContains(useWorldCoordinates ? guess.WorldRect : guess.rect, position)) return guess;
}
- var entities = entityGrid.GetEntities(
- useWorldCoordinates && Submarine.Loaded!=null ? position-Submarine.Loaded.Position : position);
+ var entities = EntityGrid.GetEntities(entityGrids, position, useWorldCoordinates);
foreach (Hull hull in entities)
{
diff --git a/Subsurface/Source/Map/Levels/Level.cs b/Subsurface/Source/Map/Levels/Level.cs
index 338de50a6..8a34933fa 100644
--- a/Subsurface/Source/Map/Levels/Level.cs
+++ b/Subsurface/Source/Map/Levels/Level.cs
@@ -181,7 +181,7 @@ namespace Barotrauma
float avgValue = (backgroundColor.R + backgroundColor.G + backgroundColor.G) / 3;
GameMain.LightManager.AmbientLight = new Color(backgroundColor*(40.0f/avgValue), 1.0f);
- float minWidth = Submarine.Loaded == null ? 0.0f : Math.Max(Submarine.Borders.Width, Submarine.Borders.Height);
+ float minWidth = Submarine.MainSub == null ? 0.0f : Math.Max(Submarine.MainSub.Borders.Width, Submarine.MainSub.Borders.Height);
minWidth = Math.Max(minWidth, 6500.0f);
startPosition = new Vector2(minWidth * 2, Rand.Range(minWidth * 2, borders.Height - minWidth * 2, false));
@@ -783,9 +783,9 @@ namespace Barotrauma
public void Update (float deltaTime)
{
- if (Submarine.Loaded != null)
+ if (Submarine.MainSub != null)
{
- WrappingWall.UpdateWallShift(Submarine.Loaded.WorldPosition, wrappingWalls);
+ WrappingWall.UpdateWallShift(Submarine.MainSub.WorldPosition, wrappingWalls);
}
renderer.Update(deltaTime);
diff --git a/Subsurface/Source/Map/MapEntity.cs b/Subsurface/Source/Map/MapEntity.cs
index 0e9867f99..e1fa83562 100644
--- a/Subsurface/Source/Map/MapEntity.cs
+++ b/Subsurface/Source/Map/MapEntity.cs
@@ -518,7 +518,7 @@ namespace Barotrauma
Vector2 placePosition = new Vector2(rect.X, rect.Y);
Vector2 placeSize = new Vector2(rect.Width, rect.Height);
- Vector2 mousePos = Submarine.MouseToWorldGrid(cam);
+ Vector2 mousePos = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
if (resizeDirX >0)
{
diff --git a/Subsurface/Source/Map/MapEntityPrefab.cs b/Subsurface/Source/Map/MapEntityPrefab.cs
index f4056f461..c16577b7d 100644
--- a/Subsurface/Source/Map/MapEntityPrefab.cs
+++ b/Subsurface/Source/Map/MapEntityPrefab.cs
@@ -128,7 +128,7 @@ namespace Barotrauma
if (placePosition == Vector2.Zero)
{
- Vector2 position = Submarine.MouseToWorldGrid(cam);
+ Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
GUI.DrawLine(spriteBatch, new Vector2(position.X-GameMain.GraphicsWidth, -position.Y), new Vector2(position.X+GameMain.GraphicsWidth, -position.Y), Color.White);
@@ -138,7 +138,7 @@ namespace Barotrauma
}
else
{
- Vector2 position = Submarine.MouseToWorldGrid(cam);
+ Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
if (resizeHorizontal) placeSize.X = position.X - placePosition.X;
if (resizeVertical) placeSize.Y = placePosition.Y - position.Y;
@@ -147,9 +147,9 @@ namespace Barotrauma
newRect.Width = (int)Math.Max(newRect.Width, Submarine.GridSize.X);
newRect.Height = (int)Math.Max(newRect.Height, Submarine.GridSize.Y);
- if (Submarine.Loaded != null)
+ if (Submarine.MainSub != null)
{
- newRect.Location -= Submarine.Loaded.Position.ToPoint();
+ newRect.Location -= Submarine.MainSub.Position.ToPoint();
}
if (PlayerInput.LeftButtonReleased())
diff --git a/Subsurface/Source/Map/Structure.cs b/Subsurface/Source/Map/Structure.cs
index 6298baf60..349498bb3 100644
--- a/Subsurface/Source/Map/Structure.cs
+++ b/Subsurface/Source/Map/Structure.cs
@@ -520,7 +520,7 @@ namespace Barotrauma
public AttackResult AddDamage(IDamageable attacker, Vector2 worldPosition, Attack attack, float deltaTime, bool playSound = false)
{
- if (Submarine.Loaded != null && Submarine.Loaded.GodMode && Submarine == Submarine.Loaded) return new AttackResult(0.0f, 0.0f);
+ if (Submarine != null && Submarine.GodMode) return new AttackResult(0.0f, 0.0f);
if (!prefab.HasBody || prefab.IsPlatform) return new AttackResult(0.0f, 0.0f);
Vector2 transformedPos = worldPosition;
@@ -546,7 +546,7 @@ namespace Barotrauma
private void SetDamage(int sectionIndex, float damage)
{
- if (Submarine.Loaded != null && Submarine.Loaded.GodMode) return;
+ if (Submarine != null && Submarine.GodMode) return;
if (!prefab.HasBody) return;
if (!MathUtils.IsValid(damage)) return;
diff --git a/Subsurface/Source/Map/StructurePrefab.cs b/Subsurface/Source/Map/StructurePrefab.cs
index abedc550c..9d9f7f123 100644
--- a/Subsurface/Source/Map/StructurePrefab.cs
+++ b/Subsurface/Source/Map/StructurePrefab.cs
@@ -128,7 +128,7 @@ namespace Barotrauma
public override void UpdatePlacing(SpriteBatch spriteBatch, Camera cam)
{
- Vector2 position = Submarine.MouseToWorldGrid(cam);
+ Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
//Vector2 placeSize = size;
Rectangle newRect = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y);
@@ -137,7 +137,7 @@ namespace Barotrauma
if (placePosition == Vector2.Zero)
{
if (PlayerInput.LeftButtonHeld())
- placePosition = Submarine.MouseToWorldGrid(cam);
+ placePosition = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
newRect.X = (int)position.X;
newRect.Y = (int)position.Y;
@@ -154,14 +154,10 @@ namespace Barotrauma
if (PlayerInput.LeftButtonReleased())
{
- if (Submarine.Loaded != null)
- {
- newRect.Location -= Submarine.Loaded.Position.ToPoint();
- }
+ newRect.Location -= Submarine.MainSub.Position.ToPoint();
- var structure = new Structure(newRect, this, Submarine.Loaded);
-
- structure.Submarine = Submarine.Loaded;
+ var structure = new Structure(newRect, this, Submarine.MainSub);
+ structure.Submarine = Submarine.MainSub;
selected = null;
return;
diff --git a/Subsurface/Source/Map/Submarine.cs b/Subsurface/Source/Map/Submarine.cs
index 7c5da46d5..87382b78c 100644
--- a/Subsurface/Source/Map/Submarine.cs
+++ b/Subsurface/Source/Map/Submarine.cs
@@ -31,7 +31,7 @@ namespace Barotrauma
public static readonly Vector2 GridSize = new Vector2(16.0f, 16.0f);
public static Submarine MainSub;
- private static List loaded;
+ private static List loaded = new List();
private SubmarineBody subBody;
@@ -97,10 +97,10 @@ namespace Barotrauma
}
}
- //public static List Loaded
- //{
- // get { return loaded; }
- //}
+ public static List Loaded
+ {
+ get { return loaded; }
+ }
public Rectangle Borders
{
@@ -789,7 +789,7 @@ namespace Barotrauma
loaded.Add(this);
- Hull.GenerateEntityGrid();
+ Hull.GenerateEntityGrid(this);
for (int i = 0; i < MapEntity.mapEntityList.Count; i++)
{
diff --git a/Subsurface/Source/Map/WayPoint.cs b/Subsurface/Source/Map/WayPoint.cs
index 2197edc70..9854a9348 100644
--- a/Subsurface/Source/Map/WayPoint.cs
+++ b/Subsurface/Source/Map/WayPoint.cs
@@ -83,7 +83,7 @@ namespace Barotrauma
}
public WayPoint(MapEntityPrefab prefab, Rectangle rectangle)
- : this (rectangle, Submarine.Loaded)
+ : this (rectangle, Submarine.MainSub)
{
if (prefab.Name.Contains("Spawn"))
{
@@ -306,7 +306,7 @@ namespace Barotrauma
return editingHUD;
}
- public static void GenerateSubWaypoints()
+ public static void GenerateSubWaypoints(Submarine submarine)
{
if (!Hull.hullList.Any())
{
@@ -332,13 +332,13 @@ namespace Barotrauma
if (hull.Rect.Width();
if (door != null)
{
- WayPoint newPoint = new WayPoint(door.Item.Position, SpawnType.Path, Submarine.Loaded);
+ WayPoint newPoint = new WayPoint(door.Item.Position, SpawnType.Path, submarine);
newPoint.Ladders = ladders;
newPoint.ConnectedGap = door.LinkedGap;
@@ -538,7 +539,7 @@ namespace Barotrauma
if (gap.Rect.Height < 150.0f) continue;
var wayPoint = new WayPoint(
- new Vector2(gap.Rect.Center.X, gap.Rect.Y - gap.Rect.Height + heightFromFloor), SpawnType.Path, Submarine.Loaded, gap);
+ new Vector2(gap.Rect.Center.X, gap.Rect.Y - gap.Rect.Height + heightFromFloor), SpawnType.Path, submarine, gap);
for (int dir = -1; dir <= 1; dir += 2)
{
@@ -557,7 +558,7 @@ namespace Barotrauma
if (gap.Rect.Width < 100.0f) continue;
var wayPoint = new WayPoint(
- new Vector2(gap.Rect.Center.X, gap.Rect.Y - gap.Rect.Height/2), SpawnType.Path, Submarine.Loaded, gap);
+ new Vector2(gap.Rect.Center.X, gap.Rect.Y - gap.Rect.Height/2), SpawnType.Path, submarine, gap);
for (int dir = -1; dir <= 1; dir += 2)
{
@@ -583,35 +584,35 @@ namespace Barotrauma
WayPoint closest = null;
- foreach (WayPoint wp in WayPointList)
+ foreach (WayPoint wp in WayPointList)
+ {
+ if (wp.SpawnType != SpawnType.Path || wp == this) continue;
+
+ float diff = 0.0f;
+ if (horizontalSearch)
{
- if (wp.SpawnType != SpawnType.Path || wp == this) continue;
+ if ((wp.Position.Y - Position.Y) < tolerance.X || (wp.Position.Y - Position.Y) > tolerance.Y) continue;
- float diff = 0.0f;
- if (horizontalSearch)
- {
- if ((wp.Position.Y - Position.Y) < tolerance.X || (wp.Position.Y - Position.Y) > tolerance.Y) continue;
-
- diff = wp.Position.X - Position.X;
- }
- else
- {
- if ((wp.Position.X - Position.X) < tolerance.X || (wp.Position.X - Position.X) > tolerance.Y) continue;
-
- diff = wp.Position.Y - Position.Y;
- }
-
- if (Math.Sign(diff) != dir) continue;
-
- float dist = Vector2.Distance(wp.Position, Position);
- if (closest == null || dist < closestDist)
- {
- if (Submarine.CheckVisibility(SimPosition, wp.SimPosition) != null) continue;
-
- closestDist = dist;
- closest = wp;
- }
+ diff = wp.Position.X - Position.X;
}
+ else
+ {
+ if ((wp.Position.X - Position.X) < tolerance.X || (wp.Position.X - Position.X) > tolerance.Y) continue;
+
+ diff = wp.Position.Y - Position.Y;
+ }
+
+ if (Math.Sign(diff) != dir) continue;
+
+ float dist = Vector2.Distance(wp.Position, Position);
+ if (closest == null || dist < closestDist)
+ {
+ if (Submarine.CheckVisibility(SimPosition, wp.SimPosition) != null) continue;
+
+ closestDist = dist;
+ closest = wp;
+ }
+ }
return closest;
diff --git a/Subsurface/Source/Networking/GameClient.cs b/Subsurface/Source/Networking/GameClient.cs
index 0cc704603..905d2e5e1 100644
--- a/Subsurface/Source/Networking/GameClient.cs
+++ b/Subsurface/Source/Networking/GameClient.cs
@@ -729,7 +729,7 @@ namespace Barotrauma.Networking
if (Screen.Selected == GameMain.GameScreen)
{
- var cinematic = new TransitionCinematic(Submarine.Loaded, GameMain.GameScreen.Cam, endPreviewLength);
+ var cinematic = new TransitionCinematic(Submarine.MainSub, GameMain.GameScreen.Cam, endPreviewLength);
float secondsLeft = endPreviewLength;
diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs
index f15001b48..0ea8f8c99 100644
--- a/Subsurface/Source/Networking/GameServer.cs
+++ b/Subsurface/Source/Networking/GameServer.cs
@@ -289,7 +289,7 @@ namespace Barotrauma.Networking
//restart if all characters are dead or submarine is at the end of the level
if ((autoRestart && isCrewDead)
||
- (endRoundAtLevelEnd && Submarine.Loaded!=null && Submarine.Loaded.AtEndPosition))
+ (endRoundAtLevelEnd && Submarine.MainSub != null && Submarine.MainSub.AtEndPosition))
{
if (AutoRestart && isCrewDead)
{
@@ -363,7 +363,8 @@ namespace Barotrauma.Networking
{
if (!(c is AICharacter) || c.IsDead) continue;
- Vector2 diff = c.WorldPosition-Submarine.Loaded.WorldPosition;
+ //todo: take multiple subs into account
+ Vector2 diff = c.WorldPosition - Submarine.MainSub.WorldPosition;
if (FarseerPhysics.ConvertUnits.ToSimUnits(diff.Length()) > NetConfig.CharacterIgnoreDistance) continue;
@@ -389,7 +390,13 @@ namespace Barotrauma.Networking
private void SparseUpdate()
{
- if (gameStarted) new NetworkEvent(Submarine.Loaded.ID, false);
+ if (gameStarted)
+ {
+ foreach (Submarine sub in Submarine.Loaded)
+ {
+ new NetworkEvent(sub.ID, false);
+ }
+ }
foreach (Character c in Character.CharacterList)
{
@@ -397,7 +404,8 @@ namespace Barotrauma.Networking
if (c is AICharacter)
{
- Vector2 diff = c.WorldPosition - Submarine.Loaded.WorldPosition;
+ //todo: take multiple subs into account
+ Vector2 diff = c.WorldPosition - Submarine.MainSub.WorldPosition;
if (FarseerPhysics.ConvertUnits.ToSimUnits(diff.Length()) > NetConfig.CharacterIgnoreDistance) continue;
}
@@ -601,7 +609,7 @@ namespace Barotrauma.Networking
case (byte)PacketTypes.SpectateRequest:
if (gameStarted && allowSpectating)
{
- var startMessage = CreateStartMessage(roundStartSeed, Submarine.Loaded, GameMain.GameSession.gameMode.Preset);
+ var startMessage = CreateStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset);
server.SendMessage(startMessage, inc.SenderConnection, NetDeliveryMethod.ReliableUnordered);
dataSender.Spectating = true;
@@ -985,7 +993,7 @@ namespace Barotrauma.Networking
GameMain.GameSession.CrewManager.characters.Add(myCharacter);
}
- var startMessage = CreateStartMessage(roundStartSeed, Submarine.Loaded, GameMain.GameSession.gameMode.Preset);
+ var startMessage = CreateStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset);
SendMessage(startMessage, NetDeliveryMethod.ReliableUnordered);
@@ -1113,7 +1121,7 @@ namespace Barotrauma.Networking
float endPreviewLength = 10.0f;
- var cinematic = new TransitionCinematic(Submarine.Loaded, GameMain.GameScreen.Cam, endPreviewLength);
+ var cinematic = new TransitionCinematic(Submarine.MainSub, GameMain.GameScreen.Cam, endPreviewLength);
float secondsLeft = endPreviewLength;
diff --git a/Subsurface/Source/Program.cs b/Subsurface/Source/Program.cs
index d330ef949..a9467f510 100644
--- a/Subsurface/Source/Program.cs
+++ b/Subsurface/Source/Program.cs
@@ -65,7 +65,7 @@ namespace Barotrauma
sb.AppendLine("Game version " + GameMain.Version);
sb.AppendLine("Selected content package: " + GameMain.SelectedPackage.Name);
sb.AppendLine("Level seed: "+ ((Level.Loaded == null) ? "no level loaded" : Level.Loaded.Seed));
- sb.AppendLine("Loaded submarine: " + ((Submarine.Loaded == null) ? "none" : Submarine.Loaded.Name +" ("+Submarine.Loaded.MD5Hash+")"));
+ sb.AppendLine("Loaded submarine: " + ((Submarine.MainSub == null) ? "none" : Submarine.MainSub.Name +" ("+Submarine.MainSub.MD5Hash+")"));
sb.AppendLine("Selected screen: " + (Screen.Selected == null ? "None" : Screen.Selected.ToString()));
if (GameMain.Server != null)
diff --git a/Subsurface/Source/Screens/EditMapScreen.cs b/Subsurface/Source/Screens/EditMapScreen.cs
index eccca1c49..2e17f1da8 100644
--- a/Subsurface/Source/Screens/EditMapScreen.cs
+++ b/Subsurface/Source/Screens/EditMapScreen.cs
@@ -46,7 +46,7 @@ namespace Barotrauma
public string GetSubName()
{
- return ((Submarine.Loaded == null) ? "" : Submarine.Loaded.Name);
+ return (Submarine.MainSub == null) ? "" : Submarine.MainSub.Name;
}
private string GetItemCount()
@@ -231,11 +231,11 @@ namespace Barotrauma
GUIComponent.MouseOn = null;
characterMode = false;
- if (Submarine.Loaded != null)
+ if (Submarine.MainSub != null)
{
- cam.Position = Submarine.Loaded.Position + Submarine.HiddenSubPosition;
- nameBox.Text = Submarine.Loaded.Name;
- descriptionBox.Text = ToolBox.LimitString(Submarine.Loaded.Description,15);
+ cam.Position = Submarine.MainSub.Position + Submarine.HiddenSubPosition;
+ nameBox.Text = Submarine.MainSub.Name;
+ descriptionBox.Text = ToolBox.LimitString(Submarine.MainSub.Description, 15);
}
else
{
@@ -303,9 +303,9 @@ namespace Barotrauma
string savePath = nameBox.Text + ".sub";
- if (Submarine.Loaded != null)
+ if (Submarine.MainSub != null)
{
- savePath = Path.Combine(Path.GetDirectoryName(Submarine.Loaded.FilePath), savePath);
+ savePath = Path.Combine(Path.GetDirectoryName(Submarine.MainSub.FilePath), savePath);
}
else
{
@@ -313,9 +313,9 @@ namespace Barotrauma
}
Submarine.SaveCurrent(savePath);
- Submarine.Loaded.CheckForErrors();
+ Submarine.MainSub.CheckForErrors();
- GUI.AddMessage("Submarine saved to " + Submarine.Loaded.FilePath, Color.Green, 3.0f);
+ GUI.AddMessage("Submarine saved to " + Submarine.MainSub.FilePath, Color.Green, 3.0f);
return false;
}
@@ -560,7 +560,7 @@ namespace Barotrauma
return false;
}
- if (Submarine.Loaded != null) Submarine.Loaded.Name = text;
+ if (Submarine.MainSub != null) Submarine.MainSub.Name = text;
textBox.Deselect();
textBox.Text = text;
@@ -572,9 +572,9 @@ namespace Barotrauma
private bool ChangeSubDescription(GUITextBox textBox, string text)
{
- if (Submarine.Loaded != null)
+ if (Submarine.MainSub != null)
{
- Submarine.Loaded.Description = text;
+ Submarine.MainSub.Description = text;
}
else
{
@@ -593,9 +593,9 @@ namespace Barotrauma
private void ExpandDescriptionBox(GUITextBox textBox, Keys key)
{
- if (Submarine.Loaded != null)
+ if (Submarine.MainSub != null)
{
- textBox.Text = Submarine.Loaded.Description;
+ textBox.Text = Submarine.MainSub.Description;
}
else if (textBox.UserData is string)
{
@@ -617,7 +617,9 @@ namespace Barotrauma
private bool GenerateWaypoints(GUIButton button, object obj)
{
- WayPoint.GenerateSubWaypoints();
+ if (Submarine.MainSub == null) return false;
+
+ WayPoint.GenerateSubWaypoints(Submarine.MainSub);
return true;
}
diff --git a/Subsurface/Source/Screens/GameScreen.cs b/Subsurface/Source/Screens/GameScreen.cs
index a00726b7c..1532eeea0 100644
--- a/Subsurface/Source/Screens/GameScreen.cs
+++ b/Subsurface/Source/Screens/GameScreen.cs
@@ -56,9 +56,9 @@ namespace Barotrauma
{
cam.Position = Character.Controlled.WorldPosition;
}
- else if (Submarine.Loaded != null)
+ else if (Submarine.MainSub != null)
{
- cam.Position = Submarine.Loaded.WorldPosition;
+ cam.Position = Submarine.MainSub.WorldPosition;
}
foreach (MapEntity entity in MapEntity.mapEntityList)
@@ -119,9 +119,11 @@ namespace Barotrauma
//Lights.LightManager.ViewPos = Character.Controlled.WorldPosition;
}
cam.MoveCamera((float)Physics.step);
-
-
- if (Submarine.Loaded != null) Submarine.Loaded.SetPrevTransform(Submarine.Loaded.Position);
+
+ foreach (Submarine sub in Submarine.Loaded)
+ {
+ sub.SetPrevTransform(sub.Position);
+ }
foreach (PhysicsBody pb in PhysicsBody.list)
{
@@ -175,7 +177,7 @@ namespace Barotrauma
if (GameMain.GameSession != null) GameMain.GameSession.Draw(spriteBatch);
- if (Character.Controlled == null && Submarine.Loaded != null) DrawSubmarineIndicator(spriteBatch, Submarine.Loaded);
+ if (Character.Controlled == null && Submarine.Loaded != null) DrawSubmarineIndicator(spriteBatch, Submarine.MainSub);
GUI.Draw((float)deltaTime, spriteBatch, cam);
@@ -187,7 +189,10 @@ namespace Barotrauma
public void DrawMap(GraphicsDevice graphics, SpriteBatch spriteBatch)
{
- if (Submarine.Loaded != null) Submarine.Loaded.UpdateTransform();
+ foreach (Submarine sub in Submarine.Loaded)
+ {
+ sub.UpdateTransform();
+ }
GameMain.LightManager.ObstructVision = Character.Controlled != null && Character.Controlled.ObstructVision;
diff --git a/Subsurface/Source/Sounds/SoundPlayer.cs b/Subsurface/Source/Sounds/SoundPlayer.cs
index 6663693a2..59606fefd 100644
--- a/Subsurface/Source/Sounds/SoundPlayer.cs
+++ b/Subsurface/Source/Sounds/SoundPlayer.cs
@@ -183,7 +183,8 @@ namespace Barotrauma
startDrone = null;
}
- if (Submarine.Loaded==null)
+ //todo: ambient sounds for multiple subs
+ if (Submarine.MainSub == null)
{
for (int i = 0; i < waterAmbienceIndexes.Length; i++)
{
@@ -213,9 +214,9 @@ namespace Barotrauma
//how fast the sub is moving, scaled to 0.0 -> 1.0
float movementFactor = 0.0f;
- if (Submarine.Loaded != null)
+ if (Submarine.MainSub != null)
{
- movementFactor = (Submarine.Loaded.Velocity == Vector2.Zero) ? 0.0f : Submarine.Loaded.Velocity.Length() / 5.0f;
+ movementFactor = (Submarine.MainSub.Velocity == Vector2.Zero) ? 0.0f : Submarine.MainSub.Velocity.Length() / 5.0f;
movementFactor = MathHelper.Clamp(movementFactor, 0.0f, 1.0f);
}
@@ -303,7 +304,7 @@ namespace Barotrauma
{
return musicClips.Where(x => x != null && x.type == "ruins").ToList();
}
- else if (Submarine.Loaded != null && Submarine.Loaded.AtDamageDepth)
+ else if (Submarine.MainSub != null && Submarine.MainSub.AtDamageDepth)
{
return musicClips.Where(x => x != null && x.type == "deep").ToList();
}
diff --git a/Subsurface/Source/Utils/SaveUtil.cs b/Subsurface/Source/Utils/SaveUtil.cs
index cd6903cd3..cf4f714d1 100644
--- a/Subsurface/Source/Utils/SaveUtil.cs
+++ b/Subsurface/Source/Utils/SaveUtil.cs
@@ -30,9 +30,9 @@ namespace Barotrauma
try
{
- if (Submarine.Loaded != null)
+ if (Submarine.MainSub != null)
{
- Submarine.Loaded.SaveAs(Path.Combine(tempPath, Submarine.Loaded.Name+".sub"));
+ Submarine.MainSub.SaveAs(Path.Combine(tempPath, Submarine.MainSub.Name+".sub"));
}
}
catch (Exception e)
diff --git a/Subsurface_Solution.sln b/Subsurface_Solution.sln
index acdb73956..19e687774 100644
--- a/Subsurface_Solution.sln
+++ b/Subsurface_Solution.sln
@@ -11,8 +11,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lidgren.Network", "Lidgren.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Launcher", "Launcher2\Launcher.csproj", "{251AAFE1-F24B-4837-9128-9D04FCBFD528}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CrashReporter", "CrashReporter\CrashReporter.csproj", "{6BE950CD-9A34-49C9-939A-786AC89C287E}"
-EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D32A29D8-AC7B-4189-B734-8ED9EB4120D0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hyper.ComponentModel", "Hyper.ComponentModel\Hyper.ComponentModel.csproj", "{3B8F9EDB-6E5E-450C-ABC2-EC49075D0B50}"
@@ -228,51 +226,6 @@ Global
{251AAFE1-F24B-4837-9128-9D04FCBFD528}.Windows8|Mixed Platforms.Build.0 = Release|x86
{251AAFE1-F24B-4837-9128-9D04FCBFD528}.Windows8|x86.ActiveCfg = Release|x86
{251AAFE1-F24B-4837-9128-9D04FCBFD528}.Windows8|x86.Build.0 = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Android|Any CPU.ActiveCfg = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Android|Mixed Platforms.ActiveCfg = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Android|Mixed Platforms.Build.0 = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Android|x86.ActiveCfg = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Android|x86.Build.0 = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Debug|Any CPU.ActiveCfg = Debug|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Debug|Mixed Platforms.Build.0 = Debug|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Debug|x86.ActiveCfg = Debug|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Debug|x86.Build.0 = Debug|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.iOS|Any CPU.ActiveCfg = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.iOS|Mixed Platforms.ActiveCfg = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.iOS|Mixed Platforms.Build.0 = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.iOS|x86.ActiveCfg = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.iOS|x86.Build.0 = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Linux|Any CPU.ActiveCfg = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Linux|Mixed Platforms.ActiveCfg = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Linux|Mixed Platforms.Build.0 = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Linux|x86.ActiveCfg = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Linux|x86.Build.0 = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.OSX|Any CPU.ActiveCfg = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.OSX|Mixed Platforms.ActiveCfg = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.OSX|Mixed Platforms.Build.0 = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.OSX|x86.ActiveCfg = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.OSX|x86.Build.0 = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.PSM|Any CPU.ActiveCfg = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.PSM|Mixed Platforms.ActiveCfg = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.PSM|Mixed Platforms.Build.0 = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.PSM|x86.ActiveCfg = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.PSM|x86.Build.0 = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Release|Any CPU.ActiveCfg = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Release|Mixed Platforms.ActiveCfg = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Release|Mixed Platforms.Build.0 = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Release|x86.ActiveCfg = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Release|x86.Build.0 = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Windows|Any CPU.ActiveCfg = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Windows|Mixed Platforms.ActiveCfg = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Windows|Mixed Platforms.Build.0 = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Windows|x86.ActiveCfg = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Windows|x86.Build.0 = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Windows8|Any CPU.ActiveCfg = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Windows8|Mixed Platforms.ActiveCfg = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Windows8|Mixed Platforms.Build.0 = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Windows8|x86.ActiveCfg = Release|x86
- {6BE950CD-9A34-49C9-939A-786AC89C287E}.Windows8|x86.Build.0 = Release|x86
{3B8F9EDB-6E5E-450C-ABC2-EC49075D0B50}.Android|Any CPU.ActiveCfg = Release|Any CPU
{3B8F9EDB-6E5E-450C-ABC2-EC49075D0B50}.Android|Any CPU.Build.0 = Release|Any CPU
{3B8F9EDB-6E5E-450C-ABC2-EC49075D0B50}.Android|Mixed Platforms.ActiveCfg = Release|Any CPU
diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo
index fd7b05d75..ab8b5bd6d 100644
Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ