Пример #1
0
    public void testHeloDetection() {

      // set up the Ssk
      ASSET.Models.Vessels.SSK ssk = new ASSET.Models.Vessels.SSK(12);
      ASSET.Participants.Status sskStat = new ASSET.Participants.Status(12, 0);
      WorldLocation origin = new WorldLocation(0, 0, 0);
      sskStat.setLocation(
          origin.add(new WorldVector(0, MWC.Algorithms.Conversions.Nm2Degs(35), 40)));
      sskStat.setSpeed(new WorldSpeed(18, WorldSpeed.M_sec));
      ssk.setStatus(sskStat);

      // ok, setup the ssk radiation
      ASSET.Models.Mediums.BroadbandRadNoise brn = new ASSET.Models.Mediums.BroadbandRadNoise(134);
      ASSET.Models.Vessels.Radiated.RadiatedCharacteristics rc =
          new ASSET.Models.Vessels.Radiated.RadiatedCharacteristics();
      rc.add(EnvironmentType.BROADBAND_PASSIVE, brn);
      ssk.setRadiatedChars(rc);

      // now setup the helo
      ASSET.Models.Vessels.Helo merlin = new ASSET.Models.Vessels.Helo(33);
      ASSET.Participants.Status merlinStat = new ASSET.Participants.Status(33, 0);
      merlinStat.setLocation(origin);
      merlinStat.setSpeed(new WorldSpeed(12, WorldSpeed.Kts));
      merlin.setStatus(merlinStat);

      // and it's sensor
      ASSET.Models.Sensor.SensorList fit = new ASSET.Models.Sensor.SensorList();
      BroadbandSensor bs = new BroadbandSensor(34);
      fit.add(bs);
      merlin.setSensorFit(fit);

      // now setup the su
      ASSET.Models.Vessels.Surface ff = new ASSET.Models.Vessels.Surface(31);
      ASSET.Participants.Status ffStat = new ASSET.Participants.Status(31, 0);
      WorldLocation sskLocation = ssk.getStatus().getLocation();
      ffStat.setLocation(
          sskLocation.add(new WorldVector(0, MWC.Algorithms.Conversions.Nm2Degs(1), -40)));
      ffStat.setSpeed(new WorldSpeed(12, WorldSpeed.M_sec));
      ff.setStatus(ffStat);
      ff.setSensorFit(fit);
      ASSET.Models.Mediums.BroadbandRadNoise ff_brn =
          new ASSET.Models.Mediums.BroadbandRadNoise(15);
      ASSET.Models.Vessels.Radiated.RadiatedCharacteristics ff_rc =
          new ASSET.Models.Vessels.Radiated.RadiatedCharacteristics();
      ff_rc.add(EnvironmentType.BROADBAND_PASSIVE, ff_brn);
      ff.setSelfNoise(ff_rc);

      // try a detection
      ASSET.Models.Environment.CoreEnvironment env = new SimpleEnvironment(1, 1, 1);
      ASSET.Models.Detection.DetectionEvent dt;
      dt = bs.detectThis(env, merlin, ssk, 0, null);
      assertTrue("helo able to detect SSK", dt != null);

      dt = bs.detectThis(env, ff, ssk, 0, null);
      assertTrue("frigate able to detect SSK", dt != null);
    }
    void construct(PlanningSegment seg, WorldLocation origin, HiResDate date) {
      // check we have some data
      if (date == null || origin == null) return;

      double timeTravelledMillis = getSecsTravelled(seg) * 1000;

      // ditch the existing items
      seg.removeAllElements();

      // ok build for this segment
      double courseDegs = seg.getCourse();
      double courseRads = MWC.Algorithms.Conversions.Degs2Rads(courseDegs);

      long timeMillis = date.getDate().getTime();
      final long timeStepMillis;
      final long ONE_MIN = 60 * 1000;
      final long ONE_HOUR = 60 * ONE_MIN;
      final long ONE_DAY = 24 * ONE_HOUR;

      // use a time step appropriate to how long we're generating the track for
      if (timeTravelledMillis <= 4 * ONE_HOUR) timeStepMillis = ONE_MIN;
      else if (timeTravelledMillis <= 12 * ONE_HOUR) timeStepMillis = 10 * ONE_MIN;
      else if (timeTravelledMillis <= 2 * ONE_DAY) timeStepMillis = 30 * ONE_MIN;
      else timeStepMillis = ONE_HOUR;

      // now work out how far he will have travelled in a time step
      double distPerMinute = getMinuteDelta(seg);
      double distPerStep = distPerMinute * (timeStepMillis / ONE_MIN);
      WorldVector vec =
          new WorldVector(courseRads, new WorldDistance(distPerStep, WorldDistance.METRES), null);

      for (long tNow = timeMillis;
          tNow <= timeMillis + timeTravelledMillis;
          tNow += timeStepMillis) {
        HiResDate thisDtg = new HiResDate(tNow);

        // ok, do this fix
        Fix thisF =
            new Fix(thisDtg, origin, courseRads, seg.getSpeed().getValueIn(WorldSpeed.ft_sec) / 3);

        // override the depth
        thisF.getLocation().setDepth(seg.getDepth().getValueIn(WorldDistance.METRES));

        FixWrapper fw = new FixWrapper(thisF);

        fw.setColor(seg.getColor());

        // and store it
        seg.add(fw);

        // reset the name, we're not going to use a human generated one
        fw.resetName();

        // produce a new position
        origin = origin.add(vec);
      }
    }
