当前位置: 首页>>代码示例>>C++>>正文


C++ inventory类代码示例

本文整理汇总了C++中inventory的典型用法代码示例。如果您正苦于以下问题:C++ inventory类的具体用法?C++ inventory怎么用?C++ inventory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了inventory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: switch

std::vector<comp_selection<tool_comp>> craft_command::check_tool_components_missing(
                                        const inventory &map_inv ) const
{
    std::vector<comp_selection<tool_comp>> missing;

    for( const auto &tool_sel : tool_selections ) {
        itype_id type = tool_sel.comp.type;
        if( tool_sel.comp.count > 0 ) {
            long count = tool_sel.comp.count * batch_size;
            switch( tool_sel.use_from ) {
                case use_from_player:
                    if( !crafter->has_charges( type, count ) ) {
                        missing.push_back( tool_sel );
                    }
                    break;
                case use_from_map:
                    if( !map_inv.has_charges( type, count ) ) {
                        missing.push_back( tool_sel );
                    }
                    break;
                case use_from_both:
                case use_from_none:
                case cancel:
                    break;
            }
        } else if( !crafter->has_amount( type, 1 ) && !map_inv.has_tools( type, 1 ) ) {
            missing.push_back( tool_sel );
        }
    }

    return missing;
}
开发者ID:BevapDin,项目名称:Cataclysm-DDA,代码行数:32,代码来源:craft_command.cpp

示例2: has

bool tool_comp::has( const inventory &crafting_inv, int batch ) const
{
    if( !by_charges() ) {
        return crafting_inv.has_tools( type, std::abs( count ) );
    } else {
        return crafting_inv.has_charges( type, count * batch );
    }
}
开发者ID:1942rob,项目名称:Cataclysm-DDA,代码行数:8,代码来源:requirements.cpp

示例3: abs

std::vector<comp_selection<item_comp>> craft_command::check_item_components_missing(
                                        const inventory &map_inv ) const
{
    std::vector<comp_selection<item_comp>> missing;

    for( const auto &item_sel : item_selections ) {
        itype_id type = item_sel.comp.type;
        item_comp component = item_sel.comp;
        long count = ( component.count > 0 ) ? component.count * batch_size : abs( component.count );

        if( item::count_by_charges( type ) && count > 0 ) {
            switch( item_sel.use_from ) {
                case use_from_player:
                    if( !crafter->has_charges( type, count ) ) {
                        missing.push_back( item_sel );
                    }
                    break;
                case use_from_map:
                    if( !map_inv.has_charges( type, count ) ) {
                        missing.push_back( item_sel );
                    }
                    break;
                case use_from_both:
                    if( !( crafter->charges_of( type ) + map_inv.charges_of( type ) >= count ) ) {
                        missing.push_back( item_sel );
                    }
                    break;
                case use_from_none:
                case cancel:
                    break;
            }
        } else {
            // Counting by units, not charges.
            switch( item_sel.use_from ) {
                case use_from_player:
                    if( !crafter->has_amount( type, count ) ) {
                        missing.push_back( item_sel );
                    }
                    break;
                case use_from_map:
                    if( !map_inv.has_components( type, count ) ) {
                        missing.push_back( item_sel );
                    }
                    break;
                case use_from_both:
                    if( !( crafter->amount_of( type ) + map_inv.amount_of( type ) >= count ) ) {
                        missing.push_back( item_sel );
                    }
                    break;
                case use_from_none:
                case cancel:
                    break;
            }
        }
    }

    return missing;
}
开发者ID:BevapDin,项目名称:Cataclysm-DDA,代码行数:58,代码来源:craft_command.cpp

示例4: player_can_build

