Beispiel #1
0
    private List <Accion> sendAlliesToDefend(int defenders, List <PersonajeBase> attackers)                          //manda los defensores necesarios
    {
        //comprobar si hay suficientes unidades que no esten peleando para mandarlas
        //sino mandar las que esten mas cerca hasta cumplir los requirimientos
        //o quedarnos sin unidades
        //añadimos a los elegidos al grupo de defensores

        List <Accion> defendActions    = new List <Accion>();
        List <float>  priorities       = new List <float>();
        float         distancePriority = 7;
        float         velocityPriotiry = 5;
        float         dmgPriority      = 5;

        for (int i = 0; i < unitsNotAsigned.Count; i++)
        {
            float prioridad = 0;
            prioridad -= (SimManagerFinal.positionToGrid(unitsNotAsigned[i].posicion) - getUnitPointOnBase(unitsNotAsigned[i], baseCoords)).magnitude * distancePriority;
            //prioridad = -getClosestPointToBase(unitsNotAsigned[i], baseCoords).magnitude * distancePriority;
            prioridad += unitsNotAsigned[i].maxMovSpeed * velocityPriotiry;
            float dmgPower = 0;
            foreach (PersonajeBase person in attackers)
            {
                dmgPower += StatsInfo.damageModifiers[(int)unitsNotAsigned[i].tipo][(int)person.tipo];
            }
            prioridad += dmgPower * dmgPriority;
            priorities.Add(prioridad);
        }

        for (int i = 0; i < defenders; i++)
        {
            float higherPriority = float.MinValue;
            int   index          = 0;
            for (int j = 0; j < priorities.Count; j++)
            {
                if (priorities[j] > higherPriority)
                {
                    higherPriority = priorities[j];
                    index          = j;
                }
            }
            defendActions.Add(createAttackingAction(unitsNotAsigned[index], getClosestEnemy(unitsNotAsigned[index], attackers)));
            defensiveGroup.Add(unitsNotAsigned[index]);
            unitsNotAsigned.Remove(unitsNotAsigned[index]); //si falla algo, mirar aqui
            priorities.RemoveAt(index);
        }

        if (patrullero.isAlive())
        {
            defendActions.Add(createAttackingAction(patrullero, getClosestEnemy(patrullero, attackers)));
        }

        return(defendActions);
    }
Beispiel #2
0
 protected internal override bool isPossible()
 {
     return((receptor && receptor.isAlive() && sujeto.isAlive()) || (receptor == null && sujeto.isAlive()));
 }