Пример #1
0
    /*
     * Checks if hex with given position exist and moves character on it if true.
     * In other case choses to make different action.
     *
     * @position position of hex to move on.
     */

    private void Move(Node.Position position)
    {
        if (Storage.GetHexByPosition(position) != null)
        {
            _gameManager.TriggerAction(Storage.characters[_gameManager.queue].id, 0, Storage.GetHexByPosition(position).id);
        }
        else
        {
            TakeAction();
        }
    }
Пример #2
0
    public int findFromOpenList(Node.Position myPos)
    {
        for (int i = 0; i < m_openList.Count; i++)
        {
            Node.Position currentTest = m_openList[i].getPosition();
            if (currentTest.isEqual(currentTest, myPos))
            {
                return(i);
            }
        }

        return(-1);
    }
Пример #3
0
    public bool isInClosedList(Node.Position myPos)
    {
        for (int i = 0; i < m_closedList.Count; i++)
        {
            Node.Position currentTest = m_closedList[i].getPosition();
            if (currentTest.isEqual(currentTest, myPos))
            {
                return(true);
            }
        }

        return(false);
    }
    void Start()
    {
        cam          = UnityEngine.Camera.main;
        tileWid      = 0.5f;
        m_halfWidth  = 0.5f;
        m_halfHeight = 0.5f;
        unWalkable   = new List <Vector2>();

        unWalkable = TileCheck.unWalkable;
        m_start.setValues(transform.position.x, transform.position.y);

        m_end.setValues(target.transform.position.x, target.transform.position.y);

        m_old.setValues(-100f, -100f);
        m_new = m_end;
        m_current.setValues(this.transform.position.x, this.transform.position.y);
        disableCheck = false;
        activatePath = false;
        //m_halfWidth = current.bounds.size.x / 2;
        //m_halfHeight = current.bounds.size.y / 2;
    }
Пример #5
0
 public static Hex GetHexByPosition(Node.Position position)
 {
     return(hexes.Find(hex => hex.GetComponent <Node>().position.Equals(position)));
 }
 PathFinding(Node.Position end, Node.Position start, Node.Position current)
 {
     m_end     = end;
     m_current = current;
     m_start   = start;
 }
    void FixedUpdate()
    {
        if (disableCheck == false)
        {
            checkIfInVision();
        }



        if (activatePath == true)
        {
            if (finalPath == null)
            {
                m_new.setValues(target.transform.position.x, target.transform.position.y);

                m_current.setValues(this.transform.position.x, this.transform.position.y);


                m_end.setValues(target.transform.position.x, target.transform.position.y);

                doPathFinding();
                m_old = m_new;
                if (finalPath == null)
                {
                    return;
                } //if its still null after checking for path ideally youd like to stop it from calculating always if its null,
                  //however this should never even occur, there should always be a path, if there isnt its bad level design OR our character is somewhere where it shouldnt get

                //
            }
            else
            {
                if (finalPath.returnCount() > 0)
                {
                    movementTarget = new Vector3(finalPath.get0().getPosition().x, finalPath.get0().getPosition().y, 0);
                }
            }

            if (transform.position == movementTarget)
            {
                //WE ARE CLOSE ENOUGH FOR THE CONSOLE TO THINK WE EQUAL, SO MAKE SURE WE DO EQUAL!!
                transform.position = movementTarget;
                m_new.setValues(target.transform.position.x, target.transform.position.y);
                m_current.setValues(this.transform.position.x, this.transform.position.y);


                m_end.setValues(target.transform.position.x, target.transform.position.y);



                //Only do this everytime the player has moved once, dont keep checking!

                if (m_old.x != m_new.x || m_old.y != m_new.y) //check if the values have changed since last update also do an extra check if there is a path(results) BUT for some reason our final path is null!! THIS SHOULD NEVER OCCUR!!! But if it were to i want to make a go around
                {
                    if (enemyMove.disableMovement == false)
                    {
                        doPathFinding();
                        m_old = m_new;
                    }
                }
            }
        }
    }
