本文整理汇总了C++中item::get_relative_rot方法的典型用法代码示例。如果您正苦于以下问题:C++ item::get_relative_rot方法的具体用法?C++ item::get_relative_rot怎么用?C++ item::get_relative_rot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类item
的用法示例。
在下文中一共展示了item::get_relative_rot方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: clamp
std::pair<int, int> player::fun_for( const item &comest ) const
{
static const trait_id trait_GOURMAND( "GOURMAND" );
static const trait_id trait_SAPROPHAGE( "SAPROPHAGE" );
static const trait_id trait_SAPROVORE( "SAPROVORE" );
static const std::string flag_EATEN_COLD( "EATEN_COLD" );
static const std::string flag_COLD( "COLD" );
if( !comest.is_comestible() ) {
return std::pair<int, int>( 0, 0 );
}
// As float to avoid rounding too many times
float fun = comest.type->comestible->fun;
// Rotten food should be pretty disgusting
const float relative_rot = comest.get_relative_rot();
if( relative_rot > 1.0f && !has_trait( trait_SAPROPHAGE ) && !has_trait( trait_SAPROVORE ) ) {
const float rottedness = clamp( 2 * relative_rot - 2.0f, 0.1f, 1.0f );
// Three effects:
// penalty for rot goes from -2 to -20
// bonus for tasty food drops from 90% to 0%
// disgusting food unfun increases from 110% to 200%
fun -= rottedness * 10;
if( fun > 0 ) {
fun *= ( 1.0f - rottedness );
} else {
fun *= ( 1.0f + rottedness );
}
}
float fun_max = fun < 0 ? fun * 6 : fun * 3;
if( comest.has_flag( flag_EATEN_COLD ) && comest.has_flag( flag_COLD ) ) {
if( fun > 0 ) {
fun *= 3;
} else {
fun = 1;
fun_max = 5;
}
}
if( has_trait( trait_GOURMAND ) ) {
if( fun < -1 ) {
fun_max = fun;
fun /= 2;
} else if( fun > 0 ) {
fun_max = fun_max * 3 / 2;
fun *= 3;
}
}
return std::pair<int, int>( fun, fun_max );
}
示例2: 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;
}
示例3: consume_effects
void player::consume_effects( const item &food )
{
if( !food.is_comestible() ) {
debugmsg( "called player::consume_effects with non-comestible" );
return;
}
const auto &comest = *food.type->comestible;
const int capacity = stomach_capacity();
if( has_trait( trait_id( "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( trait_id( "HERBIVORE" ) ) || has_trait( trait_id( "RUMINANT" ) ) ) &&
food.has_any_flag( herbivore_blacklist ) ) {
// No good can come of this.
return;
}
// Rotten food causes health loss
const float relative_rot = food.get_relative_rot();
if( relative_rot > 1.0f && !has_trait( trait_id( "SAPROPHAGE" ) ) &&
!has_trait( trait_id( "SAPROVORE" ) ) && !has_bionic( bio_digestion ) ) {
const float rottedness = clamp( 2 * relative_rot - 2.0f, 0.1f, 1.0f );
// ~-1 health per 1 nutrition at halfway-rotten-away, ~0 at "just got rotten"
// But always round down
int h_loss = -rottedness * comest.nutr;
mod_healthy_mod( h_loss, -200 );
add_msg( m_debug, "%d health from %0.2f%% rotten food", h_loss, rottedness );
}
const auto nutr = nutrition_for( food );
mod_hunger( -nutr );
mod_thirst( -comest.quench );
mod_stomach_food( nutr );
mod_stomach_water( comest.quench );
if( 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 ) );
}
// Morale is in minutes
int morale_time = HOURS( 2 ) / MINUTES( 1 );
if( food.has_flag( "HOT" ) && food.has_flag( "EATEN_HOT" ) ) {
morale_time = HOURS( 3 ) / MINUTES( 1 );
int clamped_nutr = std::max( 5, std::min( 20, nutr / 10 ) );
add_morale( MORALE_FOOD_HOT, clamped_nutr, 20, morale_time, morale_time / 2 );
}
std::pair<int, int> fun = fun_for( food );
if( fun.first < 0 ) {
add_morale( MORALE_FOOD_BAD, fun.first, fun.second, morale_time, morale_time / 2, false,
food.type );
} else if( fun.first > 0 ) {
add_morale( MORALE_FOOD_GOOD, fun.first, fun.second, morale_time, morale_time / 2, false,
food.type );
}
const bool hibernate = has_active_mutation( trait_id( "HIBERNATE" ) );
if( hibernate ) {
if( ( nutr > 0 && get_hunger() < -60 ) || ( comest.quench > 0 && get_thirst() < -60 ) ) {
//Tell the player what's going on
add_msg_if_player( _( "You gorge yourself, preparing to hibernate." ) );
if( one_in( 2 ) ) {
//50% chance of the food tiring you
mod_fatigue( nutr );
}
}
if( ( nutr > 0 && get_hunger() < -200 ) || ( comest.quench > 0 && get_thirst() < -200 ) ) {
//Hibernation should cut burn to 60/day
add_msg_if_player( _( "You feel stocked for a day or two. Got your bed all ready and secured?" ) );
if( one_in( 2 ) ) {
//And another 50%, intended cumulative
mod_fatigue( nutr );
}
}
if( ( nutr > 0 && get_hunger() < -400 ) || ( comest.quench > 0 && get_thirst() < -400 ) ) {
add_msg_if_player(
_( "Mmm. You can still fit some more in...but maybe you should get comfortable and sleep." ) );
if( !one_in( 3 ) ) {
//Third check, this one at 66%
mod_fatigue( nutr );
}
}
//.........这里部分代码省略.........