Dungeon improvements

This commit is contained in:
dingo
2025-12-28 14:22:57 -05:00
parent 1b3e47e5c2
commit 965694406d
3 changed files with 60 additions and 24 deletions
+28 -1
View File
@@ -60,6 +60,7 @@ public class DungeonGeneratorV2
// Initialize tile map with detailed tile info
// 0 = void/wall, positive = tile definition ID
layout.Tiles = new int[MapWidth, MapHeight];
layout.Walkable = new bool[MapWidth, MapHeight]; // All false by default
layout.TileDetails = new List<PlacedTile>();
// Generate rooms
@@ -304,9 +305,15 @@ public class DungeonGeneratorV2
{
layout.Tiles[worldX, worldY] = p.TileDefinitionId;
// Look up tile definition for sheet info
// Look up tile definition for sheet info and walkability
var tileDef = _tileDefinitions.GetValueOrDefault(p.TileDefinitionId);
// Set walkability based on tile definition
if (layout.Walkable != null && tileDef != null)
{
layout.Walkable[worldX, worldY] = tileDef.IsWalkable;
}
layout.TileDetails.Add(new PlacedTile
{
X = worldX,
@@ -379,6 +386,12 @@ public class DungeonGeneratorV2
{
layout.Tiles[x, y] = floorId > 0 ? floorId : 1; // 1 = walkable but no visual
// Set walkability - basic carved rooms are always walkable
if (layout.Walkable != null)
{
layout.Walkable[x, y] = true;
}
if (floorId > 0 && floorTile != null)
{
layout.TileDetails.Add(new PlacedTile
@@ -436,6 +449,13 @@ public class DungeonGeneratorV2
if (x >= 0 && x < MapWidth && ty >= 0 && ty < MapHeight && layout.Tiles[x, ty] == 0)
{
layout.Tiles[x, ty] = floorId;
// Set walkability for corridors
if (layout.Walkable != null)
{
layout.Walkable[x, ty] = true;
}
if (floorId > 0 && sheetId > 0)
{
layout.TileDetails.Add(new PlacedTile
@@ -465,6 +485,13 @@ public class DungeonGeneratorV2
if (tx >= 0 && tx < MapWidth && y >= 0 && y < MapHeight && layout.Tiles[tx, y] == 0)
{
layout.Tiles[tx, y] = floorId;
// Set walkability for corridors
if (layout.Walkable != null)
{
layout.Walkable[tx, y] = true;
}
if (floorId > 0 && sheetId > 0)
{
layout.TileDetails.Add(new PlacedTile
+19
View File
@@ -13,7 +13,12 @@ public class DungeonLayout
public int Height { get; set; }
public int TileSize { get; set; }
/// <summary>Tile IDs (for V2) or 0/1 (for V1)</summary>
public int[,] Tiles { get; set; } = new int[0, 0];
/// <summary>Walkability grid (true = can walk, false = blocked)</summary>
public bool[,]? Walkable { get; set; }
public List<DungeonRoom> Rooms { get; set; } = new();
public DungeonPoint SpawnPoint { get; set; }
public DungeonPoint? ExitPosition { get; set; } // Set when dungeon is cleared
@@ -24,6 +29,20 @@ public class DungeonLayout
public int TotalMobs { get; set; }
public int TotalChests { get; set; }
/// <summary>Check if a tile position is walkable</summary>
public bool IsWalkable(int x, int y)
{
if (x < 0 || x >= Width || y < 0 || y >= Height)
return false;
// If we have explicit walkability array, use it
if (Walkable != null)
return Walkable[x, y];
// Fallback: V1 convention (0 = wall, non-zero = floor)
return Tiles[x, y] != 0;
}
// Serialize tiles to string for DB storage
public string SerializeTiles()
{
+13 -23
View File
@@ -92,10 +92,8 @@ public class DungeonSimulation
foreach (var (tileX, tileY) in cornerPositions)
{
// Check if this is a valid floor tile (non-zero = walkable)
if (tileX >= 0 && tileX < Layout.Width &&
tileY >= 0 && tileY < Layout.Height &&
Layout.Tiles[tileX, tileY] != 0) // non-zero = floor
// Check if this is a valid floor tile
if (Layout.IsWalkable(tileX, tileY))
{
// Check surrounding tiles to avoid placing near hallways
bool nearHallway = false;
@@ -105,18 +103,16 @@ public class DungeonSimulation
{
int checkX = tileX + dx;
int checkY = tileY + dy;
if (checkX >= 0 && checkX < Layout.Width && checkY >= 0 && checkY < Layout.Height)
// Check if this position is outside the room bounds (potential hallway)
bool outsideRoom = checkX < entranceRoom.X ||
checkX >= entranceRoom.X + entranceRoom.Width ||
checkY < entranceRoom.Y ||
checkY >= entranceRoom.Y + entranceRoom.Height;
if (outsideRoom && Layout.IsWalkable(checkX, checkY)) // Floor outside room = hallway
{
// Check if this position is outside the room bounds (potential hallway)
bool outsideRoom = checkX < entranceRoom.X ||
checkX >= entranceRoom.X + entranceRoom.Width ||
checkY < entranceRoom.Y ||
checkY >= entranceRoom.Y + entranceRoom.Height;
if (outsideRoom && Layout.Tiles[checkX, checkY] != 0) // Floor outside room = hallway
{
nearHallway = true;
}
nearHallway = true;
}
}
}
@@ -146,9 +142,7 @@ public class DungeonSimulation
int portalTileX = entranceRoom.CenterX + dx;
int portalTileY = entranceRoom.CenterY + dy;
if (portalTileX >= 0 && portalTileX < Layout.Width &&
portalTileY >= 0 && portalTileY < Layout.Height &&
Layout.Tiles[portalTileX, portalTileY] != 0)
if (Layout.IsWalkable(portalTileX, portalTileY))
{
var portal = new PortalInstance
{
@@ -1012,11 +1006,7 @@ public class DungeonSimulation
int tileX = (int)(x / 32);
int tileY = (int)(y / 32);
if (tileX < 0 || tileX >= Layout.Width || tileY < 0 || tileY >= Layout.Height)
return false;
// Any non-zero tile is walkable (0 = void/wall, >0 = floor tile ID or 1 for basic floor)
return Layout.Tiles[tileX, tileY] != 0;
return Layout.IsWalkable(tileX, tileY);
}
private void MoveToward(MobInstance mob, float targetX, float targetY, float speed)