Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stomach Contents #28049

Merged
merged 19 commits into from Apr 9, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -519,5 +519,55 @@
"flags": "TRADER_AVOID",
"volume": 1,
"fun": -30
},
{
"type": "COMESTIBLE",
"id": "grass",
"name": "grass",
"name_plural": "grasses",
"weight": 100,
"color": "green",
"comestible_type": "FOOD",
"symbol": "%",
"calories": 70,
"vitamins": [ ],
"description": "Some grass, edible by grazers and ruminants only. Seeing this item is a bug.",
"price": 0,
"material": "veggy",
"flags": "TRADER_AVOID",
"volume": 1
},
{
"type": "COMESTIBLE",
"id": "underbrush",
"name": "underbrush",
"name_plural": "underbrushes",
"weight": 100,
"color": "green",
"comestible_type": "FOOD",
"symbol": "%",
"calories": 174,
"vitamins": [ ],
"description": "Some underbrush, edible by ruminants only. Seeing this item is a bug.",
"price": 0,
"material": "veggy",
"flags": "TRADER_AVOID",
"volume": 1
},
{
"type": "COMESTIBLE",
"id": "nectar",
"name": "nectar",
"name_plural": "nectars",
"weight": 100,
"color": "green",
"comestible_type": "FOOD",
"symbol": "%",
"calories": 130,
"vitamins": [ ],
"description": "Some nectar. Seeing this item is a bug.",
"price": 0,
"flags": "TRADER_AVOID",
"volume": 1
}
]
@@ -193,14 +193,14 @@ void activity_handlers::burrow_finish( player_activity *act, player *p )
g->m.ter( pos ) != t_tree ) {
// Tunneling through solid rock is hungry, sweaty, tiring, backbreaking work
// Not quite as bad as the pickaxe, though
p->mod_hunger( 10 );
p->mod_stored_nutr( 10 );
p->mod_thirst( 10 );
p->mod_fatigue( 15 );
p->mod_pain( 3 * rng( 1, 3 ) );
} else if( g->m.move_cost( pos ) == 2 && g->get_levz() == 0 &&
g->m.ter( pos ) != t_dirt && g->m.ter( pos ) != t_grass ) {
//Breaking up concrete on the surface? not nearly as bad
p->mod_hunger( 5 );
p->mod_stored_nutr( 5 );
p->mod_thirst( 5 );
p->mod_fatigue( 10 );
}
@@ -1692,8 +1692,8 @@ void activity_handlers::pickaxe_finish( player_activity *act, player *p )
g->m.ter( pos ) != t_tree ) {
// Tunneling through solid rock is hungry, sweaty, tiring, backbreaking work
// Betcha wish you'd opted for the J-Hammer ;P
p->mod_hunger( 15 - ( helpersize * 3 ) );
p->mod_thirst( 15 - ( helpersize * 3 ) );
p->mod_stored_nutr( 15 - ( helpersize * 3 ) );
p->mod_thirst( 15 - ( helpersize * 3 ) );
if( p->has_trait( trait_id( "STOCKY_TROGLO" ) ) ) {
p->mod_fatigue( 20 - ( helpersize * 3 ) ); // Yep, dwarves can dig longer before tiring
} else {
@@ -1703,7 +1703,7 @@ void activity_handlers::pickaxe_finish( player_activity *act, player *p )
} else if( g->m.move_cost( pos ) == 2 && g->get_levz() == 0 &&
g->m.ter( pos ) != t_dirt && g->m.ter( pos ) != t_grass ) {
//Breaking up concrete on the surface? not nearly as bad
p->mod_hunger( 5 - ( helpersize ) );
p->mod_stored_nutr( 5 - ( helpersize ) );
p->mod_thirst( 5 - ( helpersize ) );
p->mod_fatigue( 10 - ( helpersize * 2 ) );
}
@@ -2772,7 +2772,7 @@ void activity_handlers::hacksaw_finish( player_activity *act, player *p )
g->m.spawn_item( pos, "pipe", 12 );
}

p->mod_hunger( 5 );
p->mod_stored_nutr( 5 );
p->mod_thirst( 5 );
p->mod_fatigue( 10 );
p->add_msg_if_player( m_good, _( "You finish cutting the metal." ) );
@@ -2813,7 +2813,7 @@ void activity_handlers::chop_tree_finish( player_activity *act, player *p )
g->m.ter_set( pos, t_stump );
const std::vector<npc *> helpers = g->u.get_crafting_helpers();
const int helpersize = g->u.get_num_crafting_helpers( 3 );
p->mod_hunger( 5 - helpersize );
p->mod_stored_nutr( 5 - helpersize );
p->mod_thirst( 5 - helpersize );
p->mod_fatigue( 10 - ( helpersize * 2 ) );
p->add_msg_if_player( m_good, _( "You finish chopping down a tree." ) );
@@ -2836,7 +2836,7 @@ void activity_handlers::chop_logs_finish( player_activity *act, player *p )
g->m.ter_set( pos, t_dirt );
const std::vector<npc *> helpers = g->u.get_crafting_helpers();
const int helpersize = g->u.get_num_crafting_helpers( 3 );
p->mod_hunger( 5 - helpersize );
p->mod_stored_nutr( 5 - helpersize );
p->mod_thirst( 5 - helpersize );
p->mod_fatigue( 10 - ( helpersize * 2 ) );
p->add_msg_if_player( m_good, _( "You finish chopping wood." ) );
@@ -2861,7 +2861,7 @@ void activity_handlers::jackhammer_finish( player_activity *act, player *p )

