Skip to content

Commit

Permalink
Don't consider blacklisted recipes for nutrients
Browse files Browse the repository at this point in the history
The nutrient predictions were based on a list of recipes cached in each
item.  It turns out that list could end up with invalid recipe_ids if
those recipes became blacklisted.

Detect that case and avoid adding such recipes to the list.
  • Loading branch information
jbytheway committed Dec 22, 2019
1 parent 853b4b4 commit 065d355
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ void Item_factory::finalize()
// for each item register all (non-obsolete) potential recipes
for( const std::pair<const recipe_id, recipe> &p : recipe_dict ) {
const recipe &rec = p.second;
if( rec.obsolete ) {
if( rec.obsolete || rec.will_be_blacklisted() ) {
continue;
}
const itype_id &result = rec.result();
Expand Down
17 changes: 17 additions & 0 deletions src/recipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,23 @@ std::string recipe::result_name() const
return name;
}

bool recipe::will_be_blacklisted() const
{
if( requirements_.is_blacklisted() ) {
return true;
}

auto any_is_blacklisted = []( const std::vector<std::pair<requirement_id, int>> &reqs ) {
auto req_is_blacklisted = []( const std::pair<requirement_id, int> &req ) {
return req.first->is_blacklisted();
};

return std::any_of( reqs.begin(), reqs.end(), req_is_blacklisted );
};

return any_is_blacklisted( reqs_internal ) || any_is_blacklisted( reqs_external );
}

std::function<bool( const item & )> recipe::get_component_filter() const
{
const item result = create_result();
Expand Down
4 changes: 4 additions & 0 deletions src/recipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class recipe
return requirements_.is_blacklisted();
}

// Slower equivalent of is_blacklisted that needs to be used before
// recipe finalization happens
bool will_be_blacklisted() const;

std::function<bool( const item & )> get_component_filter() const;

/** Prevent this recipe from ever being added to the player's learned recipies ( used for special NPC crafting ) */
Expand Down

0 comments on commit 065d355

Please sign in to comment.