Ejemplo n.º 1
0
 public void Reset()
 {
     //Debug.Log("Reset");
     goalExists = false;
     goal       = null;
     GetComponent <Pathfinding>().Reset();
 }
Ejemplo n.º 2
0
    public bool ImproveMap(IMap map, IRandomProvider random)
    {
        // Let's reuse directions, but let them represent quadrants
        // So north-> north-west
        var quadrant = ChooseQuadrant(random);
        var goaltile = new GoalTile();

        (var success, var location, var openDir) = PlaceTileInQuadrant(quadrant, map, goaltile);
        if (!success)
        {
            return(success);
        }
        goaltile.Direction = openDir;
        map.Goal           = location;
        var startTile = new StartTile();

        (success, location, openDir) = PlaceTileInQuadrant(Directions.GetOpposite(quadrant), map, startTile);
        if (success)
        {
            startTile.Direction = openDir;
            map.Start           = location;
        }

        return(success);
    }
Ejemplo n.º 3
0
 public void SetTile(Tile tile)
 {
     this.tile = tile as GoalTile;
     if (this.tile != null)
     {
         CorrectRotation();
     }
 }
Ejemplo n.º 4
0
    //this is a meme name, i'm a nets fan
    //one connection succeeded
    private void JubilationInNewark(List <Tile> pathToSuccess, GoalTile goalThatWasFound)
    {
        switch (goalThatWasFound.typeOfGoal)
        {
        case GoalType.gt_bomb:
            goalThatWasFound.Jubilation();
            AudioSource.PlayClipAtPoint(explosionEffects[Random.Range(0, explosionEffects.Length)], transform.position);
            //this should actually come from removeOnUse
            Vector2Int tilePos = goalThatWasFound.GetTilePosition();
            _currentLevelTiles[tilePos.x, tilePos.y] = null;
            break;

        case GoalType.gt_score:
            AudioSource.PlayClipAtPoint(successEffects[Random.Range(0, successEffects.Length)], transform.position);
            foreach (Tile t in pathToSuccess)
            {
                t.Jubilation();
            }
            break;

        case GoalType.gt_timeBonus:
            goalThatWasFound.Jubilation();
            AudioSource.PlayClipAtPoint(timeLimitEffects[Random.Range(0, timeLimitEffects.Length)], transform.position);
            _currentLevelTimeLimit += goalThatWasFound.timeBonus;
            UpdateTimeLimitText();
            ApplyMoveLimitVisualEffects(Color.white, Color.blue);
            break;

        default:
            break;
        }

        bool allGoalsDone = true;

        foreach (StartTile st in _startTiles)
        {
            if (!st.IsUsedUp())
            {
                allGoalsDone = false;
            }
        }

        if (allGoalsDone)
        {
            nextLevelButton.interactable = true;
            nextLevelButton.GetComponent <Image>().color = Color.green;
        }
    }
Ejemplo n.º 5
0
    public void SetPath(Tile lastTile)
    {
        //Debug.Log("SET");



        if (currentPath.Count > 0)
        {
            GoalTile pathStart = currentPath.Pop();
            NetworkServer.Destroy(pathStart.gameObject);
        }

        if (pathStart != null)
        {
            NetworkServer.Destroy(pathStart.gameObject);
            pathStart = null;
        }

        Tile previousTile = placedTiles.Count > 0 ? placedTiles.Peek() : null;

        Point    start     = GetComponent <Goals>().StartPoint(lastTile, previousTile);
        GoalTile startTile = new GoalTile(start.x, start.y, start.z);

        pathStart = startTile;

        startTile.gameObject = GetComponent <Goals>().Create(start.x, start.y, start.z, false, GameScene.Instance.Path);



        int[,,] array = MapToArray(placedTiles, start);
        int center = array.GetLength(0) / 2;

        EmptyPath(currentPath);
        Queue <Point> pointQueue = Dijkstra.Solve(array, center, center, center, center);

        placedTiles.Push(lastTile);

        while (pointQueue.Count > 0)
        {
            Point    point = pointQueue.Dequeue();
            GoalTile path  = new GoalTile(point.x * blockSize + start.x, point.y * blockSize + start.y, point.z * blockSize + start.z);
            path.gameObject = GetComponent <Goals>().Create(point.x * blockSize + start.x, point.y * blockSize + start.y, point.z * blockSize + start.z, false, GameScene.Instance.Path);
            currentPath.Push(path);
        }
    }
