Skip to content

Commit

Permalink
Gorging penalties (#40284)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramza13 authored May 18, 2020
1 parent 217893b commit 3e49b53
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 59 deletions.
46 changes: 46 additions & 0 deletions data/json/effects.json
Original file line number Diff line number Diff line change
Expand Up @@ -1950,5 +1950,51 @@
"id": "ignore_fall_damage",
"//": "Used for translocation via teleporter_list as a way to avoid fall damage by teleporting Z levels",
"flags": [ "EFFECT_FEATHER_FALL" ]
},
{
"type": "effect_type",
"id": "hunger_full",
"name": [ "Full" ],
"desc": [ "You feel quite full, and a bit sluggish." ],
"apply_message": "You feel quite full, and a bit sluggish.",
"rating": "bad",
"base_mods": { "speed_mod": [ -2 ], "fatigue_amount": [ 1 ] }
},
{
"type": "effect_type",
"id": "hunger_engorged",
"name": [ "Engorged" ],
"desc": [ "Your stomach is full to bursting. This was a mistake." ],
"apply_message": "Your stomach is full to bursting. This was a mistake.",
"rating": "bad",
"base_mods": { "speed_mod": [ -10 ], "fatigue_amount": [ 2 ], "vomit_chance": [ 5 ], "vomit_tick": [ 60 ], "pain_amount": [ 3 ] }
},
{
"type": "effect_type",
"id": "hunger_satisfied"
},
{
"type": "effect_type",
"id": "hunger_hungry"
},
{
"type": "effect_type",
"id": "hunger_very_hungry"
},
{
"type": "effect_type",
"id": "hunger_near_starving"
},
{
"type": "effect_type",
"id": "hunger_starving"
},
{
"type": "effect_type",
"id": "hunger_famished"
},
{
"type": "effect_type",
"id": "hunger_blank"
}
]
143 changes: 84 additions & 59 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,23 @@ static const efftype_id effect_heating_bionic( "heating_bionic" );
static const efftype_id effect_heavysnare( "heavysnare" );
static const efftype_id effect_hot( "hot" );
static const efftype_id effect_hot_speed( "hot_speed" );
static const efftype_id effect_hunger_blank( "hunger_blank" );
static const efftype_id effect_hunger_engorged( "hunger_engorged" );
static const efftype_id effect_hunger_famished( "hunger_famished" );
static const efftype_id effect_hunger_full( "hunger_full" );
static const efftype_id effect_hunger_hungry( "hunger_hungry" );
static const efftype_id effect_hunger_near_starving( "hunger_near_starving" );
static const efftype_id effect_hunger_satisfied( "hunger_satisfied" );
static const efftype_id effect_hunger_starving( "hunger_starving" );
static const efftype_id effect_hunger_very_hungry( "hunger_very_hungry" );
static const efftype_id effect_in_pit( "in_pit" );
static const efftype_id effect_infected( "infected" );
static const efftype_id effect_jetinjector( "jetinjector" );
static const efftype_id effect_lack_sleep( "lack_sleep" );
static const efftype_id effect_lightsnare( "lightsnare" );
static const efftype_id effect_lying_down( "lying_down" );
static const efftype_id effect_melatonin_supplements( "melatonin" );
static const efftype_id effect_masked_scent( "masked_scent" );
static const efftype_id effect_melatonin_supplements( "melatonin" );
static const efftype_id effect_mending( "mending" );
static const efftype_id effect_narcosis( "narcosis" );
static const efftype_id effect_nausea( "nausea" );
Expand Down Expand Up @@ -4264,64 +4273,23 @@ std::pair<std::string, nc_color> Character::get_thirst_description() const

