@Override public Rectangle getBounds() { bounds = new Rectangle(bv.getHexLocation(step.getPosition()), bv.hex_size); return bounds; }
public StepSprite(BoardView1 boardView1, final MoveStep step, boolean isLastStep) { super(boardView1); this.step = step; this.isLastStep = isLastStep; // step is the size of the hex that this step is in bounds = new Rectangle(bv.getHexLocation(step.getPosition()), bv.hex_size); image = null; baseScaleImage = null; }
public Set<Coords> getCoordsSet() { if (coordsSet != null) { return coordsSet; } synchronized (COORD_SET_LOCK) { if (coordsSet != null) { return coordsSet; } coordsSet = new HashSet<>(); for (MoveStep step : getStepVector()) { if (step.getPosition() == null) { continue; } coordsSet.add(step.getPosition()); } } return coordsSet; }
/** * Determines if the given move path is "redundant". * In this case, it means that the path has not visited any new hexes. * @param mp The move path to examine. * @return Whether or not the move path is redundant. */ // goes through a path. // if it does not take us off-board, records the coordinates it visits // returns true if this path visits hexes that have not been visited before protected boolean pathIsRedundant(MovePath mp) { boolean newHexVisited = false; if(!mp.fliesOffBoard()) { for(MoveStep step : mp.getStepVector()) { if(!visitedCoords.containsKey(step.getPosition())) { visitedCoords.put(step.getPosition(), mp); newHexVisited = true; } } } return newHexVisited; } }
public Coords getSecondFinalPosition(Coords startPos) { Coords priorPos = startPos; Coords finalPos = getFinalCoords(); // if we moved one or fewer hexes, then just return starting position if (getHexesMoved() < 2) { return priorPos; } for (final Enumeration<MoveStep> i = getSteps(); i.hasMoreElements(); ) { final MoveStep step = i.nextElement(); if (step.getPosition() != finalPos) { priorPos = step.getPosition(); } } return priorPos; }
/** * Returns the starting {@link Coords} of this path. */ @Nullable public Coords getStartCoords() { for (final Enumeration<MoveStep> e = getSteps(); e.hasMoreElements(); ) { final MoveStep step = e.nextElement(); final Coords coords = step.getPosition(); if (coords != null) { return coords; } } return null; }
/** * Method that determines whether a given path goes through a given set of x/y coordinates * Useful for debugging mainly. * Note that battletech map coordinates begin at 1, while the internal representation begins at 0 * so subtract 1 from each axis to get the actual coordinates. * @param x X-coordinate * @param y Y-coordinate * @return Whether this path goes through the set of coordinates. */ public boolean goesThroughCoords(int x, int y) { Enumeration<MoveStep> steps = getSteps(); while(steps.hasMoreElements()) { MoveStep step = steps.nextElement(); if(step.getPosition().getX() == x && step.getPosition().getY() == y) { return true; } } return false; }
/** * Apply PSR modifier for difficult terrain at the move step position * * @param roll the PSR to modify * @param step the move step the PSR occurs at */ public void addPilotingModifierForTerrain(PilotingRollData roll, MoveStep step) { if (step.getElevation() > 0) { return; } addPilotingModifierForTerrain(roll, step.getPosition()); }
/** * Checks if a target lies under a move path, to see if an aero unit can attack it. * * @param flightPath move path to check * @param targetState used for targets position * @return TRUE if the target is under the path. */ boolean isTargetUnderFlightPath(final MovePath flightPath, final EntityState targetState) { final Coords targetCoords = targetState.getPosition(); for (final Enumeration<MoveStep> step = flightPath.getSteps(); step.hasMoreElements(); ) { final Coords stepCoords = step.nextElement().getPosition(); if (targetCoords.equals(stepCoords)) { return true; } } return false; }
/** * Searches the path for the first <code>MoveStep</code> that matches the given position and sets it * as a strafing step. In cases where there are multiple steps with the same coordinates, we want the * first one because it is the one that enters the hex. In the rare case where the path crosses * itself, select the one closest to the end of the path. * * FIXME: this does not deal with paths that cross themselves * * @param pos The <code>Coords</code> of the hex to be strafed * @return Whether the position was found in the path */ public boolean setStrafingStep(Coords pos) { MoveStep found = null; for (int i = steps.size() - 1; i >= 0; i--) { if (steps.get(i).getPosition().equals(pos)) { found = steps.get(i); } else if (found != null) { found.setStrafing(true); return true; } } if (found != null) { found.setStrafing(true); return true; } return false; }
/** * Returns the highest elevation along a jump path. * * @return */ public Coords getJumpPathHighestPoint() { Coords highestCoords = null; int highestElevation = 0; for (MoveStep step : steps) { if (getGame().getBoard().getHex(step.getPosition()).getLevel() > highestElevation) { highestElevation = step.getElevation(); highestCoords = step.getPosition(); } } return highestCoords; }
/** * Returns the highest elevation in the current path * * @return */ public int getMaxElevation() { int maxElev = 0; for (MoveStep step : steps) { maxElev = Math.max(maxElev, getGame().getBoard().getHex(step.getPosition()).getLevel()); } return maxElev; }
/** * In hexes with buildings, returns the elevation relative to the roof. Otherwise returns the elevation * relative to the surface. */ public int getClearance() { IHex hex = entity.getGame().getBoard().getHex(getPosition()); if (hex.containsTerrain(Terrains.BLDG_ELEV)) { return elevation - hex.terrainLevel(Terrains.BLDG_ELEV); } return elevation; }
@Test public void testIsTargetUnderFlightPath() { // Test the target being under the path. Vector<MoveStep> pathSteps = new Vector<>(1); MoveStep mockStep = Mockito.mock(MoveStep.class); pathSteps.add(mockStep); MovePath mockPath = Mockito.mock(MovePath.class); Mockito.when(mockPath.getSteps()).thenReturn(pathSteps.elements()); Mockito.when(mockStep.getPosition()).thenReturn(mockTargetCoords); Assert.assertTrue(testFireControl.isTargetUnderFlightPath(mockPath, mockTargetState)); // Test the target not being under the path. pathSteps = new Vector<>(1); mockStep = Mockito.mock(MoveStep.class); pathSteps.add(mockStep); mockPath = Mockito.mock(MovePath.class); Mockito.when(mockPath.getSteps()).thenReturn(pathSteps.elements()); Mockito.when(mockStep.getPosition()).thenReturn(mockShooterCoords); Assert.assertFalse(testFireControl.isTargetUnderFlightPath(mockPath, mockTargetState)); }
/** * Turns VTOL bombing on or off for this step. */ public void setVTOLBombing(boolean bombing) { if (bombing) { setTarget(new HexTarget(getPosition(), getGame().getBoard(), Targetable.TYPE_HEX_AERO_BOMB)); } else { setTarget(null); } }
/** * Turns VTOL strafing on or off for this step. */ public void setStrafing(boolean strafing) { if (strafing) { setTarget(new HexTarget(getPosition(), getGame().getBoard(), Targetable.TYPE_HEX_CLEAR)); } else { setTarget(null); } }
/** * Worker method that adds "UP" and "DOWN" steps to the given move path collection if * the entity is eligible to do so * * @param result The collection of move paths to improve * @param last The last step along the parent move path * @param entity The entity taking the move path * @param movePath The parent movePath * @see AbstractPathFinder.AdjacencyMap */ void addUpAndDown(Collection<MovePath> result, final MoveStep last, final Entity entity, final MovePath mp) { Coords pos; int elevation; pos = last != null ? last.getPosition() : entity.getPosition(); elevation = last != null ? last.getElevation() : entity.getElevation(); if (entity.canGoUp(elevation, pos)) { result.add(mp.clone().addStep(MoveStepType.UP)); } if (entity.canGoDown(elevation, pos)) { result.add(mp.clone().addStep(MoveStepType.DOWN)); } } }
/** * Searches the movement path for the first step that has the given position and sets it as * a VTOL bombing step. If found, any previous bombing step is cleared. If the coordinates are not * part of the path nothing is changed. * * @param pos The <code>Coords</code> of the hex to be bombed. * @return Whether the position was found in the movement path */ public boolean setVTOLBombStep(Coords pos) { boolean foundPos = false; MoveStep prevBombing = null; for (MoveStep step : steps) { if (step.getPosition().equals(pos)) { if (step.isVTOLBombingStep()) { return true; } else { step.setVTOLBombing(true); foundPos = true; } } else if (step.isVTOLBombingStep()) { prevBombing = step; } } if (foundPos && prevBombing != null) { prevBombing.setVTOLBombing(false); } return foundPos; }
/** * 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; } }
/** * Returns the final coordinates if a mech were to perform all the steps in * this path. */ public Coords getFinalCoords() { if(getGame().useVectorMove()) { return Compute.getFinalPosition(getEntity().getPosition(), getFinalVectors()); } if (getLastStep() != null) { return getLastStep().getPosition(); } return getEntity().getPosition(); }