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


C++ item类代码示例

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


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

示例1: find_usable_cached_invlet

void inventory::update_invlet( item &newit, bool assign_invlet ) {
    // Avoid letters that have been manually assigned to other things.
    if( newit.invlet && assigned_invlet.find( newit.invlet ) != assigned_invlet.end() &&
            assigned_invlet[newit.invlet] != newit.typeId() ) {
        newit.invlet = '\0';
    }

    // Remove letters that are not in the favorites cache
    if( newit.invlet ) {
        auto invlet_list_iter = invlet_cache.find( newit.typeId() );
        bool found = false;
        if( invlet_list_iter != invlet_cache.end() ) {
            auto &invlet_list = invlet_list_iter->second;
            found = std::find( invlet_list.begin(), invlet_list.end(), newit.invlet ) != invlet_list.end();
        }
        if( !found ) {
            newit.invlet = '\0';
        }
    }

    // Remove letters that have been assigned to other items in the inventory
    if( newit.invlet ) {
        char tmp_invlet = newit.invlet;
        newit.invlet = '\0';
        if( g->u.invlet_to_position( tmp_invlet ) == INT_MIN ) {
            newit.invlet = tmp_invlet;
        }
    }

    if( assign_invlet ) {
        // Assign a cached letter to the item
        if( !newit.invlet ) {
            newit.invlet = find_usable_cached_invlet( newit.typeId() );
        }

        // Give the item an invlet if it has none
        if( !newit.invlet ) {
            assign_empty_invlet( newit, g->u );
        }
    }
}
开发者ID:ProfoundDarkness,项目名称:Cataclysm-DDA,代码行数:41,代码来源:inventory.cpp

示例2: get_substitution

std::vector<item> json_item_substitution::get_substitution( const item &it,
        const std::vector<trait_id> &traits ) const
{
    auto iter = substitutions.find( it.typeId() );
    std::vector<item> ret;
    if( iter == substitutions.end() ) {
        for( const item &con : it.contents ) {
            const auto sub = get_substitution( con, traits );
            ret.insert( ret.end(), sub.begin(), sub.end() );
        }
        return ret;
    }

    const auto sub = std::find_if( iter->second.begin(),
    iter->second.end(), [&traits]( const substitution & s ) {
        return s.trait_reqs.meets_condition( traits );
    } );
    if( sub == iter->second.end() ) {
        return ret;
    }

    const long old_amt = it.count();
    for( const substitution::info &inf : sub->infos ) {
        item result( inf.new_item );
        const long new_amt = std::max( 1l, static_cast<long>( std::round( inf.ratio * old_amt ) ) );

        if( !result.count_by_charges() ) {
            for( long i = 0; i < new_amt; i++ ) {
                ret.push_back( result.in_its_container() );
            }
        } else {
            result.mod_charges( -result.charges + new_amt );
            while( result.charges > 0 ) {
                const item pushed = result.in_its_container();
                ret.push_back( pushed );
                result.mod_charges( pushed.contents.empty() ? -pushed.charges : -pushed.contents.back().charges );
            }
        }
    }
    return ret;
}
开发者ID:OzoneH3,项目名称:Cataclysm-DDA,代码行数:41,代码来源:profession.cpp

示例3: assign_empty_invlet

void inventory::assign_empty_invlet( item &it, const Character &p, const bool force )
{
    if( !get_option<bool>( "AUTO_INV_ASSIGN" ) ) {
        return;
    }

    invlets_bitset cur_inv = p.allocated_invlets();
    itype_id target_type = it.typeId();
    for( auto iter : assigned_invlet ) {
        if( iter.second == target_type && !cur_inv[iter.first] ) {
            it.invlet = iter.first;
            return;
        }
    }
    if( cur_inv.count() < inv_chars.size() ) {
        for( const auto &inv_char : inv_chars ) {
            if( assigned_invlet.count( inv_char ) ) {
                // don't overwrite assigned keys
                continue;
            }
            if( !cur_inv[inv_char] ) {
                it.invlet = inv_char;
                return;
            }
        }
    }
    if( !force ) {
        it.invlet = 0;
        return;
    }
    // No free hotkey exist, re-use some of the existing ones
    for( auto &elem : items ) {
        item &o = elem.front();
        if( o.invlet != 0 ) {
            it.invlet = o.invlet;
            o.invlet = 0;
            return;
        }
    }
    debugmsg( "could not find a hotkey for %s", it.tname() );
}
开发者ID:ralreegorganon,项目名称:Cataclysm-DDA,代码行数:41,代码来源:inventory.cpp

