Ejemplo n.º 1
0
  /**
   * decide the course of action to take, or return null to no be used
   *
   * @param status the current status of the participant
   * @param detections the current list of detections for this participant
   * @param time the time this decision was made
   */
  public DemandedStatus decide(
      final Status status,
      ASSET.Models.Movement.MovementCharacteristics chars,
      DemandedStatus demStatus,
      final DetectionList detections,
      final ASSET.Scenario.ScenarioActivityMonitor monitor,
      final long time) {
    // produce a steady-state demanded course - so we continue
    // what we're doing during the weapons launch
    DemandedStatus res = null;

    // clear the activity flag
    String activity = "Not in trail";

    // is it time to fire another yet?
    if ((_lastLaunch == -1)
        || (time > _lastLaunch + _coolOffTime.getValueIn(Duration.MILLISECONDS))) {

      // do we have any detections?
      if (detections != null) {
        // get bearing to first detection
        final int len = detections.size();
        if (len > 0) {
          for (int i = 0; i < len; i++) {

            final ASSET.Models.Detection.DetectionEvent de = detections.getDetection(i);
            final Float brg = de.getBearing();
            if (brg != null) {
              // do we have a target type?
              if (_myTarget != null) {
                // is this of our target type
                final ASSET.Participants.Category thisTarget = de.getTargetType();
                if (_myTarget.matches(thisTarget)) {
                  // do we have range?
                  if (de.getRange() != null) {

                    // work out distance from us to the target, not from the sensor to the target
                    WorldLocation sensorLocation = de.getSensorLocation();

                    // Work out the estimated target location
                    WorldVector sensorToTarget =
                        new WorldVector(
                            MWC.Algorithms.Conversions.Degs2Rads(de.getBearing().doubleValue()),
                            de.getRange().getValueIn(WorldDistance.DEGS),
                            0);

                    WorldLocation targetLocation = sensorLocation.add(sensorToTarget);

                    // how are are we from the target location
                    WorldVector meToTarget = status.getLocation().subtract(targetLocation);
                    double yds_to_target =
                        MWC.Algorithms.Conversions.Degs2Yds(meToTarget.getRange());
                    double brg_to_target_degs =
                        MWC.Algorithms.Conversions.Rads2Degs(meToTarget.getBearing());

                    // is it within range?
                    if (yds_to_target < _launchRange.getValueIn(WorldDistance.YARDS)) {
                      // continue in steady state
                      res = new SimpleDemandedStatus(time, status);

                      // remember the launch time
                      _lastLaunch = time;

                      // start the launch steps
                      launchWeapon(de, monitor, status, brg_to_target_degs, time);

                      activity = LaunchWeapon.LAUNCH_MESSAGE;

                      // ok, drop out, we don't need to launch any more weapons
                      return res;
                    }
                  }
                }
              }
            } // if we know the bearing
          } // looping through the detections
        } // if we have any detections
      } // if the detections object was received
    } // whether it's time to launch another
    else {
      //
    }

    super.setLastActivity(activity);

    // always return null, since we continue in steady state
    return res;
  }
Ejemplo n.º 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;
  }