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


C++ ItemList::insert方法代码示例

本文整理汇总了C++中ItemList::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ ItemList::insert方法的具体用法?C++ ItemList::insert怎么用?C++ ItemList::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ItemList的用法示例。


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

示例1: create

Item_spawn_data::ItemList Item_group::create( const time_point &birthday, RecursionList &rec ) const
{
    ItemList result;
    if( type == G_COLLECTION ) {
        for( const auto &elem : items ) {
            if( rng( 0, 99 ) >= ( elem )->probability ) {
                continue;
            }
            ItemList tmp = ( elem )->create( birthday, rec );
            result.insert( result.end(), tmp.begin(), tmp.end() );
        }
    } else if( type == G_DISTRIBUTION ) {
        int p = rng( 0, sum_prob - 1 );
        for( const auto &elem : items ) {
            p -= ( elem )->probability;
            if( p >= 0 ) {
                continue;
            }
            ItemList tmp = ( elem )->create( birthday, rec );
            result.insert( result.end(), tmp.begin(), tmp.end() );
            break;
        }
    }

    return result;
}
开发者ID:Barhandar,项目名称:Cataclysm-DDA,代码行数:26,代码来源:item_group.cpp

示例2: create

Item_spawn_data::ItemList Item_group::create(int birthday, RecursionList &rec) const
{
    ItemList result;
    if (type == G_COLLECTION) {
        for(prop_list::const_iterator a = items.begin(); a != items.end(); ++a) {
            if(rng(0, 99) >= (*a)->probability) {
                continue;
            }
            ItemList tmp = (*a)->create(birthday, rec);
            result.insert(result.end(), tmp.begin(), tmp.end());
        }
    } else if (type == G_DISTRIBUTION) {
        int p = rng(0, sum_prob - 1);
        for(prop_list::const_iterator a = items.begin(); a != items.end(); ++a) {
            p -= (*a)->probability;
            if (p >= 0) {
                continue;
            }
            ItemList tmp = (*a)->create(birthday, rec);
            result.insert(result.end(), tmp.begin(), tmp.end());
            break;
        }
    }
    if (with_ammo && !result.empty()) {
        it_gun *maybe_gun = dynamic_cast<it_gun *>(result.front().type);
        if (maybe_gun != NULL) {
            item ammo(default_ammo(maybe_gun->ammo), birthday);
            // TODO: change the spawn lists to contain proper references to containers
            ammo = ammo.in_its_container();
            result.push_back(ammo);
        }
    }
    return result;
}
开发者ID:HolyHemperor,项目名称:Cataclysm-DDA,代码行数:34,代码来源:item_group.cpp

示例3: create

Item_spawn_data::ItemList Single_item_creator::create(int birthday, RecursionList &rec) const
{
    ItemList result;
    int cnt = 1;
    if (modifier.get() != NULL) {
        cnt = (modifier->count.first == modifier->count.second) ? modifier->count.first : rng(
                  modifier->count.first, modifier->count.second);
    }
    for( ; cnt > 0; cnt--) {
        if (type == S_ITEM) {
            result.push_back(create_single(birthday, rec));
        } else {
            if (std::find(rec.begin(), rec.end(), id) != rec.end()) {
                debugmsg("recursion in item spawn list %s", id.c_str());
                return result;
            }
            rec.push_back(id);
            Item_spawn_data *isd = item_controller->get_group(id);
            if (isd == NULL) {
                debugmsg("unknown item spawn list %s", id.c_str());
                return result;
            }
            ItemList tmplist = isd->create(birthday, rec);
            if (modifier.get() != NULL) {
                for(ItemList::iterator a = tmplist.begin(); a != tmplist.end(); ++a) {
                    modifier->modify(*a);
                }
            }
            result.insert(result.end(), tmplist.begin(), tmplist.end());
        }
    }
    return result;
}
开发者ID:3721assistant,项目名称:Cataclysm-DDA,代码行数:33,代码来源:item_group.cpp

示例4: create

Item_spawn_data::ItemList Item_group::create(int birthday, RecursionList &rec) const
{
    ItemList result;
    if (type == G_COLLECTION) {
        for( const auto &elem : items ) {
            if( rng( 0, 99 ) >= ( elem )->probability ) {
                continue;
            }
            ItemList tmp = ( elem )->create( birthday, rec );
            result.insert(result.end(), tmp.begin(), tmp.end());
        }
    } else if (type == G_DISTRIBUTION) {
        int p = rng(0, sum_prob - 1);
        for( const auto &elem : items ) {
            p -= ( elem )->probability;
            if (p >= 0) {
                continue;
            }
            ItemList tmp = ( elem )->create( birthday, rec );
            result.insert(result.end(), tmp.begin(), tmp.end());
            break;
        }
    }

    for( auto& e : result ) {
        bool spawn_ammo = rng( 0, 99 ) < with_ammo;
        bool spawn_mags = rng( 0, 99 ) < with_magazine || spawn_ammo;

        if( spawn_mags && !e.magazine_integral() && !e.magazine_current() ) {
            e.contents.emplace_back( e.magazine_default(), e.bday );
        }
        if( spawn_ammo && e.ammo_capacity() > 0 && e.ammo_remaining() == 0 ) {
            itype_id ammo = default_ammo( e.ammo_type() );
            if( e.magazine_current() ) {
                e.magazine_current()->contents.emplace_back( ammo, e.bday, e.ammo_capacity() );
            } else {
                e.set_curammo( ammo );
                e.charges = e.ammo_capacity();
            }
        }
    }

    return result;
}
开发者ID:Bubbadoo,项目名称:Cataclysm-DDA,代码行数:44,代码来源:item_group.cpp

示例5: create

Item_spawn_data::ItemList Item_group::create(int birthday, RecursionList &rec) const
{
    ItemList result;
    if (type == G_COLLECTION) {
        for( const auto &elem : items ) {
            if( rng( 0, 99 ) >= ( elem )->probability ) {
                continue;
            }
            ItemList tmp = ( elem )->create( birthday, rec );
            result.insert(result.end(), tmp.begin(), tmp.end());
        }
    } else if (type == G_DISTRIBUTION) {
        int p = rng(0, sum_prob - 1);
        for( const auto &elem : items ) {
            p -= ( elem )->probability;
            if (p >= 0) {
                continue;
            }
            ItemList tmp = ( elem )->create( birthday, rec );
            result.insert(result.end(), tmp.begin(), tmp.end());
            break;
        }
    }
    if (with_ammo && !result.empty()) {
        const auto t = result.front().type;
        if( t->gun ) {
            const std::string ammoid = default_ammo( t->gun->ammo );
            if ( !ammoid.empty() ) {
                item ammo( ammoid, birthday );
                // TODO: change the spawn lists to contain proper references to containers
                ammo = ammo.in_its_container();
                result.push_back( ammo );
            }
        }
    }
    return result;
}
开发者ID:ValidAQ,项目名称:Cataclysm-DDA,代码行数:37,代码来源:item_group.cpp


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