示例4: get_heard_volume

// firing is the item that is fired. It may be the wielded gun, but it can also be an attached
// gunmod. p is the character that is firing, this may be a pseudo-character (used by monattack/
// vehicle turrets) or a NPC.
void sfx::generate_gun_sound( const player &p, const item &firing )
{
    end_sfx_timestamp = std::chrono::high_resolution_clock::now();
    sfx_time = end_sfx_timestamp - start_sfx_timestamp;
    if( std::chrono::duration_cast<std::chrono::milliseconds> ( sfx_time ).count() < 80 ) {
        return;
    }
    const tripoint source = p.pos();
    int heard_volume = get_heard_volume( source );
    if( heard_volume <= 30 ) {
        heard_volume = 30;
    }

    itype_id weapon_id = firing.typeId();
    int angle;
    int distance;
    std::string selected_sound;
    // this does not mean p == g->u (it could be a vehicle turret)
    if( g->u.pos() == source ) {
        angle = 0;
        distance = 0;
        selected_sound = "fire_gun";

        const auto mods = firing.gunmods();
        if( std::any_of( mods.begin(), mods.end(), []( const item *e ) { return e->type->gunmod->loudness < 0; } ) ) {
            weapon_id = "weapon_fire_suppressed";
        }

    } else {
        angle = get_heard_angle( source );
        distance = rl_dist( g->u.pos(), source );
        if( distance <= 17 ) {
            selected_sound = "fire_gun";
        } else {
            selected_sound = "fire_gun_distant";
        }
    }

    play_variant_sound( selected_sound, weapon_id, heard_volume, angle, 0.8, 1.2 );
    start_sfx_timestamp = std::chrono::high_resolution_clock::now();
}
开发者ID:kd8qdz,项目名称:Cataclysm-DDA,代码行数:44,代码来源:sounds.cpp

示例5: debugmsg

item_location game_menus::inv::container_for( player &p, const item &liquid, int radius )
{
    const auto filter = [ &liquid ]( const item_location & location ) {
        if( location.where() == item_location::type::character ) {
            Character *character = dynamic_cast<Character *>( g->critter_at( location.position() ) );
            if( character == nullptr ) {
                debugmsg( "Invalid location supplied to the liquid filter: no character found." );
                return false;
            }
            return location->get_remaining_capacity_for_liquid( liquid, *character ) > 0;
        }

        const bool allow_buckets = location.where() == item_location::type::map;
        return location->get_remaining_capacity_for_liquid( liquid, allow_buckets ) > 0;
    };

    return inv_internal( p, inventory_filter_preset( filter ),
                         string_format( _( "Container for %s" ), liquid.display_name( liquid.charges ).c_str() ), radius,
                         string_format( _( "You don't have a suitable container for carrying %s." ),
                                        liquid.tname().c_str() ) );
}
开发者ID:mbojan,项目名称:Cataclysm-DDA,代码行数:21,代码来源:game_inventory.cpp

示例6: set_item_inventory

void set_item_inventory( item &newit )
{
    if( newit.made_of( LIQUID ) ) {
        g->handle_all_liquid( newit, PICKUP_RANGE );
    } else {
        g->u.inv.assign_empty_invlet( newit );
        // We might not have space for the item
        if( !g->u.can_pickVolume( newit ) ) { //Accounts for result_mult
            add_msg( _( "There's no room in your inventory for the %s, so you drop it." ),
                     newit.tname().c_str() );
            g->m.add_item_or_charges( g->u.pos(), newit );
        } else if( !g->u.can_pickWeight( newit, !get_option<bool>( "DANGEROUS_PICKUPS" ) ) ) {
            add_msg( _( "The %s is too heavy to carry, so you drop it." ),
                     newit.tname().c_str() );
            g->m.add_item_or_charges( g->u.pos(), newit );
        } else {
            newit = g->u.i_add( newit );
            add_msg( m_info, "%c - %s", newit.invlet == 0 ? ' ' : newit.invlet, newit.tname().c_str() );
        }
    }
}
开发者ID:AlecWhite,项目名称:Cataclysm-DDA,代码行数:21,代码来源:crafting.cpp

示例7: aim_per_time

