diff --git a/Barotrauma/BarotraumaShared/Source/Events/ArtifactEvent.cs b/Barotrauma/BarotraumaShared/Source/Events/ArtifactEvent.cs index 41b8577c4..be7ca10b1 100644 --- a/Barotrauma/BarotraumaShared/Source/Events/ArtifactEvent.cs +++ b/Barotrauma/BarotraumaShared/Source/Events/ArtifactEvent.cs @@ -34,7 +34,7 @@ namespace Barotrauma base.Init(); 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.MoveWithLevel = true; diff --git a/Barotrauma/BarotraumaShared/Source/Events/Missions/MonsterMission.cs b/Barotrauma/BarotraumaShared/Source/Events/Missions/MonsterMission.cs index 315026dc8..bb2b00e00 100644 --- a/Barotrauma/BarotraumaShared/Source/Events/Missions/MonsterMission.cs +++ b/Barotrauma/BarotraumaShared/Source/Events/Missions/MonsterMission.cs @@ -28,7 +28,7 @@ namespace Barotrauma public override void Start(Level level) { 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.Enabled = false; diff --git a/Barotrauma/BarotraumaShared/Source/Events/Missions/SalvageMission.cs b/Barotrauma/BarotraumaShared/Source/Events/Missions/SalvageMission.cs index b5c4fc7b1..0d430ad10 100644 --- a/Barotrauma/BarotraumaShared/Source/Events/Missions/SalvageMission.cs +++ b/Barotrauma/BarotraumaShared/Source/Events/Missions/SalvageMission.cs @@ -46,7 +46,7 @@ namespace Barotrauma 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.MoveWithLevel = true; diff --git a/Barotrauma/BarotraumaShared/Source/Events/MonsterEvent.cs b/Barotrauma/BarotraumaShared/Source/Events/MonsterEvent.cs index 9c2ed6ec2..9b6d2c34e 100644 --- a/Barotrauma/BarotraumaShared/Source/Events/MonsterEvent.cs +++ b/Barotrauma/BarotraumaShared/Source/Events/MonsterEvent.cs @@ -85,7 +85,7 @@ namespace Barotrauma if (disallowed) return null; 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 repeat = false; diff --git a/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs b/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs index 236cffcfe..74abdf6df 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs @@ -817,7 +817,7 @@ namespace Barotrauma //50% chance of placing the ruins at a cave 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); @@ -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; @@ -906,7 +906,7 @@ namespace Barotrauma do { 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); @@ -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()) { @@ -945,17 +945,20 @@ namespace Barotrauma var matchingPositions = positionsOfInterest.FindAll(p => positionType.HasFlag(p.PositionType)); - if (avoidSubs) + if (minDistFromSubs > 0.0f) { 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); + matchingPositions.RemoveAll(p => Vector2.DistanceSquared(p.Position, sub.WorldPosition) < minDistFromSubs * minDistFromSubs); } } 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; return false; }