Пример #8
0
    /*
     * Takes the biggest value from policy table and checks if there is only one such number.
     * If there is only one biggest number saves index of this number and takes action associated with that index.
     * If there is more than one takes random action from all available.
     *
     * #TODO in case of repititon of the biggest number it should only random from indexes of repeaters.
     */

    public void TakeAction()
    {
        float max = _policy[0].Max();
        float index;
        int   count = 0;

        for (int i = 0; i < _policy[0].Length; i++)
        {
            if (_policy[0][i] == max)
            {
                count++;
            }
        }

        if (count == 1)
        {
            index = _policy[0].ToList().IndexOf(max);
        }
        else
        {
            index = Random.Range(0, _policy[0].Length);
        }

        //Debug.Log(index);

        Node.Position position = Storage.characters[_gameManager.queue].transform.parent.GetComponent <Node>().position;
        bool          even     = position.y % 2 == 0;

        switch (index)
        {
        case 0:
            if (!even)
            {
                Move(new Node.Position(position.x, position.y - 1));
            }
            else
            {
                Move(new Node.Position(position.x - 1, position.y - 1));
            }
            break;

        case 1:
            if (!even)
            {
                Move(new Node.Position(position.x + 1, position.y - 1));
            }
            else
            {
                Move(new Node.Position(position.x, position.y - 1));
            }
            break;

        case 2:
            Move(new Node.Position(position.x - 1, position.y));
            break;

        case 3:
            Move(new Node.Position(position.x + 1, position.y));
            break;

        case 4:
            if (!even)
            {
                Move(new Node.Position(position.x, position.y + 1));
            }
            else
            {
                Move(new Node.Position(position.x - 1, position.y + 1));
            }
            break;

        case 5:
            if (!even)
            {
                Move(new Node.Position(position.x + 1, position.y + 1));
            }
            else
            {
                Move(new Node.Position(position.x, position.y + 1));
            }
            break;

        case 6:
            _gameManager.TriggerAction(Storage.characters[_gameManager.queue].id, 2, Storage.GetHexByPosition(position).id);
            break;
        }
    }
Пример #9
0
/*
 *  public bool isInList(Vector2 checking)
 *  {
 *
 *      for(int i =0; i == m_unWalkables.Count; i++)
 *      {
 *          if(m_unWalkables[i].x == checking.x && m_unWalkables[i].y == checking.y)
 *          {
 *              return true;
 *          }
 *      }
 *      return false;
 *  }
 */

    public List <Node.Position> getAdjacentNodes(float posX, float posY, float colWidth)
    {
        //ADD A STEP INSTEAD OF 1 THAT IS THE SIZE OF THE GRID CELL
        List <Node.Position> m_results = new List <Node.Position>();

        Node.Position current = new Node.Position();
        current.setValues(posX, posY);

        if (isWalkable(current.x + (colWidth), current.y) == true)
        {
            Node.Position plusOneX = new Node.Position();
            plusOneX.setValues(posX + (colWidth), posY);
            m_results.Add(plusOneX);
        }

        if (isWalkable(current.x - (colWidth), current.y) == true)
        {
            Node.Position minusOneX = new Node.Position();
            minusOneX.setValues(posX - (colWidth), posY);
            m_results.Add(minusOneX);
        }

        if (isWalkable(current.x, current.y + (colWidth)) == true)
        {
            Node.Position plusOneY = new Node.Position();
            plusOneY.setValues(posX, posY + colWidth);
            m_results.Add(plusOneY);
        }

        if (isWalkable(current.x, current.y - (colWidth)) == true)
        {
            Node.Position minusOneY = new Node.Position();
            minusOneY.setValues(posX, posY - colWidth);
            m_results.Add(minusOneY);
        }

        if (isWalkable(current.x + colWidth, current.y + (colWidth)) == true)
        {
            Node.Position plusOneXplusY = new Node.Position();
            plusOneXplusY.setValues(posX + colWidth, posY + colWidth);
            m_results.Add(plusOneXplusY);
        }
        if (isWalkable(current.x + colWidth, current.y - colWidth) == true)
        {
            Node.Position plusOneXminusY = new Node.Position();
            plusOneXminusY.setValues(posX + colWidth, posY - colWidth);
            m_results.Add(plusOneXminusY);
        }
        if (isWalkable(current.x - colWidth, current.y - colWidth) == true)
        {
            Node.Position minusOneXminusY = new Node.Position();
            minusOneXminusY.setValues(posX - colWidth, posY - colWidth);
            m_results.Add(minusOneXminusY);
        }
        if (isWalkable(current.x - colWidth, current.y + colWidth) == true)
        {
            Node.Position minusOneXplusY = new Node.Position();
            minusOneXplusY.setValues(posX - colWidth, posY + colWidth);
            m_results.Add(minusOneXplusY);
        }

        //checks all the neighbors and adds them to the results list if they are walkable
        return(m_results);
    }