const std::vector<npc *> helpers = g->u.get_crafting_helpers();
const int helpersize = g->u.get_num_crafting_helpers( 3 );
p->mod_hunger( 5 - helpersize );
p->mod_stored_nutr( 5 - helpersize );
p->mod_thirst( 5 - helpersize );
p->mod_fatigue( 10 - ( helpersize * 2 ) );
p->add_msg_if_player( m_good, _( "You finish drilling." ) );
@@ -2934,7 +2934,7 @@ void activity_handlers::dig_finish( player_activity *act, player *p )

const std::vector<npc *> helpers = g->u.get_crafting_helpers();
const int helpersize = g->u.get_num_crafting_helpers( 3 );
p->mod_hunger( 5 - helpersize );
p->mod_stored_nutr( 5 - helpersize );
p->mod_thirst( 5 - helpersize );
p->mod_fatigue( 10 - ( helpersize * 2 ) );
if( grave ) {
@@ -2992,7 +2992,7 @@ void activity_handlers::fill_pit_finish( player_activity *act, player *p )
}
const std::vector<npc *> helpers = g->u.get_crafting_helpers();
const int helpersize = g->u.get_num_crafting_helpers( 3 );
p->mod_hunger( 5 - helpersize );
p->mod_stored_nutr( 5 - helpersize );
p->mod_thirst( 5 - helpersize );
p->mod_fatigue( 10 - ( helpersize * 2 ) );
p->add_msg_if_player( m_good, _( "You finish filling up %s." ), old_ter.obj().name() );
@@ -640,3 +640,8 @@ std::string to_string( const time_point &p )
calendar::name_season( season_of_year( p ) ), day, time );
}
}

time_point::time_point()
{
turn_ = 0;
}
@@ -538,6 +538,7 @@ class time_point
int turn_;

public:
time_point();
// TODO: make private
// TODO: make explicit
constexpr time_point( const int t ) : turn_( t ) { }
@@ -108,12 +108,12 @@ Character::Character() :
healthy = 0;
healthy_mod = 0;
hunger = 0;
starvation = 0;
thirst = 0;
fatigue = 0;
sleep_deprivation = 0;
stomach_food = 0;
stomach_water = 0;
// 45 days to starve to death
healthy_calories = 77000;
stored_calories = healthy_calories;

name.clear();

@@ -171,8 +171,6 @@ void Character::mod_stat( const std::string &stat, float modifier )
mod_healthy( modifier );
} else if( stat == "hunger" ) {
mod_hunger( modifier );
} else if( stat == "starvation" ) {
mod_starvation( modifier );
} else {
Creature::mod_stat( stat, modifier );
}
@@ -1893,6 +1891,42 @@ void Character::mod_healthy_mod( int nhealthy_mod, int cap )
healthy_mod = std::max( healthy_mod, low_cap );
}

int Character::get_stored_kcal() const
{
return stored_calories;
}

void Character::mod_stored_kcal( int nkcal )
{
// this needs to be capped until there are negative effects on being overweight
const int capped = std::min( stored_calories + nkcal,
static_cast<int>( get_healthy_kcal() * 1.1 ) );
set_stored_kcal( capped );
}

void Character::mod_stored_nutr( int nnutr )
{
// nutr is legacy type code, this function simply converts old nutrition to new kcal
mod_stored_kcal( -1 * round( nnutr * 2500.0f / ( 12 * 24 ) ) );
}

void Character::set_stored_kcal( int kcal )
{
if( stored_calories != kcal ) {
stored_calories = kcal;
}
}

int Character::get_healthy_kcal() const
{
return healthy_calories;
}

float Character::get_kcal_percent() const
{
return static_cast<float>( get_stored_kcal() ) / static_cast<float>( get_healthy_kcal() );
}

int Character::get_hunger() const
{
return hunger;
@@ -1912,22 +1946,19 @@ void Character::set_hunger( int nhunger )
}
}

// this is a translation from a legacy value
int Character::get_starvation() const
{
return starvation;
}

void Character::mod_starvation( int nstarvation )
{
set_starvation( starvation + nstarvation );
}

