Fixed monsters being able to spawn under the ocean floor. Closes #319

This commit is contained in:
Joonas Rikkonen
2018-03-06 12:13:08 +02:00
parent f5af432ad9
commit 0ab4521a7a
2 changed files with 27 additions and 2 deletions
@@ -101,7 +101,17 @@ namespace Barotrauma
var monsters = new Character[amount];
if (spawnDeep) spawnPos.Y -= Level.Loaded.Size.Y;
if (spawnDeep)
{
spawnPos.Y -= Level.Loaded.Size.Y;
//disable the event if the ocean floor is too high up to spawn the monster deep
if (spawnPos.Y < Level.Loaded.GetBottomPosition(spawnPos.X).Y)
{
repeat = false;
Finished();
return null;
}
}
for (int i = 0; i < amount; i++)
{
@@ -78,6 +78,8 @@ namespace Barotrauma
private static BackgroundSpriteManager backgroundSpriteManager;
private List<Vector2> bottomPositions;
public Vector2 StartPosition
{
get { return startPosition; }
@@ -668,7 +670,7 @@ namespace Barotrauma
BottomPos = generationParams.SeaFloorDepth;
SeaFloorTopPos = BottomPos;
List<Vector2> bottomPositions = new List<Vector2>();
bottomPositions = new List<Vector2>();
bottomPositions.Add(new Vector2(0, BottomPos));
int mountainCount = Rand.Range(generationParams.MountainCountMin, generationParams.MountainCountMax, Rand.RandSync.Server);
@@ -983,6 +985,19 @@ namespace Barotrauma
#endif
}
public Vector2 GetBottomPosition(float xPosition)
{
int index = (int)Math.Floor(xPosition / Size.X * (bottomPositions.Count - 1));
if (index < 0 || index >= bottomPositions.Count - 1) return new Vector2(xPosition, BottomPos);
float yPos = MathHelper.Lerp(
bottomPositions[index].Y,
bottomPositions[index + 1].Y,
(xPosition - bottomPositions[index].X) / (bottomPositions[index + 1].X - bottomPositions[index].X));
return new Vector2(xPosition, yPos);
}
public List<VoronoiCell> GetCells(Vector2 pos, int searchDepth = 2)
{
int gridPosX = (int)Math.Floor(pos.X / GridCellSize);