@Override double getMinuteDelta(PlanningSegment seg) { // how far will we travel in time? double metresPerSec = seg.getSpeed().getValueIn(WorldSpeed.M_sec); double metresPerMin = metresPerSec * 60d; double distanceM = metresPerSec * getSecsTravelled(seg); WorldDistance wd = new WorldDistance(distanceM, WorldDistance.METRES); seg.setDistanceSilent(new WorldDistance(wd.getValueIn(WorldDistance.NM), WorldDistance.NM)); return metresPerMin; }
public final void setPatternBuoySpacing(WorldDistance val) { _spacing = val.getValueIn(WorldDistance.NM); }
/** 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; }
/** * 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; }
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; }
/** * set the depth to travel at (though -999 is treated as null value) * * @param theHeight */ public void setHeight(WorldDistance theHeight) { // just see if it's an invalid depth if (theHeight.getValueIn(WorldDistance.METRES) == INVALID_DEPTH) { _myHeight = null; } else _myHeight = theHeight; }