예제 #1
0
    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;
    }
예제 #2
0
    public void IterateFillPattern()
    {
        if (DoneFillPatterns)
        {
            return;
        }

        //Get the current node.
        PositionalNode n = NeedToApply.Current;

        //If it is a junction, ignore it for now.
        //FilledRegions covering junctions/tunnels will be
        //   added after fill patterns are applied to rooms.
        if (NodeStates[n] == NodeState.TunnelJunction)
        {
            DoneFillPatterns = !NeedToApply.MoveNext();
            return;
        }

        //Get the best fill pattern for it and apply it if one exists.
        FillPattern  p = Settings.MostSuitable(NodeAreas[n]);
        FilledRegion tempF;

        if (p != null)
        {
            FillData.BeingFilled = NodeAreas[n];
            tempF = p.Apply(FillData);
            //If the area has no team spawns, add one at the top.
            if (tempF.PotentialSpawns[Spawns.Team].Count == 0 && tempF.Covering.Width + 1 >= 4)
            {
                tempF.PotentialSpawns[Spawns.Team].Add(new Region(tempF.Covering.Left, tempF.Covering.Top, tempF.Covering.Width, 0));
            }
            FilledRegions.Add(tempF);
        }
        else
        {
            FilledRegions.Add(new NoRegion(NodeAreas[n]));
        }

        //Continue the iteration.
        DoneFillPatterns = !NeedToApply.MoveNext();
    }
    public override bool Equals(object obj)
    {
        PositionalNode other = obj as PositionalNode;

        if (other == null)
        {
            return(false);
        }
        if (other.Coordinate.Length != Coordinate.Length)
        {
            return(false);
        }

        for (int i = 0; i < Coordinate.Length; ++i)
        {
            if (Coordinate[i] != other.Coordinate[i])
            {
                return(false);
            }
        }

        return(true);
    }
예제 #4
0
    public void IterateBase()
    {
        if (DoneBaseGen)
        {
            return;
        }

        count += 1;

        PositionalNode current = baseGenIterateCounter.Current;

        //Make either a room or a tunnel junction at the given spot.
        if (GeneratorSettings.R.NextDouble() < Settings.PercentRooms)
        {
            //Room.

            Location size = new Location(Settings.RoomDimensions.X + (int)Settings.RoomXVariance.Random(),
                                         Settings.RoomDimensions.Y + (int)Settings.RoomYVariance.Random());
            size = new Location(System.Math.Max(size.X, Settings.TunnelThickness.X),
                                System.Math.Max(size.Y, Settings.TunnelThickness.Y));
            Region room = new Region((int)current.Coordinate[0],
                                     (int)current.Coordinate[1],
                                     size.X - 1, size.Y - 1);
            if (!room.SubRegionOf(new Region(0, 0, Map.GetLength(0), Map.GetLength(1))))
            {
                DoneBaseGen = !baseGenIterateCounter.MoveNext();
                NodeStates.Remove(current);
                return;
            }

            //Move the room to the center.
            Location offset = new Location((int)Math.Round((MaxRoomSize.X - room.Width - 1) / 2.0f, 0), (int)Math.Round((MaxRoomSize.Y - room.Height - 1) / 2.0f, 0));
            room = new Region(room.TopLeft + offset, room.BottomRight + offset);

            //Clear the room area.
            Regions.Add(room);
            FillData.FillRegion(false, room);
            //Add the room data.
            NodeStates[current] = NodeState.Room;
            NodeAreas.Add(current, room);
        }
        else
        {
            //Tunnel junction.

            Location size  = MaxRoomSize;
            Region   space = new Region((int)current.Coordinate[0],
                                        (int)current.Coordinate[1],
                                        size.X - 1, size.Y - 1);

            space = new Region(space.Left + Settings.JunctionOffset.X,
                               space.Top + Settings.JunctionOffset.Y,
                               Settings.TunnelThickness.Y - 1,
                               Settings.TunnelThickness.X - 1);
            if (!space.SubRegionOf(new Region(0, 0, Map.GetLength(0), Map.GetLength(1))))
            {
                DoneBaseGen = !baseGenIterateCounter.MoveNext();
                NodeStates.Remove(current);
                return;
            }

            Regions.Add(space);
            FillData.FillRegion(false, space);

            //Add the room data.
            NodeStates[current] = NodeState.TunnelJunction;
            NodeAreas.Add(current, space);
        }

        //Prepare for the next iteration.
        DoneBaseGen = !baseGenIterateCounter.MoveNext();
    }