Ejemplo n.º 1
0
  @Override
  public void advance(float amount) {
    if (!missile.getSource().isAlive()) {
      IceUtils.destroy(missile);
      return;
    }

    super.advance(amount);

    weaponCooldown = Math.max(0, weaponCooldown - amount);

    if (target == null) return;

    Vector2f.add(destOffset, target.getLocation(), dest);

    accelerate();
    turnToward(dest);

    if (ammo > 0 && weaponCooldown == 0) {
      CombatEntityAPI nearest = null;
      float record = Float.MAX_VALUE;

      for (int i = 0; i < potentialTargets.size(); ++i) {
        CombatEntityAPI m = (CombatEntityAPI) potentialTargets.get(i);

        float dist2 = MathUtils.getDistanceSquared(missile, m);

        if (dist2 < record && dist2 <= WEAPON_RANGE_SQUARED) {
          record = dist2;
          nearest = m;
        }
      }

      if (nearest != null) {
        Global.getCombatEngine()
            .spawnProjectile(
                missile.getSource(),
                null,
                WEAPON_ID,
                missile.getLocation(),
                VectorUtils.getAngle(missile.getLocation(), nearest.getLocation()),
                new Vector2f());

        --ammo;
        weaponCooldown = WEAPON_COOLDOWN;
      }
    }
  }
Ejemplo n.º 2
0
  @Override
  public void evaluateCircumstances() {
    super.evaluateCircumstances();

    //        if(target == null || (!(target instanceof ShipAPI) || !((ShipAPI)target).isAlive())) {
    //            findTarget();
    //            return;
    //        }

    Vector2f.sub(
        MathUtils.getRandomPointInCircle(target.getLocation(), target.getCollisionRadius()),
        target.getLocation(),
        destOffset);

    if (missile.isFading() || ammo <= 0 || !missile.getSource().isAlive())
      IceUtils.destroy(missile);

    potentialTargets.clear();
    potentialTargets.addAll(AIUtils.getNearbyEnemyMissiles(missile, POTENTIAL_TARGET_RANGE));
    potentialTargets.addAll(AIUtils.getNearbyEnemies(missile, POTENTIAL_TARGET_RANGE));
  }