bool player_can_build(player &p, inventory pinv, construction *con)
{
    if (p.skillLevel("carpentry") < con->difficulty) {
        return false;
    }

    bool has_tool = false;
    bool has_component = false;
    bool tools_required = false;
    bool components_required = false;

    for (int j = 0; j < con->tools.size(); j++) {
        if (con->tools[j].size() > 0) {
            tools_required = true;
            has_tool = false;
            for (unsigned k = 0; k < con->tools[j].size(); k++) {
                if (pinv.has_amount(con->tools[j][k].type, 1)) {
                    has_tool = true;
                    con->tools[j][k].available = 1;
                } else {
                    con->tools[j][k].available = -1;
                }
            }
            if (!has_tool) { // missing one of the tools for this stage
                break;
            }
        }
    }

    for (int j = 0; j < con->components.size(); ++j) {
        if (con->components[j].size() > 0) {
            components_required = true;
            has_component = false;
            for (unsigned k = 0; k < con->components[j].size(); k++) {
                if (( item_controller->find_template(con->components[j][k].type)->is_ammo() &&
                      pinv.has_charges(con->components[j][k].type,
                                       con->components[j][k].count)    ) ||
                    (!item_controller->find_template(con->components[j][k].type)->is_ammo() &&
                      pinv.has_amount (con->components[j][k].type,
                                       con->components[j][k].count)    ))
                {
                    has_component = true;
                    con->components[j][k].available = 1;
                } else {
                    con->components[j][k].available = -1;
                }
            }
            if (!has_component) { // missing one of the comps for this stage
                break;
            }
        }
    }

    return (has_component || !components_required) &&
           (has_tool || !tools_required);
}
开发者ID:Ferk,项目名称:Cataclysm-DDA,代码行数:56,代码来源:construction.cpp

示例5: get_color

std::string tool_comp::get_color( bool has_one, const inventory &crafting_inv, int batch ) const
{
    if( available == a_insufficent ) {
        return "brown";
    } else if( !by_charges() && crafting_inv.has_tools( type, std::abs( count ) ) ) {
        return "green";
    } else if( by_charges() && crafting_inv.has_charges( type, count * batch ) ) {
        return "green";
    }
    return has_one ? "dkgray" : "red";
}
开发者ID:DocHoncho,项目名称:Cataclysm-DDA,代码行数:11,代码来源:requirements.cpp

示例6: has

bool tool_comp::has( const inventory &crafting_inv, int batch ) const
{
    if( g->u.has_trait( "DEBUG_HS" ) ) {
        return true;
    }

    if( !by_charges() ) {
        return crafting_inv.has_tools( type, std::abs( count ) );
    } else {
        return crafting_inv.has_charges( type, count * batch );
    }
}
开发者ID:DocHoncho,项目名称:Cataclysm-DDA,代码行数:12,代码来源:requirements.cpp

示例7: has

bool tool_comp::has( const inventory &crafting_inv, int batch ) const
{
    if( type == "goggles_welding" ) {
        if( g->u.has_bionic( "bio_sunglasses" ) || g->u.is_wearing( "rm13_armor_on" ) ) {
            return true;
        }
    }
    if( !by_charges() ) {
        return crafting_inv.has_tools( type, std::abs( count ) );
    } else {
        return crafting_inv.has_charges( type, count * batch );
    }
}
开发者ID:ValidAQ,项目名称:Cataclysm-DDA,代码行数:13,代码来源:requirements.cpp

示例8: get_remaining_charges

int get_remaining_charges( const std::string &tool_id )
{
    const inventory crafting_inv = g->u.crafting_inventory();
    std::vector<const item *> items =
    crafting_inv.items_with( [tool_id]( const item & i ) {
        return i.typeId() == tool_id;
    } );
    int remaining_charges = 0;
    for( const item *instance : items ) {
        remaining_charges += instance->charges;
    }
    return remaining_charges;
}
开发者ID:cellxiecao,项目名称:Cataclysm-DDA,代码行数:13,代码来源:player_helpers.cpp

示例9: player_can_build

bool game::player_can_build(player &p, inventory inv, constructable* con,
                            int level, bool specific)
// defaults: level==0,  specific==false
{
 if (level < 0) // used as escape value in place_construction()
  return false;

 int stop = (specific ? level : con->stages.size());
 do {
  construction_stage stage = con->stages[level];
  int number_of_tools = 0, number_of_components = 0;
  int number_of_req_tools = 0, number_of_req_components = 0;

  for (int j = 0; j < 3; j++) {
// counting available tools
   if (stage.tools[j].size() > 0) {
    number_of_req_tools++;
    for (int k = 0; k < stage.tools[j].size(); k++)
     if (inv.has_amount(stage.tools[j][k], 1)) {
      number_of_tools++;
      break;
     }
   }
// counting available components
   if (stage.components[j].size() > 0) {
    number_of_req_components++;
    for (int k = 0; k < stage.components[j].size(); k++)
     if (( itypes[stage.components[j][k].type]->is_ammo() &&
          inv.has_charges(stage.components[j][k].type,
                          stage.components[j][k].count)    ) ||
         (!itypes[stage.components[j][k].type]->is_ammo() &&
          inv.has_amount (stage.components[j][k].type,
                          stage.components[j][k].count)    )) {
      number_of_components++;
      break;
     }
   }
  }
// difficulty check + summary
  if (!(p.sklevel[sk_carpentry] < stage.difficulty) &&
      number_of_tools == number_of_req_tools &&
      number_of_components == number_of_req_components)
   return true;

  level++;
 } while (level < stop);
 return false;
}
开发者ID:8Z,项目名称:Cataclysm,代码行数:48,代码来源:construction.cpp

