Ejemplo n.º 1
0
 /**
  * Orders the given structure to attack a random enemy.
  *
  * @param world the world
  * @param ship the ship
  */
 public static void defaultAttackBehavior(SpacewarWorld world, SpacewarStructure ship) {
   if (ship.canDirectFire()) {
     if (ship.type == StructureType.STATION || ship.type == StructureType.PROJECTOR) {
       ship.guard = true;
       selectNewTarget(world, ship);
     } else if (ship.type == StructureType.SHIP) {
       selectNewTarget(world, ship);
     }
   }
 }
Ejemplo n.º 2
0
 /**
  * Handle fighter kamikaze.
  *
  * @param world the world
  * @param p the player
  */
 static void handleKamikaze(SpacewarWorld world, Player p) {
   if (!world.battle().enemyFlee) {
     for (SpacewarStructure s : world.structures(p)) {
       s.guard |= s.type == StructureType.STATION || s.type == StructureType.PROJECTOR;
       if (s.type == StructureType.SHIP
           && s.item != null
           && s.item.type.category == ResearchSubCategory.SPACESHIPS_FIGHTERS
           && s.attack != null
           && !s.attack.isDestroyed()) {
         if (s.count == 1 && s.hp * 10 < s.hpMax) {
           world.attack(s, s.attack, Mode.KAMIKAZE);
         }
       }
     }
   }
 }
Ejemplo n.º 3
0
 /**
  * Attack out-of-range ships with the remaining idles.
  *
  * @param world the world object
  * @param idles the list of idles
  * @return all enemies
  */
 static List<SpacewarStructure> defaultAttackOutOfRange(
     SpacewarWorld world, List<SpacewarStructure> idles) {
   List<SpacewarStructure> esl = new ArrayList<>();
   if (!idles.isEmpty()) {
     esl.addAll(world.enemiesOf(idles.get(0)));
   }
   if (!esl.isEmpty()) {
     List<SpacewarStructure> esl2 = U.newArrayList(esl);
     for (SpacewarStructure ship : idles) {
       if (ship.attack == null && ship.type == StructureType.SHIP && ship.canDirectFire()) {
         SpacewarStructure t = selectNewTarget(world, ship, esl);
         if (t != null) {
           esl.remove(t);
           if (esl.isEmpty()) {
             esl.addAll(esl2);
           }
         }
       }
     }
   }
   return esl;
 }
Ejemplo n.º 4
0
 /**
  * Select a target in range which the current ship can do most damage.
  *
  * @param world the world object.
  * @param ship the current ship
  */
 static void selectNewTarget(SpacewarWorld world, final SpacewarStructure ship) {
   List<SpacewarStructure> es = world.enemiesInRange(ship);
   ModelUtils.shuffle(es);
   SpacewarStructure best = null;
   double bestEfficiency = 0d;
   for (SpacewarStructure s : es) {
     BattleEfficiencyModel bem = ship.getEfficiency(s);
     double eff = bem != null ? bem.damageMultiplier : 1d;
     if (eff > bestEfficiency) {
       best = s;
       bestEfficiency = eff;
     }
   }
   if (best != null) {
     world.attack(ship, best, Mode.BEAM);
   }
 }