Increased the minimum distance between monster spawns and subs (20 000 units in monster events, 30% of the width of the level in monster missions). Closes #63 and closes #151

This commit is contained in:
Joonas Rikkonen
2017-12-14 20:01:45 +02:00
parent 58e98977df
commit e17b5a195c
5 changed files with 14 additions and 11 deletions

View File

@@ -34,7 +34,7 @@ namespace Barotrauma
base.Init(); base.Init();
Vector2 position = Level.Loaded.GetRandomItemPos( Vector2 position = Level.Loaded.GetRandomItemPos(
Level.PositionType.Cave | Level.PositionType.MainPath | Level.PositionType.Ruin, 500.0f, 30.0f); Level.PositionType.Cave | Level.PositionType.MainPath | Level.PositionType.Ruin, 500.0f, 10000.0f, 30.0f);
item = new Item(itemPrefab, position, null); item = new Item(itemPrefab, position, null);
item.MoveWithLevel = true; item.MoveWithLevel = true;

View File

@@ -28,7 +28,7 @@ namespace Barotrauma
public override void Start(Level level) public override void Start(Level level)
{ {
Vector2 spawnPos; Vector2 spawnPos;
Level.Loaded.TryGetInterestingPosition(true, Level.PositionType.MainPath, true, out spawnPos); Level.Loaded.TryGetInterestingPosition(true, Level.PositionType.MainPath, Level.Loaded.Size.X * 0.3f, out spawnPos);
monster = Character.Create(monsterFile, spawnPos, null, GameMain.Client != null, true, false); monster = Character.Create(monsterFile, spawnPos, null, GameMain.Client != null, true, false);
monster.Enabled = false; monster.Enabled = false;

View File

@@ -46,7 +46,7 @@ namespace Barotrauma
public override void Start(Level level) public override void Start(Level level)
{ {
Vector2 position = Level.Loaded.GetRandomItemPos(spawnPositionType, 100.0f, 30.0f); Vector2 position = Level.Loaded.GetRandomItemPos(spawnPositionType, 100.0f, Level.Loaded.Size.X * 0.3f, 30.0f);
item = new Item(itemPrefab, position, null); item = new Item(itemPrefab, position, null);
item.MoveWithLevel = true; item.MoveWithLevel = true;

View File

@@ -85,7 +85,7 @@ namespace Barotrauma
if (disallowed) return null; if (disallowed) return null;
Vector2 spawnPos; Vector2 spawnPos;
if (!Level.Loaded.TryGetInterestingPosition(true, spawnPosType, true, out spawnPos)) if (!Level.Loaded.TryGetInterestingPosition(true, spawnPosType, 20000.0f, out spawnPos))
{ {
//no suitable position found, disable the event //no suitable position found, disable the event
repeat = false; repeat = false;

View File

@@ -817,7 +817,7 @@ namespace Barotrauma
//50% chance of placing the ruins at a cave //50% chance of placing the ruins at a cave
if (Rand.Range(0.0f, 1.0f, Rand.RandSync.Server) < 0.5f) if (Rand.Range(0.0f, 1.0f, Rand.RandSync.Server) < 0.5f)
{ {
TryGetInterestingPosition(true, PositionType.Cave, false, out ruinPos); TryGetInterestingPosition(true, PositionType.Cave, 0.0f, out ruinPos);
} }
ruinPos.Y = Math.Min(ruinPos.Y, borders.Y + borders.Height - ruinSize.Y / 2); ruinPos.Y = Math.Min(ruinPos.Y, borders.Y + borders.Height - ruinSize.Y / 2);
@@ -894,7 +894,7 @@ namespace Barotrauma
} }
} }
public Vector2 GetRandomItemPos(PositionType spawnPosType, float randomSpread, float offsetFromWall = 10.0f) public Vector2 GetRandomItemPos(PositionType spawnPosType, float randomSpread, float minDistFromSubs, float offsetFromWall = 10.0f)
{ {
if (!positionsOfInterest.Any()) return Size*0.5f; if (!positionsOfInterest.Any()) return Size*0.5f;
@@ -906,7 +906,7 @@ namespace Barotrauma
do do
{ {
Vector2 startPos; Vector2 startPos;
Level.Loaded.TryGetInterestingPosition(true, spawnPosType, true, out startPos); Loaded.TryGetInterestingPosition(true, spawnPosType, minDistFromSubs, out startPos);
startPos += Rand.Vector(Rand.Range(0.0f, randomSpread, Rand.RandSync.Server), Rand.RandSync.Server); startPos += Rand.Vector(Rand.Range(0.0f, randomSpread, Rand.RandSync.Server), Rand.RandSync.Server);
@@ -935,7 +935,7 @@ namespace Barotrauma
public bool TryGetInterestingPosition(bool useSyncedRand, PositionType positionType, bool avoidSubs, out Vector2 position) public bool TryGetInterestingPosition(bool useSyncedRand, PositionType positionType, float minDistFromSubs, out Vector2 position)
{ {
if (!positionsOfInterest.Any()) if (!positionsOfInterest.Any())
{ {
@@ -945,17 +945,20 @@ namespace Barotrauma
var matchingPositions = positionsOfInterest.FindAll(p => positionType.HasFlag(p.PositionType)); var matchingPositions = positionsOfInterest.FindAll(p => positionType.HasFlag(p.PositionType));
if (avoidSubs) if (minDistFromSubs > 0.0f)
{ {
foreach (Submarine sub in Submarine.Loaded) foreach (Submarine sub in Submarine.Loaded)
{ {
float minDist = Math.Max(sub.Borders.Width, sub.Borders.Height); matchingPositions.RemoveAll(p => Vector2.DistanceSquared(p.Position, sub.WorldPosition) < minDistFromSubs * minDistFromSubs);
matchingPositions.RemoveAll(p => Vector2.Distance(p.Position, sub.WorldPosition) < minDist);
} }
} }
if (!matchingPositions.Any()) if (!matchingPositions.Any())
{ {
#if DEBUG
DebugConsole.ThrowError("Could not find a suitable position of interest. (PositionType: " + positionType + ", minDistFromSubs: " + minDistFromSubs + "\n" + Environment.StackTrace);
#endif
position = positionsOfInterest[Rand.Int(positionsOfInterest.Count, (useSyncedRand ? Rand.RandSync.Server : Rand.RandSync.Unsynced))].Position; position = positionsOfInterest[Rand.Int(positionsOfInterest.Count, (useSyncedRand ? Rand.RandSync.Server : Rand.RandSync.Unsynced))].Position;
return false; return false;
} }