Exemple #1
0
    /// <summary>
    /// Calculates if shortcut should be placed.
    /// </summary>
    /// <param name="wallTile"></param>
    /// <param name="otherWallTile"></param>
    /// <param name="direction"></param>
    /// <returns></returns>
    private bool CheckIfUsefulToPlace(Vector2Int wallTile, Vector2Int otherWallTile, Vector2Int direction)
    {
        // calculate tiles to run pathfinding on
        Vector2Int[] tilesToCalculateFrom = new Vector2Int[2];
        Vector2Int[] tilesToCalculateTo   = new Vector2Int[2];
        double[]     costs = new double[2];
        tilesToCalculateFrom[0] = new Vector2Int(wallTile.x - direction.x, wallTile.y - direction.y);
        tilesToCalculateFrom[1] = new Vector2Int(wallTile.x - direction.x + Math.Abs(direction.y) * m_tunnelWidth, wallTile.y - direction.y + Math.Abs(direction.x) * m_tunnelWidth);
        tilesToCalculateTo[0]   = new Vector2Int(otherWallTile.x + direction.x, otherWallTile.y + direction.y);
        tilesToCalculateTo[1]   = new Vector2Int(otherWallTile.x + direction.x + Math.Abs(direction.y) * m_tunnelWidth, otherWallTile.y + direction.y + Math.Abs(direction.x) * m_tunnelWidth);

        // run DStarLite twice
        GameEnvironment ge = GameEnvironment.CreateInstance(m_map, new List <Tile>()
        {
            Tile.Wall, Tile.Reflector
        });
        DStarLite dStarLite = new DStarLite(ge, true);

        dStarLite.RunDStarLite(tilesToCalculateFrom[0], tilesToCalculateTo[0]);
        costs[0] = dStarLite.Map.GetNode(tilesToCalculateFrom[0].x, tilesToCalculateFrom[0].y).CostFromStartingPoint;
        dStarLite.RunDStarLite(tilesToCalculateFrom[1], tilesToCalculateTo[1]);
        costs[1] = dStarLite.Map.GetNode(tilesToCalculateFrom[1].x, tilesToCalculateFrom[1].y).CostFromStartingPoint;

        // see if the distance between the two points without a shortcut is larger than the minimum distance
        if (costs[0] >= m_shortcutMinSkipDistance && costs[1] >= m_shortcutMinSkipDistance)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Exemple #2
0
    private void OnEnable()
    {
        m_environment = GameEnvironment.CreateInstance(BoardManager.GetMap(), new List <Tile>()
        {
            Tile.Wall, Tile.BreakableWall, Tile.Reflector
        });
        m_searchBehaviour = GetComponent <SearchBehaviour>();
        m_attackBehaviour = GetComponent <AttackBehaviour>();
        m_sonarBehaviour  = GetComponent <SonarBehaviour>();

        m_searchBehaviour.Environment = m_environment;
        m_attackBehaviour.Environment = m_environment;
    }