Пример #3
0
 public static ReferencedEnvelope toEnvelope(WorldArea worldArea) {
   if (worldArea != null) {
     WorldLocation bottomLeft = worldArea.getBottomLeft();
     WorldLocation topRight = worldArea.getTopRight();
     return new ReferencedEnvelope(
         bottomLeft.getLong(),
         topRight.getLong(),
         bottomLeft.getLat(),
         topRight.getLat(),
         LATLONG);
   }
   return new ReferencedEnvelope(LATLONG);
 }
Пример #4
0
 /** Determine how far away we are from this point. or return null if it can't be calculated */
 public double rangeFrom(final WorldLocation other) {
   final WorldLocation loc = getPath().getLocationAt(_myIndex);
   return loc.rangeFrom(other);
 }
Пример #5
0
  /**
   * this method is called by the 'Create' function, and it fills in the buoys into the correct
   * pattern
   */
  protected final void addBuoys(Debrief.Wrappers.BuoyPatternWrapper pattern) {
    WorldLocation origin = getKingpin();
    // note that as we calculate the LH angle
    double lh_orient_rads = MWC.Algorithms.Conversions.Degs2Rads(_orientation2);
    double rh_orient_rads = MWC.Algorithms.Conversions.Degs2Rads(_orientation1);
    double spacing_degs = MWC.Algorithms.Conversions.Nm2Degs(_spacing);

    // how many bouys in each leg?
    // an even number means we don't have one at the tip, which becomes a special case
    int num_buoys = getNumberOfBuoys().intValue();
    boolean even_num = false;
    if ((num_buoys % 2) == 0) {
      even_num = true;
    }

    // sort out how many there are in each leg
    int num_in_leg = num_buoys / 2;

    // sort out the direction
    double this_orient = rh_orient_rads;

    int buoy_counter = 0;

    // remember that we are looking at the first buoy
    boolean first_buoy = true;

    // do the first leg
    for (int i = 0; i < num_in_leg; i++) {
      // create the new symbol
      Debrief.Wrappers.LabelWrapper lw =
          new Debrief.Wrappers.LabelWrapper("W" + (buoy_counter + 1), origin, java.awt.Color.red);

      buoy_counter++;

      // get the parent to do the formatting
      this.formatSymbol(lw, pattern);

      // if this is the first buoy, mark it as the kingping
      if (first_buoy) {
        lw.setSymbolType("Kingpin");
        first_buoy = false;
      }

      // create the step to use to get to the next buoy
      WorldVector thisStep = new MWC.GenericData.WorldVector(this_orient, spacing_degs, 0.0);

      // place buoy
      origin = origin.add(thisStep);
    }

    // if we have an even number, we need to move forward 1/2 distance for one more step before we
    // change direction
    if (even_num) {
      // calculate the size of this small step
      double reverse_rh_rads = MWC.Algorithms.Conversions.Degs2Rads(_orientation1 + 180.0);
      WorldVector short_hop = new WorldVector(reverse_rh_rads, spacing_degs / 2, 0.0);

      // move the origin forward
      origin = origin.add(short_hop);

      // calculate the size of this small step
      short_hop = new WorldVector(lh_orient_rads, spacing_degs / 2, 0.0);

      // move the origin forward
      origin = origin.add(short_hop);
    } else {

      // drop a buoy at the current point
      Debrief.Wrappers.LabelWrapper lw =
          new Debrief.Wrappers.LabelWrapper("W" + (buoy_counter + 1), origin, java.awt.Color.red);
      buoy_counter++;

      // move to the correct location for the next point
      WorldVector short_hop = new WorldVector(lh_orient_rads, spacing_degs, 0.0);

      // move the origin forward
      origin = origin.add(short_hop);

      // get the parent to do the formatting
      this.formatSymbol(lw, pattern);
    }

    // now travel back down the reverse side
    // sort out the direction
    this_orient = lh_orient_rads;

    // do the first leg
    for (int i = 0; i < num_in_leg; i++) {

      // create the new symbol
      Debrief.Wrappers.LabelWrapper lw =
          new Debrief.Wrappers.LabelWrapper("W" + (buoy_counter + 1), origin, java.awt.Color.red);

      buoy_counter++;

      // get the parent to do the formatting
      this.formatSymbol(lw, pattern);

      // create the step to use to get to the next buoy
      WorldVector thisStep = new MWC.GenericData.WorldVector(this_orient, spacing_degs, 0.0);

      // start moving down the return leg
      // move buoy
      origin = origin.add(thisStep);
    }
  }
