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!"); } } }