Beispiel #1
0
    IEnumerator MoveAIUnit(Unit unit)
    {
        while (isInAction)
        {
            yield return(null);
        }

        isInAction = true;

        //simulate thinking
        yield return(new WaitForSeconds(1f));

        UnitMovement      dmove      = unit.GetComponent <UnitMovement>();
        List <GameObject> moveFields = dmove.GetMoveFields(BoardManager.TileType.Move);

        while (GameController.Instance.State == GameController.GameState.PerformingAction)
        {
            yield return(null);
        }


        if (unit.Type == Unit.UnitType.CommandUnit)
        {
            if (isInDangerField(BoardManager.Instance.GetPositionOfUnit(unit)) && moveFields.Count > 0)
            {
                GameObject fPos = BoardManager.Instance.GetPositionOfUnit(unit);

                GameObject mFiled = FindSafestField(fPos, moveFields);

                if (mFiled != fPos)
                {
                    //simulate thinking
                    yield return(new WaitForSeconds(1f));

                    dmove.Move(FindSafestField(fPos, moveFields));
                }
            }
        }
        else
        {
            if (moveFields.Count > 0 && unit.CanMove)
            {
                //simulate thinking
                yield return(new WaitForSeconds(1f));

                if (unit.Type == Unit.UnitType.Dreadnought)
                {
                    dmove.Move(AttackFieldClosestToEnemy(unit, moveFields, true));
                }
                else
                {
                    GameObject m_field = AttackFieldClosestToEnemy(unit, moveFields, false);
                    //move drones only if the field is not in danger
                    if (!isInDangerField(m_field))
                    {
                        dmove.Move(m_field);
                    }
                }
            }
        }

        unit.CanMove = false;

        //simulate thinking
        yield return(new WaitForSeconds(1f));

        isInAction = false;
    }