private void VisualiseConnectivityGraph(MapModel graphModel) { var visualiser = new DoorClueGraphvizExport(graphModel); visualiser.OutputFullGraph("bsptree-full"); try { var graphVizLocation = Game.Config.Entries[Config.GraphVizLocation]; GraphVizUtils.RunGraphVizPNG(graphVizLocation, "bsptree-full"); GraphVizUtils.DisplayPNGInChildWindow("bsptree-full"); } catch (Exception) { LogFile.Log.LogEntryDebug("Can't find graphViz in config file", LogDebugLevel.High); } }
/// <summary> /// Adds levels and interconnecting staircases /// </summary> private void SetupMapsGraphingDemoCycles() { Dungeon dungeon = Game.Dungeon; MapGeneratorBSP hallsGen = new MapGeneratorBSP(); //Clip to 60 hallsGen.Width = 50; hallsGen.Height = 25; hallsGen.NoSplitChance = 3; Map hallMap = hallsGen.GenerateMap(3); //Optionally add door locks //Firstly find the node in the reduced map that corresponds to the player start location var connectivityModel = hallsGen.GraphModel; LogFile.Log.LogEntryDebug("PC start vertex: " + connectivityModel.StartVertex, LogDebugLevel.High); DoorClueGraphvizExport visualiser = new DoorClueGraphvizExport(connectivityModel); visualiser.OutputClueDoorGraph("bsptree-door"); visualiser.OutputDoorDependencyGraph("bsptree-dep"); //We've altered the map now, so get a new copy before we store it hallMap = hallsGen.GetOriginalMap(); int levelNo = Game.Dungeon.AddMap(hallMap); //Store the hallGen //Will get sorted in level order levelGen.Add(0, hallsGen); //Place the player, so monster placing can be checked against it //Game.Dungeon.Player.LocationLevel = 0; //on reload, don't reset this //needs to be done before placing items Game.Dungeon.Player.LocationMap = Game.Dungeon.Levels[Game.Dungeon.Player.LocationLevel].PCStartLocation; //Run graphviz to png the output then display try { var graphVizLocation = Game.Config.Entries[Config.GraphVizLocation]; GraphVizUtils.RunGraphVizPNG(graphVizLocation, "bsptree-base"); GraphVizUtils.RunGraphVizPNG(graphVizLocation, "bsptree-nocycles"); GraphVizUtils.DisplayPNGInChildWindow("bsptree-base"); GraphVizUtils.DisplayPNGInChildWindow("bsptree-nocycles"); } catch (Exception) { LogFile.Log.LogEntryDebug("Can't find graphViz in config file", LogDebugLevel.High); } //Add standard dock triggers (allows map abortion & completion) //AddStandardEntryExitTriggers(dungeon, hallsGen, levelNo); //Place dock bay feature at PC startloc Game.Dungeon.AddFeature(new Features.DockBay(), levelNo, Game.Dungeon.Levels[levelNo].PCStartLocation); }
private void VisualiseLevelConnectivityGraph(MapModel graphModel, Dictionary<int, string> levelNaming) { var visualiser = new DoorClueGraphvizExport(graphModel, levelNaming); visualiser.OutputClueDoorGraph("levellinks-full"); if (Game.Config.DebugMode) { try { var graphVizLocation = Game.Config.Entries[Config.GraphVizLocation]; GraphVizUtils.RunGraphVizPNG(graphVizLocation, "levellinks-full"); GraphVizUtils.DisplayPNGInChildWindow("levellinks-full"); } catch (Exception) { LogFile.Log.LogEntryDebug("Can't find graphViz in config file", LogDebugLevel.High); } } }
/// <summary> /// Adds levels and interconnecting staircases /// </summary> private void SetupMapsGraphingDemo(bool doLocks, int noLocks) { Dungeon dungeon = Game.Dungeon; MapGeneratorBSP hallsGen = new MapGeneratorBSP(); hallsGen.NoSplitChance = 3; //Clip to 60 hallsGen.Width = 40; if(doLocks) hallsGen.Width = 50; hallsGen.Height = 25; hallsGen.GenerateMap(0); MapModel connectivityModel = null; if (doLocks) { //Optionally add door locks //Firstly find the node in the reduced map that corresponds to the player start location connectivityModel = hallsGen.GraphModel; int startNode = connectivityModel.StartVertexNoCycleMap; LogFile.Log.LogEntryDebug("PC start vertex: " + startNode, LogDebugLevel.High); connectivityModel.LockRandomEdgeRandomClue("red"); if (noLocks > 1) { connectivityModel.LockRandomEdgeRandomClue("green"); connectivityModel.LockRandomEdgeRandomClue("blue"); connectivityModel.LockRandomEdgeRandomClue("yellow"); } var visualiser = new DoorClueGraphvizExport(connectivityModel); visualiser.OutputClueDoorGraph("bsptree-door"); visualiser.OutputDoorDependencyGraph("bsptree-dep"); //Find the doors corresponding to locked connections and lock them foreach (var door in connectivityModel.DoorAndClueManager.DoorMap) { //The door knows its location in the full map, so this should work with cycles hallsGen.LockConnection(door.Value); } } //Add map to dungeon int levelNo = Game.Dungeon.AddMap(hallsGen.BaseMap); //Add locks to dungeon as simple doors foreach (var locksInLocation in hallsGen.MapSquareLocks) { var lockLocation = locksInLocation.Key; foreach(var thisLock in locksInLocation.Value) { var lockedDoor = new Locks.SimpleLockedDoor(thisLock); lockedDoor.LocationLevel = levelNo; lockedDoor.LocationMap = lockLocation; Game.Dungeon.AddLock(lockedDoor); } } //Place the player, so monster placing can be checked against it //Game.Dungeon.Player.LocationLevel = 0; //on reload, don't reset this //needs to be done before placing items Game.Dungeon.Player.LocationMap = Game.Dungeon.Levels[Game.Dungeon.Player.LocationLevel].PCStartLocation; if (doLocks) { //Find a random room corresponding to a vertex with a clue and place a clue there foreach (var cluesAtVertex in connectivityModel.DoorAndClueManager.ClueMap) { foreach (var clue in cluesAtVertex.Value) { var possibleRooms = clue.PossibleClueRoomsInFullMap; var randomRoom = possibleRooms[Game.Random.Next(possibleRooms.Count)]; var pointInRoom = hallsGen.RandomPointInRoomById(randomRoom); Game.Dungeon.AddItem(new Items.Clue(clue), 0, pointInRoom.GetPointInRoomOnly()); } } } //Run graphviz to png the output then display try { var graphVizLocation = Game.Config.Entries[Config.GraphVizLocation]; GraphVizUtils.RunGraphVizPNG(graphVizLocation, "bsptree-base"); GraphVizUtils.DisplayPNGInChildWindow("bsptree-base"); if (doLocks) { GraphVizUtils.RunGraphVizPNG(graphVizLocation, "bsptree-door"); GraphVizUtils.RunGraphVizPNG(graphVizLocation, "bsptree-dep"); GraphVizUtils.DisplayPNGInChildWindow("bsptree-door"); GraphVizUtils.DisplayPNGInChildWindow("bsptree-dep"); } } catch(Exception) { LogFile.Log.LogEntryDebug("Can't find graphViz in config file", LogDebugLevel.High); } //Add standard dock triggers (allows map abortion & completion) //AddStandardEntryExitTriggers(dungeon, hallsGen, levelNo); //Setup pathfinding CalculateWalkableAndTCOD(); //Place dock bay feature at PC startloc Game.Dungeon.AddFeature(new Features.DockBay(), levelNo, Game.Dungeon.Levels[levelNo].PCStartLocation); }