本文整理汇总了C++中item::set_damage方法的典型用法代码示例。如果您正苦于以下问题:C++ item::set_damage方法的具体用法?C++ item::set_damage怎么用?C++ item::set_damage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类item
的用法示例。
在下文中一共展示了item::set_damage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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 );
}
}