Example #1
0
    private IEnumerator ActivateArea(int turns, UpgradeArea area)
    {
        int activatingTurn = _currentTurn + turns;

        while (_currentTurn < activatingTurn)
        {
            yield return(null);
        }

        area.EnableArea(true);
    }
Example #2
0
    private void ActivateAreas(int n)
    {
        for (int i = 0; i < n; i++)
        {
            UpgradeArea area   = GetRandomDisabledArea();
            UnitClass   uClass = (UnitClass)Random.Range(0, 4);
            area.SetAreaClass(uClass);

            int turns = Random.Range(_activateAreaTime.x, _activateAreaTime.y);

            StartCoroutine(ActivateArea(turns, area));
            _activeAreasCounter++;
        }
    }
Example #3
0
    private UpgradeArea GetRandomDisabledArea()
    {
        UpgradeArea area = null;

        while (area == null)
        {
            int i = Random.Range(0, _upgradeAreas.Length);

            if (!_upgradeAreas[i].isAvaible)
            {
                area = _upgradeAreas[i];
            }
        }

        return(area);
    }
Example #4
0
    /// <summary>
    /// Encuentra la Upgrade Area más próxima a la unidad
    /// </summary>
    /// <param name="selectedNode">Nodo sobre el que se ha clickado</param>
    private UpgradeArea NearestBoostArea(Unit chip)
    {
        UpgradeArea[] boostAreas = boostScript._upgradeAreas;

        int         min     = int.MaxValue;
        UpgradeArea nearest = null;

        foreach (UpgradeArea boost in boostAreas)
        {
            if (boost.isAvaible && boost.GetGridNode() != null && chip.GetGridNode() != null)
            {
                if (boost.currentClass == chip.unitClass || boost.currentClass == UnitClass.Neutral)
                {
                    int len = path.BestPathLength(chip.GetGridNode(), boost.GetGridNode());
                    if (len < min)
                    {
                        min     = len;
                        nearest = boost;
                    }
                }
            }
        }
        return(nearest);
    }
Example #5
0
 public void DisableArea(UpgradeArea area)
 {
     area.EnableArea(false);
     _activeAreasCounter--;
 }
Example #6
0
    void Start()
    {
        if (Application.loadedLevelName == "Restore Point")
            upgradeArea = GameObject.Find ("Upgrade Area Trigger").GetComponent<UpgradeArea> ();

        playerInventory = GameObject.Find ("Inventory Manager").GetComponent<PlayerInventory> ();
        inv_HUD = GameObject.Find("HUD_Inventory").GetComponent<HUD_Inventory>();
        anim = GetComponent<Animator> ();

        // set the 3D model colour to the colour set in the inspector
        Renderer[] childMeshes = GetComponentsInChildren<Renderer> ();
        foreach(Renderer rend in childMeshes)
        {
            rend.material.color = itemColor;
        }
    }
