From 4a8845c6040379473b208be9d7749f2a18f5ad38 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Tue, 24 Jul 2018 13:21:36 +0300 Subject: [PATCH] Fixed docking ports creating duplicate hulls and gaps during loading --- .../Source/Items/Components/DockingPort.cs | 15 +++++++-------- .../BarotraumaShared/Source/Map/MapEntity.cs | 12 ++++++------ .../BarotraumaShared/Source/Map/Submarine.cs | 11 ++++++++++- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/DockingPort.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/DockingPort.cs index 076c3307f..f3137e284 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/DockingPort.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/DockingPort.cs @@ -418,9 +418,7 @@ namespace Barotrauma.Items.Components } gap = new Gap(new Rectangle(hullRects[0].Right - 2, hullRects[0].Y, 4, hullRects[0].Height), true, subs[0]); - if (gapId != null) gap.ID = (ushort)gapId; - - LinkHullsToGap(); + if (gapId != null) gap.ID = (ushort)gapId; } else { @@ -443,19 +441,20 @@ namespace Barotrauma.Items.Components gap = new Gap(new Rectangle(hullRects[0].X, hullRects[0].Y+2, hullRects[0].Width, 4), false, subs[0]); if (gapId != null) gap.ID = (ushort)gapId; - - LinkHullsToGap(); } - item.linkedTo.Add(hulls[0]); - item.linkedTo.Add(hulls[1]); + LinkHullsToGap(); hullIds[0] = hulls[0].ID; hullIds[1] = hulls[1].ID; + hulls[0].ShouldBeSaved = false; + hulls[1].ShouldBeSaved = false; + item.linkedTo.Add(hulls[0]); + item.linkedTo.Add(hulls[1]); gap.DisableHullRechecks = true; + gap.ShouldBeSaved = false; gapId = gap.ID; - item.linkedTo.Add(gap); foreach (Body body in bodies) diff --git a/Barotrauma/BarotraumaShared/Source/Map/MapEntity.cs b/Barotrauma/BarotraumaShared/Source/Map/MapEntity.cs index 5f620dd21..ab868b2d1 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/MapEntity.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/MapEntity.cs @@ -29,6 +29,8 @@ namespace Barotrauma get; set; } + + public bool ShouldBeSaved = true; //the position and dimensions of the entity protected Rectangle rect; @@ -45,7 +47,8 @@ namespace Barotrauma private static bool resizing; private int resizeDirX, resizeDirY; - public virtual Rectangle Rect { + public virtual Rectangle Rect + { get { return rect; } set { rect = value; } } @@ -353,15 +356,12 @@ namespace Barotrauma foreach (ushort i in e.linkedToID) { - MapEntity linked = FindEntityByID(i) as MapEntity; - - if (linked != null) e.linkedTo.Add(linked); + if (FindEntityByID(i) is MapEntity linked) e.linkedTo.Add(linked); } } List linkedSubs = new List(); - - for (int i = 0; i= 0; i--) + { + if (!e.linkedTo[i].ShouldBeSaved) e.linkedTo.RemoveAt(i); + } + } + + foreach (MapEntity e in MapEntity.mapEntityList) + { + if (e.MoveWithLevel || e.Submarine != this || !e.ShouldBeSaved) continue; e.Save(element); } }