From 40f5f352f57080a49fdaea56b5487fa94e07c20b Mon Sep 17 00:00:00 2001 From: Regalis Date: Wed, 15 Mar 2017 23:59:23 +0200 Subject: [PATCH] - pasted entities are assigned to the main sub (-> entities copypasted from another sub are saved) - fixed submarinebody attempting to generate a physics body for a sub with no walls if there are some other walls loaded - MathUtils.GiftWrap doesn't throw an exception if passed an empty list of points --- Subsurface/Source/Map/MapEntity.cs | 6 +++++- Subsurface/Source/Map/SubmarineBody.cs | 8 ++++---- Subsurface/Source/Utils/MathUtils.cs | 2 ++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Subsurface/Source/Map/MapEntity.cs b/Subsurface/Source/Map/MapEntity.cs index 6ec889944..51c2c3a09 100644 --- a/Subsurface/Source/Map/MapEntity.cs +++ b/Subsurface/Source/Map/MapEntity.cs @@ -464,7 +464,11 @@ namespace Barotrauma Vector2 moveAmount = Submarine.VectorToWorldGrid(cam.WorldViewCenter - center); selectedList = new List(clones); - selectedList.ForEach(c => c.Move(moveAmount)); + foreach (MapEntity clone in selectedList) + { + clone.Move(moveAmount); + clone.Submarine = Submarine.MainSub; + } } } diff --git a/Subsurface/Source/Map/SubmarineBody.cs b/Subsurface/Source/Map/SubmarineBody.cs index 9b4ab743b..876354fd6 100644 --- a/Subsurface/Source/Map/SubmarineBody.cs +++ b/Subsurface/Source/Map/SubmarineBody.cs @@ -160,17 +160,17 @@ namespace Barotrauma private List GenerateConvexHull() { - if (!Structure.WallList.Any()) + List subWalls = Structure.WallList.FindAll(wall => wall.Submarine == submarine); + + if (subWalls.Count == 0) { return new List { new Vector2(-1.0f, 1.0f), new Vector2(1.0f, 1.0f), new Vector2(0.0f, -1.0f) }; } List points = new List(); - foreach (Structure wall in Structure.WallList) + foreach (Structure wall in subWalls) { - if (wall.Submarine != submarine) continue; - points.Add(new Vector2(wall.Rect.X, wall.Rect.Y)); points.Add(new Vector2(wall.Rect.X + wall.Rect.Width, wall.Rect.Y)); points.Add(new Vector2(wall.Rect.X, wall.Rect.Y - wall.Rect.Height)); diff --git a/Subsurface/Source/Utils/MathUtils.cs b/Subsurface/Source/Utils/MathUtils.cs index 0aa6b5760..62f11fab1 100644 --- a/Subsurface/Source/Utils/MathUtils.cs +++ b/Subsurface/Source/Utils/MathUtils.cs @@ -381,6 +381,8 @@ namespace Barotrauma public static List GiftWrap(List points) { + if (points.Count == 0) return points; + Vector2 leftMost = points[0]; foreach (Vector2 point in points) {