From 9806ce594052a6348127cceb4a21e92de4dc2ff5 Mon Sep 17 00:00:00 2001 From: dingo Date: Sun, 28 Dec 2025 21:56:55 -0500 Subject: [PATCH] Dungeon Building p12 --- Game/Dungeon/DungeonGeneratorV2.cs | 42 +++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/Game/Dungeon/DungeonGeneratorV2.cs b/Game/Dungeon/DungeonGeneratorV2.cs index 913c82c..f33beab 100644 --- a/Game/Dungeon/DungeonGeneratorV2.cs +++ b/Game/Dungeon/DungeonGeneratorV2.cs @@ -361,15 +361,29 @@ public class DungeonGeneratorV2 } // If no connection points defined, create default ones on each edge + // These are positioned AT the room edge (not inside) if (room.ConnectionPoints.Count == 0) { room.ConnectionPoints = new List { - new() { X = room.Width / 2, Y = 0, Direction = "north", Width = 2 }, - new() { X = room.Width / 2, Y = room.Height - 1, Direction = "south", Width = 2 }, - new() { X = 0, Y = room.Height / 2, Direction = "west", Width = 2 }, - new() { X = room.Width - 1, Y = room.Height / 2, Direction = "east", Width = 2 } + // North: center of top edge, Y=0 is top of room + new() { X = room.Width / 2, Y = 0, Direction = "north", Width = 3 }, + // South: center of bottom edge + new() { X = room.Width / 2, Y = room.Height - 1, Direction = "south", Width = 3 }, + // West: center of left edge + new() { X = 0, Y = room.Height / 2, Direction = "west", Width = 3 }, + // East: center of right edge + new() { X = room.Width - 1, Y = room.Height / 2, Direction = "east", Width = 3 } }; + Console.WriteLine($"[DungeonGenV2] Created default connection points for room at ({x},{y})"); + } + else + { + Console.WriteLine($"[DungeonGenV2] Room has {room.ConnectionPoints.Count} connection points from template"); + foreach (var cp in room.ConnectionPoints) + { + Console.WriteLine($" - ({cp.X},{cp.Y}) direction={cp.Direction} width={cp.Width}"); + } } // If no tiles were placed, do basic carve @@ -477,6 +491,10 @@ public class DungeonGeneratorV2 var cpA = a.GetConnectionPoint(aDirection); var cpB = b.GetConnectionPoint(bDirection); + Console.WriteLine($"[DungeonGenV2] Connecting {a.TemplateName ?? "room"} to {b.TemplateName ?? "room"}"); + Console.WriteLine($" A wants {aDirection}, got cp: {(cpA != null ? $"({cpA.X},{cpA.Y}) dir={cpA.Direction}" : "null")}"); + Console.WriteLine($" B wants {bDirection}, got cp: {(cpB != null ? $"({cpB.X},{cpB.Y}) dir={cpB.Direction}" : "null")}"); + int startX, startY, endX, endY; int corridorWidth = 2; @@ -878,8 +896,20 @@ public class DungeonRoomV2 : DungeonRoom /// Get the best connection point for a given direction public ConnectionPoint? GetConnectionPoint(string direction) { - return ConnectionPoints.FirstOrDefault(c => c.Direction.Equals(direction, StringComparison.OrdinalIgnoreCase)) - ?? ConnectionPoints.FirstOrDefault(); // Fallback to any + // First try exact match + var exact = ConnectionPoints.FirstOrDefault(c => c.Direction.Equals(direction, StringComparison.OrdinalIgnoreCase)); + if (exact != null) return exact; + + // No exact match - create a default one for this direction rather than using wrong direction + // This ensures the connection point is actually on the correct edge + return direction.ToLower() switch + { + "north" => new ConnectionPoint { X = Width / 2, Y = 0, Direction = "north", Width = 3 }, + "south" => new ConnectionPoint { X = Width / 2, Y = Height - 1, Direction = "south", Width = 3 }, + "east" => new ConnectionPoint { X = Width - 1, Y = Height / 2, Direction = "east", Width = 3 }, + "west" => new ConnectionPoint { X = 0, Y = Height / 2, Direction = "west", Width = 3 }, + _ => ConnectionPoints.FirstOrDefault() // Last resort fallback + }; } /// Get world position of a connection point