public void onHit() { // launchExplodeFirework(loc); int radius = (int) yield; HashSet<Buildable> structuresHit = new HashSet<Buildable>(); for (int x = -radius; x < radius; x++) { for (int z = -radius; z < radius; z++) { for (int y = -radius; y < radius; y++) { Block b = loc.getBlock().getRelative(x, y, z); if (ItemManager.getId(b) == CivData.BEDROCK) { continue; } if (loc.distance(b.getLocation()) <= yield) { bcoord.setFromLocation(b.getLocation()); StructureBlock sb = CivGlobal.getStructureBlock(bcoord); CampBlock cb = CivGlobal.getCampBlock(bcoord); if (sb == null && cb == null) { explodeBlock(b); continue; } if (sb != null) { if (!sb.isDamageable()) { continue; } if (sb.getOwner() instanceof TownHall) { TownHall th = (TownHall) sb.getOwner(); if (th.getControlPoints().containsKey(bcoord)) { continue; } } if (!sb.getOwner().isDestroyed()) { if (!structuresHit.contains(sb.getOwner())) { structuresHit.add(sb.getOwner()); if (sb.getOwner() instanceof TownHall) { TownHall th = (TownHall) sb.getOwner(); if (th.getHitpoints() == 0) { explodeBlock(b); } else { th.onCannonDamage(cannon.getDamage()); } } else { Player player = null; try { player = CivGlobal.getPlayer(whoFired); } catch (CivException e) { } if (!sb.getCiv().getDiplomacyManager().atWarWith(whoFired.getCiv())) { if (player != null) { CivMessage.sendError( player, "Cannot damage structures in civilizations we're not at war with."); return; } } sb.getOwner() .onDamage(cannon.getDamage(), b.getWorld(), player, sb.getCoord(), sb); CivMessage.sendCiv( sb.getCiv(), CivColor.Yellow + "Our " + sb.getOwner().getDisplayName() + " at (" + sb.getOwner().getCenterLocation().getX() + "," + sb.getOwner().getCenterLocation().getY() + "," + sb.getOwner().getCenterLocation().getZ() + ")" + " was hit by a cannon! (" + sb.getOwner().getHitpoints() + "/" + sb.getOwner().getMaxHitPoints() + ")"); } CivMessage.sendCiv( whoFired.getCiv(), CivColor.LightGreen + "We've hit " + sb.getOwner().getTown().getName() + "'s " + sb.getOwner().getDisplayName() + " with a cannon!" + " (" + sb.getOwner().getHitpoints() + "/" + sb.getOwner().getMaxHitPoints() + ")"); } } else { if (!IronCannon.cannonBlocks.containsKey(bcoord)) { explodeBlock(b); } } continue; } } } } } /* Instantly kill any players caught in the blast. */ LinkedList<Entity> players = EntityProximity.getNearbyEntities(null, loc, yield, EntityPlayer.class); for (Entity e : players) { Player player = (Player) e; player.damage(playerDamage); if (player.isDead()) { CivMessage.global( CivColor.LightGray + whoFired.getName() + " obliterated " + player.getName() + " with a cannon blast!"); } } }
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; }