std::pair<std::string, nc_color> Character::get_hunger_description() const
{
const bool calorie_deficit = get_bmi() < character_weight_category::normal;
const units::volume contains = stomach.contains();
const units::volume cap = stomach.capacity( *this );
std::string hunger_string;
nc_color hunger_color = c_white;
// i ate just now!
const bool just_ate = stomach.time_since_ate() < 15_minutes;
// i ate a meal recently enough that i shouldn't need another meal
const bool recently_ate = stomach.time_since_ate() < 3_hours;
if( calorie_deficit ) {
if( contains >= cap ) {
hunger_string = _( "Engorged" );
hunger_color = c_green;
} else if( contains > cap * 3 / 4 ) {
hunger_string = _( "Sated" );
hunger_color = c_green;
} else if( just_ate && contains > cap / 2 ) {
hunger_string = _( "Full" );
hunger_color = c_green;
} else if( just_ate ) {
hunger_string = _( "Hungry" );
hunger_color = c_yellow;
} else if( recently_ate ) {
hunger_string = _( "Very Hungry" );
hunger_color = c_yellow;
} else if( get_bmi() < character_weight_category::emaciated ) {
hunger_string = _( "Starving!" );
hunger_color = c_red;
} else if( get_bmi() < character_weight_category::underweight ) {
hunger_string = _( "Near starving" );
hunger_color = c_red;
} else {
hunger_string = _( "Famished" );
hunger_color = c_light_red;
}
} else {
if( contains >= cap * 5 / 6 ) {
hunger_string = _( "Engorged" );
hunger_color = c_green;
} else if( contains > cap * 11 / 20 ) {
hunger_string = _( "Sated" );
hunger_color = c_green;
} else if( recently_ate && contains >= cap * 3 / 8 ) {
hunger_string = _( "Full" );
hunger_color = c_green;
} else if( !just_ate && ( recently_ate || contains > 0_ml ) ) {
hunger_string.clear();
} else {
if( get_bmi() > character_weight_category::overweight ) {
hunger_string = _( "Hungry" );
} else {
hunger_string = _( "Very Hungry" );
}
hunger_color = c_yellow;
std::map<efftype_id, std::pair<std::string, nc_color> > hunger_states = {
{ effect_hunger_engorged, std::make_pair( _( "Engorged" ), c_red ) },
{ effect_hunger_full, std::make_pair( _( "Full" ), c_yellow ) },
{ effect_hunger_satisfied, std::make_pair( _( "Satisfied" ), c_green ) },
{ effect_hunger_blank, std::make_pair( _( "" ), c_white ) },
{ effect_hunger_hungry, std::make_pair( _( "Hungry" ), c_yellow ) },
{ effect_hunger_very_hungry, std::make_pair( _( "Very Hungry" ), c_yellow ) },
{ effect_hunger_near_starving, std::make_pair( _( "Near starving" ), c_red ) },
{ effect_hunger_starving, std::make_pair( _( "Starving!" ), c_red ) },
{ effect_hunger_famished, std::make_pair( _( "Famished" ), c_light_red ) }
};
for( auto &hunger_state : hunger_states ) {
if( has_effect( hunger_state.first ) ) {
return hunger_state.second;
}
}

return std::make_pair( hunger_string, hunger_color );
return std::make_pair( _( "ERROR!" ), c_light_red );
}

std::pair<std::string, nc_color> Character::get_fatigue_description() const
Expand Down Expand Up @@ -4697,7 +4665,7 @@ void Character::update_stomach( const time_point &from, const time_point &to )
// you're engorged! your stomach is full to bursting!
set_hunger( -61 );
} else if( stomach.contains() >= stomach_capacity / 2 && get_hunger() > -21 ) {
// sated
// full
set_hunger( -21 );
} else if( stomach.contains() >= stomach_capacity / 8 && get_hunger() > -1 ) {
// that's really all the food you need to feel full
Expand All @@ -4722,7 +4690,7 @@ void Character::update_stomach( const time_point &from, const time_point &to )
// you're engorged! your stomach is full to bursting!
set_hunger( -61 );
} else if( stomach.contains() >= stomach_capacity * 3 / 4 && get_hunger() > -21 ) {
// sated
// full
set_hunger( -21 );
} else if( stomach.contains() >= stomach_capacity / 2 && get_hunger() > -1 ) {
// that's really all the food you need to feel full
Expand All @@ -4741,6 +4709,63 @@ void Character::update_stomach( const time_point &from, const time_point &to )
if( mycus || mouse ) {
set_thirst( 0 );
}

const bool calorie_deficit = get_bmi() < character_weight_category::normal;
const units::volume contains = stomach.contains();
const units::volume cap = stomach.capacity( *this );

efftype_id hunger_effect;
// i ate just now!
const bool just_ate = stomach.time_since_ate() < 15_minutes;
// i ate a meal recently enough that i shouldn't need another meal
const bool recently_ate = stomach.time_since_ate() < 3_hours;
if( calorie_deficit ) {
if( contains >= cap ) {
hunger_effect = effect_hunger_engorged;
} else if( contains > cap * 3 / 4 ) {
hunger_effect = effect_hunger_full;
} else if( just_ate && contains > cap / 2 ) {
hunger_effect = effect_hunger_satisfied;
} else if( just_ate ) {
hunger_effect = effect_hunger_hungry;
} else if( recently_ate ) {
hunger_effect = effect_hunger_very_hungry;
} else if( get_bmi() < character_weight_category::underweight ) {
hunger_effect = effect_hunger_near_starving;
} else if( get_bmi() < character_weight_category::emaciated ) {
hunger_effect = effect_hunger_starving;
} else {
hunger_effect = effect_hunger_famished;
}
} else {
if( contains >= cap * 5 / 6 ) {
hunger_effect = effect_hunger_engorged;
} else if( contains > cap * 11 / 20 ) {
hunger_effect = effect_hunger_full;
} else if( recently_ate && contains >= cap * 3 / 8 ) {
hunger_effect = effect_hunger_satisfied;
} else if( !just_ate && ( recently_ate || contains > 0_ml ) ) {
hunger_effect = effect_hunger_blank;
} else {
if( get_bmi() > character_weight_category::overweight ) {
hunger_effect = effect_hunger_hungry;
} else {
hunger_effect = effect_hunger_very_hungry;
}
}
}
if( !has_effect( hunger_effect ) ) {
remove_effect( effect_hunger_engorged );
remove_effect( effect_hunger_full );
remove_effect( effect_hunger_satisfied );
remove_effect( effect_hunger_hungry );
remove_effect( effect_hunger_very_hungry );
remove_effect( effect_hunger_near_starving );
remove_effect( effect_hunger_starving );
remove_effect( effect_hunger_famished );
remove_effect( effect_hunger_blank );
add_effect( hunger_effect, 24_hours, num_bp, true );
}
}

void Character::update_needs( int rate_multiplier )
Expand Down

0 comments on commit 3e49b53

Please sign in to comment.