Пример #1
0
 /**
  * Handle rockets.
  *
  * @param world the world object
  * @param p the player
  * @param esl all enemy vessels
  */
 static void handleRockets(SpacewarWorld world, Player p, List<SpacewarStructure> esl) {
   List<SpacewarStructure> rocketTargets = world.enemiesOf(p);
   Collections.shuffle(rocketTargets);
   for (SpacewarStructure s : rocketTargets) {
     if (world.isFleeing(s)) {
       continue;
     }
     // do not fire rocket at tagged objects unless it is the last enemy
     if (esl.size() == 1 || (s.item == null || s.item.tag == null)) {
       int found = 0;
       if (s.type == StructureType.SHIP || s.type == StructureType.STATION) {
         Pair<SpacewarStructure, SpacewarWeaponPort> w =
             findReadyPort(world.structures(p), EnumSet.of(Mode.ROCKET, Mode.MULTI_ROCKET));
         if (w != null) {
           world.attack(w.first, s, w.second.projectile.mode);
           found++;
         }
       }
       if (s.type == StructureType.SHIELD || s.type == StructureType.PROJECTOR) {
         Pair<SpacewarStructure, SpacewarWeaponPort> w =
             findReadyPort(world.structures(p), EnumSet.of(Mode.BOMB, Mode.VIRUS));
         if (w != null) {
           world.attack(w.first, s, w.second.projectile.mode);
           found++;
         }
       }
       if (found == 0) {
         // don't bother with other targets, out of ammo
         break;
       }
     }
   }
 }
Пример #2
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;
 }