Ejemplo n.º 6
0
    public void SetGoal(Tile lastTile)
    {
        if (goalExists)
        {
            return;
        }

        goalExists = true;

        int x = lastTile.x + blockSize * rng.Next(-5, 6);
        int y = lastTile.y;
        int z = lastTile.z + blockSize * rng.Next(2, 10);

        //calculate time for chronometer

        goal            = new GoalTile(x, y, z);
        goal.gameObject = Create(x, y, z, true, GameScene.Instance.Goal);
    }
Ejemplo n.º 7
0
    public bool Place()
    {
        if (lastGoal != null)
        {
            lastGoal = null;
        }

        lastPlaced += 1;
        bool output = Random.Next(0, 5) > 3;

        if (output)
        {
            lastPlaced = 1;
        }

        //output = true;
        return(output);
    }
Ejemplo n.º 8
0
    public Point StartPoint(Tile lastTile, Tile previousTile)
    {
        Point output = new Point(lastTile.x, lastTile.y, lastTile.z);


        if (!lastTile.init && !missedGoal && lastTile.gameObject.name == "CrossTile")
        {
            GoalTile pathStart = GetComponent <Pathfinding>().currentPath.Peek();
            return(new Point(pathStart.x, pathStart.y, pathStart.z));
        }


        try
        {
            Quaternion next = new Quaternion(1, 0, 0, 0);
            Quaternion i    = new Quaternion(0, 1, 0, 0);
            if (lastTile.gameObject.name == "CornerTile")
            {
                next *= i * i;
            }

            int rotation = (int)lastTile.gameObject.transform.rotation.eulerAngles.y + ArchitectAI.tileCompensation[lastTile.gameObject.name];

            while (rotation > 0)
            {
                rotation -= 90;
                next     *= i;
            }

            output.x += (int)next.x * blockSize;
            output.z += (int)next.y * blockSize;

            if (Array.Exists(ArchitectAI.linearTiles, element => element == lastTile.gameObject.name) && previousTile != null && output.x == previousTile.x && output.y == previousTile.y)
            {
                output.x -= 2 * (int)next.x * blockSize;
                output.z -= 2 * (int)next.y * blockSize;
            }
        }
        catch (Exception) { }

        return(output);
    }
Ejemplo n.º 9
0
    private void CheckForConnectivity()
    {
        bool connectionFound = false;

        foreach (StartTile st in _startTiles)
        {
            if (st.IsUsedUp())
            {
                continue;
            }

            //check if this tile reaches any goal tiles by connecting via the pipes
            List <Tile> pathToSuccess    = new List <Tile>();
            GoalTile    goalThatWasFound = null;
            connectionFound = CheckTileConnections(st, Vector2Int.zero, st, pathToSuccess, out goalThatWasFound);

            if (connectionFound)
            {
                JubilationInNewark(pathToSuccess, goalThatWasFound);

                break;
            }
        }
    }
Ejemplo n.º 10
0
    public int Position(Tile currentTile, Tile lastTile)
    {
        GoalTile position = GetComponent <Pathfinding>().currentPath.Peek();

        GoalTile nextPath;

        try
        {
            nextPath = GetComponent <Pathfinding>().currentPath.Skip(1).First();
        }
        catch (Exception e)
        {
            Debug.Log("path too short");
            nextPath = new GoalTile(Goals.goal.x, Goals.goal.y, Goals.goal.z);
        }


        //unset crosstiles to avoid weird bugs
        if (currentTile.gameObject.name == "CrossTile")
        {
            NetworkServer.Destroy(currentTile.gameObject);
            currentTile.gameObject = Instantiate(GameScene.Instance.tiles[0].tile,
                                                 new Vector3(currentTile.x, GameScene.Instance.tiles[0].tile.transform.position.y, currentTile.z), Quaternion.identity);
            currentTile.gameObject.name = GameScene.Instance.tiles[0].tile.name;
        }

        //set corner when needed
        //yes, the ai is basically cheating (but for the greater good)
        if ((nextPath.x - lastTile.x == 16 || nextPath.x - lastTile.x == -16) && (nextPath.z - lastTile.z == 16 || nextPath.z - lastTile.z == -16))
        {
            NetworkServer.Destroy(currentTile.gameObject);
            currentTile.gameObject = Instantiate(GameScene.Instance.tiles[2].tile,
                                                 new Vector3(currentTile.x, GameScene.Instance.tiles[2].tile.transform.position.y, currentTile.z), Quaternion.identity);
            currentTile.gameObject.name = GameScene.Instance.tiles[2].tile.name;
        }
        else if (currentTile.gameObject.name == "CornerTile")
        {
            NetworkServer.Destroy(currentTile.gameObject);
            currentTile.gameObject = Instantiate(GameScene.Instance.tiles[0].tile,
                                                 new Vector3(currentTile.x, GameScene.Instance.tiles[0].tile.transform.position.y, currentTile.z), Quaternion.identity);
            currentTile.gameObject.name = GameScene.Instance.tiles[0].tile.name;
        }



        int direction = 0;

        Vector3 delta = new Vector3(position.x - lastTile.x, 0, position.z - lastTile.z);

        if (delta.x > 0)
        {
            direction = 2;
        }
        if (delta.x < 0)
        {
            direction = 1;
        }


        return(direction);
    }
