コード例 #1
0
  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();
  }
コード例 #2
0
ファイル: LaunchWeapon.java プロジェクト: waqas64/debrief
    // 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();
      }
    }