private int buildWallSegment( Player player, BlockCoord first, BlockCoord second, int blockCount, HashMap<String, SimpleBlock> simpleBlocks, int verticalSegments) throws CivException { Location locFirst = first.getLocation(); Location locSecond = second.getLocation(); Vector dir = new Vector( locFirst.getX() - locSecond.getX(), locFirst.getY() - locSecond.getY(), locFirst.getZ() - locSecond.getZ()); dir.normalize(); dir.multiply(0.5); HashMap<String, SimpleBlock> thisWallBlocks = new HashMap<String, SimpleBlock>(); this.getTown().lastBuildableBuilt = null; getVerticalWallSegment(player, locSecond, thisWallBlocks); simpleBlocks.putAll(thisWallBlocks); verticalSegments++; double distance = locSecond.distance(locFirst); BlockCoord lastBlockCoord = new BlockCoord(locSecond); BlockCoord currentBlockCoord = new BlockCoord(locSecond); while (locSecond.distance(locFirst) > 1.0) { locSecond.add(dir); ChunkCoord coord = new ChunkCoord(locSecond); CivGlobal.addWallChunk(this, coord); currentBlockCoord.setFromLocation(locSecond); if (lastBlockCoord.equals(currentBlockCoord)) { continue; } else { lastBlockCoord.setFromLocation(locSecond); } blockCount++; if (blockCount > Wall.RECURSION_LIMIT) { throw new CivException( "ERROR: Building wall blocks exceeded recusion limit! Halted to keep server alive."); } getVerticalWallSegment(player, locSecond, thisWallBlocks); simpleBlocks.putAll(thisWallBlocks); verticalSegments++; // Distance should always be going down, as a failsave // check that it is. Abort if our distance goes up. double tmpDist = locSecond.distance(locFirst); if (tmpDist > distance) { break; } } /* build the last wall segment. */ if (!wallBlocks.containsKey(new BlockCoord(locFirst))) { try { getVerticalWallSegment(player, locFirst, thisWallBlocks); simpleBlocks.putAll(thisWallBlocks); verticalSegments++; } catch (CivException e) { CivLog.warning("Couldn't build the last wall segment, oh well."); } } for (SimpleBlock sb : simpleBlocks.values()) { BlockCoord bcoord = new BlockCoord(sb); int old_id = ItemManager.getId(bcoord.getBlock()); int old_data = ItemManager.getData(bcoord.getBlock()); if (!wallBlocks.containsKey(bcoord)) { try { WallBlock wb = new WallBlock(bcoord, this, old_id, old_data, sb.getType(), sb.getData()); wallBlocks.put(bcoord, wb); this.addStructureBlock(bcoord, true); wb.save(); } catch (SQLException e) { e.printStackTrace(); } } } return verticalSegments; }