Dungeon Building p12

This commit is contained in:
dingo
2025-12-28 21:56:55 -05:00
parent bb25336752
commit 9806ce5940
+36 -6
View File
@@ -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<ConnectionPoint>
{
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
/// <summary>Get the best connection point for a given direction</summary>
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
};
}
/// <summary>Get world position of a connection point</summary>