Esempio n. 1
0
  /**
   * subtract the two points to produce a vector
   *
   * @param other the offset to add to this point
   * @return a new point
   */
  public final WorldDistance rangeFrom(final WorldLocation other, final WorldDistance res) {
    // check we have our model
    if (_model == null) {
      _model = new MWC.Algorithms.EarthModels.FlatEarth();
    }

    // ok, how far apart are they?
    final WorldVector sep = _model.subtract(other, this);

    // update the results object
    res.setValues(sep.getRange(), WorldDistance.DEGS);

    // and return it.
    return res;
  }
Esempio n. 2
0
  public boolean actPrimary(
      ServerInterface server,
      LocalConfiguration config,
      LocalPlayer player,
      LocalSession session,
      WorldVector clicked) {

    BlockBag bag = session.getBlockBag(player);

    LocalWorld world = clicked.getWorld();
    EditSession editSession =
        WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1, bag, player);

    try {
      editSession.setBlock(clicked, targetBlock);
    } catch (MaxChangedBlocksException e) {
    } finally {
      if (bag != null) {
        bag.flushChanges();
      }
      session.remember(editSession);
    }

    return true;
  }
Esempio n. 3
0
  public boolean actPrimary(
      ServerInterface server,
      LocalConfiguration config,
      LocalPlayer player,
      LocalSession session,
      WorldVector clicked) {

    EditSession editSession = session.createEditSession(player);

    try {
      boolean successful = false;

      for (int i = 0; i < 10; i++) {
        if (gen.generate(editSession, clicked.add(0, 1, 0))) {
          successful = true;
          break;
        }
      }

      if (!successful) {
        player.printError("A tree can't go there.");
      }
    } catch (MaxChangedBlocksException e) {
      player.printError("Max. blocks changed reached.");
    } finally {
      session.remember(editSession);
    }

    return true;
  }
Esempio n. 4
0
  /**
   * note that ADD returns a new object, this remains constant
   *
   * @param delta the offset to add to this point
   * @return a new point
   */
  public final WorldLocation add(final WorldVector delta) {
    // check we have our model
    if (_model == null) {
      _model = new MWC.Algorithms.EarthModels.FlatEarth();
    }

    // do the calculation with our current model

    // do we have a range?
    final WorldLocation res;

    if ((delta.getRange() == 0) && (delta.getDepth() == 0)) {
      res = new WorldLocation(this);
    } else {
      res = new WorldLocation(_model.add(this, delta));
    }

    // and return the resutls
    return res;
  }
Esempio n. 5
0
  @Override
  public boolean act(
      ServerInterface server,
      LocalConfiguration config,
      LocalPlayer player,
      LocalSession session,
      WorldVector clicked) {

    LocalWorld world = clicked.getWorld();
    EditSession editSession = new EditSession(server, world, session.getBlockChangeLimit());

    try {
      editSession.makePineTree(clicked.add(0, 1, 0));
    } catch (MaxChangedBlocksException e) {
      player.printError("Max blocks change limit reached.");
    } finally {
      session.remember(editSession);
    }

    return true;
  }
Esempio n. 6
0
  public boolean actSecondary(
      ServerInterface server,
      LocalConfiguration config,
      LocalPlayer player,
      LocalSession session,
      WorldVector clicked) {

    LocalWorld world = clicked.getWorld();
    EditSession editSession =
        WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1, player);
    targetBlock = (editSession).getBlock(clicked);
    BlockType type = BlockType.fromID(targetBlock.getType());

    if (type != null) {
      player.print("Replacer tool switched to: " + type.getName());
    }

    return true;
  }
Esempio n. 7
0
 public final void setSubtract() {
   final WorldVector wvv = w4.subtract(w1);
   assertTrue(wvv.equals(wv1));
 }
Esempio n. 8
0
  /**
   * calculate the bearing from the other point (rads)
   *
   * @return the bearing (rads)
   */
  public final double bearingFrom(final WorldLocation other) {
    final WorldVector res = subtract(other, _myWorldVector);

    return res.getBearing();
  }
Esempio n. 9
0
  /**
   * calculate the range from the other point (Degs)
   *
   * @return the range (in degrees)
   */
  public final double rangeFrom(final WorldLocation other) {
    final WorldVector res = subtract(other, _myWorldVector);

    return res.getRange();
  }
Esempio n. 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();
      }
    }
Esempio n. 11
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;
  }