本文整理汇总了C++中item::is_tool方法的典型用法代码示例。如果您正苦于以下问题:C++ item::is_tool方法的具体用法?C++ item::is_tool怎么用?C++ item::is_tool使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类item
的用法示例。
在下文中一共展示了item::is_tool方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: switch
/*static*/ bool inventory::has_category(const item& it, item_cat cat, const player& u) {
switch (cat)
{
case IC_COMESTIBLE: // food
if (it.is_food(&u) || it.is_food_container(&u))
{
return true;
}
break;
case IC_AMMO: // ammo
if (it.is_ammo() || it.is_ammo_container())
{
return true;
}
break;
case IC_ARMOR: // armour
if (it.is_armor())
{
return true;
}
break;
case IC_BOOK: // books
if (it.is_book())
{
return true;
}
break;
case IC_TOOL: // tools
if (it.is_tool())
{
return true;
}
break;
case IC_CONTAINER: // containers for liquid handling
if (it.is_tool() || it.is_gun())
{
if (it.ammo_type() == "gasoline")
{
return true;
}
}
else
{
if (it.is_container())
{
return true;
}
}
break;
}
return false;
}
示例2: select
virtual void select(int entnum, uimenu *menu) {
const int starty = 3;
const int startx = menu->w_width - menu->pad_right;
itype *ity = item_controller->find_template(standard_itype_ids[entnum]);
std::string padding = std::string(menu->pad_right - 1, ' ');
for(int i = 0; i < lastlen + starty + 1; i++ ) {
mvwprintw(menu->window, 1 + i, startx, "%s", padding.c_str() );
}
if ( ity != NULL ) {
tmp.make(item_controller->find_template(standard_itype_ids[entnum]));
tmp.bday = g->turn;
if (tmp.is_tool()) {
tmp.charges = dynamic_cast<it_tool *>(tmp.type)->max_charges;
} else if (tmp.is_ammo()) {
tmp.charges = 100;
} else if (tmp.is_gun()) {
tmp.charges = 0;
} else if (tmp.is_gunmod() && (tmp.has_flag("MODE_AUX") ||
tmp.typeId() == "spare_mag")) {
tmp.charges = 0;
} else {
tmp.charges = -1;
}
if( tmp.is_stationary() ) {
tmp.note = SNIPPET.assign( (dynamic_cast<it_stationary *>(tmp.type))->category );
}
std::vector<std::string> desc = foldstring(tmp.info(true), menu->pad_right - 1);
int dsize = desc.size();
if ( dsize > menu->w_height - 5 ) {
dsize = menu->w_height - 5;
}
lastlen = dsize;
std::string header = string_format("#%d: %s%s",
entnum,
standard_itype_ids[entnum].c_str(),
( incontainer ? " (contained)" : "" )
);
mvwprintz(menu->window, 1, startx + ( menu->pad_right - 1 - header.size() ) / 2, c_cyan, "%s",
header.c_str()
);
for(int i = 0; i < desc.size(); i++ ) {
mvwprintw(menu->window, starty + i, startx, "%s", desc[i].c_str() );
}
mvwprintz(menu->window, menu->w_height - 3, startx, c_green, "%s", msg.c_str());
msg = padding;
mvwprintw(menu->window, menu->w_height - 2, startx, "[/] find, [f] container, [q]uit");
}
}
示例3: modify
void Item_modifier::modify(item &new_item) const
{
if(new_item.is_null()) {
return;
}
new_item.damage = std::min( std::max( (int) rng( damage.first, damage.second ), MIN_ITEM_DAMAGE ), MAX_ITEM_DAMAGE );
long ch = (charges.first == charges.second) ? charges.first : rng(charges.first, charges.second);
if(ch != -1) {
if( new_item.count_by_charges() || new_item.made_of( LIQUID ) ) {
// food, ammo
// count_by_charges requires that charges is at least 1. It makes no sense to
// spawn a "water (0)" item.
new_item.charges = std::max( 1l, ch );
} else if( new_item.is_tool() ) {
const auto qty = std::min( ch, new_item.ammo_capacity() );
new_item.charges = qty;
if( new_item.ammo_type() != "NULL" && qty > 0 ) {
new_item.ammo_set( new_item.ammo_type(), qty );
}
} else if( !new_item.is_gun() ) {
//not gun, food, ammo or tool.
new_item.charges = ch;
}
}
if( new_item.is_gun() && ( ammo.get() != nullptr || ch > 0 ) ) {
if( ammo.get() == nullptr ) {
// In case there is no explicit ammo item defined, use the default ammo
if( new_item.ammo_type() != "NULL" ) {
new_item.charges = ch;
new_item.set_curammo( new_item.ammo_type() );
}
} else {
const item am = ammo->create_single( new_item.bday );
new_item.set_curammo( am );
// Prefer explicit charges of the gun, else take the charges of the ammo item,
// Gun charges are easier to define: {"item":"gun","charge":10,"ammo-item":"ammo"}
if( ch > 0 ) {
new_item.charges = ch;
} else {
new_item.charges = am.charges;
}
}
// Make sure the item is in valid state
if( new_item.ammo_data() && new_item.magazine_integral() ) {
new_item.charges = std::min( new_item.charges, new_item.ammo_capacity() );
} else {
new_item.charges = 0;
}
}
if(container.get() != NULL) {
item cont = container->create_single(new_item.bday);
if (!cont.is_null()) {
if (new_item.made_of(LIQUID)) {
long rc = cont.get_remaining_capacity_for_liquid(new_item);
if(rc > 0 && (new_item.charges > rc || ch == -1)) {
// make sure the container is not over-full.
// fill up the container (if using default charges)
new_item.charges = rc;
}
}
cont.put_in(new_item);
new_item = cont;
}
}
if (contents.get() != NULL) {
Item_spawn_data::ItemList contentitems = contents->create(new_item.bday);
new_item.contents.insert(new_item.contents.end(), contentitems.begin(), contentitems.end());
}
}
示例4: value
int npc::value(item &it)
{
int ret = it.price() / 50;
skill best = best_skill();
if (best != sk_unarmed) {
int weapon_val = it.weapon_value(sklevel) - weapon.weapon_value(sklevel);
if (weapon_val > 0)
ret += weapon_val;
}
if (it.is_food()) {
it_comest* comest = dynamic_cast<it_comest*>(it.type);
if (comest->nutr > 0 || comest->quench > 0)
ret++;
if (hunger > 40)
ret += (comest->nutr + hunger - 40) / 6;
if (thirst > 40)
ret += (comest->quench + thirst - 40) / 4;
}
if (it.is_ammo()) {
it_ammo* ammo = dynamic_cast<it_ammo*>(it.type);
it_gun* gun;
if (weapon.is_gun()) {
gun = dynamic_cast<it_gun*>(weapon.type);
if (ammo->type == gun->ammo)
ret += 14;
}
for (int i = 0; i < inv.size(); i++) {
if (inv[i].is_gun()) {
gun = dynamic_cast<it_gun*>(inv[i].type);
if (ammo->type == gun->ammo)
ret += 6;
}
}
}
if (it.is_book()) {
it_book* book = dynamic_cast<it_book*>(it.type);
if (book->intel <= int_cur) {
ret += book->fun;
if (sklevel[book->type] < book->level && sklevel[book->type] >= book->req)
ret += book->level * 3;
}
}
// TODO: Sometimes we want more than one tool? Also we don't want EVERY tool.
if (it.is_tool() && !has_amount(itype_id(it.type->id), 1)) {
ret += 8;
}
// TODO: Artifact hunting from relevant factions
// ALSO TODO: Bionics hunting from relevant factions
if (fac_has_job(FACJOB_DRUGS) && it.is_food() &&
(dynamic_cast<it_comest*>(it.type))->addict >= 5)
ret += 10;
if (fac_has_job(FACJOB_DOCTORS) && it.type->id >= itm_bandages &&
it.type->id <= itm_prozac)
ret += 10;
if (fac_has_value(FACVAL_BOOKS) && it.is_book())
ret += 14;
if (fac_has_job(FACJOB_SCAVENGE)) { // Computed last for _reasons_.
ret += 6;
ret *= 1.3;
}
return ret;
}
示例5: modify
void Item_modifier::modify( item &new_item ) const
{
if( new_item.is_null() ) {
return;
}
new_item.set_damage( rng( damage.first, damage.second ) );
long ch = ( charges.first == charges.second ) ? charges.first : rng( charges.first,
charges.second );
if( ch != -1 ) {
if( new_item.count_by_charges() || new_item.made_of( LIQUID ) ) {
// food, ammo
// count_by_charges requires that charges is at least 1. It makes no sense to
// spawn a "water (0)" item.
new_item.charges = std::max( 1l, ch );
} else if( new_item.is_tool() ) {
const auto qty = std::min( ch, new_item.ammo_capacity() );
new_item.charges = qty;
if( new_item.ammo_type() && qty > 0 ) {
new_item.ammo_set( new_item.ammo_type()->default_ammotype(), qty );
}
} else if( !new_item.is_gun() ) {
//not gun, food, ammo or tool.
new_item.charges = ch;
}
}
if( ch > 0 && ( new_item.is_gun() || new_item.is_magazine() ) ) {
if( ammo == nullptr ) {
// In case there is no explicit ammo item defined, use the default ammo
if( new_item.ammo_type() ) {
new_item.ammo_set( new_item.ammo_type()->default_ammotype(), ch );
}
} else {
const item am = ammo->create_single( new_item.birthday() );
new_item.ammo_set( am.typeId(), ch );
}
// Make sure the item is in valid state
if( new_item.ammo_data() && new_item.magazine_integral() ) {
new_item.charges = std::min( new_item.charges, new_item.ammo_capacity() );
} else {
new_item.charges = 0;
}
}
if( new_item.is_tool() || new_item.is_gun() || new_item.is_magazine() ) {
bool spawn_ammo = rng( 0, 99 ) < with_ammo && new_item.ammo_remaining() == 0 && ch == -1 &&
( !new_item.is_tool() || new_item.type->tool->rand_charges.empty() );
bool spawn_mag = rng( 0, 99 ) < with_magazine && !new_item.magazine_integral() &&
!new_item.magazine_current();
if( spawn_mag ) {
new_item.contents.emplace_back( new_item.magazine_default(), new_item.birthday() );
}
if( spawn_ammo ) {
if( ammo ) {
const item am = ammo->create_single( new_item.birthday() );
new_item.ammo_set( am.typeId() );
} else {
new_item.ammo_set( new_item.ammo_type()->default_ammotype() );
}
}
}
if( container != nullptr ) {
item cont = container->create_single( new_item.birthday() );
if( !cont.is_null() ) {
if( new_item.made_of( LIQUID ) ) {
long rc = cont.get_remaining_capacity_for_liquid( new_item );
if( rc > 0 && ( new_item.charges > rc || ch == -1 ) ) {
// make sure the container is not over-full.
// fill up the container (if using default charges)
new_item.charges = rc;
}
}
cont.put_in( new_item );
new_item = cont;
}
}
if( contents != nullptr ) {
Item_spawn_data::ItemList contentitems = contents->create( new_item.birthday() );
new_item.contents.insert( new_item.contents.end(), contentitems.begin(), contentitems.end() );
}
for( auto &flag : custom_flags ) {
new_item.set_flag( flag );
}
}