本文整理汇总了C++中inventory::has_items_with_quality方法的典型用法代码示例。如果您正苦于以下问题:C++ inventory::has_items_with_quality方法的具体用法?C++ inventory::has_items_with_quality怎么用?C++ inventory::has_items_with_quality使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inventory
的用法示例。
在下文中一共展示了inventory::has_items_with_quality方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: check_enough_materials
bool requirements::check_enough_materials( const item_comp& comp, const inventory& crafting_inv ) const
{
if( comp.available != a_true ) {
return false;
}
const itype *it = item_controller->find_template( comp.type );
const tool_comp *tq = find_by_type( tools, comp.type );
if( tq != nullptr ) {
// The very same item type is also needed as tool!
// Use charges of it, or use it by count?
const int tc = tq->count < 0 ? std::abs( tq->count ) : 1;
// Check for components + tool count. Check item amount (excludes
// pseudo items) and tool amount (includes pseudo items)
// Imagine: required = 1 welder (component) + 1 welder (tool),
// available = 1 welder (real item), 1 welding rig (creates
// a pseudo welder item). has_components(welder,2) returns false
// as there is only one real welder available, but has_tools(welder,2)
// returns true.
// Keep in mind that both requirements (tool+component) are checked
// before this. That assures that one real item is actually available,
// two welding rigs (and no real welder) would make this component
// non-available even before this function is called.
// Only ammo and (some) food is counted by charges, both are unlikely
// to appear as tool, but it's possible /-:
bool has_comps;
if( it->count_by_charges() && comp.count > 0 ) {
has_comps = crafting_inv.has_charges( comp.type, comp.count + tc );
} else {
has_comps = crafting_inv.has_components( comp.type, abs( comp.count ) + tc );
}
if( !has_comps && !crafting_inv.has_tools( comp.type, comp.count + tc ) ) {
comp.available = a_insufficent;
}
}
for( const auto &ql : it->qualities ) {
const quality_requirement *qr = find_by_type( qualities, ql.first );
if( qr == nullptr || qr->level > ql.second ) {
continue;
}
// This item can be used for the quality requirement, same as above for specific
// tools applies.
if( !crafting_inv.has_items_with_quality( qr->type, qr->level, qr->count + abs(comp.count) ) ) {
comp.available = a_insufficent;
}
}
return comp.available == a_true;
}
示例2: has
bool quality_requirement::has( const inventory &crafting_inv, int ) const
{
return crafting_inv.has_items_with_quality( type, level, count );
}