Dungeon improvements
This commit is contained in:
@@ -60,6 +60,7 @@ public class DungeonGeneratorV2
|
|||||||
// Initialize tile map with detailed tile info
|
// Initialize tile map with detailed tile info
|
||||||
// 0 = void/wall, positive = tile definition ID
|
// 0 = void/wall, positive = tile definition ID
|
||||||
layout.Tiles = new int[MapWidth, MapHeight];
|
layout.Tiles = new int[MapWidth, MapHeight];
|
||||||
|
layout.Walkable = new bool[MapWidth, MapHeight]; // All false by default
|
||||||
layout.TileDetails = new List<PlacedTile>();
|
layout.TileDetails = new List<PlacedTile>();
|
||||||
|
|
||||||
// Generate rooms
|
// Generate rooms
|
||||||
@@ -304,9 +305,15 @@ public class DungeonGeneratorV2
|
|||||||
{
|
{
|
||||||
layout.Tiles[worldX, worldY] = p.TileDefinitionId;
|
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);
|
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
|
layout.TileDetails.Add(new PlacedTile
|
||||||
{
|
{
|
||||||
X = worldX,
|
X = worldX,
|
||||||
@@ -379,6 +386,12 @@ public class DungeonGeneratorV2
|
|||||||
{
|
{
|
||||||
layout.Tiles[x, y] = floorId > 0 ? floorId : 1; // 1 = walkable but no visual
|
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)
|
if (floorId > 0 && floorTile != null)
|
||||||
{
|
{
|
||||||
layout.TileDetails.Add(new PlacedTile
|
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)
|
if (x >= 0 && x < MapWidth && ty >= 0 && ty < MapHeight && layout.Tiles[x, ty] == 0)
|
||||||
{
|
{
|
||||||
layout.Tiles[x, ty] = floorId;
|
layout.Tiles[x, ty] = floorId;
|
||||||
|
|
||||||
|
// Set walkability for corridors
|
||||||
|
if (layout.Walkable != null)
|
||||||
|
{
|
||||||
|
layout.Walkable[x, ty] = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (floorId > 0 && sheetId > 0)
|
if (floorId > 0 && sheetId > 0)
|
||||||
{
|
{
|
||||||
layout.TileDetails.Add(new PlacedTile
|
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)
|
if (tx >= 0 && tx < MapWidth && y >= 0 && y < MapHeight && layout.Tiles[tx, y] == 0)
|
||||||
{
|
{
|
||||||
layout.Tiles[tx, y] = floorId;
|
layout.Tiles[tx, y] = floorId;
|
||||||
|
|
||||||
|
// Set walkability for corridors
|
||||||
|
if (layout.Walkable != null)
|
||||||
|
{
|
||||||
|
layout.Walkable[tx, y] = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (floorId > 0 && sheetId > 0)
|
if (floorId > 0 && sheetId > 0)
|
||||||
{
|
{
|
||||||
layout.TileDetails.Add(new PlacedTile
|
layout.TileDetails.Add(new PlacedTile
|
||||||
|
|||||||
@@ -13,7 +13,12 @@ public class DungeonLayout
|
|||||||
public int Height { get; set; }
|
public int Height { get; set; }
|
||||||
public int TileSize { 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];
|
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 List<DungeonRoom> Rooms { get; set; } = new();
|
||||||
public DungeonPoint SpawnPoint { get; set; }
|
public DungeonPoint SpawnPoint { get; set; }
|
||||||
public DungeonPoint? ExitPosition { get; set; } // Set when dungeon is cleared
|
public DungeonPoint? ExitPosition { get; set; } // Set when dungeon is cleared
|
||||||
@@ -24,6 +29,20 @@ public class DungeonLayout
|
|||||||
public int TotalMobs { get; set; }
|
public int TotalMobs { get; set; }
|
||||||
public int TotalChests { 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
|
// Serialize tiles to string for DB storage
|
||||||
public string SerializeTiles()
|
public string SerializeTiles()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -92,10 +92,8 @@ public class DungeonSimulation
|
|||||||
|
|
||||||
foreach (var (tileX, tileY) in cornerPositions)
|
foreach (var (tileX, tileY) in cornerPositions)
|
||||||
{
|
{
|
||||||
// Check if this is a valid floor tile (non-zero = walkable)
|
// Check if this is a valid floor tile
|
||||||
if (tileX >= 0 && tileX < Layout.Width &&
|
if (Layout.IsWalkable(tileX, tileY))
|
||||||
tileY >= 0 && tileY < Layout.Height &&
|
|
||||||
Layout.Tiles[tileX, tileY] != 0) // non-zero = floor
|
|
||||||
{
|
{
|
||||||
// Check surrounding tiles to avoid placing near hallways
|
// Check surrounding tiles to avoid placing near hallways
|
||||||
bool nearHallway = false;
|
bool nearHallway = false;
|
||||||
@@ -105,18 +103,16 @@ public class DungeonSimulation
|
|||||||
{
|
{
|
||||||
int checkX = tileX + dx;
|
int checkX = tileX + dx;
|
||||||
int checkY = tileY + dy;
|
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)
|
nearHallway = true;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -146,9 +142,7 @@ public class DungeonSimulation
|
|||||||
int portalTileX = entranceRoom.CenterX + dx;
|
int portalTileX = entranceRoom.CenterX + dx;
|
||||||
int portalTileY = entranceRoom.CenterY + dy;
|
int portalTileY = entranceRoom.CenterY + dy;
|
||||||
|
|
||||||
if (portalTileX >= 0 && portalTileX < Layout.Width &&
|
if (Layout.IsWalkable(portalTileX, portalTileY))
|
||||||
portalTileY >= 0 && portalTileY < Layout.Height &&
|
|
||||||
Layout.Tiles[portalTileX, portalTileY] != 0)
|
|
||||||
{
|
{
|
||||||
var portal = new PortalInstance
|
var portal = new PortalInstance
|
||||||
{
|
{
|
||||||
@@ -1012,11 +1006,7 @@ public class DungeonSimulation
|
|||||||
int tileX = (int)(x / 32);
|
int tileX = (int)(x / 32);
|
||||||
int tileY = (int)(y / 32);
|
int tileY = (int)(y / 32);
|
||||||
|
|
||||||
if (tileX < 0 || tileX >= Layout.Width || tileY < 0 || tileY >= Layout.Height)
|
return Layout.IsWalkable(tileX, tileY);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MoveToward(MobInstance mob, float targetX, float targetY, float speed)
|
private void MoveToward(MobInstance mob, float targetX, float targetY, float speed)
|
||||||
|
|||||||
Reference in New Issue
Block a user