Ejemplo n.º 11
0
    public int Rotation(Tile currentTile, Tile lastTile)
    {
        int lastCompensate = -90;

        try
        {
            lastCompensate = tileCompensation[lastTile.gameObject.name];
            if (lastTile.gameObject.name == "CornerTile")
            {
                switch (((int)lastTile.gameObject.transform.rotation.eulerAngles.y) + 360 % 360)
                {
                case 0:
                case 90:
                    lastCompensate = 270;
                    break;

                case 270:
                case -90:
                    lastCompensate = 270;
                    break;

                default:
                    lastCompensate = 0;
                    break;
                }
            }
        }
        catch (Exception e) { };

        int compensate = tileCompensation[currentTile.gameObject.name] - lastCompensate;

        int delta = 0;

        if (currentTile.gameObject.name == "CornerTile")
        {
            GoalTile goal = Goals.goal;
            delta = goal.x - currentTile.x;
            if (delta == 0)
            {
                delta = lastTile.x - currentTile.x > 0 ? 90 : 180;//z increases
            }
            else
            {
                delta = (delta > 0 ? 90 : 180); //x modifies
            }
        }



        try
        {
            if (lastTile != null && lastTile.gameObject.name == "JumpTile" && currentTile.gameObject.name == "JumpTile")
            {
                compensate += 180;
            }

            if (lastTile != null && lastTile.gameObject.name == "CrossTile" && (lastTile.x != currentTile.x || lastTile.z != currentTile.z))
            {
                if (lastTile.x - currentTile.x == 0)
                {
                    return(90 + compensate);
                }
                else if (lastTile.x - currentTile.x > 0)
                {
                    return(180 + compensate);
                }
                return(0 + compensate);
            }

            //Debug.Log(currentTile.gameObject.name + ": " + new Vector3((int)lastTile.gameObject.transform.rotation.eulerAngles.y, compensate, delta));
            //Debug.Log(lastTile.gameObject.name);
            return((int)lastTile.gameObject.transform.rotation.eulerAngles.y + compensate + delta);
        }
        catch (Exception e) { Debug.Log(e); }
        return(compensate + delta);
    }
Ejemplo n.º 12
0
    private bool CheckTileConnections(Tile tile, Vector2Int incomingDir, Tile lastEncounteredStartTile, List <Tile> pathToSuccess, out GoalTile goalThatWasFound)
    {
        if (tile is StartTile)
        {
            lastEncounteredStartTile = tile;
            pathToSuccess.Clear();
        }

        bool goalFound = tile is GoalTile && !tile.IsUsedUp();

        goalThatWasFound = goalFound ? (GoalTile)tile : null;

        bool linkedToPreviousTile = (tile == lastEncounteredStartTile);

        foreach (Vector2Int cd in tile.ConnectionDirs)
        {
            if (cd == incomingDir)
            {
                //this is where the line comes from, no need to take this into account for future
                //but we need to assure we have connection here
                linkedToPreviousTile = true;
                break;
            }
        }

        if (!linkedToPreviousTile)
        {
            return(false);
        }
        else
        {
            pathToSuccess.Add(tile);
        }

        foreach (Vector2Int cd in tile.ConnectionDirs)
        {
            if (cd != incomingDir && !goalFound)
            {
                Vector2Int targetPosition = tile.GetTilePosition() + cd;

                if (IsWithinBounds(targetPosition))
                {
                    //recursive call, what's important is reversing the direction so that incoming tile is properly controlled
                    //we should be afraid of loops!
                    Tile targetTile = _currentLevelTiles[targetPosition.x, targetPosition.y];

                    if (targetTile) //space could be empty altogether
                    {
                        goalFound = CheckTileConnections(targetTile, new Vector2Int(-cd.x, -cd.y), lastEncounteredStartTile, pathToSuccess, out goalThatWasFound);
                    }
                }
            }
        }
        return(goalFound);
    }