Exemplo n.º 1
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="start"></param>
    /// <param name="destination"></param>
    /// <param name="teamId"></param>
    /// <returns></returns>
    public List <DijkstraInfo> DijkstraToBuilding(DijkstraInfo start, List <Buildings> destination, int teamId)
    {
        List <DijkstraInfo> temp = new List <DijkstraInfo>();
        bool destinationFound    = false;
        bool noValidPath         = false;

        open.Add(start);
        DijkstraInfo destinationTile = new DijkstraInfo();

        AddConnectionsToOpen(start);

        while (!destinationFound && !noValidPath)
        {
            DijkstraInfo tile = GetLowestCost();
            for (int i = 0; i < GlobalAttributes.Global.Buildings.Count; ++i)
            {
                if (GlobalAttributes.Global.Buildings[i].hexTransform.Position == tile.GetComponent <HexTile>().hexTransform.Position)
                {
                    for (int j = 0; j < destination.Count; ++j)
                    {
                        if (GlobalAttributes.Global.Buildings[i].BuildingType == destination[j])
                        {
                            destinationFound = true;
                            destinationTile  = tile;
                        }
                        if (tile != null && GlobalAttributes.Global.Buildings[i].BuildingType != destination[j])
                        {
                            AddConnectionsToOpen(tile);
                        }
                        else
                        {
                            noValidPath = true;
                        }
                    }
                }
            }
        }

        if (destinationFound)
        {
            DijkstraInfo tempTile = destinationTile;
            // THIS NEEDS TO LOOK FOR A TILE ON THE building's exclusion zone
            //tempTile.hexTransform.position = destination.hexTransform.position;
            while (tempTile != start && tempTile != null)
            {
                temp.Add(tempTile);
                //tempTile.SetColour(Color.magenta);
                tempTile = (DijkstraInfo)tempTile.root;
            }

            temp.Reverse();
        }
        //state = DJStates.waitingForClear;

        return(temp);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Dijkstra method to find a tile that has a script attached of type T
    /// </summary>
    /// <typeparam name="T">Type to find on destination tile</typeparam>
    /// <param name="start">Tile to start from</param>
    /// <returns>List of tiles between the start and found tile</returns>
    public List <DijkstraInfo> Dijkstra <T>(DijkstraInfo start)
    {
        List <DijkstraInfo> temp = new List <DijkstraInfo>();
        bool destinationFound    = false;
        bool noValidPath         = false;

        open.Add(start);
        DijkstraInfo destination = new DijkstraInfo();

        AddConnectionsToOpen(start);

        while (!destinationFound && !noValidPath)
        {
            DijkstraInfo tile = GetLowestCost();
            if (tile != null && tile != destination)
            {
                AddConnectionsToOpen(tile);
            }
            else if (tile.GetComponent <T>() != null)
            {
                destination      = tile;
                destinationFound = true;
            }
            else
            {
                noValidPath = true;
            }
        }

        if (destinationFound)
        {
            DijkstraInfo tempTile = destination;
            while (tempTile != start && tempTile != null)
            {
                temp.Add(tempTile);
                //tempTile.SetColour(Color.magenta);
                tempTile = (DijkstraInfo)tempTile.root;
            }

            temp.Reverse();
        }
        //state = DJStates.waitingForClear;

        return(temp);
    }