Example #7
0
    /// <summary>
    /// Devuelve el nodo más adecuado de la lista de nodos accesibles
    /// </summary>
    /// <param name="_selectedNodes">Lista de nodos aceccesibles</param>
    private GridNode BestNodeSelection(Unit chip)
    {
        // mutate return
        float seed = 0.15f;

        if (chip.role == StrategicRole.Defense)
        {
            seed = 0.3f;
        }
        else if (chip.role == StrategicRole.Center)
        {
            seed = 0.2f;
        }
        else if (chip.role == StrategicRole.Forward)
        {
            seed = 0.1f;
        }

        if (Random.value < seed)
        {
            return(Mutate(chip));
        }

        // comportamientos
        GridNode        best         = null;
        GridNode        objective    = flagEnemy;
        List <GridNode> menances     = new List <GridNode>();
        UpgradeArea     nearestBoost = NearestBoostArea(chip); // saca el upgrade area compatible más cercana
        int             len          = int.MaxValue;
        bool            priority     = false;

        foreach (GridNode g in _selectedNodes) // buscar elementos con prioridad
        {
            if (IsNodeOnArea(g) && g.isOccupied != null)
            {
                if (g == flagEnemy) // si es la bandera enemiga
                {
                    return(g);
                }
                else if (g.isOccupied.tag == "Unit") // si es una ficha
                {
                    Unit anotherUnit = (Unit)g.isOccupied;
                    if (!_team.IsUnitInTeam(anotherUnit)) // si la unidad no es amiga
                    {
                        float power      = chip.GetUnitPower(anotherUnit);
                        float powerEnemy = anotherUnit.GetUnitPower(chip);
                        if (power < powerEnemy) // si la enemiga es más fuerte
                        {
                            menances.Add(g);
                            priority = true;
                        }
                        else if (power > powerEnemy) // si la enemiga es más debil
                        {
                            best = g;
                        }
                    }
                }
                else if (nearestBoost != null && g == nearestBoost.GetGridNode())
                {
                    best = g;
                }
            }
        }

        if (priority) // se activa el return prioritario cuando hay amenazas
        {
            // returnea el nodo accesible más lejano al enemigo y más proximo al objetivo
            return(path.GetOptimalFurtherNode(_selectedNodes, menances, flagEnemy));
        }
        else if (best != null)
        {
            return(best);
        }
        else // si no se han encontrado elementos con prioridad
        {
            switch (chip.role) // modificar objetivo según rol estratégico
            {
            case StrategicRole.Forward:     // modo ataque
                if (nearestBoost != null)
                {
                    if (path.GetDistance(chip.GetGridNode(), nearestBoost.GetGridNode()) < totalDistance / 6)
                    {
                        objective = nearestBoost.GetGridNode();
                    }
                    else
                    {
                        objective = flagEnemy;
                    }
                }
                else
                {
                    objective = flagEnemy;
                }
                break;

            case StrategicRole.Defense:     // modo defensa
                if (nearestBoost != null)
                {
                    if (path.GetDistance(chip.GetGridNode(), nearestBoost.GetGridNode()) < totalDistance / 10)
                    {
                        objective = nearestBoost.GetGridNode();
                    }
                    else
                    {
                        objective = flagAlly;
                    }
                }
                else
                {
                    objective = flagAlly;
                }
                break;

            default:     // modo cobertura
                if (nearestBoost != null)
                {
                    if (path.GetDistance(chip.GetGridNode(), nearestBoost.GetGridNode()) < totalDistance / 3)
                    {
                        objective = nearestBoost.GetGridNode();
                    }
                    else
                    {
                        objective = flagEnemy;
                    }
                }
                else
                {
                    objective = flagEnemy;
                }

                break;
            }

            foreach (GridNode g in _selectedNodes) // recorrer la lista de nodos accesibles y elegir el camino más corto
            {
                if (IsNodeOnArea(g))               // si el nodo es accesible
                {
                    if (g.isOccupied == null)      // si el nodo está vacio
                    {
                        int newLen = path.BestPathLength(g, objective);
                        if (newLen < len)  // si el camino actual es mas corto que el mejor registrado
                        {
                            len  = newLen; // actualizar camino mas corto encontrado
                            best = g;      // actualizar mejor nodo
                        }
                    }
                }
            }
        }

        return(best);
    }
Example #8
0
    // Use this for initialization
    void Start()
    {
        zoomedOutPos = transform.position;
        zoomedOutRot = transform.rotation;
        lookAtTarget = true;
        distance = 1000;

        invHUD = GameObject.Find("HUD_Inventory").GetComponent<HUD_Inventory>();
        healthHUD = GameObject.Find("HUD_Healthbar").GetComponent<HUD_Healthbar>();
        hidePause = GameObject.Find("PauseButton").GetComponent<HideHUDElement>();
        hideTime = GameObject.Find("Time Button").GetComponent<HideHUDElement>();
        hideMap = GameObject.Find ("Map Button").GetComponent<HideHUDElement> ();

        pManager = GameObject.Find ("Pause Manager").GetComponent<PauseManager> ();
        hManager = GameObject.Find ("Health Manager").GetComponent<HealthManager> ();

        if(Application.loadedLevelName == "Restore Point"){
            tScreen = GameObject.Find("Title Screen Canvas").GetComponent<TitleScreen>();
            upArea = GameObject.Find("Upgrade Area Trigger").GetComponent<UpgradeArea>();
            if(tScreen.showTitleScreen){
                invHUD.hide();
                healthHUD.hide();
                hidePause.hide();
                hideTime.hide();
                hideMap.hide();
            }
        }
    }