int Character::aim_per_time( const item& gun, int recoil ) const
{
    int penalty = 0;

    // Range [0 - 10] after adjustment
    penalty += skill_dispersion( gun, false ) / 60;

    // Ranges [0 - 12] after adjustment
    penalty += ranged_dex_mod() / 15;

    // Range [0 - 10]
    penalty += gun.aim_speed( recoil );

    // @todo consider character status effects

    // always improve by at least 1MOC
    penalty = std::max( 1, 32 - penalty );

    // improvement capped by max aim level of the gun sight being used.
    return std::min( penalty, recoil - gun.sight_dispersion( recoil ) );
}
开发者ID:NateBrune,项目名称:Cataclysm-DDA,代码行数:21,代码来源:character.cpp

示例8:

// technique
std::vector<matec_id> player::get_all_techniques( const item &weap ) const
{
    std::vector<matec_id> tecs;
    // Grab individual item techniques
    const auto &weapon_techs = weap.get_techniques();
    tecs.insert( tecs.end(), weapon_techs.begin(), weapon_techs.end() );
    // and martial art techniques
    const auto &style = style_selected.obj();
    tecs.insert( tecs.end(), style.techniques.begin(), style.techniques.end() );

    return tecs;
}
开发者ID:Nukesor,项目名称:Cataclysm-DDA,代码行数:13,代码来源:martialarts.cpp

示例9: handle_problematic_pickup

pickup_answer handle_problematic_pickup( const item &it, bool &offered_swap, const std::string &explain )
{
    player &u = g->u;

    uimenu amenu;
    amenu.return_invalid = true;

    amenu.selected = 0;
    amenu.text = explain;

    offered_swap = true;
    // @todo Gray out if not enough hands
    amenu.addentry( WIELD, !u.weapon.has_flag( "NO_UNWIELD" ), 'w',
                    _("Dispose of %s and wield %s"), u.weapon.display_name().c_str(),
                    it.display_name().c_str() );
    if( it.is_armor() ) {
        amenu.addentry( WEAR, u.can_wear( it ), 'W', _("Wear %s"), it.display_name().c_str() );
    }
    if( !it.is_container_empty() && u.can_pickVolume( it.volume() ) ) {
        amenu.addentry( SPILL, true, 's', _("Spill %s, then pick up %s"),
                        it.contents.front().tname().c_str(), it.display_name().c_str() );
    }

    amenu.query();
    int choice = amenu.ret;

    if( choice <= CANCEL || choice >= NUM_ANSWERS ) {
        return CANCEL;
    }

    return static_cast<pickup_answer>( choice );
}
开发者ID:1942rob,项目名称:Cataclysm-DDA,代码行数:32,代码来源:pickup.cpp

示例10: nutrition_for

// TODO: Move pizza scraping here.
// Same for other kinds of nutrition alterations
// This is used by item display, making actual nutrition available to player.
int player::nutrition_for( const item &comest ) const
{
    static const trait_id trait_CARNIVORE( "CARNIVORE" );
    static const trait_id trait_GIZZARD( "GIZZARD" );
    static const trait_id trait_SAPROPHAGE( "SAPROPHAGE" );
    static const std::string flag_CARNIVORE_OK( "CARNIVORE_OK" );
    if( !comest.is_comestible() ) {
        return 0;
    }

    // As float to avoid rounding too many times
    float nutr = comest.type->comestible->nutr;

    if( has_trait( trait_GIZZARD ) ) {
        nutr *= 0.6f;
    }


    if( has_trait( trait_CARNIVORE ) && comest.has_flag( flag_CARNIVORE_OK ) &&
        comest.has_any_flag( carnivore_blacklist ) ) {
        // TODO: Comment pizza scrapping
        nutr *= 0.5f;
    }

    const float relative_rot = comest.get_relative_rot();
    // Saprophages get full nutrition from rotting food
    if( relative_rot > 1.0f && !has_trait( trait_SAPROPHAGE ) ) {
        // everyone else only gets a portion of the nutrition
        // Scaling linearly from 100% at just-rotten to 0 at halfway-rotten-away
        const float rottedness = clamp( 2 * relative_rot - 2.0f, 0.1f, 1.0f );
        nutr *= ( 1.0f - rottedness );
    }

    // Bio-digestion gives extra nutrition
    if( has_bionic( bio_digestion ) ) {
        nutr *= 1.5f;
    }

    return ( int )nutr;
}
开发者ID:Caeous,项目名称:Cataclysm-DDA,代码行数:43,代码来源:consumption.cpp

示例11: check_invlet

