Skip to content

Commit

Permalink
feat(balance): Allow for use of multiple sleep aids (#5848)
Browse files Browse the repository at this point in the history
* Allow for use of multiple sleep aids

And print them out too!

* style(autofix.ci): automated formatting

* remove the uncessary if statement

thanks scarf, very cool

Co-authored-by: scarf <[email protected]>

* style(autofix.ci): automated formatting

* Remove unnecessary vector clearing

initialization should handle it

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: scarf <[email protected]>
  • Loading branch information
3 people authored Dec 28, 2024
1 parent 6b574de commit ddc7bd7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 7 additions & 9 deletions src/character_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,11 @@ comfort_response_t base_comfort_value( const Character &who, const tripoint &p )
const std::optional<vpart_reference> board = vp.part_with_feature( "BOARDABLE", true );
if( carg ) {
const vehicle_stack items = vp->vehicle().get_items( carg->part_index() );
for( const item *items_it : items ) {
for( item *items_it : items ) {
if( items_it->has_flag( STATIC( flag_id( "SLEEP_AID" ) ) ) ) {
// Note: BED + SLEEP_AID = 9 pts, or 1 pt below very_comfortable
comfort += 1 + static_cast<int>( comfort_level::slightly_comfortable );
comfort_response.aid = items_it;
break; // prevents using more than 1 sleep aid
comfort_response.aid.push_back( items_it );
}
}
}
Expand Down Expand Up @@ -278,14 +277,13 @@ comfort_response_t base_comfort_value( const Character &who, const tripoint &p )
comfort -= here.move_cost( p );
}

if( comfort_response.aid == nullptr ) {
if( comfort_response.aid.empty() ) {
const map_stack items = here.i_at( p );
for( const item *items_it : items ) {
for( item *items_it : items ) {
if( items_it->has_flag( STATIC( flag_id( "SLEEP_AID" ) ) ) ) {
// Note: BED + SLEEP_AID = 9 pts, or 1 pt below very_comfortable
comfort += 1 + static_cast<int>( comfort_level::slightly_comfortable );
comfort_response.aid = items_it;
break; // prevents using more than 1 sleep aid
comfort_response.aid.push_back( items_it );
}
}
}
Expand Down Expand Up @@ -341,8 +339,8 @@ int rate_sleep_spot( const Character &who, const tripoint &p )
{
const int current_stim = who.get_stim();
const comfort_response_t comfort_info = base_comfort_value( who, p );
if( comfort_info.aid != nullptr ) {
who.add_msg_if_player( m_info, _( "You use your %s for comfort." ), comfort_info.aid->tname() );
for( item *comfort_item : comfort_info.aid ) {
who.add_msg_if_player( m_info, _( "You use your %s for comfort." ), comfort_item->tname() );
}

int sleepy = static_cast<int>( comfort_info.level );
Expand Down
2 changes: 1 addition & 1 deletion src/character_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ enum class comfort_level {

struct comfort_response_t {
comfort_level level = comfort_level::neutral;
const item *aid = nullptr;
std::vector<item *> aid;
};

/** Rate point's ability to serve as a bed. Only takes certain mutations into account, and not fatigue nor stimulants. */
Expand Down

0 comments on commit ddc7bd7

Please sign in to comment.