Пример #6
0
  /**
   * over-ridden method, where we write out our data
   *
   * @param theData the data to plot
   * @param out the stream to write to
   * @throws java.io.IOException file-related troubles
   */
  protected final void plotData(MWC.GUI.Layers theData, java.io.BufferedWriter out)
      throws java.io.IOException {

    java.text.DateFormat df = new java.text.SimpleDateFormat("ddHHmm");
    df.setTimeZone(TimeZone.getTimeZone("GMT"));

    // work through the layers
    int num = _theData.size();
    for (int i = 0; i < num; i++) {
      Layer l = (Layer) _theData.elementAt(i);
      Enumeration<Editable> iter = l.elements();
      while (iter.hasMoreElements()) {
        Object oj = iter.nextElement();
        if (oj instanceof Debrief.Wrappers.FixWrapper) {
          Debrief.Wrappers.FixWrapper fw = (Debrief.Wrappers.FixWrapper) oj;
          WorldLocation pos = fw.getLocation();

          if (fw.getSymbolShowing()) {
            String lbl = fw.getName();
            writeBox(out, pos.getLong(), pos.getLat(), pos.getDepth(), fw.getColor(), lbl);
          }

          if (fw.getLabelShowing()) {
            String str = DebriefFormatDateTime.toStringHiRes(fw.getTime());
            writeText(out, pos.getLong(), pos.getLat(), pos.getDepth(), str, fw.getColor());
          }
        }
      }
    }

    // now draw the line connectors
    num = _theData.size();
    for (int i = 0; i < num; i++) {
      Layer l = (Layer) _theData.elementAt(i);
      Enumeration<Editable> iter = l.elements();
      int len = 0;
      while (iter.hasMoreElements()) {
        Object oj = iter.nextElement();

        if (oj instanceof MWC.GenericData.WatchableList) {
          // just check that we haven't got any dangling Fix lines
          // waiting to be finished
          if (len > 0) {
            // we have clearly written some fixes to the file, write the footer
            writeLineFooter(out, len);
            len = 0;
          }

          MWC.GenericData.WatchableList tw = (MWC.GenericData.WatchableList) oj;
          java.awt.Color col = tw.getColor();
          writeLineHeader(out, col);
        }

        if (oj instanceof Debrief.Wrappers.FixWrapper) {
          len++;
          Debrief.Wrappers.FixWrapper fw = (Debrief.Wrappers.FixWrapper) oj;
          WorldLocation pos = fw.getLocation();

          writeLineEntry(out, pos.getLong(), pos.getLat(), pos.getDepth());
        }
      }

      if (len > 0) {
        // we have clearly written some fixes to the file, write the footer
        writeLineFooter(out, len);
      }
    }
  }
