MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / getPreciseRecipeForMaterials

Method getPreciseRecipeForMaterials

source/game/StarItemDatabase.cpp:321–351  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

319}
320
321ItemRecipe ItemDatabase::getPreciseRecipeForMaterials(String const& group, List<ItemPtr> const& bag, StringMap<uint64_t> const& availableCurrencies) const {
322 // picks the recipe that:
323 // * can be crafted (duh)
324 // * uses all the input material types
325 // * uses the most materials (if recipes exist with the same input materials)
326
327 auto options = recipesFromBagContents(bag, availableCurrencies);
328 ItemRecipe result;
329 int ingredientsCount = 0;
330 for (auto const& recipe : options) {
331 if (!recipe.groups.contains(group))
332 continue;
333 bool usesAllItemTypes = true;
334 for (auto const& item : bag) {
335 bool match = false;
336 for (auto const& input : recipe.inputs)
337 if (item->matches(input, recipe.matchInputParameters))
338 match = true;
339 if (!match)
340 usesAllItemTypes = false;
341 }
342 if (!usesAllItemTypes)
343 continue;
344 int count = 0;
345 for (auto const& input : recipe.inputs)
346 count += input.count();
347 if (count > ingredientsCount)
348 result = recipe;
349 }
350 return result;
351}
352
353ItemRecipe ItemDatabase::parseRecipe(Json const& config) const {
354 ItemRecipe res;

Callers 1

recipeForMaterialsMethod · 0.80

Calls 3

containsMethod · 0.45
matchesMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected