Esempio n. 1
0
  public void fire(int count, Entity target) {
    if (!prepareToFire(count, target)) {
      return;
    }

    Detonation d = new Detonation(target.getSimulation(), this, target, null);

    target.setProperty(EntityConstants.PROPERTY_DAMAGE, DamageStatus.destroyed);
    getEntity().getSimulation().detonate(d);
  }
  /* (non-Javadoc)
   * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
   */
  public void actionPerformed(ActionEvent arg0) {
    Object o = getSelectionManager().getSelectedObject();
    if (!(o instanceof Entity)) {
      return;
    }
    Entity e = (Entity) o;
    if (!EntityTools.isVisible(e)) {
      return;
    }

    SimulationMainFrame mf = findService(SimulationMainFrame.class);
    if (mf != null) {
      mf.getActivePlanViewDisplay().showPosition(e.getPosition());
    }
  }
Esempio n. 3
0
  /* (non-Javadoc)
   * @see com.soartech.simjr.sim.entities.AbstractEntity#tick(double)
   */
  @Override
  public void processTick(double dt) {
    if (hit) {
      return;
    }

    Vector3 targetPos = target != null ? target.getPosition() : staticTarget;
    Vector3 dir = targetPos.subtract(getPosition()).normalized();

    setHeading(Math.atan2(dir.y, dir.x));
    setVelocity(dir.multiply(speed));

    super.processTick(dt);

    Vector3 newPos = getPosition();
    if (newPos.subtract(targetPos).length() < speed * dt * 1.5) {
      hit = true;

      getSimulation().detonate(new Detonation(getSimulation(), weapon, target, staticTarget));
      // if (shooter != null)
      // {
      //    removeFlyOut(shooter, this);
      // }
      weapon.removeFlyout(this);
      getSimulation().removeEntity(this);
    }
  }
Esempio n. 4
0
 public double getClosingSpeed() {
   if (target == null) {
     return this.getSpeed();
   } else {
     return ((this.getVelocity()).subtract(target.getVelocity())).length();
   }
 }
Esempio n. 5
0
 /**
  * Generate a unique name for a missile. Exactly one of target or staticTarget must be non-null.
  *
  * @param weapon The associated weapon
  * @param target The target
  * @param staticTarget The target position
  * @return A new name
  */
 private static String generateName(Weapon weapon, Entity target, Vector3 staticTarget) {
   int id = generateFlyoutId(weapon);
   if (target != null) {
     return weapon.getEntity().getName()
         + "."
         + weapon.getName()
         + "."
         + id
         + "."
         + target.getName();
   } else if (staticTarget != null) {
     return weapon.getEntity().getName() + "." + weapon.getName() + "." + id + "." + staticTarget;
   } else {
     throw new IllegalArgumentException("One of target and staticTarget must be non-null");
   }
 }
Esempio n. 6
0
 public double getBearingToTarget() {
   Vector3 targetPos = target != null ? target.getPosition() : staticTarget;
   targetPos.subtract(getPosition());
   return Math.toDegrees(Angles.boundedAngleRadians(Angles.getBearing(targetPos)));
 }
Esempio n. 7
0
 public double getRangeToTarget() {
   Vector3 targetPos = target != null ? target.getPosition() : staticTarget;
   return targetPos.distance(getPosition());
 }
Esempio n. 8
0
 public int getTimeToTarget() {
   Vector3 targetPos = target != null ? target.getPosition() : staticTarget;
   return (int) Math.round(targetPos.distance(getPosition()) / this.getClosingSpeed());
 }