public AIUnit yieldUnit(UnitType ut, AIObject o) {
        float unitWeight = 99f;
        AIUnit yieldedUnit = null;
        boolean isOwnUnit = false;


        Iterator<AIUnit> uit = getOwnedAIUnitsIterator();
        while (uit.hasNext()) {
            AIUnit u = uit.next();
            //all units in one goal have the same weight, so no need to compare
            if (u.getUnit().getType().equals(ut)) {
                unitWeight = getAbsoluteWeight();
                yieldedUnit = u;
                isOwnUnit = true;
            }
        }
        //check subgoals
        Iterator<Goal> git = getSubGoalIterator();
        while (git!=null && git.hasNext()) {
            Goal g = git.next();
            float newWeight = g.getYieldedUnitWeight(ut, o);
            if (newWeight < unitWeight) {
                unitWeight = newWeight;
                yieldedUnit = g.yieldUnit(ut, o);
                isOwnUnit = false;
            }
        }
        if (isOwnUnit) {
            removeUnit(yieldedUnit);
            needsPlanning = true;
        }
        return yieldedUnit;
    }