Exemplo n.º 1
0
  /**
   * right - store ourselves into the supplied memento object
   *
   * @param memento
   */
  @Override
  public void saveState(final IMemento memento) {
    // let our parent go for it first
    super.saveState(memento);

    final String _scenarioFileName = _myPresenter.getScenarioName();
    final String _controlFileName = _myPresenter.getControlName();

    if (_scenarioFileName != null) memento.putString(SCENARIO_FILE_INDEX, _scenarioFileName);
    if (_controlFileName != null) memento.putString(CONTROL_FILE_INDEX, _controlFileName);

    if (_myTimeControlProps != null) {
      final Duration stepSize = _myTimeControlProps.getAutoInterval();
      if (stepSize != null) {
        final String stepSizeStr = "" + stepSize.getValueIn(Duration.MILLISECONDS);
        memento.putString("StepInterval", stepSizeStr);
      }
    }
  }
Exemplo n.º 2
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;
  }