Пример #7
0
 public static Coordinate toCoord(WorldLocation val) {
   return new Coordinate(val.getLong(), val.getLat(), val.getDepth());
 }
  public static void main(String[] args) {

    // create a movement model
    Wander wander =
        new Wander(new WorldLocation(1, 1, 0), new WorldDistance(3000, WorldDistance.YARDS));

    // set up the Ssk
    ASSET.Models.Vessels.SSK ssk = new ASSET.Models.Vessels.SSK(12);
    ASSET.Participants.Status sskStat = new ASSET.Participants.Status(12, 0);
    WorldLocation origin = new WorldLocation(0, 0, 0);
    sskStat.setLocation(origin.add(new WorldVector(0, MWC.Algorithms.Conversions.Nm2Degs(3), 40)));
    sskStat.setSpeed(new WorldSpeed(12, WorldSpeed.M_sec));
    ssk.setMovementChars(SSMovementCharacteristics.getSampleChars());
    ssk.setStatus(sskStat);
    ssk.setDecisionModel(wander);
    ssk.setName("SSK");

    // ok, setup the ssk radiation
    ASSET.Models.Mediums.BroadbandRadNoise brn = new ASSET.Models.Mediums.BroadbandRadNoise(134);
    ASSET.Models.Vessels.Radiated.RadiatedCharacteristics rc =
        new ASSET.Models.Vessels.Radiated.RadiatedCharacteristics();
    rc.add(EnvironmentType.BROADBAND_PASSIVE, brn);
    ssk.setRadiatedChars(rc);

    // now setup the helo
    final ASSET.Models.Vessels.Helo merlin = new ASSET.Models.Vessels.Helo(33);
    merlin.setMovementChars(HeloMovementCharacteristics.getSampleChars());
    ASSET.Participants.Status merlinStat = new ASSET.Participants.Status(33, 0);
    merlinStat.setLocation(
        origin.add(new WorldVector(0, MWC.Algorithms.Conversions.Nm2Degs(1), -400)));
    merlinStat.setSpeed(new WorldSpeed(60, WorldSpeed.M_sec));
    merlin.setStatus(merlinStat);
    merlin.setDecisionModel(wander);
    merlin.setName("Merlin");

    // and it's sensor
    ASSET.Models.Sensor.SensorList fit = new ASSET.Models.Sensor.SensorList();
    final OpticLookupSensor optic = OpticLookupSensor.OpticLookupTest.getTestOpticSensor();
    fit.add(optic);
    merlin.setSensorFit(fit);
    merlin.setCategory(
        new Category(Category.Force.BLUE, Category.Environment.AIRBORNE, Category.Type.HELO));

    // now setup the su
    ASSET.Models.Vessels.Surface ff = new ASSET.Models.Vessels.Surface(31);
    ASSET.Participants.Status ffStat = new ASSET.Participants.Status(31, 0);
    WorldLocation sskLocation = ssk.getStatus().getLocation();
    ffStat.setLocation(
        sskLocation.add(new WorldVector(0, MWC.Algorithms.Conversions.Nm2Degs(4), -40)));
    ffStat.setSpeed(new WorldSpeed(6, WorldSpeed.M_sec));
    ff.setMovementChars(MovementCharacteristics.getSampleChars());
    ff.setStatus(ffStat);

    ASSET.Models.Sensor.SensorList fit2 = new ASSET.Models.Sensor.SensorList();
    final BroadbandSensor bs2 = new BroadbandSensor(34);
    fit2.add(bs2);
    ff.setSensorFit(fit2);
    ASSET.Models.Mediums.BroadbandRadNoise ff_brn = new ASSET.Models.Mediums.BroadbandRadNoise(35);
    ASSET.Models.Vessels.Radiated.RadiatedCharacteristics ff_rc =
        new ASSET.Models.Vessels.Radiated.RadiatedCharacteristics();
    ff_rc.add(EnvironmentType.BROADBAND_PASSIVE, ff_brn);
    ff.setSelfNoise(ff_rc);
    ff.setDecisionModel(wander);
    ff.setRadiatedChars(rc);
    ff.setName("FF");
    ff.setCategory(
        new Category(Category.Force.RED, Category.Environment.SURFACE, Category.Type.FRIGATE));

    // setup the scenario
    final ASSET.Scenario.CoreScenario cs = new ASSET.Scenario.CoreScenario();
    cs.addParticipant(ff.getId(), ff);
    cs.addParticipant(merlin.getId(), merlin);
    cs.addParticipant(ssk.getId(), ssk);
    cs.setEnvironment(new SimpleEnvironment(0, 1, 0));

    // and the viewer!!
    JFrame viewer = new JFrame();
    viewer.setSize(400, 300);
    viewer.setVisible(true);

    MWC.GUI.Properties.Swing.SwingPropertiesPanel props =
        new MWC.GUI.Properties.Swing.SwingPropertiesPanel(null, null, null, null);

    ////    props.addEditor(optic.getInfo(), null);

    LookupSensorComponentViewer sv = new LookupSensorComponentViewer();
    sv.setName("optic");
    sv.setObject(new SensorFitEditor.WrappedSensor(optic));
    props.add(sv);

    viewer.getContentPane().setLayout(new BorderLayout());
    viewer.getContentPane().add(props, BorderLayout.CENTER);

    JButton stepper = new JButton("Step");
    stepper.addActionListener(
        new java.awt.event.ActionListener() {
          /** Invoked when an action occurs. */
          public void actionPerformed(ActionEvent e) {
            // move the scenario forward
            cs.step();
          }
        });
    viewer.getContentPane().add(stepper, BorderLayout.SOUTH);

    viewer.doLayout();
    viewer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    viewer.pack();
  }
