Exemplo n.º 1
0
 public void selectWeaponE()
 {
     if (!RangedBattle && attackAngle != Defender.UnitRotation)           // No counter in ranged or back attacks
     {
         float bestDamage = 0;
         foreach (TurretSpec turret in Defender.UnitBodySpec.turrets)
         {
             float   newDamage;
             GunSpec weapon = turret.gunStat;
             if (Defender.UnitRotation == GameUnit.OppositeRotationStatus(attackAngle) || // Head on attack
                 turret.turnableIndex() >= 0)                                             // Or the turret is turnable
             {
                 if (weapon.counter && canTarget(Defender, Attacker, distance, turret, weapon))
                 {
                     newDamage = estimateRawDamage(Attacker.getArmor(
                                                       attackAngle, false), weapon,
                                                   Attacker.UnitBodySpec.getNumbers());
                     if (newDamage > bestDamage)
                     {
                         bestDamage      = newDamage;
                         TurretOfChoiceE = turret;
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 public string AttackDirectionType()
 {
     if (attackAngle == Defender.UnitRotation)
     {
         return("Back");
     }
     else if (Defender.UnitRotation == GameUnit.OppositeRotationStatus(attackAngle))
     {
         return("Front");
     }
     else
     {
         return("Flank");
     }
 }
Exemplo n.º 3
0
    public void selectWeapon()
    {
        float bestDamage = 0;

        foreach (TurretSpec turret in Attacker.UnitBodySpec.turrets)
        {
            float   newDamage;
            GunSpec weapon = turret.gunStat;
            if (canTarget(Attacker, Defender, distance, turret, weapon))
            {
                newDamage = estimateRawDamage(Defender.getArmor(
                                                  GameUnit.OppositeRotationStatus(attackAngle)), weapon,
                                              Defender.UnitBodySpec.getNumbers());
                if (newDamage > bestDamage)
                {
                    bestDamage     = newDamage;
                    TurretOfChoice = turret;
                }
            }
        }
    }
Exemplo n.º 4
0
    public static UnitControlBattle CalculateBattle(GameUnit attacker, int ax, int ay, int dx, int dy)
    {
        if (attacker != null && ((UnitControl)PlayMap.GridController).HasUnit(dx, dy))
        {
            GameUnit defender = ((UnitControl)PlayMap.GridController).getUnitData(dx, dy);
            int      xd       = ax - dx;
            int      yd       = ay - dy;
            float    atkpen   = 1;
            float    defpen   = 1;
            if (attacker.terrainStatus != GameUnit.UnitTerrainStatus.Air && attacker.terrainStatus != GameUnit.UnitTerrainStatus.Deep)
            {
                defpen = 1.0f - PlayMap.Grid.getTileSpec(ax, ay).defense;
            }
            if (defender.terrainStatus != GameUnit.UnitTerrainStatus.Air && defender.terrainStatus != GameUnit.UnitTerrainStatus.Deep)
            {
                atkpen = 1.0f - PlayMap.Grid.getTileSpec(dx, dy).defense;
            }


            if (Mathf.Abs(xd) == Mathf.Abs(yd))                 // Diagonal attack
            {
                GameUnit.UnitRotationStatus xr;
                GameUnit.UnitRotationStatus yr;
                if (xd < 0)                   //Left to Right
                {
                    xr = GameUnit.UnitRotationStatus.E;
                }
                else                     //Right to Left
                {
                    xr = GameUnit.UnitRotationStatus.W;
                }
                if (yd < 0)                   //Down to Up
                {
                    yr = GameUnit.UnitRotationStatus.N;
                }
                else                     //Up to Down
                {
                    yr = GameUnit.UnitRotationStatus.S;
                }

                if (xr == defender.UnitRotation || xr == GameUnit.OppositeRotationStatus(defender.UnitRotation))
                {
                    return(new UnitControlBattle(attacker, defender, Mathf.Abs(xd) + Mathf.Abs(yd), yr, atkpen, defpen));
                }
                else
                {
                    return(new UnitControlBattle(attacker, defender, Mathf.Abs(xd) + Mathf.Abs(yd), xr, atkpen, defpen));
                }
            }
            else if (Mathf.Abs(xd) > Mathf.Abs(yd)) //East or West
            {
                if (xd < 0)                         //Left to Right
                {
                    return(new UnitControlBattle(attacker, defender, Mathf.Abs(xd) + Mathf.Abs(yd), GameUnit.UnitRotationStatus.E, atkpen, defpen));
                }
                else                     //Right to Left
                {
                    return(new UnitControlBattle(attacker, defender, Mathf.Abs(xd) + Mathf.Abs(yd), GameUnit.UnitRotationStatus.W, atkpen, defpen));
                }
            }
            else                 //North or South
            {
                if (yd < 0)      //Down to Up
                {
                    return(new UnitControlBattle(attacker, defender, Mathf.Abs(xd) + Mathf.Abs(yd), GameUnit.UnitRotationStatus.N, atkpen, defpen));
                }
                else                     //Up to Down
                {
                    return(new UnitControlBattle(attacker, defender, Mathf.Abs(xd) + Mathf.Abs(yd), GameUnit.UnitRotationStatus.S, atkpen, defpen));
                }
            }
        }
        return(null);
    }
Exemplo n.º 5
0
 public float AttackerDamage()
 {
     return(AttackerPenalty * estimateRawDamage(Defender.getArmor(
                                                    GameUnit.OppositeRotationStatus(attackAngle)), TurretOfChoice.gunStat,
                                                Defender.UnitBodySpec.getNumbers()));
 }