Preventing monsters from spawning too close to any sub (not just the main sub)
This commit is contained in:
@@ -28,17 +28,7 @@ namespace Barotrauma
|
||||
|
||||
public override void Start(Level level)
|
||||
{
|
||||
float minDist = Math.Max(Submarine.MainSub.Borders.Width, Submarine.MainSub.Borders.Height);
|
||||
|
||||
//find a random spawnpos that isn't too close to the main sub
|
||||
int tries = 0;
|
||||
Vector2 spawnPos = Vector2.Zero;
|
||||
do
|
||||
{
|
||||
spawnPos = Level.Loaded.GetRandomInterestingPosition(true, Level.PositionType.MainPath);
|
||||
tries++;
|
||||
} while (tries < 50 && Vector2.Distance(spawnPos, Submarine.MainSub.WorldPosition) < minDist);
|
||||
|
||||
Vector2 spawnPos = Level.Loaded.GetRandomInterestingPosition(true, Level.PositionType.MainPath, true);
|
||||
|
||||
monster = Character.Create(monsterFile, spawnPos, null, GameMain.Client != null);
|
||||
monster.Enabled = false;
|
||||
|
||||
@@ -62,30 +62,17 @@ namespace Barotrauma
|
||||
private void SpawnMonsters()
|
||||
{
|
||||
if (disallowed) return;
|
||||
|
||||
float minDist = Math.Max(Submarine.MainSub.Borders.Width, Submarine.MainSub.Borders.Height);
|
||||
|
||||
//find a random spawnpos that isn't too close to the main sub
|
||||
int tries = 0;
|
||||
Vector2 spawnPos = Vector2.Zero;
|
||||
do
|
||||
{
|
||||
spawnPos = Level.Loaded.GetRandomInterestingPosition(true, spawnPosType);
|
||||
tries++;
|
||||
} while (tries < 50 && Vector2.Distance(spawnPos, Submarine.MainSub.WorldPosition) < minDist);
|
||||
|
||||
|
||||
Vector2 spawnPos = Level.Loaded.GetRandomInterestingPosition(true, spawnPosType, true);
|
||||
|
||||
int amount = Rand.Range(minAmount, maxAmount, false);
|
||||
|
||||
monsters = new Character[amount];
|
||||
|
||||
if (spawnDeep) spawnPos.Y -= Level.Loaded.Size.Y;
|
||||
|
||||
for (int i = 0; i < amount; i++)
|
||||
{
|
||||
if (spawnDeep)
|
||||
{
|
||||
spawnPos.Y -= Level.Loaded.Size.Y;
|
||||
}
|
||||
|
||||
spawnPos.X += Rand.Range(-0.5f, 0.5f, false);
|
||||
spawnPos.Y += Rand.Range(-0.5f, 0.5f, false);
|
||||
monsters[i] = Character.Create(characterFile, spawnPos, null, GameMain.Client != null);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user