This commit is contained in:
EvilFactory
2023-06-21 10:36:16 -03:00
30 changed files with 242 additions and 137 deletions
@@ -178,7 +178,7 @@ namespace Barotrauma
if (eventSet is null) { continue; }
int count = childElement.GetAttributeInt("count", 0);
if (count < 1) { continue; }
FinishedEvents.Add(eventSet, count);
FinishedEvents.TryAdd(eventSet, count);
}
static EventSet FindSetRecursive(EventSet parentSet, Identifier setIdentifier)
@@ -365,7 +365,7 @@ namespace Barotrauma
if (FinishedEvents.Any())
{
var finishedEventsElement = new XElement(nameof(FinishedEvents));
foreach (var (set, count) in FinishedEvents)
foreach (var (set, count) in FinishedEvents.DistinctBy(f => f.Key.Identifier))
{
var element = new XElement(nameof(FinishedEvents),
new XAttribute("set", set.Identifier),
@@ -1353,44 +1353,38 @@ namespace Barotrauma
if (startWaypoint.WorldPosition.X > endWaypoint.WorldPosition.X)
{
var temp = startWaypoint;
startWaypoint = endWaypoint;
endWaypoint = temp;
(endWaypoint, startWaypoint) = (startWaypoint, endWaypoint);
}
if (hallwayLength > 100 && isHorizontal)
{
//if the hallway is longer than 100 pixels, generate some waypoints inside it
//for vertical hallways this isn't necessarily, it's done as a part of the ladder generation in AlignLadders
WayPoint prevWayPoint = startWaypoint;
WayPoint firstWayPoint = null;
for (float x = leftHull.Rect.Right + 50; x < rightHull.Rect.X - 50; x += 100.0f)
{
var newWayPoint = new WayPoint(new Vector2(x, hullBounds.Y + 110.0f), SpawnType.Path, sub);
firstWayPoint ??= newWayPoint;
prevWayPoint.linkedTo.Add(newWayPoint);
newWayPoint.linkedTo.Add(prevWayPoint);
prevWayPoint = newWayPoint;
}
if (firstWayPoint != null)
{
firstWayPoint.linkedTo.Add(startWaypoint);
startWaypoint.linkedTo.Add(firstWayPoint);
}
if (prevWayPoint != null)
{
prevWayPoint.linkedTo.Add(endWaypoint);
endWaypoint.linkedTo.Add(prevWayPoint);
}
}
WayPoint closestWaypoint = null;
float closestDistSqr = 30.0f * 30.0f;
foreach (WayPoint waypoint in WayPoint.WayPointList)
else
{
if (waypoint == startWaypoint) { continue; }
float dist = Vector2.DistanceSquared(waypoint.WorldPosition, startWaypoint.WorldPosition);
if (dist < closestDistSqr)
{
closestWaypoint = waypoint;
closestDistSqr = dist;
}
}
if (closestWaypoint != null)
{
startWaypoint.linkedTo.Add(closestWaypoint);
closestWaypoint.linkedTo.Add(startWaypoint);
startWaypoint.linkedTo.Add(endWaypoint);
endWaypoint.linkedTo.Add(startWaypoint);
}
}
}
@@ -1444,7 +1438,7 @@ namespace Barotrauma
{
foreach (MapEntity me in entities[module])
{
if (!(me is Gap gap)) { continue; }
if (me is not Gap gap) { continue; }
var door = gap.ConnectedDoor;
if (door != null && !door.UseBetweenOutpostModules) { continue; }
if (placedModules.Any(m => m.PreviousGap == gap || m.ThisGap == gap))
@@ -1524,15 +1518,38 @@ namespace Barotrauma
static void RemoveLinkedEntity(MapEntity linked)
{
if (linked is Item linkedItem && linkedItem.Connections != null)
if (linked is Item linkedItem)
{
foreach (Connection connection in linkedItem.Connections)
if (linkedItem.Connections != null)
{
foreach (Wire w in connection.Wires.ToArray())
foreach (Connection connection in linkedItem.Connections)
{
w?.Item.Remove();
foreach (Wire w in connection.Wires.ToArray())
{
w?.Item.Remove();
}
}
}
//if we end up removing a ladder, remove its waypoints too
if (linkedItem.GetComponent<Ladder>() is Ladder ladder)
{
var ladderWaypoints = WayPoint.WayPointList.FindAll(wp => wp.Ladders == ladder);
foreach (var ladderWaypoint in ladderWaypoints)
{
//got through all waypoints linked to the ladder waypoints, and link them together
//so we don't end up breaking up any paths by removing the ladder waypoints
for (int i = 0; i < ladderWaypoint.linkedTo.Count; i++)
{
if (ladderWaypoint.linkedTo[i] is not WayPoint waypoint1 || waypoint1.Ladders == ladder) { continue; }
for (int j = i + 1; j < ladderWaypoint.linkedTo.Count; j++)
{
if (ladderWaypoint.linkedTo[j] is not WayPoint waypoint2 || waypoint2.Ladders == ladder) { continue; }
waypoint1.ConnectTo(waypoint2);
}
}
}
ladderWaypoints.ForEach(wp => wp.Remove());
}
}
linked.Remove();
}