private void GenerateDebugStructure(DungeonStructure dungeonStructure) { Destroy(_debugStructure); _debugStructure = new GameObject("DebugStructure"); DungeonDebugger.GenerateDungeonDebugStructure(dungeonStructure, _debugStructure.transform); _debugStructure.SetActive(drawDebugView); }
public void Generate(string name, int itemId, int floorPlan) { var test = DungeonClass.LoadDungeonClass(TxtDungeonName.Text); if (test == null) { MessageBox.Show("Dungeon not found.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { var dungeon = new DungeonStructure(name, 0, itemId, "", 0, floorPlan); if (!ChkImage.Checked) { TxtDungeon.Text = GetMazeAsString(dungeon); TxtDungeon.Visible = true; ImgDungeon.Visible = false; } else { ImgDungeon.Image = GetBitmap(dungeon); TxtDungeon.Visible = false; ImgDungeon.Visible = true; } } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message + ".", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Draws the dungeon debug data in editor scene view /// Should only be called from OnDrawGizmos or OnDrawGizmosSelected unity functions /// </summary> public static void DrawDungeonDebugGizmos(DungeonStructure structure) { structure.StartElement.ForeachDepthFirst((n, d) => { Gizmos.color = ElementColorBasedOnPath(n, d); var bounds = n.Room.GetBounds(); Gizmos.DrawCube(bounds.center, bounds.extents * 2.1f); }); }
internal static DungeonStructure ConcretizeStructure(AbstractDungeonStructure inputStructure, Random random) { var structure = new DungeonStructure(ConcretizeDungeonTree(inputStructure.StartElement, random, new ReadOnlyDictionary <string, AbstractDungeonStructure>(inputStructure.EmbeddedDungeons)), inputStructure.StructureMetaData, inputStructure); structure.NodeMetaData.BranchDataWrapper = inputStructure.BranchDataWrapper; return(structure); }
static string GetMazeAsString(DungeonStructure dungeon) { var sw = new System.IO.StringWriter(); for (int floorN = 0; floorN < dungeon.floors.Count; ++floorN) { var floor = dungeon.floors[floorN]; var rooms = floor.maze_generator.rooms; sw.WriteLine("Floor {0}", floorN + 1); sw.WriteLine(" 000102030405060708"); for (int y = floor.maze_generator.height - 1; y >= 0; --y) { var row = string.Format("{0,0:D2} ", y); for (int x = 0; x < floor.maze_generator.width; ++x) { if (floor.maze_generator.start_pos.X == x && floor.maze_generator.start_pos.Y == y) { row += "S "; } else if (floor.maze_generator.end_pos.X == x && floor.maze_generator.end_pos.Y == y) { row += "B "; } else if (floor.maze_generator.rooms[x][y].isVisited > 0) { row += "X "; } else { row += " "; } } sw.WriteLine(row); } sw.WriteLine(); } var result = sw.ToString(); sw.Close(); return(result.Trim()); }
private void BuildDungeon( AbstractDungeonStructure structure, int generationSeed, float branchPercent, float margin, PrototypeDungeonGenerator.GenerationParameters parameters) { if (structure.BranchDataWrapper != null) { structure.BranchDataWrapper.BranchPercentage = branchPercent; } structure.StructureMetaData.MarginUnit = margin; var generator = new PrototypeDungeonGenerator(structure, generationSeed, parameters); var prototypeDungeon = generator.BuildPrototype(); _actualStructure = prototypeDungeon.BuildDungeonInUnitySpace(transform); OnDungeonRebuilt?.Invoke(_actualStructure); }
public PrototypeDungeonGenerator(AbstractDungeonStructure structure, int seed, GenerationParameters generationParameters = null) { _seed = seed; _random = new Random(seed); _generationParameters = generationParameters; _loadedStructure = DungeonStructureConcretizer.ConcretizeStructure(structure, _random); _loadedRooms = RoomResourceLoader.LoadRoomPrototypes(_loadedStructure); _marginHalf = structure.StructureMetaData.MarginUnit / 2f; CollectMetaData(_loadedStructure); if (_generationParameters != null) { ParameterizeDungeon(); } if (_stepBackCounter == null) { _stepBackCounter = new StepBackCounter(DefaultMaxSteps); } }
internal static Dictionary <string, RoomCollection> LoadRoomPrototypes(DungeonStructure dungeonStructure, Func <string, RoomCollection> roomLoaderOverwrite = null) { var collector = new Dictionary <string, RoomCollection>(); var roomLoader = roomLoaderOverwrite ?? LoadRoom; var startElement = dungeonStructure.StartElement; LoadRoomPrototypesRecur(startElement, collector, roomLoader); if (dungeonStructure.NodeMetaData.BranchDataWrapper != null) { foreach (var prototypeName in dungeonStructure.NodeMetaData.BranchDataWrapper.BranchPrototypeNames) { LoadRoomPrototypesRecur(dungeonStructure.AbstractStructure.EmbeddedDungeons[prototypeName].StartElement, collector, roomLoader); } } return(collector); }
private static void CollectMetaData(DungeonStructure dungeonStructure) { CollectMetaData(dungeonStructure.StartElement); }
/// <summary> /// Builds an object structure around the dungeon with the debug informations /// Can be used in built games /// </summary> public static void GenerateDungeonDebugStructure(DungeonStructure structure, Transform parent = null) { structure.StartElement.ForeachDepthFirst((n, d) => { BuildDebugCube(parent, n, ElementColorBasedOnPath(n, d)); }); }
private Bitmap GetBitmap(DungeonStructure dungeon) { var colorBackground = Color.FromArgb(0xf8, 0xdb, 0xb3); var colorPath = Color.FromArgb(0x9e, 0x85, 0x67); var colorStart = Color.FromArgb(0xff, 0xff, 0xff); var colorEnd = Color.FromArgb(0x5b, 0x4d, 0x3b); var solidBlack = new SolidBrush(Color.Black); var tileSize = 20; var maxTilesX = 0; var maxTilesY = 0; var perLine = 3; var fontSize = 10; var font = new Font(FontFamily.GenericSansSerif, fontSize); var textHeight = 10; using (var bmp = new Bitmap(1, 1)) using (var g = Graphics.FromImage(bmp)) textHeight = (int)g.MeasureString("test", font).Height; foreach (var floor in dungeon.floors) { if (floor.maze_generator.width > maxTilesX) { maxTilesX = floor.maze_generator.width; } if (floor.maze_generator.height > maxTilesY) { maxTilesY = floor.maze_generator.height; } } maxTilesX++; maxTilesY++; var imageW = (maxTilesX * tileSize) * (dungeon.floors.Count >= perLine ? perLine : dungeon.floors.Count) + tileSize * 2; var imageH = (maxTilesY * tileSize) * (int)Math.Ceiling(dungeon.floors.Count / (float)perLine) + tileSize * 2 + 10 + textHeight; var result = new Bitmap(imageW, imageH); using (var g = Graphics.FromImage(result)) { g.FillRectangle(new SolidBrush(colorBackground), new Rectangle(0, 0, imageW, imageH)); g.DrawString(dungeon.name, font, solidBlack, new PointF(10, 10)); var xoff = tileSize; var yoff = tileSize + 10 + textHeight; var xcount = 0; for (int i = 0; i < dungeon.floors.Count; ++i) { var floor = dungeon.floors[i]; var rooms = floor.maze_generator.rooms; if (i > 0) { xoff += (maxTilesX * tileSize); if (++xcount >= perLine) { xoff = tileSize; yoff += (maxTilesY * tileSize); xcount = 0; } } for (int y = 0; y < floor.maze_generator.height; ++y) { for (int x = 0; x < floor.maze_generator.width; ++x) { var color = Color.Transparent; if (floor.maze_generator.start_pos.X == x && floor.maze_generator.start_pos.Y == y) { color = colorStart; } else if (floor.maze_generator.end_pos.X == x && floor.maze_generator.end_pos.Y == y) { color = colorEnd; } else if (rooms[x][y].isVisited > 0) { color = colorPath; } if (color != Color.Transparent) { var brush = new SolidBrush(color); var xp = x * tileSize + xoff; var yp = (floor.maze_generator.height - y - 1) * tileSize + yoff; var wp = tileSize; var hp = tileSize; if (color != colorPath) { g.FillRectangle(new SolidBrush(color), new Rectangle(xp, yp, wp, hp)); } else { var subTileSize = (int)(tileSize / 4f); wp = subTileSize * 2; hp = subTileSize * 2; xp += subTileSize; yp += subTileSize; g.FillRectangle(new SolidBrush(color), new Rectangle(xp, yp, wp, hp)); var code = 0; for (var d = 0; d < 4; ++d) { if (rooms[x][y].directions[d] > 0) { code |= 1 << d * 4; } } if ((code & 0x1000) != 0) { g.FillRectangle(brush, new Rectangle(xp - subTileSize, yp, wp, hp)); } if ((code & 0x0100) != 0) { g.FillRectangle(brush, new Rectangle(xp, yp + subTileSize, wp, hp)); } if ((code & 0x0010) != 0) { g.FillRectangle(brush, new Rectangle(xp + subTileSize, yp, wp, hp)); } if ((code & 0x0001) != 0) { g.FillRectangle(brush, new Rectangle(xp, yp - subTileSize, wp, hp)); } } //g.DrawString(x + "," + y, new Font(FontFamily.GenericSansSerif, 8), solidBlack, new PointF(x * tileSize + xoff, (floor.maze_generator.height - y - 1) * tileSize + yoff)); //g.DrawRectangle(new Pen(Color.Black), new Rectangle(x * tileSize + xoff, (floor.maze_generator.height - y - 1) * tileSize + yoff, tileSize, tileSize)); } } } } } return(result); }