16
Bug Reports & Support / Re: Random Code Mistakes Thread
« on: February 03, 2022, 02:50:12 PM »Code: java
protected ShipAPI findTarget(ShipAPI ship) {
float range = getMaxRange(ship);
boolean player = ship == Global.getCombatEngine().getPlayerShip();
ShipAPI target = ship.getShipTarget();
if (target != null) {
float dist = Misc.getDistance(ship.getLocation(), target.getLocation());
float radSum = ship.getCollisionRadius() + target.getCollisionRadius();
if (dist > range + radSum) target = null;
/* no ally check if have target */
} else {
/* ally check only if target is null */
if (target == null || target.getOwner() == ship.getOwner()) {
if (player) {
target = Misc.findClosestShipEnemyOf(ship, ship.getMouseTarget(), HullSize.FIGHTER, range, true);
} else {
Object test = ship.getAIFlags().getCustom(AIFlags.MANEUVER_TARGET);
if (test instanceof ShipAPI) {
target = (ShipAPI) test;
float dist = Misc.getDistance(ship.getLocation(), target.getLocation());
float radSum = ship.getCollisionRadius() + target.getCollisionRadius();
if (dist > range + radSum) target = null;
}
}
}
if (target == null) {
target = Misc.findClosestShipEnemyOf(ship, ship.getLocation(), HullSize.FIGHTER, range, true);
}
}
return target;
}