Exemplo n.º 1
0
  /**
   * Handle the spacewar between a trader and a pirate.
   *
   * @param war the war context
   * @param task the task index
   */
  void spacewarStartTraderVsPirate(SpacewarWorld war, int task) {
    if (isMissionSpacewar(war.battle(), "Mission-2-Task-" + task)) {
      if (startJointSpaceBattle(
          war, MISSION_2_TRADER, player("Traders"), MISSION_2_PIRATE, player("Pirates"))) {
        Player tr = player("Traders");
        int tidx = ((AITrader) tr.ai).fleetIndex(findTaggedFleet(MISSION_2_TRADER, tr));
        war.battle().chat = "chat.mission-2.defend.merchant" + (1 + tidx % 6);

        missionAttack = true;
      }
    }
  }
Exemplo 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);
         }
       }
     }
   }
 }
Exemplo n.º 3
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);
   }
 }
Exemplo n.º 4
0
  /**
   * Finish the war for the trader vs pirate missions.
   *
   * @param war the war context
   * @param task the task index
   */
  void spacewarFinishTraderVsPirate(SpacewarWorld war, int task) {
    if (isMissionSpacewar(war.battle(), "Mission-2-Task-" + task)) {
      // find the status of the trader ship
      Player traders = player("Traders");
      List<SpacewarStructure> sts = war.structures(traders);

      // which trader message to show
      int textIndex = (traderMessage - 1) % 6;

      boolean traderSurvived = !sts.isEmpty();
      completeTaskN(traderSurvived, task);
      if (traderSurvived) {
        war.battle().messageText =
            format("battlefinish.mission-2.merchant" + (textIndex + 1), moneyReward[task]);
        war.battle().rewardText = format("mission-2.save_trader.reward", moneyReward[task]);
        war.battle().rewardImage = imageReward[task];
      }
    }
  }
Exemplo n.º 5
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;
       }
     }
   }
 }
Exemplo n.º 6
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;
 }