diff --git a/Barotrauma/BarotraumaShared/Source/Map/Levels/BackgroundSpriteManager.cs b/Barotrauma/BarotraumaShared/Source/Map/Levels/BackgroundSpriteManager.cs index 565d8e90f..8d90ae775 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Levels/BackgroundSpriteManager.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Levels/BackgroundSpriteManager.cs @@ -243,7 +243,13 @@ namespace Barotrauma if (prefab.SpawnPos.HasFlag(BackgroundSpritePrefab.SpawnPosType.Wall)) cells.AddRange(level.GetCells(randomPos)); if (prefab.SpawnPos.HasFlag(BackgroundSpritePrefab.SpawnPosType.SeaFloor)) cells.AddRange(level.ExtraWalls[0].Cells); - + + //make sure the cells are in the same order regardless of whether the level is mirrored or not + cells.Sort((c1, c2) => { return level.Mirrored ? Math.Sign(c1.Center.X - c2.Center.X) : -Math.Sign(c1.Center.X - c2.Center.X); }); + + /*System.Diagnostics.Debug.WriteLine("FindSpritePosition - prefab: "+System.IO.Path.GetFileNameWithoutExtension(prefab.Sprite.FilePath)+" cells: "+cells.Count+" spawnpos: "+ prefab.SpawnPos+" randompos: "+ randomPos); + System.Diagnostics.Debug.WriteLine(string.Join(", ",cells.Select(c => level.cells.IndexOf(c))));*/ + if (cells.Any()) { VoronoiCell cell = cells[Rand.Int(cells.Count, Rand.RandSync.Server)]; diff --git a/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs b/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs index a8a394c14..5c46f7405 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs @@ -55,7 +55,8 @@ namespace Barotrauma //private float shaftHeight; //List bodies; - private List cells; + //TODO: change back to private + public List cells; //private VertexBuffer vertexBuffer; @@ -452,11 +453,16 @@ namespace Barotrauma edge.point2.X = borders.Width - edge.point2.X; if (!mirroredSites.Contains(edge.site1)) { + //make sure that sites right at the edge of a grid cell end up in the same cell as in the non-mirrored level + if (edge.site1.coord.x % GridCellSize < 1.0f && + edge.site1.coord.x % GridCellSize >= 0.0f) edge.site1.coord.x += 1.0f; edge.site1.coord.x = borders.Width - edge.site1.coord.x; mirroredSites.Add(edge.site1); } if (!mirroredSites.Contains(edge.site2)) { + if (edge.site2.coord.x % GridCellSize < 1.0f && + edge.site2.coord.x % GridCellSize >= 0.0f) edge.site2.coord.x += 1.0f; edge.site2.coord.x = borders.Width - edge.site2.coord.x; mirroredSites.Add(edge.site2); }