Preventing monsters from spawning too close to any sub (not just the main sub)

This commit is contained in:
Regalis
2016-10-06 21:17:33 +03:00
parent 0ea9600198
commit 70b8bf1937
3 changed files with 16 additions and 29 deletions

View File

@@ -784,11 +784,21 @@ namespace Barotrauma
return position;
}
public Vector2 GetRandomInterestingPosition(bool useSyncedRand, PositionType positionType)
public Vector2 GetRandomInterestingPosition(bool useSyncedRand, PositionType positionType, bool avoidSubs)
{
if (!positionsOfInterest.Any()) return Size * 0.5f;
var matchingPositions = positionsOfInterest.FindAll(p => positionType.HasFlag(p.PositionType));
if (avoidSubs)
{
foreach (Submarine sub in Submarine.Loaded)
{
float minDist = Math.Max(sub.Borders.Width, sub.Borders.Height);
matchingPositions.RemoveAll(p => Vector2.Distance(p.Position, sub.WorldPosition) < minDist);
}
}
if (!matchingPositions.Any())
{
return positionsOfInterest[Rand.Int(positionsOfInterest.Count, !useSyncedRand)].Position;