Пример #1
0
    /// <summary>
    /// Get the DungeonLevel graph from a list of vectors
    /// </summary>
    /// <param name="vectors"></param>
    /// <param name="connectedness"></param> Determines how connected the DungeonLevel is - 0.0 being a minimum spanning tree
    /// <returns></returns>
    public Dictionary <Vector2Int, List <Vector2Int> > GetDungeonMap(List <Vector2Int> vectors, float connectedness)
    {
        triangulator = new Triangulator();
        triangulator.GenerateMst(vectors);
        dungeonExits = FindStartAndEnd();

        // Prime mst to be more like DungeonLevel hallways
        RemoveMstFromGraph();
        RemoveLongShortEdges(Mathf.RoundToInt(triangulator.connectedVertices.Count / 3f));
        AddRandomEdgesToMst(Mathf.RoundToInt(triangulator.connectedVertices.Count * connectedness));

        // Convert back to vectors
        Dictionary <Vector2Int, List <Vector2Int> > links = new Dictionary <Vector2Int, List <Vector2Int> >();

        foreach (var kV in triangulator.mst)
        {
            List <Vector2Int> adj = new List <Vector2Int>();
            foreach (var vertex in kV.Value)
            {
                adj.Add(new Vector2Int(Mathf.RoundToInt((float)vertex.X), Mathf.RoundToInt((float)vertex.Y)));
            }

            links.Add(new Vector2Int(Mathf.RoundToInt((float)kV.Key.X), Mathf.RoundToInt((float)kV.Key.Y)), adj);
        }

        return(links);
    }