/** * 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); } } }
/** * Handle fighter kamikaze. * * @param world the world * @param p the player */ static void handleKamikaze(SpacewarWorld world, Player p) { if (!world.battle().enemyFlee) { for (SpacewarStructure s : world.structures(p)) { s.guard |= s.type == StructureType.STATION || s.type == StructureType.PROJECTOR; if (s.type == StructureType.SHIP && s.item != null && s.item.type.category == ResearchSubCategory.SPACESHIPS_FIGHTERS && s.attack != null && !s.attack.isDestroyed()) { if (s.count == 1 && s.hp * 10 < s.hpMax) { world.attack(s, s.attack, Mode.KAMIKAZE); } } } } }