/** * Returns filtered collection by removing those objects that fail * {@link #shouldStay(T)} test. * * @param collection collection to be filtered * @return filtered collection */ @Override public Collection<MovePath> doFilter(Collection<MovePath> collection) { List<MovePath> filteredMoves = new ArrayList<>(); for (MovePath e : collection) { // if the path does not go off board, then we add it to the returned collection if (shouldStay(e)) { filteredMoves.add(e); } else { // if the path *does* go off board, we want to compare its length to // our current shortest off-board path and keep it in mind if it's both shorter and safe // at the end of the process, we will add the shortest path off board to the list of moves if(shortestPath == null || (shortestPath.length() > e.length()) && AeroPathUtil.isSafePathOffBoard(e)) { shortestPath = e; } } } return filteredMoves; }
private void LogAeroMoveLegalityEvaluation(String whyNot, MovePath path) { this.getOwner().log(this.getClass(), "isLegalAeroMove", LogLevel.DEBUG, path.length() + ":" + path.toString() + ":" + whyNot); }
@Override public String toString() { final StringBuffer sb = new StringBuffer(); sb.append("MOVE PATH:"); sb.append(this.getKey().hashCode()); sb.append(' '); // it's useful to know for debugging purposes which path you're looking at. sb.append("Length: " + this.length()); sb.append("Final Coords: " + this.getFinalCoords()); sb.append(System.lineSeparator()); for (final Enumeration<MoveStep> i = steps.elements(); i.hasMoreElements(); ) { sb.append(i.nextElement().toString()); sb.append(' '); } if(!getGame().getBoard().contains(this.getFinalCoords())) { sb.append("OUT!"); } if(this.getFliesOverEnemy()) { sb.append("E! "); } return sb.toString(); }
if(path.length() == 0) { return;
MovePath returnPath = ((candidates.get(0).length() == 1) && (cachedPath != null)) ? cachedPath : candidates.get(0);
private void updateRecklessButton() { final Entity ce = ce(); if (null == ce) { return; } if (ce.isAirborne()) { setRecklessEnabled(false); } if (ce instanceof Protomech) { setRecklessEnabled(false); } else { setRecklessEnabled((null == cmd) || (cmd.length() == 0)); } }
if(startingPath.length() > 0) { return paths;
@Override public boolean shouldStay(MovePath edge) { if (edge.getEntity().isAero()) { /* * isMovemementPossible is currently not working for aero units, * so we have to use a substitute. */ if (edge.length() == 0) { return true; } else { MoveStep lastStep = edge.getLastStep(); return (lastStep == null) || lastStep.getMovementType(true) != EntityMovementType.MOVE_ILLEGAL; } } Coords previousPosition; int previousElevation; if (edge.length() > 1) { MoveStep previousStep = edge.getSecondLastStep(); previousElevation = previousStep.getElevation(); previousPosition = previousStep.getPosition(); } else { Entity entity = edge.getEntity(); previousElevation = entity.getElevation(); previousPosition = entity.getPosition(); } return (edge.getLastStep().isMovementPossible( game, previousPosition, previousElevation)); } }
/** * Returns true if last step reduces distance to destination or if the * last step is a turn, get_up... . */ @Override public boolean shouldStay(MovePath movePath) { if (movePath.length() < 2) return true; MoveStep prevStep = movePath.getSecondLastStep(); Coords prevC = prevStep.getPosition(); int prevDist = dest.distance(prevC), mpDist = dest.distance(movePath.getFinalCoords()); if (prevDist > mpDist) return true; if (prevDist == mpDist) { //the distance has not changed //if we are in the same hex, then we are changing facing and it's ok. return prevC.equals(movePath.getFinalCoords()); } return false; } }
private void removeLastStep() { cmd.removeLastStep(); if (cmd.length() == 0) { clear(); if ((gear == MovementDisplay.GEAR_JUMP) && (!cmd.isJumping())) { cmd.addStep(MoveStepType.START_JUMP); } else if (ce().isConvertingNow()) { cmd.addStep(MoveStepType.CONVERT_MODE); } } else { clientgui.bv.drawMovementData(ce(), cmd); clientgui.bv.setWeaponFieldofFire(ce(), cmd); // Set the button's label to "Done" // if the entire move is impossible. MovePath possible = cmd.clone(); possible.clipToPossible(); if (possible.length() == 0) { butDone.setText("<html><b>" + Messages.getString("MovementDisplay.Done") + "</b></html>"); //$NON-NLS-1$ } } updateButtons(); }
private synchronized void updateTakeOffButtons() { if ((null != cmd) && (cmd.length() > 0)) { // you can't take off if you have already moved // http://www.classicbattletech.com/forums/index.php?topic=54112.0 setTakeOffEnabled(false); setVTakeOffEnabled(false); return; } final Entity ce = ce(); if (null == ce) { return; } if (ce.isAero()) { if (ce.isAirborne()) { setTakeOffEnabled(false); setVTakeOffEnabled(false); } else if (!ce.isShutDown()) { setTakeOffEnabled(((IAero) ce).canTakeOffHorizontally()); setVTakeOffEnabled(((IAero) ce).canTakeOffVertically()); } } else { setTakeOffEnabled(false); setVTakeOffEnabled(false); } }
private synchronized void updateLandButtons() { if ((null != cmd) && (cmd.length() > 0)) {
if ((cmd.length() > 0) || (cen == Entity.NONE)) { setLoadEnabled(false); setTowEnabled(false);
private void updateConvertModeButton() { if (cmd.length() > 0 && cmd.getLastStep().getType() != MoveStepType.CONVERT_MODE) { setModeConvertEnabled(false); return;
if (possible.length() == 0) { butDone.setText("<html><b>" + Messages.getString("MovementDisplay.Done")