invlet_state check_invlet( player &p, item &it, char invlet ) {
    if( it.invlet == '\0' ) {
        return NONE;
    } else if( it.invlet == invlet ) {
        if( p.inv.assigned_invlet.find( invlet ) != p.inv.assigned_invlet.end() &&
            p.inv.assigned_invlet[invlet] == it.typeId() ) {
            return ASSIGNED;
        } else {
            return CACHED;
        }
    }
    return UNEXPECTED;
}
开发者ID:alapazam,项目名称:Cataclysm-DDA,代码行数:13,代码来源:invlet_test.cpp

示例12: set_worn

void player_morale::set_worn( const item &it, bool worn )
{
    const bool just_fancy = it.has_flag( "FANCY" );
    const bool super_fancy = it.has_flag( "SUPER_FANCY" );

    if( just_fancy || super_fancy ) {
        const int sign = ( worn ) ? 1 : -1;

        for( int i = 0; i < num_bp; i++ ) {
            const auto bp = static_cast<body_part>( i );
            if( it.covers( bp ) ) {
                covered[i] = std::max( covered[i] + sign, 0 );
            }
        }

        if( super_fancy ) {
            super_fancy_bonus += 2 * sign;
        }

        update_stylish_bonus();
    }
}
开发者ID:Bubbadoo,项目名称:Cataclysm-DDA,代码行数:22,代码来源:morale.cpp

示例13: retroactively_fill_from_funnel

/**
 * Determine what a funnel has filled out of game, using funnelcontainer.bday as a starting point.
 */
void retroactively_fill_from_funnel( item &it, const trap &tr, int startturn, int endturn,
                                     const tripoint &location )
{
    if( startturn > endturn || !tr.is_funnel() ) {
        return;
    }

    it.bday = endturn; // bday == last fill check
    auto data = sum_conditions( startturn, endturn, location );

    // Technically 0.0 division is OK, but it will be cleaner without it
    if( data.rain_amount > 0 ) {
        const int rain = divide_roll_remainder( 1.0 / tr.funnel_turns_per_charge( data.rain_amount ), 1.0f );
        it.add_rain_to_container( false, rain );
        // add_msg(m_debug, "Retroactively adding %d water from turn %d to %d", rain, startturn, endturn);
    }

    if( data.acid_amount > 0 ) {
        const int acid = divide_roll_remainder( 1.0 / tr.funnel_turns_per_charge( data.acid_amount ), 1.0f );
        it.add_rain_to_container( true, acid );
    }
}
开发者ID:Bubbadoo,项目名称:Cataclysm-DDA,代码行数:25,代码来源:weather.cpp

示例14: assign_empty_invlet

void inventory::add_item(item newit, bool keep_invlet)
{
 if (keep_invlet && !newit.invlet_is_okay())
  assign_empty_invlet(newit); // Keep invlet is true, but invlet is invalid!

 if (newit.is_style())
  return; // Styles never belong in our inventory.
 for (unsigned int i = 0; i < items.size(); i++) {
  if (items[i][0].stacks_with(newit)) {
    newit.invlet = items[i][0].invlet;
   items[i].push_back(newit);
   return;
  } else if (keep_invlet && items[i][0].invlet == newit.invlet)
   assign_empty_invlet(items[i][0]);
 }
 if (!newit.invlet_is_okay() || index_by_letter(newit.invlet) != -1)
  assign_empty_invlet(newit);

 std::vector<item> newstack;
 newstack.push_back(newit);
 items.push_back(newstack);
}
开发者ID:AkrionXxarr,项目名称:Cataclysm-DDA,代码行数:22,代码来源:inventory.cpp

示例15: handle_quiver_insertion

//helper function for Pickup::pick_up
//return value is amount of ammo added to quiver
int Pickup::handle_quiver_insertion(item &here, bool inv_on_fail, int &moves_to_decrement,
                                    bool &picked_up)
{
    //add ammo to quiver
    int quivered = here.add_ammo_to_quiver(&g->u, true);
    if(quivered > 0) {
        moves_to_decrement = 0; //moves already decremented in item::add_ammo_to_quiver()
        picked_up = true;
        return quivered;
    } else if (inv_on_fail) {
        //add to inventory instead
        g->u.i_add(here);
        picked_up = true;

        //display output message
        std::map<std::string, int> map_pickup;
        int charges = (here.count_by_charges()) ? here.charges : 1;
        map_pickup.insert(std::pair<std::string, int>(here.tname(), charges));
        show_pickup_message(map_pickup);
    }
    return 0;
}
开发者ID:ZwodahS,项目名称:Cataclysm-DDA,代码行数:24,代码来源:pickup.cpp


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