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()); } }
/* (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); } }
public double getClosingSpeed() { if (target == null) { return this.getSpeed(); } else { return ((this.getVelocity()).subtract(target.getVelocity())).length(); } }
/** * 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"); } }
public double getBearingToTarget() { Vector3 targetPos = target != null ? target.getPosition() : staticTarget; targetPos.subtract(getPosition()); return Math.toDegrees(Angles.boundedAngleRadians(Angles.getBearing(targetPos))); }
public double getRangeToTarget() { Vector3 targetPos = target != null ? target.getPosition() : staticTarget; return targetPos.distance(getPosition()); }
public int getTimeToTarget() { Vector3 targetPos = target != null ? target.getPosition() : staticTarget; return (int) Math.round(targetPos.distance(getPosition()) / this.getClosingSpeed()); }