예제 #1
0
 // returns the quality of the ingredients conditioning given recipe, -1 if
 // no recipe is near them
 public int getIngredientQuality(BRecipe recipe) {
   float quality = 10;
   int count;
   int badStuff = 0;
   if (recipe.isMissingIngredients(ingredients)) {
     // when ingredients are not complete
     return -1;
   }
   for (Material ingredient : ingredients.keySet()) {
     count = ingredients.get(ingredient);
     if (recipe.amountOf(ingredient) == 0) {
       // this ingredient doesnt belong into the recipe
       if (count > (getIngredientsCount() / 2)) {
         // when more than half of the ingredients dont fit into the
         // recipe
         return -1;
       }
       badStuff++;
       if (badStuff < ingredients.size()) {
         // when there are other ingredients
         quality -= count * (recipe.getDifficulty() / 2);
         continue;
       } else {
         // ingredients dont fit at all
         return -1;
       }
     }
     // calculate the quality
     quality -=
         ((float) Math.abs(count - recipe.amountOf(ingredient))
                 / recipe.allowedCountDiff(recipe.amountOf(ingredient)))
             * 10.0;
   }
   if (quality >= 0) {
     return Math.round(quality);
   }
   return -1;
 }