/** * Orders the given structure to attack a random enemy. * * @param world the world * @param ship the ship */ public static void defaultAttackBehavior(SpacewarWorld world, SpacewarStructure ship) { if (ship.canDirectFire()) { if (ship.type == StructureType.STATION || ship.type == StructureType.PROJECTOR) { ship.guard = true; selectNewTarget(world, ship); } else if (ship.type == StructureType.SHIP) { selectNewTarget(world, ship); } } }
/** * Attack out-of-range ships with the remaining idles. * * @param world the world object * @param idles the list of idles * @return all enemies */ static List<SpacewarStructure> defaultAttackOutOfRange( SpacewarWorld world, List<SpacewarStructure> idles) { List<SpacewarStructure> esl = new ArrayList<>(); if (!idles.isEmpty()) { esl.addAll(world.enemiesOf(idles.get(0))); } if (!esl.isEmpty()) { List<SpacewarStructure> esl2 = U.newArrayList(esl); for (SpacewarStructure ship : idles) { if (ship.attack == null && ship.type == StructureType.SHIP && ship.canDirectFire()) { SpacewarStructure t = selectNewTarget(world, ship, esl); if (t != null) { esl.remove(t); if (esl.isEmpty()) { esl.addAll(esl2); } } } } } return esl; }