public void FlipYsForGenSpecificData() { //The size of the cell grid is found by combining each node // (assumed to have the largest-possible room size) with each connecting tunnel. Location cells = new Location(((Settings.NumberOfNodes.X - 1) * Settings.TunnelLength.X) + (Settings.NumberOfNodes.X * MaxRoomSize.X) + 2, ((Settings.NumberOfNodes.Y - 1) * Settings.TunnelLength.Y) + (Settings.NumberOfNodes.Y * MaxRoomSize.Y) + 2); //Set up the graph/pather. Graph = new LimitedRectangularGrid(new RectangularGrid(Settings.TunnelLength.X + MaxRoomSize.X, Settings.TunnelLength.Y + MaxRoomSize.Y, false), false, false, new Interval(0, cells.X - 1, true, 0), new Interval(0, cells.Y - 1, true, 0)); GraphPather = new PathFinder <PositionalNode>(Graph, new PositionalNode(new float[2] { Single.NaN, Single.NaN }, 0), (n, n2) => new PositionalEdge(n.Coordinate, n2.Coordinate, 0)); //Rebuild the node areas and states. Dictionary <PositionalNode, Region> newNodeAreas = new Dictionary <PositionalNode, Region>(); Dictionary <PositionalNode, NodeState> newNodeStates = new Dictionary <PositionalNode, NodeState>(); PositionalNode oldNode; Region oldNodeArea; //First get all Y coordinates for rooms/tunnels. List <float> nodeYs = new List <float>(); foreach (PositionalNode n in NodeStates.Keys) { if (!nodeYs.Contains(n.Coordinate[1])) { nodeYs.Add(n.Coordinate[1]); } } //Go through every node and flip its Y value. foreach (PositionalNode n in Graph.AllNodes(new PositionalNode(new float[2] { 1.0f, 1.0f }))) { int indexOf = nodeYs.IndexOf(n.Coordinate[1]); int flippedIndexOf = nodeYs.Count - 1 - indexOf; oldNode = new PositionalNode(new float[2] { n.Coordinate[0], nodeYs[flippedIndexOf] }); oldNodeArea = NodeAreas[oldNode]; newNodeStates.Add(n, NodeStates[oldNode]); newNodeAreas.Add(n, new Region(oldNodeArea.X, Map.GetLength(1) - 1 - oldNodeArea.Y, oldNodeArea.Width, -oldNodeArea.Height, true)); } NodeAreas = newNodeAreas; NodeStates = newNodeStates; }
//Base generation (i.e. the rooms/junctions). public void InitializeBase() { //The size of the cell grid is found by combining each node // (assumed to have the largest-possible room size) with each connecting tunnel. Location cells = new Location(((Settings.NumberOfNodes.X - 1) * Settings.TunnelLength.X) + (Settings.NumberOfNodes.X * MaxRoomSize.X) + 2, ((Settings.NumberOfNodes.Y - 1) * Settings.TunnelLength.Y) + (Settings.NumberOfNodes.Y * MaxRoomSize.Y) + 2); //Set up the graph/pather. Graph = new LimitedRectangularGrid(new RectangularGrid(Settings.TunnelLength.X + MaxRoomSize.X, Settings.TunnelLength.Y + MaxRoomSize.Y, false), false, false, new Interval(0, cells.X - 1, true, 0), new Interval(0, cells.Y - 1, true, 0)); GraphPather = new PathFinder <PositionalNode>(Graph, new PositionalNode(new float[2] { Single.NaN, Single.NaN }, 0), (n, n2) => new PositionalEdge(n.Coordinate, n2.Coordinate, 0)); //Set up the room map. Initial value is a fully-filled room. Map = new bool[cells.X, cells.Y]; for (int i = 0; i < Map.GetLength(0); ++i) { for (int j = 0; j < Map.GetLength(1); ++j) { Map[i, j] = true; } } //Initialize the room nodes. NodeAreas = new Dictionary <PositionalNode, Region>(); NodeStates = new Dictionary <PositionalNode, NodeState>(); foreach (PositionalNode n in Graph.AllNodes(new PositionalNode(new float[2] { 1.0f, 1.0f }))) { NodeStates.Add(n, NodeState.Untouched); } //Initialize other data. Regions = new List <Region>(); FilledRegions = new List <FilledRegion>(); Holes = new List <Location>(); //Initialize counter to iterate through base room generation. DoneBaseGen = false; listVersionBGIC = NodeStates.Keys.ToList(); baseGenIterateCounter = listVersionBGIC.GetEnumerator(); baseGenIterateCounter.MoveNext(); //Set up the fill data. FillData = new FillData(Map, new Region(-1, -1, -1, -1), Regions, Holes, GenSettings.WrapX, GenSettings.WrapY, true); }