void Character::set_starvation( int nstarvation )
{
if( starvation != nstarvation ) {
starvation = std::max( 0, nstarvation );
on_stat_change( "starvation", starvation );
static const std::vector<std::pair<float, float>> starv_thresholds = { {
std::make_pair( 0.0f, 6000.0f ),
std::make_pair( 0.8f, 300.0f ),
std::make_pair( 0.95f, 100.0f )
}
};
if( get_kcal_percent() < 0.95f ) {
return round( multi_lerp( starv_thresholds, get_kcal_percent() ) );
}
return 0;
}

int Character::get_thirst() const
@@ -1937,7 +1968,9 @@ int Character::get_thirst() const

std::pair<std::string, nc_color> Character::get_thirst_description() const
{
int thirst = get_thirst();
// some delay from water in stomach is desired, but there needs to be some visceral response
int thirst = get_thirst() - ( std::max( units::to_milliliter<int>( g->u.stomach.get_water() ) / 5 -
100, 0 ) );
std::string hydration_string;
nc_color hydration_color = c_white;
if( thirst > 520 ) {
@@ -2029,31 +2062,6 @@ void Character::set_thirst( int nthirst )
}
}

int Character::get_stomach_food() const
{
return stomach_food;
}
void Character::mod_stomach_food( int n_stomach_food )
{
stomach_food = std::max( 0, stomach_food + n_stomach_food );
}
void Character::set_stomach_food( int n_stomach_food )
{
stomach_food = std::max( 0, n_stomach_food );
}
int Character::get_stomach_water() const
{
return stomach_water;
}
void Character::mod_stomach_water( int n_stomach_water )
{
stomach_water = std::max( 0, stomach_water + n_stomach_water );
}
void Character::set_stomach_water( int n_stomach_water )
{
stomach_water = std::max( 0, n_stomach_water );
}

void Character::mod_fatigue( int nfatigue )
{
set_fatigue( fatigue + nfatigue );
@@ -217,6 +217,9 @@ class Character : public Creature, public visitable<Character>
virtual void set_healthy_mod( int nhealthy_mod );

/** Getter for need values exclusive to characters */
virtual int get_stored_kcal() const;
virtual int get_healthy_kcal() const;
virtual float get_kcal_percent() const;
virtual int get_hunger() const;
virtual int get_starvation() const;
virtual int get_thirst() const;
@@ -225,26 +228,21 @@ class Character : public Creature, public visitable<Character>
virtual std::pair<std::string, nc_color> get_fatigue_description() const;
virtual int get_fatigue() const;
virtual int get_sleep_deprivation() const;
virtual int get_stomach_food() const;
virtual int get_stomach_water() const;

/** Modifiers for need values exclusive to characters */
virtual void mod_stored_kcal( int nkcal );
virtual void mod_stored_nutr( int nnutr );
virtual void mod_hunger( int nhunger );
virtual void mod_starvation( int nstarvation );
virtual void mod_thirst( int nthirst );
virtual void mod_fatigue( int nfatigue );
virtual void mod_sleep_deprivation( int nsleep_deprivation );
virtual void mod_stomach_food( int n_stomach_food );
virtual void mod_stomach_water( int n_stomach_water );

/** Setters for need values exclusive to characters */
virtual void set_stored_kcal( int kcal );
virtual void set_hunger( int nhunger );
virtual void set_starvation( int nstarvation );
virtual void set_thirst( int nthirst );
virtual void set_fatigue( int nfatigue );
virtual void set_sleep_deprivation( int nsleep_deprivation );
virtual void set_stomach_food( int n_stomach_food );
virtual void set_stomach_water( int n_stomach_water );

void mod_stat( const std::string &stat, float modifier ) override;

@@ -827,15 +825,14 @@ class Character : public Creature, public visitable<Character>

private:
/** Needs (hunger, starvation, thirst, fatigue, etc.) */
int stored_calories;
int healthy_calories;

int hunger;
int starvation;
int thirst;

int fatigue;
int sleep_deprivation;

int stomach_food;
int stomach_water;
};

#endif
@@ -1044,7 +1044,7 @@ void construct::done_digormine_stair( const tripoint &p, bool dig )

int no_mut_penalty = dig_muts ? 10 : 0;
int mine_penalty = dig ? 0 : 10;
g->u.mod_hunger( 5 + mine_penalty + no_mut_penalty );
g->u.mod_stored_nutr( 5 + mine_penalty + no_mut_penalty );
g->u.mod_thirst( 5 + mine_penalty + no_mut_penalty );
g->u.mod_fatigue( 10 + mine_penalty + no_mut_penalty );

@@ -1117,7 +1117,7 @@ void construct::done_mine_upstair( const tripoint &p )
bool dig_muts = g->u.has_trait( trait_PAINRESIST_TROGLO ) || g->u.has_trait( trait_STOCKY_TROGLO );

int no_mut_penalty = dig_muts ? 15 : 0;
g->u.mod_hunger( 20 + no_mut_penalty );
g->u.mod_stored_nutr( 20 + no_mut_penalty );
g->u.mod_thirst( 20 + no_mut_penalty );
g->u.mod_fatigue( 25 + no_mut_penalty );

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.