예제 #1
0
파일: AI.java 프로젝트: hcodename47/open-ig
 /**
  * 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
파일: AI.java 프로젝트: hcodename47/open-ig
 /**
  * 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);
         }
       }
     }
   }
 }
예제 #3
0
파일: AI.java 프로젝트: hcodename47/open-ig
 /**
  * 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);
   }
 }