本文整理汇总了C++中item::is_food方法的典型用法代码示例。如果您正苦于以下问题:C++ item::is_food方法的具体用法?C++ item::is_food怎么用?C++ item::is_food使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类item
的用法示例。
在下文中一共展示了item::is_food方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: is_crafting_component
const std::function<bool( const item & )> recipe::get_component_filter() const
{
const item result = create_result();
// Disallow crafting of non-perishables with rotten components
// Make an exception for seeds
// TODO: move seed extraction recipes to uncraft
std::function<bool( const item & )> rotten_filter = return_true<item>;
if( result.is_food() && !result.goes_bad() && !has_flag( "ALLOW_ROTTEN" ) ) {
rotten_filter = []( const item & component ) {
return !component.rotten();
};
}
// If the result is made hot, we can allow frozen components.
// EDIBLE_FROZEN components ( e.g. flour, chocolate ) are allowed as well
// Otherwise forbid them
std::function<bool( const item & )> frozen_filter = return_true<item>;
if( result.is_food() && !hot_result() ) {
frozen_filter = []( const item & component ) {
return !component.has_flag( "FROZEN" ) || component.has_flag( "EDIBLE_FROZEN" );
};
}
return [ rotten_filter, frozen_filter ]( const item & component ) {
return is_crafting_component( component ) && rotten_filter( component ) &&
frozen_filter( component );
};
}
示例2: finalize_crafted_item
void finalize_crafted_item( item &newit, float used_age_tally, int used_age_count )
{
if( newit.is_food() ) {
set_item_food( newit );
}
if( used_age_count > 0 && newit.goes_bad() ) {
set_item_spoilage( newit, used_age_tally, used_age_count );
}
}
示例3: 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;
}
示例4: rate_action_eat
hint_rating player::rate_action_eat( const item &it ) const
{
if( !it.is_food_container( this ) && !it.is_food( this ) ) {
return HINT_CANT;
}
const auto rating = can_eat( it );
if( rating == EDIBLE ) {
return HINT_GOOD;
} else if( rating == INEDIBLE || rating == INEDIBLE_MUTATION ) {
return HINT_CANT;
}
return HINT_IFFY;
}
示例5: 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;
}
示例6: eat
bool player::eat( item &food, bool force )
{
if( !food.is_food() ) {
return false;
}
// Check if it's rotten before eating!
food.calc_rot( global_square_location() );
const auto ret = force ? can_eat( food ) : will_eat( food, is_player() );
if( !ret.success() ) {
return false;
}
if( food.type->has_use() ) {
if( food.type->invoke( *this, food, pos() ) <= 0 ) {
return false;
}
}
// Note: the block below assumes we decided to eat it
// No coming back from here
const bool hibernate = has_active_mutation( trait_id( "HIBERNATE" ) );
const int nutr = nutrition_for( food );
const int quench = food.type->comestible->quench;
const bool spoiled = food.rotten();
// The item is solid food
const bool chew = food.type->comestible->comesttype == "FOOD" || food.has_flag( "USE_EAT_VERB" );
// This item is a drink and not a solid food (and not a thick soup)
const bool drinkable = !chew && food.type->comestible->comesttype == "DRINK";
// If neither of the above is true then it's a drug and shouldn't get mealtime penalty/bonus
if( hibernate &&
( get_hunger() > -60 && get_thirst() > -60 ) &&
( get_hunger() - nutr < -60 || get_thirst() - quench < -60 ) ) {
add_memorial_log( pgettext( "memorial_male", "Began preparing for hibernation." ),
pgettext( "memorial_female", "Began preparing for hibernation." ) );
add_msg_if_player(
_( "You've begun stockpiling calories and liquid for hibernation. You get the feeling that you should prepare for bed, just in case, but...you're hungry again, and you could eat a whole week's worth of food RIGHT NOW." ) );
}
const bool will_vomit = get_hunger() < 0 && nutr >= 5 && !has_trait( trait_id( "GOURMAND" ) ) &&
!hibernate &&
!has_trait( trait_id( "SLIMESPAWNER" ) ) && !has_trait( trait_id( "EATHEALTH" ) ) &&
rng( -200, 0 ) > get_hunger() - nutr;
const bool saprophage = has_trait( trait_id( "SAPROPHAGE" ) );
if( spoiled && !saprophage ) {
add_msg_if_player( m_bad, _( "Ick, this %s doesn't taste so good..." ), food.tname().c_str() );
if( !has_trait( trait_id( "SAPROVORE" ) ) && !has_trait( trait_id( "EATDEAD" ) ) &&
( !has_bionic( bio_digestion ) || one_in( 3 ) ) ) {
add_effect( effect_foodpoison, rng( 60, ( nutr + 1 ) * 60 ) );
}
consume_effects( food );
} else if( spoiled && saprophage ) {
add_msg_if_player( m_good, _( "Mmm, this %s tastes delicious..." ), food.tname().c_str() );
consume_effects( food );
} else {
consume_effects( food );
}
const bool amorphous = has_trait( trait_id( "AMORPHOUS" ) );
int mealtime = 250;
if( drinkable || chew ) {
// Those bonuses/penalties only apply to food
// Not to smoking weed or applying bandages!
if( has_trait( trait_id( "MOUTH_TENTACLES" ) ) || has_trait( trait_id( "MANDIBLES" ) ) ) {
mealtime /= 2;
} else if( has_trait( trait_id( "GOURMAND" ) ) ) {
// Don't stack those two - that would be 25 moves per item
mealtime -= 100;
}
if( has_trait( trait_id( "BEAK_HUM" ) ) && !drinkable ) {
mealtime += 200; // Much better than PROBOSCIS but still optimized for fluids
} else if( has_trait( trait_id( "SABER_TEETH" ) ) ) {
mealtime += 250; // They get In The Way
}
if( amorphous ) {
mealtime *= 1.1;
// Minor speed penalty for having to flow around it
// rather than just grab & munch
}
}
moves -= mealtime;
// If it's poisonous... poison us.
// TODO: Move this to a flag
if( food.poison > 0 && !has_trait( trait_id( "EATPOISON" ) ) &&
!has_trait( trait_id( "EATDEAD" ) ) ) {
if( food.poison >= rng( 2, 4 ) ) {
add_effect( effect_poison, food.poison * 100 );
}
add_effect( effect_foodpoison, food.poison * 300 );
}
if( amorphous ) {
add_msg_player_or_npc( _( "You assimilate your %s." ), _( "<npcname> assimilates a %s." ),
//.........这里部分代码省略.........
示例7: consume_effects
void player::consume_effects( item &food, bool rotten )
{
if( !food.is_food() ) {
debugmsg( "called player::consume_effects with non-comestible" );
return;
}
const auto comest = food.type->comestible.get();
const int capacity = stomach_capacity();
if( has_trait( "THRESH_PLANT" ) && food.type->can_use( "PLANTBLECH" ) ) {
// Just keep nutrition capped, to prevent vomiting
cap_nutrition_thirst( *this, capacity, true, true );
return;
}
if( ( has_trait( "HERBIVORE" ) || has_trait( "RUMINANT" ) ) &&
food.has_any_flag( herbivore_blacklist ) ) {
// No good can come of this.
return;
}
float factor = 1.0f;
float hunger_factor = 1.0f;
bool unhealthy_allowed = true;
if( has_trait( "GIZZARD" ) ) {
factor *= 0.6f;
}
if( has_trait( "CARNIVORE" ) && food.has_flag( "CARNIVORE_OK" ) ) {
// At least partially edible
if( food.has_any_flag( carnivore_blacklist ) ) {
// Other things are in it, we only get partial benefits
add_msg_if_player( _( "You pick out the edible parts and throw away the rest." ) );
factor *= 0.5f;
} else {
// Carnivores don't get unhealthy off pure meat diets
unhealthy_allowed = false;
}
}
// Saprophages get full nutrition from rotting food
if( rotten && !has_trait( "SAPROPHAGE" ) ) {
// everyone else only gets a portion of the nutrition
hunger_factor *= rng_float( 0, 1 );
// and takes a health penalty if they aren't adapted
if( !has_trait( "SAPROVORE" ) && !has_bionic( "bio_digestion" ) ) {
mod_healthy_mod( -30, -200 );
}
}
// Bio-digestion gives extra nutrition
if( has_bionic( "bio_digestion" ) ) {
hunger_factor += rng_float( 0, 1 );
}
const auto nutr = nutrition_for( food.type );
mod_hunger( -nutr * factor * hunger_factor );
mod_thirst( -comest->quench * factor );
mod_stomach_food( nutr * factor * hunger_factor );
mod_stomach_water( comest->quench * factor );
if( unhealthy_allowed || comest->healthy > 0 ) {
// Effectively no cap on health modifiers from food
mod_healthy_mod( comest->healthy, ( comest->healthy >= 0 ) ? 200 : -200 );
}
if( comest->stim != 0 &&
( abs( stim ) < ( abs( comest->stim ) * 3 ) ||
sgn( stim ) != sgn( comest->stim ) ) ) {
if( comest->stim < 0 ) {
stim = std::max( comest->stim * 3, stim + comest->stim );
} else {
stim = std::min( comest->stim * 3, stim + comest->stim );
}
}
add_addiction( comest->add, comest->addict );
if( addiction_craving( comest->add ) != MORALE_NULL ) {
rem_morale( addiction_craving( comest->add ) );
}
if( food.has_flag( "HOT" ) && food.has_flag( "EATEN_HOT" ) ) {
add_morale( MORALE_FOOD_HOT, 5, 10 );
}
auto fun = comest->fun;
if( food.has_flag( "COLD" ) && food.has_flag( "EATEN_COLD" ) && fun > 0 ) {
if( fun > 0 ) {
add_morale( MORALE_FOOD_GOOD, fun * 3, fun * 3, 60, 30, false, food.type );
} else {
fun = 1;
}
}
const bool gourmand = has_trait( "GOURMAND" );
const bool hibernate = has_active_mutation( "HIBERNATE" );
if( gourmand ) {
if( fun < -2 ) {
add_morale( MORALE_FOOD_BAD, fun * 0.5, fun, 60, 30, false, food.type );
} else if( fun > 0 ) {
add_morale( MORALE_FOOD_GOOD, fun * 3, fun * 6, 60, 30, false, food.type );
}
} else if( fun < 0 ) {
add_morale( MORALE_FOOD_BAD, fun, fun * 6, 60, 30, false, food.type );
} else if( fun > 0 ) {
add_morale( MORALE_FOOD_GOOD, fun, fun * 4, 60, 30, false, food.type );
//.........这里部分代码省略.........