diff --git a/Barotrauma/BarotraumaShared/Source/Map/Levels/Ruins/RuinGenerator.cs b/Barotrauma/BarotraumaShared/Source/Map/Levels/Ruins/RuinGenerator.cs index 26c6bc01f..a963828f1 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Levels/Ruins/RuinGenerator.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Levels/Ruins/RuinGenerator.cs @@ -28,7 +28,7 @@ namespace Barotrauma.RuinGeneration } public List Walls; - + public virtual void CreateWalls() { } public Alignment GetLineAlignment(Line line) @@ -344,9 +344,68 @@ namespace Barotrauma.RuinGeneration Rectangle backgroundRect = new Rectangle(leaf.Rect.X, leaf.Rect.Y + leaf.Rect.Height, leaf.Rect.Width, leaf.Rect.Height); new Structure(backgroundRect, (background.Prefab as StructurePrefab), null).MoveWithLevel = true; - } + List doorlessRooms = new List(shapes); + + //generate doors & sensors that close them ------------------------------------------------------------- + + var sensorPrefab = MapEntityPrefab.Find("Alien Motion Sensor") as ItemPrefab; + var wirePrefab = MapEntityPrefab.Find("Wire") as ItemPrefab; + + foreach (Corridor corridor in corridors) + { + var doorPrefab = RuinStructure.GetRandom(corridor.IsHorizontal ? RuinStructureType.Door : RuinStructureType.Hatch, Alignment.Center); + if (doorPrefab == null) continue; + + //find all walls that are parallel to the corridor + var suitableWalls = corridor.IsHorizontal ? + corridor.Walls.FindAll(c => c.A.Y == c.B.Y) : corridor.Walls.FindAll(c => c.A.X == c.B.X); + + if (!suitableWalls.Any()) continue; + + doorlessRooms.Remove(corridor); + Vector2 doorPos = corridor.Center; + + //choose a random wall to place the door next to + var wall = suitableWalls[Rand.Int(suitableWalls.Count, Rand.RandSync.Server)]; + if (corridor.IsHorizontal) + { + doorPos.X = (wall.A.X + wall.B.X) / 2.0f; + } + else + { + doorPos.Y = (wall.A.Y + wall.B.Y) / 2.0f; + } + + var door = new Item(doorPrefab.Prefab as ItemPrefab, doorPos, null); + door.MoveWithLevel = true; + + door.GetComponent().IsOpen = Rand.Range(0.0f, 1.0f, Rand.RandSync.Server) < 0.8f; + + if (sensorPrefab == null || wirePrefab == null) continue; + + var sensorRoom = corridor.ConnectedRooms.FirstOrDefault(r => r != null && rooms.Contains(r)); + if (sensorRoom == null) continue; + + var sensor = new Item(sensorPrefab, new Vector2( + Rand.Range(sensorRoom.Rect.X, sensorRoom.Rect.Right, Rand.RandSync.Server), + Rand.Range(sensorRoom.Rect.Y, sensorRoom.Rect.Bottom, Rand.RandSync.Server)), null); + sensor.MoveWithLevel = true; + + var wire = new Item(wirePrefab, sensorRoom.Center, null).GetComponent(); + wire.Item.MoveWithLevel = false; + + var conn1 = door.Connections.Find(c => c.Name == "set_state"); + conn1.AddLink(0, wire); + wire.Connect(conn1, false); + + var conn2 = sensor.Connections.Find(c => c.Name == "state_out"); + conn2.AddLink(0, wire); + wire.Connect(conn2, false); + } + + //generate props -------------------------------------------------------------- for (int i = 0; i < shapes.Count*2; i++ ) { @@ -356,7 +415,10 @@ namespace Barotrauma.RuinGeneration Vector2 size = (prop.Prefab is StructurePrefab) ? ((StructurePrefab)prop.Prefab).Size : Vector2.Zero; - var shape = shapes[Rand.Int(shapes.Count, Rand.RandSync.Server)]; + //if the prop is placed at the center of the room, we have to use a room without a door (because they're also placed at the center) + var shape = prop.Alignment.HasFlag(Alignment.Center) ? + doorlessRooms[Rand.Int(doorlessRooms.Count, Rand.RandSync.Server)] : + shapes[Rand.Int(shapes.Count, Rand.RandSync.Server)]; Vector2 position = shape.Rect.Center.ToVector2(); if (prop.Alignment.HasFlag(Alignment.Top)) @@ -389,62 +451,6 @@ namespace Barotrauma.RuinGeneration prop.Prefab as StructurePrefab, null).MoveWithLevel = true; } } - - //generate doors & sensors that close them ------------------------------------------------------------- - - var sensorPrefab = MapEntityPrefab.Find("Alien Motion Sensor") as ItemPrefab; - var wirePrefab = MapEntityPrefab.Find("Wire") as ItemPrefab; - - foreach (Corridor corridor in corridors) - { - var doorPrefab = RuinStructure.GetRandom(corridor.IsHorizontal ? RuinStructureType.Door : RuinStructureType.Hatch, Alignment.Center); - if (doorPrefab == null) continue; - - //find all walls that are parallel to the corridor - var suitableWalls = corridor.IsHorizontal ? - corridor.Walls.FindAll(c => c.A.Y == c.B.Y) : corridor.Walls.FindAll(c => c.A.X == c.B.X); - - if (!suitableWalls.Any()) continue; - - Vector2 doorPos = corridor.Center; - - //choose a random wall to place the door next to - var wall = suitableWalls[Rand.Int(suitableWalls.Count, Rand.RandSync.Server)]; - if (corridor.IsHorizontal) - { - doorPos.X = (wall.A.X + wall.B.X) / 2.0f; - } - else - { - doorPos.Y = (wall.A.Y + wall.B.Y) / 2.0f; - } - - var door = new Item(doorPrefab.Prefab as ItemPrefab, doorPos, null); - door.MoveWithLevel = true; - - door.GetComponent().IsOpen = Rand.Range(0.0f, 1.0f, Rand.RandSync.Server) < 0.8f; - - if (sensorPrefab == null || wirePrefab == null) continue; - - var sensorRoom = corridor.ConnectedRooms.FirstOrDefault(r => r != null && rooms.Contains(r)); - if (sensorRoom == null) continue; - - var sensor = new Item(sensorPrefab, new Vector2( - Rand.Range(sensorRoom.Rect.X, sensorRoom.Rect.Right, Rand.RandSync.Server), - Rand.Range(sensorRoom.Rect.Y, sensorRoom.Rect.Bottom, Rand.RandSync.Server)), null); - sensor.MoveWithLevel = true; - - var wire = new Item(wirePrefab, sensorRoom.Center, null).GetComponent(); - wire.Item.MoveWithLevel = false; - - var conn1 = door.Connections.Find(c => c.Name == "set_state"); - conn1.AddLink(0, wire); - wire.Connect(conn1, false); - - var conn2 = sensor.Connections.Find(c => c.Name == "state_out"); - conn2.AddLink(0, wire); - wire.Connect(conn2, false); - } return shapes; }