Example #1
0
  /** do the actual launch */
  private void launchWeapon(
      final DetectionEvent detection,
      final ASSET.Scenario.ScenarioActivityMonitor monitor,
      final Status currentLocation,
      final double initial_course_degs,
      final long time) {

    // have we read in the weapon description yet?
    if ((_launchThis == null) || (_launchThis.length() == 0))
      _launchThis = readWeaponFromThisFile(this._fileName);

    final ParticipantType newPart = getWeapon(detection, currentLocation, _launchThis, _myTarget);

    // create the target
    monitor.createParticipant(newPart);

    // set it's status
    final Status newState = new Status(currentLocation);
    // update the status for the object's new id
    newState.setId(newPart.getId());

    // and put it in the participant
    newPart.setStatus(newState);

    // give it a faster speed though
    newState.setSpeed(new WorldSpeed(30, WorldSpeed.M_sec));

    // give the weapon a hint about direction to travel in
    SimpleDemandedStatus ds = new SimpleDemandedStatus(time, newState);
    ds.setCourse(initial_course_degs);

    newPart.setDemandedStatus(ds);
  }
Example #2
0
  public DemandedStatus decide(
      final Status status,
      ASSET.Models.Movement.MovementCharacteristics chars,
      DemandedStatus demStatus,
      ASSET.Models.Detection.DetectionList detections,
      ASSET.Scenario.ScenarioActivityMonitor monitor,
      final long time) {
    // create the output object
    SimpleDemandedStatus res = null;

    String thisActivity = null;

    // have we completed this manoeuvre?
    if (_transit_complete) {
      res = null;
      return res;
    }

    // find out where we are
    WorldLocation currentLoc = status.getLocation();

    // are we running towards a destination?
    if (_theDistance == null) {
      // ok, we're not heading towards a particular point, just put us onto the correct course and
      // speed
      double curSpeed = status.getSpeed().getValueIn(WorldSpeed.M_sec);
      double curCourse = status.getCourse();
      double curHeight = -status.getLocation().getDepth();

      thisActivity = "";

      // are we already working to a simple demanded course/speed/depth?
      if (demStatus instanceof SimpleDemandedStatus) {
        res = new SimpleDemandedStatus(time, (SimpleDemandedStatus) demStatus);
      } else {
        res = new SimpleDemandedStatus(time, status);
      }

      if (_mySpeed != null) {
        if (curSpeed != _mySpeed.getValueIn(WorldSpeed.M_sec)) {
          thisActivity += " speed to:" + (int) _mySpeed.getValueIn(WorldSpeed.Kts);
          res.setSpeed(_mySpeed.getValueIn(WorldSpeed.M_sec));
        }
      }

      if (_myCourse != null) {
        if (curCourse != _myCourse.doubleValue()) {
          thisActivity += " course to:" + _myCourse.doubleValue();
          res.setCourse(_myCourse.doubleValue());
        }
      }

      if (_myHeight != null) {
        if (curHeight != _myHeight.getValueIn(WorldDistance.METRES)) {
          thisActivity += " height to:" + _myHeight.getValueIn(WorldDistance.METRES);
          res.setHeight(_myHeight.getValueIn(WorldDistance.METRES));
        }
      }

      // did we update any?
      if (thisActivity == "") {
        // no - we must be ok,
        res = null;
      } else {
        // cool, the res is set already
      }

    } else {

      // do we have our destination?
      if (_theDestination == null) {
        // no, this is the first time we've been called.  Calculate where we're going to
        WorldVector vector =
            new WorldVector(
                MWC.Algorithms.Conversions.Degs2Rads(this._myCourse.doubleValue()),
                _theDistance.getValueIn(WorldDistance.DEGS),
                0);

        _theDestination = new WorldLocation(currentLoc);
        _theDestination.addToMe(vector);
      } else {
        // ok, we're up and running, have we reached our destination

        // how far to the target
        double rngDegs = currentLoc.subtract(_theDestination).getRange();

        // and in yards
        double rngYds = MWC.Algorithms.Conversions.Degs2Yds(rngDegs);

        if (rngYds < _threshold) {
          // right, we've got there. Mark complete
          _transit_complete = true;

          super.setLastActivity(thisActivity);

          // and drop out
          return res;
        }
      }

      // ok, now steer to the destination
      double brg_rads = _theDestination.subtract(currentLoc).getBearing();
      final double brgDegs = MWC.Algorithms.Conversions.Rads2Degs(brg_rads);

      // and set the course in degs
      res = new SimpleDemandedStatus(time, status);
      res.setCourse(brgDegs);

      // do we have depth?
      if (_myHeight != null) res.setHeight(_myHeight.getValueIn(WorldDistance.METRES));

      // and the speed
      if (_mySpeed != null) res.setSpeed(_mySpeed.getValueIn(WorldSpeed.M_sec));

      thisActivity = "Heading for target location";
    }

    super.setLastActivity(thisActivity);

    return res;
  }