From f1cdad099799baf70ff1697cef0ec70096cf4c7e Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Sun, 26 Jan 2020 11:13:14 +0100 Subject: [PATCH 1/7] Only give message about sleeping aid once --- src/character.cpp | 11 ++++++++--- src/character.h | 2 +- src/player.cpp | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/character.cpp b/src/character.cpp index 0d3a360342c25..53a765e502dd7 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -4878,7 +4878,7 @@ void Character::temp_equalizer( body_part bp1, body_part bp2 ) temp_cur[bp1] += diff; } -Character::comfort_level Character::base_comfort_value( const tripoint &p ) const +Character::comfort_level Character::base_comfort_value( const tripoint &p, bool message ) const { // Comfort of sleeping spots is "objective", while sleep_spot( p ) is "subjective" // As in the latter also checks for fatigue and other variables while this function @@ -4917,7 +4917,10 @@ Character::comfort_level Character::base_comfort_value( const tripoint &p ) cons if( items_it.has_flag( "SLEEP_AID" ) ) { // Note: BED + SLEEP_AID = 9 pts, or 1 pt below very_comfortable comfort += 1 + static_cast( comfort_level::slightly_comfortable ); - add_msg_if_player( m_info, _( "You use your %s for comfort." ), items_it.tname() ); + if( message ) { + add_msg_if_player( m_info, _( "You use your %s for comfort." ), items_it.tname() ); + } + break; // prevents using more than 1 sleep aid } } @@ -4953,7 +4956,9 @@ Character::comfort_level Character::base_comfort_value( const tripoint &p ) cons if( items_it.has_flag( "SLEEP_AID" ) ) { // Note: BED + SLEEP_AID = 9 pts, or 1 pt below very_comfortable comfort += 1 + static_cast( comfort_level::slightly_comfortable ); - add_msg_if_player( m_info, _( "You use your %s for comfort." ), items_it.tname() ); + if( message ) { + add_msg_if_player( m_info, _( "You use your %s for comfort." ), items_it.tname() ); + } break; // prevents using more than 1 sleep aid } } diff --git a/src/character.h b/src/character.h index 7a5d3953ff265..e8f3ac6fe8785 100644 --- a/src/character.h +++ b/src/character.h @@ -459,7 +459,7 @@ class Character : public Creature, public visitable void temp_equalizer( body_part bp1, body_part bp2 ); /** Rate point's ability to serve as a bed. Only takes certain mutations into account, and not fatigue nor stimulants. */ - comfort_level base_comfort_value( const tripoint &p ) const; + comfort_level base_comfort_value( const tripoint &p, bool message = false ) const; /** Define blood loss (in percents) */ int blood_loss( body_part bp ) const; diff --git a/src/player.cpp b/src/player.cpp index b70dd6907b0b6..3ab7ec34fa0c1 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -4466,7 +4466,7 @@ void player::try_to_sleep( const time_duration &dur ) int player::sleep_spot( const tripoint &p ) const { const int current_stim = get_stim(); - comfort_level base_level = base_comfort_value( p ); + comfort_level base_level = base_comfort_value( p, true ); int sleepy = static_cast( base_level ); bool watersleep = has_trait( trait_WATERSLEEP ); From 57260db5bfe44f5142c31c10bc56ba6b2bbd5e16 Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Sun, 26 Jan 2020 11:18:33 +0100 Subject: [PATCH 2/7] remove some auto --- src/character.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/character.cpp b/src/character.cpp index 53a765e502dd7..2bf04af7fc8a7 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -4908,12 +4908,11 @@ Character::comfort_level Character::base_comfort_value( const tripoint &p, bool comfort += 1 + static_cast( comfort_level::slightly_comfortable ); // Note: shelled individuals can still use sleeping aids! } else if( vp ) { - vehicle &veh = vp->vehicle(); const cata::optional carg = vp.part_with_feature( "CARGO", false ); const cata::optional board = vp.part_with_feature( "BOARDABLE", true ); if( carg ) { - vehicle_stack items = veh.get_items( carg->part_index() ); - for( auto &items_it : items ) { + const vehicle_stack items = vp->vehicle().get_items( carg->part_index() ); + for( const item &items_it : items ) { if( items_it.has_flag( "SLEEP_AID" ) ) { // Note: BED + SLEEP_AID = 9 pts, or 1 pt below very_comfortable comfort += 1 + static_cast( comfort_level::slightly_comfortable ); @@ -4951,8 +4950,8 @@ Character::comfort_level Character::base_comfort_value( const tripoint &p, bool comfort -= g->m.move_cost( p ); } - auto items = g->m.i_at( p ); - for( auto &items_it : items ) { + const map_stack items = g->m.i_at( p ); + for( const item &items_it : items ) { if( items_it.has_flag( "SLEEP_AID" ) ) { // Note: BED + SLEEP_AID = 9 pts, or 1 pt below very_comfortable comfort += 1 + static_cast( comfort_level::slightly_comfortable ); From 0e59d058873a8d75fe097416b895ab0618696777 Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Mon, 27 Jan 2020 17:53:32 +0100 Subject: [PATCH 3/7] apply suggestions --- src/character.cpp | 40 ++++++++++++++++++++-------------------- src/character.h | 6 +++++- src/player.cpp | 8 ++++++-- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/character.cpp b/src/character.cpp index 2bf04af7fc8a7..13b3b84255790 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -3956,7 +3956,7 @@ void Character::update_needs( int rate_multiplier ) rest_modifier += 1; } - comfort_level comfort = base_comfort_value( pos() ); + const comfort_level comfort = base_comfort_value( pos() ).level; if( comfort >= comfort_level::very_comfortable ) { rest_modifier *= 3; @@ -4878,7 +4878,7 @@ void Character::temp_equalizer( body_part bp1, body_part bp2 ) temp_cur[bp1] += diff; } -Character::comfort_level Character::base_comfort_value( const tripoint &p, bool message ) const +Character::comfort_response_t Character::base_comfort_value( const tripoint &p ) const { // Comfort of sleeping spots is "objective", while sleep_spot( p ) is "subjective" // As in the latter also checks for fatigue and other variables while this function @@ -4886,6 +4886,8 @@ Character::comfort_level Character::base_comfort_value( const tripoint &p, bool // as arachnids who sleep in webs will find most places comfortable for instance. int comfort = 0; + comfort_response_t comfort_response; + comfort_response.aid = &item( "null" ); bool plantsleep = has_trait( trait_CHLOROMORPH ); bool fungaloid_cosplay = has_trait( trait_M_SKIN3 ); bool websleep = has_trait( trait_WEB_WALKER ); @@ -4916,10 +4918,7 @@ Character::comfort_level Character::base_comfort_value( const tripoint &p, bool if( items_it.has_flag( "SLEEP_AID" ) ) { // Note: BED + SLEEP_AID = 9 pts, or 1 pt below very_comfortable comfort += 1 + static_cast( comfort_level::slightly_comfortable ); - if( message ) { - add_msg_if_player( m_info, _( "You use your %s for comfort." ), items_it.tname() ); - } - + comfort_response.aid = &items_it; break; // prevents using more than 1 sleep aid } } @@ -4950,18 +4949,18 @@ Character::comfort_level Character::base_comfort_value( const tripoint &p, bool comfort -= g->m.move_cost( p ); } - const map_stack items = g->m.i_at( p ); - for( const item &items_it : items ) { - if( items_it.has_flag( "SLEEP_AID" ) ) { - // Note: BED + SLEEP_AID = 9 pts, or 1 pt below very_comfortable - comfort += 1 + static_cast( comfort_level::slightly_comfortable ); - if( message ) { - add_msg_if_player( m_info, _( "You use your %s for comfort." ), items_it.tname() ); + if( comfort_response.aid->is_null() ) { + const map_stack items = g->m.i_at( p ); + for( const item &items_it : items ) { + if( items_it.has_flag( "SLEEP_AID" ) ) { + // Note: BED + SLEEP_AID = 9 pts, or 1 pt below very_comfortable + comfort += 1 + static_cast( comfort_level::slightly_comfortable ); + comfort_response.aid = &items_it; + + break; // prevents using more than 1 sleep aid } - break; // prevents using more than 1 sleep aid } } - if( fungaloid_cosplay && g->m.has_flag_ter_or_furn( "FUNGUS", pos() ) ) { comfort += static_cast( comfort_level::very_comfortable ); } else if( watersleep && g->m.has_flag_ter( "SWIMMABLE", pos() ) ) { @@ -4997,16 +4996,17 @@ Character::comfort_level Character::base_comfort_value( const tripoint &p, bool } if( comfort > static_cast( comfort_level::comfortable ) ) { - return comfort_level::very_comfortable; + comfort_response.level = comfort_level::very_comfortable; } else if( comfort > static_cast( comfort_level::slightly_comfortable ) ) { - return comfort_level::comfortable; + comfort_response.level = comfort_level::comfortable; } else if( comfort > static_cast( comfort_level::neutral ) ) { - return comfort_level::slightly_comfortable; + comfort_response.level = comfort_level::slightly_comfortable; } else if( comfort == static_cast( comfort_level::neutral ) ) { - return comfort_level::neutral; + comfort_response.level = comfort_level::neutral; } else { - return comfort_level::uncomfortable; + comfort_response.level = comfort_level::uncomfortable; } + return comfort_response; } int Character::blood_loss( body_part bp ) const diff --git a/src/character.h b/src/character.h index e8f3ac6fe8785..332ad3d81af45 100644 --- a/src/character.h +++ b/src/character.h @@ -458,8 +458,12 @@ class Character : public Creature, public visitable /** Equalizes heat between body parts */ void temp_equalizer( body_part bp1, body_part bp2 ); + struct comfort_response_t { + comfort_level level; + const item *aid; + }; /** Rate point's ability to serve as a bed. Only takes certain mutations into account, and not fatigue nor stimulants. */ - comfort_level base_comfort_value( const tripoint &p, bool message = false ) const; + comfort_response_t base_comfort_value( const tripoint &p ) const; /** Define blood loss (in percents) */ int blood_loss( body_part bp ) const; diff --git a/src/player.cpp b/src/player.cpp index 3ab7ec34fa0c1..2a01ba6adf054 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -4466,8 +4466,12 @@ void player::try_to_sleep( const time_duration &dur ) int player::sleep_spot( const tripoint &p ) const { const int current_stim = get_stim(); - comfort_level base_level = base_comfort_value( p, true ); - int sleepy = static_cast( base_level ); + const comfort_response_t comfort_info = base_comfort_value( p ); + if( !comfort_info.aid->is_null() ) { + add_msg_if_player( m_info, _( "You use your %s for comfort." ), comfort_info.aid->tname() ); + } + + int sleepy = static_cast( comfort_info.level ); bool watersleep = has_trait( trait_WATERSLEEP ); if( has_addiction( ADD_SLEEP ) ) { From fd785661cbfdb3038718e0818e037ab107d59fe8 Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Mon, 27 Jan 2020 17:56:00 +0100 Subject: [PATCH 4/7] astyle --- src/character.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/character.cpp b/src/character.cpp index 13b3b84255790..8df8e4e3975cc 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -4956,7 +4956,6 @@ Character::comfort_response_t Character::base_comfort_value( const tripoint &p ) // Note: BED + SLEEP_AID = 9 pts, or 1 pt below very_comfortable comfort += 1 + static_cast( comfort_level::slightly_comfortable ); comfort_response.aid = &items_it; - break; // prevents using more than 1 sleep aid } } From 4b8962426fc12fd06a8abd1bfa48c260a9f0ec9f Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Mon, 27 Jan 2020 18:07:53 +0100 Subject: [PATCH 5/7] use pointer properly --- src/character.cpp | 4 ++-- src/player.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/character.cpp b/src/character.cpp index 8df8e4e3975cc..9b25e0e21ff17 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -4887,7 +4887,7 @@ Character::comfort_response_t Character::base_comfort_value( const tripoint &p ) int comfort = 0; comfort_response_t comfort_response; - comfort_response.aid = &item( "null" ); + bool plantsleep = has_trait( trait_CHLOROMORPH ); bool fungaloid_cosplay = has_trait( trait_M_SKIN3 ); bool websleep = has_trait( trait_WEB_WALKER ); @@ -4949,7 +4949,7 @@ Character::comfort_response_t Character::base_comfort_value( const tripoint &p ) comfort -= g->m.move_cost( p ); } - if( comfort_response.aid->is_null() ) { + if( comfort_response.aid == nullptr ) { const map_stack items = g->m.i_at( p ); for( const item &items_it : items ) { if( items_it.has_flag( "SLEEP_AID" ) ) { diff --git a/src/player.cpp b/src/player.cpp index 2a01ba6adf054..efb88d00eb4c1 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -4467,7 +4467,7 @@ int player::sleep_spot( const tripoint &p ) const { const int current_stim = get_stim(); const comfort_response_t comfort_info = base_comfort_value( p ); - if( !comfort_info.aid->is_null() ) { + if( comfort_info.aid != nullptr ) { add_msg_if_player( m_info, _( "You use your %s for comfort." ), comfort_info.aid->tname() ); } From 4d3612bbf9a58af3919f3c2b1afb7f60df81e91e Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Mon, 27 Jan 2020 22:50:51 +0100 Subject: [PATCH 6/7] init pointer --- src/character.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/character.h b/src/character.h index 332ad3d81af45..0d8f1f2dd6391 100644 --- a/src/character.h +++ b/src/character.h @@ -460,7 +460,7 @@ class Character : public Creature, public visitable struct comfort_response_t { comfort_level level; - const item *aid; + const item *aid = nullptr; }; /** Rate point's ability to serve as a bed. Only takes certain mutations into account, and not fatigue nor stimulants. */ comfort_response_t base_comfort_value( const tripoint &p ) const; From 94e28b87a48fea2ec13e4b7d57afb4e7b182d10c Mon Sep 17 00:00:00 2001 From: Fris0uman Date: Thu, 30 Jan 2020 18:21:56 +0100 Subject: [PATCH 7/7] fix merge --- src/character.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/character.cpp b/src/character.cpp index d7dfa7b2d0246..a31eaf6ec0989 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -3948,7 +3948,7 @@ void Character::update_needs( int rate_multiplier ) recovered *= .5; } mod_fatigue( -recovered ); - + // 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 @@ -3962,7 +3962,7 @@ void Character::update_needs( int rate_multiplier ) rest_modifier += 1; } - comfort_level comfort = base_comfort_value( pos() ); + const comfort_level comfort = base_comfort_value( pos() ).level; if( comfort >= comfort_level::very_comfortable ) { rest_modifier *= 3;