Esempio n. 1
0
    //IEnumerator Choose(int _seconds)
    //{
    //    if (m_MyState == CurrentState.MOVINGTOTILE || m_Moving || m_MyState == CurrentState.RETURNINGTORDP)
    //        yield return null;

    //    ChangeState( CurrentState.MAKINGDECISION;
    //    yield return new WaitForSeconds(_seconds); // Makes it so this code only runs x times per second.

    //    var _rdpMan = m_MyRDP.GetComponent<RDPManager>();
    //    int _minerAmount = _rdpMan.m_Miners.Count;
    //    int _lumberAmount = _rdpMan.m_Lumberjacks.Count;
    //    if (_minerAmount > _lumberAmount)
    //    { // More Miners
    //        int _slowMovers = 0, _regMovers = 0, _fastMovers = 0, _slowMiners = 0, _regMiners = 0, _fastMiners = 0;
    //        for (int i = 0; i < _rdpMan.m_Miners.Count; i++)
    //        {
    //            var _miner = _rdpMan.m_Miners[i].GetComponent<AgentMiner>();
    //            if (_miner.m_MovSpeed > 2.0f)
    //                _fastMovers++;
    //            else if (_miner.m_MovSpeed > 0.75f)
    //                _regMovers++;
    //            else
    //                _slowMovers++;

    //            if (_miner.m_MineSpeed > 0.4f)
    //                _fastMiners++;
    //            else if (_miner.m_MineSpeed > 0.2f)
    //                _regMiners++;
    //            else
    //                _slowMiners++;
    //        }
    //        if (_slowMovers > _slowMiners)
    //        {
    //            // MoveMineBuild

    //            m_CurrentBuilding = m_MineMoveBuilding;
    //            FindBuildTile();
    //            yield break;
    //        }
    //        else if (_slowMovers < _slowMiners)
    //        {
    //            // Build MineSpeed Upgrade

    //            m_CurrentBuilding = m_MineSpeedBuilding;
    //            FindBuildTile();
    //            yield break;

    //        }
    //        yield return null;
    //    }
    //    else if (_minerAmount < _lumberAmount)
    //    {
    //        int _slowMovers = 0, _regMovers = 0, _fastMovers = 0, _slowChoppers = 0, _regChoppers = 0, _fastChoppers = 0;
    //        for (int i = 0; i < _rdpMan.m_Lumberjacks.Count; i++)
    //        {
    //            var _lumber = _rdpMan.m_Lumberjacks[i].GetComponent<AgentLumberJack>();
    //            if (_lumber.m_MovSpeed > 2.0f)
    //                _fastMovers++;
    //            else if (_lumber.m_MovSpeed > 0.75f)
    //                _regMovers++;
    //            else
    //                _slowMovers++;

    //            if (_lumber.m_ChopSpeed > 0.4f)
    //                _fastChoppers++;
    //            else if (_lumber.m_ChopSpeed > 0.2f)
    //                _regChoppers++;
    //            else
    //                _slowChoppers++;
    //        }
    //        if (_slowMovers > _slowChoppers)
    //        {
    //            // Build Move Upgrade

    //            m_CurrentBuilding = m_ChopMoveBuilding;
    //            FindBuildTile();
    //            yield break;


    //        }
    //        else if (_slowMovers < _slowChoppers)
    //        {
    //            // Build Chop Upgrade

    //            m_CurrentBuilding = m_ChopSpeedBuilding;
    //            FindBuildTile();
    //            yield break;

    //        }
    //        yield return null;

    //    }
    //    yield break;

    //}

    void FindBuildTile()
    {
        if (m_Moving || m_MyState == CurrentState.MOVINGTOTILE)
        {
            return;
        }

        bool _found = false;

        ChangeState(CurrentState.FINDINGTILE);

        int[] _matsToFind = new int[] { 4, 7, 10, 13 };

        GameObject[] _go = m_WangObject.FindCollection(transform.position, _matsToFind, 5);

        for (int i = 0; i < _go.Length; i++)
        {
            if (_go[i] != null && !_go[i].GetComponent <TileResources>().m_HasBuilding)
            {
                m_MyLerp.enabled = true;
                m_Seeker.StopAllCoroutines();
                m_Seeker.StartPath(transform.position, _go[i].transform.position, OnPathComplete);
                m_Moving = true;
                _found   = true;
                _go[i].GetComponent <TileResources>().m_HasBuilding = true;
                m_BuildingTile = _go[i].transform.position;
                ChangeState(CurrentState.MOVINGTOTILE);
                break;
            }
        }
        if (!_found)
        {
            ChangeState(CurrentState.FINISHED);
        }
    }
