/** * Invalidate all paths that go through this set of coordinates (because of a building or bridge collapse), or some other terrain change * either directly or by connecting to a path that goes through this set of coordinates. * @param coords */ public void invalidatePaths(Coords coords) { // identify if this set of coordinates has a path that leads to an edge // loop through all paths in the path cache destined for the edge, and invalidate the ones that connect to the initial identified path // invalidate the first path for(Map<Coords, MovePath> coordinatePaths : edgePathCache.values()) { MovePath directPath = coordinatePaths.get(coords); if(directPath != null) { // first, clear out all cached coordinate-path entries for this path for(Coords pathCoords : directPath.getCoordsSet()) { coordinatePaths.remove(pathCoords); } // for each path that connects to this path, invalidate it if(connectedPaths.containsKey(directPath)) { for(MovePath connectedPath : connectedPaths.get(directPath)) { invalidatePaths(connectedPath.getStartCoords()); } } } } }
for(Coords coords : path.getCoordsSet()) { if(!coordinatePathMap.containsKey(coords) || coordinatePathMap.get(coords).getMpUsed() > path.getMpUsed()) {
private void adjustPathForBridge(MovePath path) { boolean needsAdjust = false; for (Coords c : path.getCoordsSet()) { IHex hex = getGame().getBoard().getHex(c); if ((hex != null) && hex.containsTerrain(Terrains.BRIDGE)) { if (getGame().getBoard().getBuildingAt(c).getCurrentCF(c) >= path.getEntity().getWeight()) { needsAdjust = true; break; } else { needsAdjust = false; break; } } } if (!needsAdjust) { return; } MovePath adjusted = new MovePath(getGame(), path.getEntity()); adjusted.addStep(MoveStepType.CLIMB_MODE_ON); adjusted.addSteps(path.getStepVector(), true); adjusted.addStep(MoveStepType.CLIMB_MODE_OFF); path.replaceSteps(adjusted.getStepVector()); }