Unstable 0.1300.0.10

This commit is contained in:
Markus Isberg
2021-04-16 15:51:16 +03:00
parent f48dfb5862
commit 245b48c3a3
29 changed files with 289 additions and 84 deletions
@@ -203,9 +203,9 @@ namespace Barotrauma
public void AutoOrient()
{
Vector2 searchPosLeft = new Vector2(rect.X, rect.Y - rect.Height / 2);
Hull hullLeft = Hull.FindHullOld(searchPosLeft, null, false);
Hull hullLeft = Hull.FindHullUnoptimized(searchPosLeft, null, false);
Vector2 searchPosRight = new Vector2(rect.Right, rect.Y - rect.Height / 2);
Hull hullRight = Hull.FindHullOld(searchPosRight, null, false);
Hull hullRight = Hull.FindHullUnoptimized(searchPosRight, null, false);
if (hullLeft != null && hullRight != null && hullLeft != hullRight)
{
@@ -214,9 +214,9 @@ namespace Barotrauma
}
Vector2 searchPosTop = new Vector2(rect.Center.X, rect.Y);
Hull hullTop = Hull.FindHullOld(searchPosTop, null, false);
Hull hullTop = Hull.FindHullUnoptimized(searchPosTop, null, false);
Vector2 searchPosBottom = new Vector2(rect.Center.X, rect.Y - rect.Height);
Hull hullBottom = Hull.FindHullOld(searchPosBottom, null, false);
Hull hullBottom = Hull.FindHullUnoptimized(searchPosBottom, null, false);
if (hullTop != null && hullBottom != null && hullTop != hullBottom)
{
@@ -261,8 +261,8 @@ namespace Barotrauma
for (int i = 0; i < 2; i++)
{
hulls[i] = Hull.FindHullOld(searchPos[i], null, false);
if (hulls[i] == null) hulls[i] = Hull.FindHullOld(searchPos[i], null, false, true);
hulls[i] = Hull.FindHullUnoptimized(searchPos[i], null, false);
if (hulls[i] == null) hulls[i] = Hull.FindHullUnoptimized(searchPos[i], null, false, true);
}
if (hulls[0] == null && hulls[1] == null) { return; }
@@ -990,7 +990,13 @@ namespace Barotrauma
return float.MaxValue;
}
//returns the water block which contains the point (or null if it isn't inside any)
/// <summary>
/// Returns the hull which contains the point (or null if it isn't inside any)
/// </summary>
/// <param name="position">The position to check</param>
/// <param name="guess">This hull is checked first: if the current hull is known, this can be used as an optimization</param>
/// <param name="useWorldCoordinates">Should world coordinates or the sub's local coordinates be used?</param>
/// <param name="inclusive">Does being exactly at the edge of the hull count as being inside?</param>
public static Hull FindHull(Vector2 position, Hull guess = null, bool useWorldCoordinates = true, bool inclusive = true)
{
if (EntityGrids == null) return null;
@@ -1038,20 +1044,19 @@ namespace Barotrauma
return null;
}
//returns the water block which contains the point (or null if it isn't inside any)
public static Hull FindHullOld(Vector2 position, Hull guess = null, bool useWorldCoordinates = true, bool inclusive = true)
/// <summary>
/// Returns the hull which contains the point (or null if it isn't inside any). The difference to FindHull is that this method goes through all hulls without trying
/// to first find the sub the point is inside and checking the hulls in that sub.
/// = This is slower, use with caution in situations where the sub's extents or hulls may have changed after it was loaded.
/// </summary>
public static Hull FindHullUnoptimized(Vector2 position, Hull guess = null, bool useWorldCoordinates = true, bool inclusive = true)
{
return FindHullOld(position, hullList, guess, useWorldCoordinates, inclusive);
}
public static Hull FindHullOld(Vector2 position, List<Hull> hulls, Hull guess = null, bool useWorldCoordinates = true, bool inclusive = true)
{
if (guess != null && hulls.Contains(guess))
if (guess != null && hullList.Contains(guess))
{
if (Submarine.RectContains(useWorldCoordinates ? guess.WorldRect : guess.rect, position, inclusive)) return guess;
}
foreach (Hull hull in hulls)
foreach (Hull hull in hullList)
{
if (Submarine.RectContains(useWorldCoordinates ? hull.WorldRect : hull.rect, position, inclusive)) return hull;
}
@@ -166,7 +166,7 @@ namespace Barotrauma
public class AbyssIsland
{
public readonly Rectangle Area;
public Rectangle Area;
public readonly List<VoronoiCell> Cells;
public AbyssIsland(Rectangle area, List<VoronoiCell> cells)
@@ -844,6 +844,11 @@ namespace Barotrauma
}
}
foreach (AbyssIsland island in AbyssIslands)
{
island.Area = new Rectangle(borders.Width - island.Area.Right, island.Area.Y, island.Area.Width, island.Area.Height);
}
foreach (Cave cave in Caves)
{
cave.Area = new Rectangle(borders.Width - cave.Area.Right, cave.Area.Y, cave.Area.Width, cave.Area.Height);
@@ -1328,7 +1333,6 @@ namespace Barotrauma
for (int i = 0; i < tunnel.Cells.Count; i++)
{
tunnel.Cells[i].CellType = CellType.Path;
var newWaypoint = new WayPoint(new Rectangle((int)tunnel.Cells[i].Site.Coord.X, (int)tunnel.Cells[i].Center.Y, 10, 10), null)
{
Tunnel = tunnel
@@ -1385,8 +1389,23 @@ namespace Barotrauma
ConvertUnits.ToSimUnits(wayPoint.WorldPosition),
ConvertUnits.ToSimUnits(closestWaypoint.WorldPosition), collisionCategory: Physics.CollisionLevel | Physics.CollisionWall) == null)
{
wayPoint.linkedTo.Add(closestWaypoint);
closestWaypoint.linkedTo.Add(wayPoint);
Vector2 diff = closestWaypoint.WorldPosition - wayPoint.WorldPosition;
float dist = diff.Length();
float step = ConvertUnits.ToDisplayUnits(Steering.AutopilotMinDistToPathNode) * 0.8f;
WayPoint prevWaypoint = wayPoint;
for (float x = step; x < dist - step; x += step)
{
var newWaypoint = new WayPoint(wayPoint.WorldPosition + (diff / dist * x), SpawnType.Path, submarine: null)
{
Tunnel = tunnel
};
prevWaypoint.linkedTo.Add(newWaypoint);
newWaypoint.linkedTo.Add(prevWaypoint);
prevWaypoint = newWaypoint;
}
prevWaypoint.linkedTo.Add(closestWaypoint);
closestWaypoint.linkedTo.Add(prevWaypoint);
}
}
}
@@ -1104,8 +1104,35 @@ namespace Barotrauma
DebugConsole.ThrowError($"Failed to connect waypoints between outpost modules. No waypoint in the {GetOpposingGapPosition(module.ThisGapPosition).ToString().ToLower()} gap of the module \"{module.PreviousModule.Info.Name}\".");
continue;
}
startWaypoint.linkedTo.Add(endWaypoint);
endWaypoint.linkedTo.Add(startWaypoint);
if (startWaypoint.WorldPosition.X > endWaypoint.WorldPosition.X)
{
var temp = startWaypoint;
startWaypoint = endWaypoint;
endWaypoint = temp;
}
if (hallwayLength > 100 && isHorizontal)
{
WayPoint prevWayPoint = startWaypoint;
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);
prevWayPoint.linkedTo.Add(newWayPoint);
newWayPoint.linkedTo.Add(prevWayPoint);
prevWayPoint = newWayPoint;
}
if (prevWayPoint != null)
{
prevWayPoint.linkedTo.Add(endWaypoint);
endWaypoint.linkedTo.Add(prevWayPoint);
}
}
else
{
startWaypoint.linkedTo.Add(endWaypoint);
endWaypoint.linkedTo.Add(startWaypoint);
}
WayPoint closestWaypoint = null;
float closestDistSqr = 30.0f * 30.0f;
@@ -786,6 +786,13 @@ namespace Barotrauma
public void FindHull()
{
CurrentHull = Hull.FindHull(WorldPosition, CurrentHull);
#if CLIENT
//we may not be able to find the hull with the optimized method in the sub editor if new hulls have been added, use the unoptimized method
if (Screen.Selected == GameMain.SubEditorScreen)
{
CurrentHull ??= Hull.FindHullUnoptimized(WorldPosition);
}
#endif
}
public override void OnMapLoaded()