Пример #9
0
 public void paintSymbol(final CanvasType dest, final WorldLocation loc, final Point pt) {
   dest.drawText(_nf.format(loc.getDepth()), pt.x, pt.y);
 }
Пример #10
0
    // TODO FIX-TEST
    public void NtestLaunch() {

      final double rngToHim = 5000;
      final double crseToHim = 45;

      final WorldLocation origin = new WorldLocation(0, 0, 0);
      final WorldLocation hisLoc =
          origin.add(
              new WorldVector(
                  MWC.Algorithms.Conversions.Degs2Rads(crseToHim),
                  MWC.Algorithms.Conversions.Yds2Degs(rngToHim),
                  0));
      final Status blueStat = new Status(13, 0);
      blueStat.setLocation(origin);
      blueStat.setCourse(0);
      blueStat.setSpeed(new WorldSpeed(4, WorldSpeed.M_sec));

      final Status redStat = new Status(blueStat);
      redStat.setLocation(hisLoc);

      // setup a couple of targets
      final ASSET.Models.Vessels.SSN ssn = new ASSET.Models.Vessels.SSN(1);
      ssn.setName("ssn");
      ssn.setMovementChars(
          SSMovementCharacteristics.generateDebug("scrap", 1, 1, 0, 20, 1, 300, 1, 1, 10, 100));
      ssn.setCategory(
          new ASSET.Participants.Category(
              Category.Force.BLUE, Category.Environment.SUBSURFACE, Category.Type.SUBMARINE));
      ssn.setStatus(blueStat);
      final ASSET.Models.Sensor.Initial.OpticSensor periscope =
          new ASSET.Models.Sensor.Initial.OpticSensor(12);
      ssn.addSensor(periscope);
      RadiatedCharacteristics rc = new RadiatedCharacteristics();
      rc.add(EnvironmentType.VISUAL, new Optic(12, new WorldDistance(12, WorldDistance.METRES)));
      ssn.setRadiatedChars(rc);

      final ASSET.Models.Vessels.Surface su = new ASSET.Models.Vessels.Surface(4);
      su.setName("su");
      su.setMovementChars(
          SurfaceMovementCharacteristics.generateDebug("scrap", 1, 1, 0.001, 14, 1, 299));
      su.setCategory(
          new ASSET.Participants.Category(
              Category.Force.RED, Category.Environment.SURFACE, Category.Type.CARRIER));
      su.setStatus(redStat);
      rc = new RadiatedCharacteristics();
      rc.add(EnvironmentType.VISUAL, new Optic(12, new WorldDistance(12, WorldDistance.METRES)));
      su.setRadiatedChars(rc);

      /** create the scenario */
      final CoreScenario scenario = new CoreScenario();
      scenario.setScenarioStepTime(10000);
      scenario.setTime(0);
      scenario.setName("Testing weapon launch");

      // get somebody to listen to the tracks
      final ASSET.Scenario.Observers.Recording.DebriefReplayObserver debrief_writer =
          new ASSET.Scenario.Observers.Recording.DebriefReplayObserver(
              "�test_reports", null, true, "test observer", true);
      debrief_writer.setup(scenario);

      // DON'T BOTHER RECORDING JUST YET!
      debrief_writer.setActive(false);

      /** now the behaviours */
      final Trail trailRed = new Trail(new WorldDistance(2000, WorldDistance.YARDS));
      final TargetType getRed = new TargetType();
      getRed.addTargetType(Category.Force.RED);
      trailRed.setTargetType(getRed);

      final LaunchWeapon launchWeapon = new LaunchWeapon();
      launchWeapon.setTargetType(getRed);
      launchWeapon.setLaunchRange(new WorldDistance(4000, WorldDistance.YARDS));
      launchWeapon.setCoolOffTime(new Duration(Duration.DAYS, 3)); // 24 hr cool off time
      launchWeapon.setLaunchType(launchBehaviour);

      final Waterfall blueWaterfall = new Waterfall();
      blueWaterfall.insertAtFoot(trailRed);
      blueWaterfall.insertAtHead(launchWeapon);
      ssn.setDecisionModel(blueWaterfall);

      scenario.addParticipant(1, ssn);
      scenario.addParticipant(4, su);

      // move forward a while
      boolean found = false;
      double lastRange = -1;
      double thisRange = -1;

      int counter = 0;

      while (!found && counter <= 100000) {
        scenario.step();
        final WorldVector sep =
            ssn.getStatus().getLocation().subtract(su.getStatus().getLocation());
        thisRange = MWC.Algorithms.Conversions.Degs2Yds(sep.getRange());

        if (lastRange == -1) {
          lastRange = thisRange;
        }

        if (ssn.getActivity().equals(LaunchWeapon.LAUNCH_MESSAGE)) {
          found = true;
          System.out.println("LAUNCHED");
        } else {
          lastRange = thisRange;
        }

        // just do "MAD" check to ensure we don't go on for ever
        counter++;
      }

      // check we didn't time out
      assertTrue(" we just ran to end of loop (no fire)", counter < 100000);

      // check we launched at the right point
      final double launchYds = launchWeapon.getLaunchRange().getValueIn(WorldDistance.YARDS);
      assertTrue("didn't fire too soon", lastRange > launchYds);
      assertTrue(
          "didn't fire too late, got:" + launchYds + " but wanted:" + thisRange,
          thisRange <= launchYds);

      // so, we've launched the weapon - see how many participants are in the scenario
      assertEquals("New participant created", 3, scenario.getListOfParticipants().length);

      // find the weapon
      //      final ParticipantType torpedo =
      // scenario.getThisParticipant(scenario.getListOfParticipants()[0].intValue());

      // check if the torpedo gets to the target
      while (scenario.getListOfParticipants().length == 3) {
        scenario.step();
      }

      // check that the torpedo destroys the SU, and they are both removed
      assertEquals("surface participant destroyed", 1, scenario.getListOfParticipants().length);

      // move a bit further just to give us some more blue track
      for (int ii = 0; ii < 20; ii++) {
        scenario.step();
      }
    }