示例10: has_comps

bool requirement_data::has_comps( const inventory &crafting_inv,
                                  const std::vector< std::vector<T> > &vec,
                                  int batch )
{
    bool retval = true;
    int total_UPS_charges_used = 0;
    for( const auto &set_of_tools : vec ) {
        bool has_tool_in_set = false;
        int UPS_charges_used = std::numeric_limits<int>::max();
        for( const auto &tool : set_of_tools ) {
            if( tool.has( crafting_inv, batch, [ &UPS_charges_used ]( int charges ) {
            UPS_charges_used = std::min( UPS_charges_used, charges );
            } ) ) {
                tool.available = a_true;
            } else {
                tool.available = a_false;
            }
            has_tool_in_set = has_tool_in_set || tool.available == a_true;
        }
        if( !has_tool_in_set ) {
            retval = false;
        }
        if( UPS_charges_used != std::numeric_limits<int>::max() ) {
            total_UPS_charges_used += UPS_charges_used;
        }
    }
    if( total_UPS_charges_used > 0 &&
        total_UPS_charges_used > crafting_inv.charges_of( "UPS" ) ) {
        return false;
    }
    return retval;
}
开发者ID:auto-load,项目名称:Cataclysm-DDA,代码行数:32,代码来源:requirements.cpp

示例11: get_color

std::string tool_comp::get_color( bool has_one, const inventory &crafting_inv, int batch ) const
{
    if( type == "goggles_welding" ) {
        if( g->u.has_bionic( "bio_sunglasses" ) || g->u.is_wearing( "rm13_armor_on" ) ) {
            return "cyan";
        }
    }
    if( available == a_insufficent ) {
        return "brown";
    } else if( !by_charges() && crafting_inv.has_tools( type, std::abs( count ) ) ) {
        return "green";
    } else if( by_charges() && crafting_inv.has_charges( type, count * batch ) ) {
        return "green";
    }
    return has_one ? "dkgray" : "red";
}
开发者ID:ValidAQ,项目名称:Cataclysm-DDA,代码行数:16,代码来源:requirements.cpp

示例12: 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;
}
开发者ID:Daidalon,项目名称:Cataclysm-DDA,代码行数:47,代码来源:requirements.cpp

示例13: take_all

			void take_all(inventory &container)
			{
				for (item_ptr loot : container.m_items)
				{
					add(loot);
				}
				container.clear();
			}
开发者ID:is0urce,项目名称:press-x-lat,代码行数:8,代码来源:inventory.hpp

示例14: has

bool quality_requirement::has( const inventory &crafting_inv, int,
                               std::function<void( int )> ) const
{
    if( g->u.has_trait( trait_DEBUG_HS ) ) {
        return true;
    }

    return crafting_inv.has_quality( type, level, count );
}
开发者ID:auto-load,项目名称:Cataclysm-DDA,代码行数:9,代码来源:requirements.cpp

示例15: get_color

std::string item_comp::get_color( bool has_one, const inventory &crafting_inv, int batch ) const
{
    if( type == "rope_30" || type == "rope_6" ) {
        if( g->u.has_trait( "WEB_ROPE" ) && g->u.get_hunger() <= 300 ) {
            return "ltgreen"; // Show that WEB_ROPE is on the job!
        }
    }
    const int cnt = std::abs( count ) * batch;
    if( available == a_insufficent ) {
        return "brown";
    } else if( item::count_by_charges( type ) ) {
        if( crafting_inv.has_charges( type, cnt ) ) {
            return "green";
        }
    } else if( crafting_inv.has_components( type, cnt ) ) {
        return "green";
    }
    return has_one ? "dkgray" : "red";
}
开发者ID:1942rob,项目名称:Cataclysm-DDA,代码行数:19,代码来源:requirements.cpp


注:本文中的inventory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。