Esempio n. 2
0
    // Stone Priorities: Cube6 -> Cube8&14 -> Cube2&5, -> Cube16
    // Iron  Priorities: Cube6 -> Cube2&5 -> Cube1

    void SearchForRes()
    {
        bool _foundTile = false;

        while (!_foundTile)
        {
            int[] _matsToFind = new int[] { };
            if (m_MyChoice == Choice.STONE)
            {
                _matsToFind = new int[] { 6, 8, 14 }
            }
            ;
            else if (m_MyChoice == Choice.IRON)
            {
                _matsToFind = new int[] { 6, 2, 5 }
            }
            ;

            GameObject[] _found = m_WangObject.FindCollection(transform.position, _matsToFind, 15);

            if (_found != null)
            {
                for (int i = 0; i < _found.Length; i++)
                {
                    _found[i].SetActive(true);
                    if (!_found[i].GetComponent <TileResources>().m_NWoodDepleted)
                    {
                        m_MyState = CurrentState.MOVINGTOTILE;

                        m_Seeker.StartPath(transform.position, _found[i].transform.position, OnPathComplete);

                        _foundTile     = true;
                        m_CurrentTile  = _found[i];
                        m_ShouldSearch = false;
                        break;
                    }
                    else
                    {
                        _found[i].SetActive(false);
                        continue;
                    }
                }
                break;
            }
        }
    }

    void DepositResources()
    {
        if (m_CurrentStone > 0)
        {
            m_MyRDP.GetComponent <RDPManager>().m_StoneAmount += m_CurrentStone;
            m_CurrentStone = 0;
        }
        else if (m_CurrentIron > 0)
        {
            m_MyRDP.GetComponent <RDPManager>().m_IronAmount += m_CurrentIron;
            m_CurrentIron = 0;
        }
    }

    IEnumerator IMine(GameObject _currentTile, Choice _type)
    {
        var _tileRes = _currentTile.GetComponent <TileResources>();

        if (_type == Choice.STONE)
        {
            m_MyState = CurrentState.MININGRESOURCES;
            while (m_CurrentStone < m_InventorySize || !_tileRes.m_StoneDepleted)
            {
                m_CurrentStone++;
                _currentTile.GetComponent <TileResources>().m_Stone--;
                yield return(new WaitForSeconds(m_MineSpeed));

                if (m_CurrentStone == m_InventorySize)
                {
                    break;
                }
            }
        }
        else if (_type == Choice.IRON)
        {
            m_MyState = CurrentState.MININGRESOURCES;
            while (m_CurrentIron <= m_InventorySize || !_tileRes.m_IronDepleted)
            {
                m_CurrentIron++;
                _tileRes.m_Iron--;
                yield return(new WaitForSeconds(m_MineSpeed * 3f));

                if (m_CurrentIron == m_InventorySize)
                {
                    break;
                }
            }
        }
        else
        {
            yield break;
        }

        if (m_CurrentStone == m_InventorySize || m_CurrentIron == m_InventorySize || _tileRes.m_StoneDepleted || _tileRes.m_IronDepleted)
        {
            _currentTile.SetActive(false);
            SetRDP();
            ReturnToRDP();
            m_IsMining = false;
            yield return(null);
        }
    }

    bool SetRDP()
    {
        if (m_MyRDP == null)
        {
            m_MyRDP = m_WangObject.FindRDP(transform.position);
            if (m_MyRDP != null)
            {
                m_MyRDP.GetComponent <RDPManager>().m_Miners.Add(gameObject);
            }
            return(true);
        }
        return(false);
    }

    void ReturnToRDP()
    {
        if (m_MyRDP != null)
        {
            m_MyLerp.enabled = true;
            m_Seeker.StartPath(transform.position, m_MyRDP.transform.position, Deposit);
        }
    }

    void OnPathComplete(Path p)
    {
        if (!p.error)
        {
            m_Path = p;
        }
    }

    void Deposit(Path p)
    {
        if (!p.error)
        {
            m_Path    = p;
            m_MyState = CurrentState.MOVINGTORDP;
        }
    }
}
Esempio n. 3
0
    // NWood Priorities: Cube11 -> Cube12&15 -> Cube3&9 -> Cube16 -> Cube1 -> Cube8&14 -> Cube2&5 -> Cube6
    // Pine  Priorities: Cube1 -> Cube3&9 -> Cube11 ->Cube2&5 -> Cube12&15

    void SearchForTrees()
    {
        bool _foundTile = false;

        while (!_foundTile)
        {
            int[] _matsToFind = new int[] { };
            if (m_MyChoice == Choice.NWOOD)
            {
                _matsToFind = new int[] { 11, 12, 15 }
            }
            ;
            else if (m_MyChoice == Choice.PINE)
            {
                _matsToFind = new int[] { 1, 3, 9 }
            }
            ;

            GameObject[] _found = m_WangObject.FindCollection(transform.position, _matsToFind, 15);

            if (_found != null)
            {
                for (int i = 0; i < _found.Length; i++)
                {
                    _found[i].SetActive(true);
                    if (!_found[i].GetComponent <TileResources>().m_NWoodDepleted)
                    {
                        m_MyState = CurrentState.MOVINGTOTILE;

                        m_Seeker.StartPath(transform.position, _found[i].transform.position, OnPathComplete);

                        _foundTile     = true;
                        m_CurrentTile  = _found[i];
                        m_ShouldSearch = false;
                        break;
                    }
                    else
                    {
                        _found[i].SetActive(false);
                        continue;
                    }
                }
                break;
            }
        }
    }

    void DepositResources()
    {
        if (m_CurrentNWood > 0)
        {
            m_MyRDP.GetComponent <RDPManager>().m_WoodAmount += m_CurrentNWood;
            m_CurrentNWood = 0;
        }
        else if (m_CurrentPine > 0)
        {
            m_MyRDP.GetComponent <RDPManager>().m_PineAmount += m_CurrentPine;
            m_CurrentPine = 0;
        }
    }

    IEnumerator IChop(GameObject _currentTile, Choice _type)
    {
        var _tileRes = _currentTile.GetComponent <TileResources>();

        if (_type == Choice.NWOOD)
        {
            m_MyState = CurrentState.CHOPPINGWOOD;
            while (m_CurrentNWood < m_InventorySize || !_tileRes.m_NWoodDepleted)
            {
                m_CurrentNWood++;
                _tileRes.m_NWood--;
                yield return(new WaitForSeconds(m_ChopSpeed));

                if (m_CurrentNWood == m_InventorySize)
                {
                    break;
                }
            }
        }
        else if (_type == Choice.PINE)
        {
            m_MyState = CurrentState.CHOPPINGWOOD;
            while (m_CurrentPine <= m_InventorySize || !_tileRes.m_PineDepleted)
            {
                m_CurrentPine++;
                _tileRes.m_Pine--;
                yield return(new WaitForSeconds(m_ChopSpeed * 3f));

                if (m_CurrentPine == m_InventorySize)
                {
                    break;
                }
            }
        }
        else
        {
            yield break;
        }

        if (m_CurrentPine == m_InventorySize || m_CurrentNWood == m_InventorySize || _tileRes.m_NWoodDepleted || _tileRes.m_PineDepleted)
        {
            _currentTile.SetActive(false);

            while (!SetRDP())
            {
                yield return(new WaitForSeconds(3));
            }

            ReturnToRDP();
            m_IsChopping = false;
            yield return(null);
        }
    }

    bool SetRDP()
    {
        if (m_MyRDP == null)
        {
            m_MyRDP = m_WangObject.FindRDP(transform.position);
            if (m_MyRDP != null)
            {
                m_MyRDP.GetComponent <RDPManager>().m_Lumberjacks.Add(gameObject);
            }
            return(true);
        }
        return(false);
    }

    void ReturnToRDP()
    {
        if (m_MyRDP != null)
        {
            m_MyLerp.enabled = true;
            m_Seeker.StartPath(transform.position, m_MyRDP.transform.position, Deposit);
        }
    }

    void OnPathComplete(Path p)
    {
        if (!p.error)
        {
            m_Path = p;
        }
    }

    void Deposit(Path p)
    {
        if (!p.error)
        {
            m_Path    = p;
            m_MyState = CurrentState.MOVINGTORDP;
        }
    }
}