Fixed hulls not being linked to gaps if the center of the gap is exactly at the edge of the adjacent hulls.
Closes #147
This commit is contained in:
@@ -163,8 +163,11 @@ namespace Barotrauma
|
|||||||
searchPos[1] = new Vector2(rect.Center.X, rect.Y - rect.Height);
|
searchPos[1] = new Vector2(rect.Center.X, rect.Y - rect.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
hulls[0] = Hull.FindHullOld(searchPos[0], null, false);
|
for (int i = 0; i < 2; i++)
|
||||||
hulls[1] = Hull.FindHullOld(searchPos[1], null, false);
|
{
|
||||||
|
hulls[i] = Hull.FindHullOld(searchPos[i], null, false);
|
||||||
|
if (hulls[i] == null) hulls[i] = Hull.FindHullOld(searchPos[i], null, false, true);
|
||||||
|
}
|
||||||
|
|
||||||
if (hulls[0] == null && hulls[1] == null) return;
|
if (hulls[0] == null && hulls[1] == null) return;
|
||||||
|
|
||||||
|
|||||||
@@ -560,21 +560,21 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
|
|
||||||
//returns the water block which contains the point (or null if it isn't inside any)
|
//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)
|
public static Hull FindHullOld(Vector2 position, Hull guess = null, bool useWorldCoordinates = true, bool inclusive = false)
|
||||||
{
|
{
|
||||||
return FindHullOld(position, hullList, guess, useWorldCoordinates);
|
return FindHullOld(position, hullList, guess, useWorldCoordinates, inclusive);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Hull FindHullOld(Vector2 position, List<Hull> hulls, Hull guess = null, bool useWorldCoordinates = true)
|
public static Hull FindHullOld(Vector2 position, List<Hull> hulls, Hull guess = null, bool useWorldCoordinates = true, bool inclusive = false)
|
||||||
{
|
{
|
||||||
if (guess != null && hulls.Contains(guess))
|
if (guess != null && hulls.Contains(guess))
|
||||||
{
|
{
|
||||||
if (Submarine.RectContains(useWorldCoordinates ? guess.WorldRect : guess.rect, position)) return guess;
|
if (Submarine.RectContains(useWorldCoordinates ? guess.WorldRect : guess.rect, position, inclusive)) return guess;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Hull hull in hulls)
|
foreach (Hull hull in hulls)
|
||||||
{
|
{
|
||||||
if (Submarine.RectContains(useWorldCoordinates ? hull.WorldRect : hull.rect, position)) return hull;
|
if (Submarine.RectContains(useWorldCoordinates ? hull.WorldRect : hull.rect, position, inclusive)) return hull;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -491,10 +491,18 @@ namespace Barotrauma
|
|||||||
return new Rectangle((int)pos.X, (int)pos.Y, (int)size.X, (int)size.Y);
|
return new Rectangle((int)pos.X, (int)pos.Y, (int)size.X, (int)size.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool RectContains(Rectangle rect, Vector2 pos)
|
public static bool RectContains(Rectangle rect, Vector2 pos, bool inclusive = false)
|
||||||
{
|
{
|
||||||
return (pos.X > rect.X && pos.X < rect.X + rect.Width
|
if (inclusive)
|
||||||
&& pos.Y < rect.Y && pos.Y > rect.Y - rect.Height);
|
{
|
||||||
|
return (pos.X >= rect.X && pos.X <= rect.X + rect.Width
|
||||||
|
&& pos.Y <= rect.Y && pos.Y >= rect.Y - rect.Height);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return (pos.X > rect.X && pos.X < rect.X + rect.Width
|
||||||
|
&& pos.Y < rect.Y && pos.Y > rect.Y - rect.Height);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool RectsOverlap(Rectangle rect1, Rectangle rect2, bool inclusive=true)
|
public static bool RectsOverlap(Rectangle rect1, Rectangle rect2, bool inclusive=true)
|
||||||
|
|||||||
Reference in New Issue
Block a user