本文整理汇总了C++中item::is_null方法的典型用法代码示例。如果您正苦于以下问题:C++ item::is_null方法的具体用法?C++ item::is_null怎么用?C++ item::is_null使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类item
的用法示例。
在下文中一共展示了item::is_null方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: set_drop
void projectile::set_drop( const item &it )
{
if( it.is_null() ) {
unset_drop();
} else {
drop.reset( new item( it ) );
}
}
示例2: weapon_valid
bool martialart::weapon_valid( const item &it ) const
{
if( it.is_null() ) {
return true;
}
if( has_weapon( it.typeId() ) ) {
return true;
}
return !strictly_unarmed && it.has_flag( "UNARMED_WEAPON" );
}
示例3: modify
void Item_modifier::modify(item &new_item) const
{
if(new_item.is_null()) {
return;
}
int dm = (damage.first == damage.second) ? damage.first : rng(damage.first, damage.second);
if(dm >= -1 && dm <= 4) {
new_item.damage = dm;
}
long ch = (charges.first == charges.second) ? charges.first : rng(charges.first, charges.second);
if(ch != -1) {
it_tool *t = dynamic_cast<it_tool *>(new_item.type);
it_gun *g = dynamic_cast<it_gun *>(new_item.type);
if(new_item.count_by_charges()) {
// food, ammo
new_item.charges = ch;
} else if(t != NULL) {
new_item.charges = std::min(ch, t->max_charges);
} else if(g != NULL && ammo.get() != NULL) {
item am = ammo->create_single(new_item.bday);
it_ammo *a = dynamic_cast<it_ammo *>(am.type);
if(!am.is_null() && a != NULL) {
new_item.curammo = a;
new_item.charges = std::min<long>(am.charges, new_item.clip_size());
}
}
}
if(container.get() != NULL) {
item cont = container->create_single(new_item.bday);
if (!cont.is_null()) {
if (new_item.made_of(LIQUID)) {
LIQUID_FILL_ERROR err;
int rc = cont.get_remaining_capacity_for_liquid(new_item, err);
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: can_reload
bool vehicle_part::can_reload( const item &obj ) const
{
// first check part is not destroyed and can contain ammo
if( !is_fuel_store() ) {
return false;
}
if( !obj.is_null() ) {
const itype_id obj_type = obj.typeId();
if( is_reactor() ) {
return base.is_reloadable_with( obj_type );
}
// forbid filling tanks with solids or non-material things
if( is_tank() && ( obj.made_of( SOLID ) || obj.made_of( PNULL ) ) ) {
return false;
}
// forbid putting liquids, gasses, and plasma in things that aren't tanks
else if( !obj.made_of( SOLID ) && !is_tank() ) {
return false;
}
// prevent mixing of different ammo
if( ammo_current() != "null" && ammo_current() != obj_type ) {
return false;
}
// For storage with set type, prevent filling with different types
if( info().fuel_type != fuel_type_none && info().fuel_type != obj_type ) {
return false;
}
// don't fill magazines with inappropriate fuel
if( !is_tank() && !base.is_reloadable_with( obj_type ) ) {
return false;
}
}
return ammo_remaining() < ammo_capacity();
}
示例5: 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());
}
}
示例6: 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);
const auto g = new_item.type->gun.get();
const auto t = dynamic_cast<const it_tool *>(new_item.type);
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(t != NULL) {
new_item.charges = std::min(ch, t->max_charges);
} else if (g == nullptr){
//not gun, food, ammo or tool.
new_item.charges = ch;
}
}
if( g != nullptr && ( ammo.get() != nullptr || ch > 0 ) ) {
if( ammo.get() == nullptr ) {
// In case there is no explicit ammo item defined, use the default ammo
const auto ammoid = default_ammo( g->ammo );
if ( !ammoid.empty() ) {
new_item.set_curammo( ammoid );
new_item.charges = ch;
}
} 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 a valid state curammo==0 <=> charges==0 and respect clip size
if( !new_item.has_curammo() ) {
new_item.charges = 0;
} else {
new_item.charges = std::min<long>( new_item.charges, new_item.clip_size() );
}
}
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());
}
}
示例7: 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 );
}
}
示例8: get_skill_level
int SkillLevelMap::get_skill_level( const skill_id &ident, const item &context ) const
{
const auto id = context.is_null() ? ident : context.contextualize_skill( ident );
return get_skill_level( id );
}