Пример #11
0
  /** put our keywords into the XML description */
  protected static String swapKeywords(
      final DetectionEvent detection,
      final Status currentLocation,
      final String weapon,
      final TargetType theTarget) {
    // amend string template to include available parameters
    final Float brg_degs = detection.getBearing();
    final WorldDistance rng = detection.getRange();

    // take a copy of the string
    String working = new String(weapon);

    // swap the bearing
    if (brg_degs != null) {
      final String brg_val = "" + brg_degs.floatValue();
      working = replaceAll(working, "$BRG$", brg_val);
    }

    // swap the range
    if (rng != null) {
      final String rng_val = "" + rng.getValueIn(WorldDistance.YARDS);
      working = replaceAll(working, "$RNG$", rng_val);
    }

    // insert the location of the target
    if (brg_degs != null) {
      final float brg_val = brg_degs.floatValue();

      // do we know range?
      if (rng != null) {
        // yes, compute target location
        final WorldVector newVector =
            new WorldVector(
                MWC.Algorithms.Conversions.Degs2Rads(brg_val),
                rng.getValueIn(WorldDistance.DEGS),
                0);
        final WorldLocation newLoc = currentLocation.getLocation().add(newVector);

        // produce strings from this location
        final String theDepth = "" + newLoc.getDepth();
        final String theLat = "" + newLoc.getLat();
        final String theLong = "" + newLoc.getLong();

        // put these strings into the new behaviour
        working = replaceAll(working, "$TGT_DEPTH$", theDepth);
        working = replaceAll(working, "$TGT_LAT$", theLat);
        working = replaceAll(working, "$TGT_LONG$", theLong);

      } else {
        // no, send the weapon down a bearing for XXXX yds
        // compute target location
        final double TGT_RANGE = 5000;
        final WorldVector newVector =
            new WorldVector(
                MWC.Algorithms.Conversions.Degs2Rads(brg_val),
                MWC.Algorithms.Conversions.Yds2Degs(TGT_RANGE),
                0);
        final WorldLocation newLoc = currentLocation.getLocation().add(newVector);

        // produce strings from this location
        final String theDepth = "" + newLoc.getDepth();
        final String theLat = "" + newLoc.getLat();
        final String theLong = "" + newLoc.getLong();

        // put these strings into the new behaviour
        working = replaceAll(working, "$TGT_DEPTH$", theDepth);
        working = replaceAll(working, "$TGT_LAT$", theLat);
        working = replaceAll(working, "$TGT_LONG$", theLong);
      }
    }

    if (theTarget != null) {
      // output the XML header stuff
      // output the plot
      final java.io.StringWriter newString = new StringWriter();
      //      final com.sun.xml.tree.XmlDocument doc = new com.sun.xml.tree.XmlDocument();
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      Document doc = null;
      try {
        DocumentBuilder builder = factory.newDocumentBuilder();
        doc = builder.newDocument();
        final org.w3c.dom.Element type =
            ASSET.Util.XML.Decisions.Util.TargetTypeHandler.getElement(theTarget, doc);
        doc.appendChild(type);
        doc.setNodeValue(type.getTagName());
        //    doc.changeNodeOwner(type);
        //   doc.setSystemId("ASSET XML Version 1.0");

        // Use a Transformer for output
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer transformer = tFactory.newTransformer();

        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(newString);
        transformer.transform(source, result);
      } catch (ParserConfigurationException e) {
        e.printStackTrace(); // To change body of catch statement use Options | File Templates.
      } catch (DOMException e) {
        e.printStackTrace(); // To change body of catch statement use Options | File Templates.
      } catch (TransformerFactoryConfigurationError transformerFactoryConfigurationError) {
        transformerFactoryConfigurationError
            .printStackTrace(); // To change body of catch statement use Options | File Templates.
      } catch (TransformerException e) {
        e.printStackTrace(); // To change body of catch statement use Options | File Templates.
      }

      //      // ok, we should be done now
      //      try
      //      {
      //        doc.write(newString);
      //      }
      //      catch(java.io.IOException e)
      //      {
      //        e.printStackTrace();
      //      }

      // try to extract the <target type portion
      if (newString != null) {
        final String val = newString.toString();
        final String startIdentifier = "<TargetType";
        final String endIdentifier = "</TargetType";
        final int start = val.indexOf(startIdentifier);
        final int end = val.lastIndexOf(endIdentifier);
        final String detail = val.substring(start, end + endIdentifier.length() + 1);

        // lastly, replace the string
        working = replaceAll(working, "<TargetType/>", detail);
      }
    }

    return working;
  }
Пример #12
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;
  }
Пример #13
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;
  }