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

Sleep deprivation cleanup #37423

Merged
merged 1 commit into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions data/json/game_balance.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,6 @@
"stype": "bool",
"value": false
},
{
"type": "EXTERNAL_OPTION",
"name": "SLEEP_DEPRIVATION",
"info": "Enables sleep deprivation mechanics. If true, stimulants will only help you so far, and you might have to enforce proper sleep hygiene for a while.",
"stype": "bool",
"value": true
},
{
"type": "EXTERNAL_OPTION",
"name": "CBM_SLOTS_ENABLED",
Expand Down
5 changes: 0 additions & 5 deletions data/json/item_actions.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@
"id": "PICKAXE",
"name": "Dig through rock"
},
{
"type": "item_action",
"id": "MELATONIN_TABLET",
"name": "Take a melatonin tablet"
},
{
"type": "item_action",
"id": "PACK_CBM",
Expand Down
6 changes: 5 additions & 1 deletion data/json/items/comestibles/med.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
"stack_size": 30,
"symbol": "!",
"color": "yellow",
"use_action": "MELATONIN_TABLET"
"use_action": {
"type": "consume_drug",
"activation_message": "You pop a melatonin tablet.",
"effects": [ { "id": "melatonin", "duration": "16 h" } ]
}
},
{
"id": "adderall",
Expand Down
82 changes: 38 additions & 44 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3569,10 +3569,6 @@ int Character::get_fatigue() const

int Character::get_sleep_deprivation() const
{
if( !get_option< bool >( "SLEEP_DEPRIVATION" ) ) {
return 0;
}

return sleep_deprivation;
}

Expand Down Expand Up @@ -3913,18 +3909,17 @@ void Character::update_needs( int rate_multiplier )
int fatigue_roll = roll_remainder( rates.fatigue * rate_multiplier );
mod_fatigue( fatigue_roll );

if( get_option< bool >( "SLEEP_DEPRIVATION" ) ) {
// Synaptic regen bionic stops SD while awake and boosts it while sleeping
if( !has_active_bionic( bio_synaptic_regen ) ) {
// fatigue_roll should be around 1 - so the counter increases by 1 every minute on average,
// but characters who need less sleep will also get less sleep deprived, and vice-versa.
// Synaptic regen bionic stops SD while awake and boosts it while sleeping
if( !has_active_bionic( bio_synaptic_regen ) ) {
// fatigue_roll should be around 1 - so the counter increases by 1 every minute on average,
// but characters who need less sleep will also get less sleep deprived, and vice-versa.

// Note: Since needs are updated in 5-minute increments, we have to multiply the roll again by
// 5. If rate_multiplier is > 1, fatigue_roll will be higher and this will work out.
mod_sleep_deprivation( fatigue_roll * 5 );
}
// Note: Since needs are updated in 5-minute increments, we have to multiply the roll again by
// 5. If rate_multiplier is > 1, fatigue_roll will be higher and this will work out.
mod_sleep_deprivation( fatigue_roll * 5 );
}


if( npc_no_food && get_fatigue() > TIRED ) {
set_fatigue( TIRED );
set_sleep_deprivation( 0 );
Expand All @@ -3942,41 +3937,40 @@ void Character::update_needs( int rate_multiplier )
recovered *= .5;
}
mod_fatigue( -recovered );
if( get_option< bool >( "SLEEP_DEPRIVATION" ) ) {
// Sleeping on the ground, no bionic = 1x rest_modifier
// Sleeping on a bed, no bionic = 2x rest_modifier
// Sleeping on a comfy bed, no bionic= 3x rest_modifier

// Sleeping on the ground, bionic = 3x rest_modifier
// Sleeping on a bed, bionic = 6x rest_modifier
// Sleeping on a comfy bed, bionic = 9x rest_modifier
float rest_modifier = ( has_active_bionic( bio_synaptic_regen ) ? 3 : 1 );
// Melatonin supplements also add a flat bonus to recovery speed
if( has_effect( effect_melatonin_supplements ) ) {
rest_modifier += 1;
}

comfort_level comfort = base_comfort_value( pos() );
// Sleeping on the ground, no bionic = 1x rest_modifier
// Sleeping on a bed, no bionic = 2x rest_modifier
// Sleeping on a comfy bed, no bionic= 3x rest_modifier

// Sleeping on the ground, bionic = 3x rest_modifier
// Sleeping on a bed, bionic = 6x rest_modifier
// Sleeping on a comfy bed, bionic = 9x rest_modifier
float rest_modifier = ( has_active_bionic( bio_synaptic_regen ) ? 3 : 1 );
// Melatonin supplements also add a flat bonus to recovery speed
if( has_effect( effect_melatonin_supplements ) ) {
rest_modifier += 1;
}

if( comfort >= comfort_level::very_comfortable ) {
rest_modifier *= 3;
} else if( comfort >= comfort_level::comfortable ) {
rest_modifier *= 2.5;
} else if( comfort >= comfort_level::slightly_comfortable ) {
rest_modifier *= 2;
}
comfort_level comfort = base_comfort_value( pos() );

// If we're just tired, we'll get a decent boost to our sleep quality.
// The opposite is true for very tired characters.
if( get_fatigue() < DEAD_TIRED ) {
rest_modifier += 2;
} else if( get_fatigue() >= EXHAUSTED ) {
rest_modifier = ( rest_modifier > 2 ) ? rest_modifier - 2 : 1;
}
if( comfort >= comfort_level::very_comfortable ) {
rest_modifier *= 3;
} else if( comfort >= comfort_level::comfortable ) {
rest_modifier *= 2.5;
} else if( comfort >= comfort_level::slightly_comfortable ) {
rest_modifier *= 2;
}

// Recovered is multiplied by 2 as well, since we spend 1/3 of the day sleeping
mod_sleep_deprivation( -rest_modifier * ( recovered * 2 ) );
// If we're just tired, we'll get a decent boost to our sleep quality.
// The opposite is true for very tired characters.
if( get_fatigue() < DEAD_TIRED ) {
rest_modifier += 2;
} else if( get_fatigue() >= EXHAUSTED ) {
rest_modifier = ( rest_modifier > 2 ) ? rest_modifier - 2 : 1;
}

// Recovered is multiplied by 2 as well, since we spend 1/3 of the day sleeping
mod_sleep_deprivation( -rest_modifier * ( recovered * 2 ) );

}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,6 @@ void Item_factory::init()
add_iuse( "WEED_CAKE", &iuse::weed_cake );
add_iuse( "XANAX", &iuse::xanax );
add_iuse( "BREAK_STICK", &iuse::break_stick );
add_iuse( "MELATONIN_TABLET", &iuse::melatonin_tablet );

add_actor( std::make_unique<ammobelt_actor>() );
add_actor( std::make_unique<bandolier_actor>() );
Expand Down
9 changes: 7 additions & 2 deletions src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,13 @@ std::unique_ptr<iuse_actor> consume_drug_iuse::clone() const

static effect_data load_effect_data( const JsonObject &e )
{
return effect_data( efftype_id( e.get_string( "id" ) ),
time_duration::from_turns( e.get_int( "duration", 0 ) ),
time_duration time;
if( e.has_string( "duration" ) ) {
time = read_from_json_string<time_duration>( *e.get_raw( "duration" ), time_duration::units );
} else {
time = time_duration::from_turns( e.get_int( "duration", 0 ) );
}
return effect_data( efftype_id( e.get_string( "id" ) ), time,
get_body_part_token( e.get_string( "bp", "NUM_BP" ) ), e.get_bool( "permanent", false ) );
}

Expand Down
2 changes: 2 additions & 0 deletions tests/stomach_contents_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ static time_duration time_until_hungry( player &p )
{
unsigned int thirty_minutes = 0;
do {
p.set_sleep_deprivation( 0 );
p.set_fatigue( 0 );
pass_time( p, 30_minutes );
thirty_minutes++;
} while( p.get_hunger() < 40 ); // hungry
Expand Down