Docking port fixes again. Closes #551
- Non-saveable entities aren't removed from the linkedTo-list during saving, because that causes gaps to become unlinked with the hulls between docking ports when starting a campaign round. - Hull rechecks are disabled on docking port gaps, because moving linked subs into place may cause the gaps to become unlinked if they're positioned in a certain way (for example in some subs the hulls between the docking ports end up inside the gap). - Dockingports only connect the waypoints linked to their gap to each other, instead of every waypoint that happens to be inside the gap.
This commit is contained in:
@@ -201,22 +201,16 @@ namespace Barotrauma.Items.Components
|
|||||||
Math.Sign(dockingTarget.item.WorldPosition.X - item.WorldPosition.X) :
|
Math.Sign(dockingTarget.item.WorldPosition.X - item.WorldPosition.X) :
|
||||||
Math.Sign(dockingTarget.item.WorldPosition.Y - item.WorldPosition.Y);
|
Math.Sign(dockingTarget.item.WorldPosition.Y - item.WorldPosition.Y);
|
||||||
dockingTarget.dockingDir = -dockingDir;
|
dockingTarget.dockingDir = -dockingDir;
|
||||||
|
|
||||||
|
|
||||||
foreach (WayPoint wp in WayPoint.WayPointList)
|
if (door != null && dockingTarget.door != null)
|
||||||
{
|
{
|
||||||
if (wp.Submarine != item.Submarine || wp.SpawnType != SpawnType.Path) continue;
|
WayPoint myWayPoint = WayPoint.WayPointList.Find(wp => door.LinkedGap == wp.ConnectedGap);
|
||||||
|
WayPoint targetWayPoint = WayPoint.WayPointList.Find(wp => dockingTarget.door.LinkedGap == wp.ConnectedGap);
|
||||||
|
|
||||||
if (!Submarine.RectContains(item.Rect, wp.Position)) continue;
|
if (myWayPoint != null && targetWayPoint != null)
|
||||||
|
|
||||||
foreach (WayPoint wp2 in WayPoint.WayPointList)
|
|
||||||
{
|
{
|
||||||
if (wp2.Submarine != dockingTarget.item.Submarine || wp2.SpawnType != SpawnType.Path) continue;
|
myWayPoint.linkedTo.Add(targetWayPoint);
|
||||||
|
targetWayPoint.linkedTo.Add(myWayPoint);
|
||||||
if (!Submarine.RectContains(dockingTarget.item.Rect, wp2.Position)) continue;
|
|
||||||
|
|
||||||
wp.linkedTo.Add(wp2);
|
|
||||||
wp2.linkedTo.Add(wp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -498,29 +492,31 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
Gap gap = i == 0 ? door?.LinkedGap : dockingTarget?.door?.LinkedGap;
|
Gap doorGap = i == 0 ? door?.LinkedGap : dockingTarget?.door?.LinkedGap;
|
||||||
if (gap == null || gap.linkedTo.Count == 2) continue;
|
if (doorGap == null) continue;
|
||||||
|
doorGap.DisableHullRechecks = true;
|
||||||
|
if (doorGap.linkedTo.Count >= 2) continue;
|
||||||
|
|
||||||
if (IsHorizontal)
|
if (IsHorizontal)
|
||||||
{
|
{
|
||||||
if (item.WorldPosition.X < dockingTarget.item.WorldPosition.X)
|
if (item.WorldPosition.X < dockingTarget.item.WorldPosition.X)
|
||||||
{
|
{
|
||||||
if (!gap.linkedTo.Contains(hulls[0])) gap.linkedTo.Add(hulls[0]);
|
if (!doorGap.linkedTo.Contains(hulls[0])) doorGap.linkedTo.Add(hulls[0]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!gap.linkedTo.Contains(hulls[1])) gap.linkedTo.Add(hulls[1]);
|
if (!doorGap.linkedTo.Contains(hulls[1])) doorGap.linkedTo.Add(hulls[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (item.WorldPosition.Y < dockingTarget.item.WorldPosition.Y)
|
if (item.WorldPosition.Y < dockingTarget.item.WorldPosition.Y)
|
||||||
{
|
{
|
||||||
if (!gap.linkedTo.Contains(hulls[0])) gap.linkedTo.Add(hulls[0]);
|
if (!doorGap.linkedTo.Contains(hulls[0])) doorGap.linkedTo.Add(hulls[0]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!gap.linkedTo.Contains(hulls[1])) gap.linkedTo.Add(hulls[1]);
|
if (!doorGap.linkedTo.Contains(hulls[1])) doorGap.linkedTo.Add(hulls[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -536,25 +532,19 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
dockingTarget.item.Submarine.DockedTo.Remove(item.Submarine);
|
dockingTarget.item.Submarine.DockedTo.Remove(item.Submarine);
|
||||||
item.Submarine.DockedTo.Remove(dockingTarget.item.Submarine);
|
item.Submarine.DockedTo.Remove(dockingTarget.item.Submarine);
|
||||||
|
|
||||||
//remove all waypoint links between this sub and the dockingtarget
|
if (door != null && dockingTarget.door != null)
|
||||||
foreach (WayPoint wp in WayPoint.WayPointList)
|
|
||||||
{
|
{
|
||||||
if (wp.Submarine != item.Submarine || wp.SpawnType != SpawnType.Path) continue;
|
WayPoint myWayPoint = WayPoint.WayPointList.Find(wp => door.LinkedGap == wp.ConnectedGap);
|
||||||
|
WayPoint targetWayPoint = WayPoint.WayPointList.Find(wp => dockingTarget.door.LinkedGap == wp.ConnectedGap);
|
||||||
|
|
||||||
for (int i = wp.linkedTo.Count - 1; i >= 0; i--)
|
if (myWayPoint != null && targetWayPoint != null)
|
||||||
{
|
{
|
||||||
var wp2 = wp.linkedTo[i] as WayPoint;
|
myWayPoint.linkedTo.Remove(targetWayPoint);
|
||||||
if (wp2 == null) continue;
|
targetWayPoint.linkedTo.Remove(myWayPoint);
|
||||||
|
|
||||||
if (wp.Submarine == dockingTarget.item.Submarine)
|
|
||||||
{
|
|
||||||
wp.linkedTo.RemoveAt(i);
|
|
||||||
wp2.linkedTo.Remove(wp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
item.linkedTo.Clear();
|
item.linkedTo.Clear();
|
||||||
|
|
||||||
docked = false;
|
docked = false;
|
||||||
|
|||||||
@@ -1939,16 +1939,15 @@ namespace Barotrauma
|
|||||||
(int)(rect.X - Submarine.HiddenSubPosition.X) + "," +
|
(int)(rect.X - Submarine.HiddenSubPosition.X) + "," +
|
||||||
(int)(rect.Y - Submarine.HiddenSubPosition.Y)));
|
(int)(rect.Y - Submarine.HiddenSubPosition.Y)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (linkedTo != null && linkedTo.Count > 0)
|
if (linkedTo != null && linkedTo.Count > 0)
|
||||||
{
|
{
|
||||||
string[] linkedToIDs = new string[linkedTo.Count];
|
var saveableLinked = linkedTo.Where(l => l.ShouldBeSaved).ToList();
|
||||||
|
string[] linkedToIDs = new string[saveableLinked.Count];
|
||||||
for (int i = 0; i < linkedTo.Count; i++)
|
for (int i = 0; i < saveableLinked.Count; i++)
|
||||||
{
|
{
|
||||||
linkedToIDs[i] = linkedTo[i].ID.ToString();
|
linkedToIDs[i] = saveableLinked[i].ID.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
element.Add(new XAttribute("linked", string.Join(",", linkedToIDs)));
|
element.Add(new XAttribute("linked", string.Join(",", linkedToIDs)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -135,13 +135,21 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
base.Move(amount);
|
base.Move(amount);
|
||||||
|
|
||||||
FindHulls();
|
if (!DisableHullRechecks) FindHulls();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UpdateHulls()
|
public static void UpdateHulls()
|
||||||
{
|
{
|
||||||
foreach (Gap g in GapList)
|
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;
|
if (g.DisableHullRechecks) continue;
|
||||||
g.FindHulls();
|
g.FindHulls();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -261,22 +261,16 @@ namespace Barotrauma
|
|||||||
if (saveElement.Attribute("pos") != null) saveElement.Attribute("pos").Remove();
|
if (saveElement.Attribute("pos") != null) saveElement.Attribute("pos").Remove();
|
||||||
saveElement.Add(new XAttribute("pos", XMLExtensions.Vector2ToString(Position - Submarine.HiddenSubPosition)));
|
saveElement.Add(new XAttribute("pos", XMLExtensions.Vector2ToString(Position - Submarine.HiddenSubPosition)));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var linkedPort = linkedTo.FirstOrDefault(lt => (lt is Item) && ((Item)lt).GetComponent<DockingPort>() != null);
|
var linkedPort = linkedTo.FirstOrDefault(lt => (lt is Item) && ((Item)lt).GetComponent<DockingPort>() != null);
|
||||||
if (linkedPort != null)
|
if (linkedPort != null)
|
||||||
{
|
{
|
||||||
if (saveElement.Attribute("linkedto") != null) saveElement.Attribute("linkedto").Remove();
|
if (saveElement.Attribute("linkedto") != null) saveElement.Attribute("linkedto").Remove();
|
||||||
|
|
||||||
saveElement.Add(new XAttribute("linkedto", linkedPort.ID));
|
saveElement.Add(new XAttribute("linkedto", linkedPort.ID));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
saveElement = new XElement("LinkedSubmarine");
|
saveElement = new XElement("LinkedSubmarine");
|
||||||
|
|
||||||
|
|
||||||
sub.SaveToXElement(saveElement);
|
sub.SaveToXElement(saveElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1250,16 +1250,7 @@ namespace Barotrauma
|
|||||||
element.Add(new XAttribute("recommendedcrewsizemax", RecommendedCrewSizeMax));
|
element.Add(new XAttribute("recommendedcrewsizemax", RecommendedCrewSizeMax));
|
||||||
element.Add(new XAttribute("recommendedcrewexperience", RecommendedCrewExperience ?? ""));
|
element.Add(new XAttribute("recommendedcrewexperience", RecommendedCrewExperience ?? ""));
|
||||||
element.Add(new XAttribute("compatiblecontentpackages", string.Join(", ", CompatibleContentPackages)));
|
element.Add(new XAttribute("compatiblecontentpackages", string.Join(", ", CompatibleContentPackages)));
|
||||||
|
|
||||||
foreach (MapEntity e in MapEntity.mapEntityList)
|
|
||||||
{
|
|
||||||
if (e.linkedTo == null) continue;
|
|
||||||
for (int i = e.linkedTo.Count - 1; i >= 0; i--)
|
|
||||||
{
|
|
||||||
if (!e.linkedTo[i].ShouldBeSaved) e.linkedTo.RemoveAt(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (MapEntity e in MapEntity.mapEntityList)
|
foreach (MapEntity e in MapEntity.mapEntityList)
|
||||||
{
|
{
|
||||||
if (e.Submarine != this || !e.ShouldBeSaved) continue;
|
if (e.Submarine != this || !e.ShouldBeSaved) continue;
|
||||||
|
|||||||
@@ -636,6 +636,7 @@ namespace Barotrauma
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
foreach (MapEntity e in linkedTo)
|
foreach (MapEntity e in linkedTo)
|
||||||
{
|
{
|
||||||
|
if (!e.ShouldBeSaved) continue;
|
||||||
element.Add(new XAttribute("linkedto" + i, e.ID));
|
element.Add(new XAttribute("linkedto" + i, e.ID));
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user