/** * Assign a carrier for this treasure. * * @param lb A <code>LogBuilder</code> to log to. * @return A suitable carrier <code>AIUnit</code>, to which this unit has been queued for * transport. */ private AIUnit assignCarrier(LogBuilder lb) { final AIUnit aiUnit = getAIUnit(); final Unit unit = getUnit(); final Player player = unit.getOwner(); final Europe europe = player.getEurope(); List<Unit> carriers = player.getCarriersForUnit(unit); if (carriers.isEmpty()) return null; // Pick the closest carrier and queue this unit. final Location here = unit.getLocation(); int turns = INFINITY; Unit closest = null; for (Unit c : carriers) { int t = c.getTurnsToReach(here); if (turns > t) { turns = t; closest = c; } } final AIMain aiMain = getAIMain(); TransportMission tm; AIUnit aiCarrier; if (closest != null && (aiCarrier = aiMain.getAIUnit(closest)) != null && (tm = aiCarrier.getMission(TransportMission.class)) != null) { setTarget(europe); aiUnit.changeTransport(aiCarrier); if (tm.forceCollection(aiUnit, lb)) { lb.add(" forced collection on ", aiCarrier.getUnit()); return aiCarrier; } } return null; }