Skip to content

Commit

Permalink
Expand weary (debugging) info (#46757)
Browse files Browse the repository at this point in the history
  • Loading branch information
actual-nh authored Jan 16, 2021
1 parent 89a68d7 commit 1582f28
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5043,9 +5043,13 @@ std::string Character::debug_weary_info() const
int input = weary.tracker;
int thresh = weary_threshold();
int current = weariness_level();
int morale = get_morale_level();
int weight = units::to_gram<int>( bodyweight() );
float bmi = get_bmi();

return string_format( "Weariness: %s Max Exertion: %s Mult: %g\nBMR: %d Intake: %d Tracker: %d Thresh: %d At: %d\nCalories: %d",
amt, max_act, move_mult, bmr, intake, input, thresh, current, stored_calories );
return string_format( "Weariness: %s Max Full Exert: %s Mult: %g\nBMR: %d Intake: %d Tracker: %d Thresh: %d At: %d\nCal: %d/%d Fatigue: %d Morale: %d Wgt: %d (BMI %.1f)",
amt, max_act, move_mult, bmr, intake, input, thresh, current, stored_calories,
healthy_calories, fatigue, morale, weight, bmi );
}

void weariness_tracker::clear()
Expand Down
4 changes: 2 additions & 2 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -2689,6 +2689,8 @@ class Character : public Creature, public visitable
time_duration get_consume_time( const item &it );

int weariness_level() const;
int weary_threshold() const;
int weariness() const;
float activity_level() const;
float exertion_adjusted_move_multiplier( float level = -1.0f ) const;
void try_reduce_weariness( float exertion );
Expand Down Expand Up @@ -2754,8 +2756,6 @@ class Character : public Creature, public visitable
int healthy_mod = 0;

weariness_tracker weary;
int weary_threshold() const;
int weariness() const;
// Our bmr at no activity level
int base_bmr() const;

Expand Down
15 changes: 11 additions & 4 deletions tests/activity_scheduling_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ weariness_events do_activity( tasklist tasks )
tasks.advance( task.interval );
// If we're more weary than we were when we started, report it
if( new_weariness != weariness_lvl ) {
activity_log.log( weariness_lvl, new_weariness, spent );
int new_weary = guy.weariness();
int new_thresh = guy.weary_threshold();
activity_log.log( weariness_lvl, new_weariness, spent,
new_weary, new_thresh );
weariness_lvl = new_weariness;
}
}
Expand Down Expand Up @@ -167,12 +170,15 @@ time_duration tasklist::duration()
return ret;
}

void weariness_events::log( const int old_level, const int new_level, const time_duration &when )
void weariness_events::log( const int old_level, const int new_level, const time_duration &when,
const int new_weariness, const int new_threshold )
{
weary_transition added;
added.from = old_level;
added.to = new_level;
added.minutes = to_minutes<int>( when );
added.new_weariness = new_weariness;
added.new_threshold = new_threshold;

transitions.insert( transitions.end(), added );
}
Expand All @@ -196,8 +202,9 @@ std::string weariness_events::summarize() const
{
std::string buffer;
for( const weary_transition &change : transitions ) {
buffer += string_format( "Transition: Weariness from %d to %d at %d minutes\n", change.from,
change.to, change.minutes );
buffer += string_format( "Transition: Weariness lvl from %d to %d at %d min (W %d Th %d)\n",
change.from, change.to, change.minutes,
change.new_weariness, change.new_threshold );
}
return buffer;
}
Expand Down
5 changes: 4 additions & 1 deletion tests/activity_scheduling_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,15 @@ struct weariness_events {
int minutes = 0;
int from = 0;
int to = 0;
int new_weariness = 0;
int new_threshold = 0;
};

std::vector<weary_transition> transitions;

public:
void log( int old_level, int new_level, const time_duration &when );
void log( int old_level, int new_level, const time_duration &when,
int new_weariness, int new_threshold );

// Return the first time a transition between `from` and `to` occurs, in minutes
// if around = 0_seconds or equivalent, otherwise return the time closest to around
Expand Down
7 changes: 7 additions & 0 deletions tests/weary_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ TEST_CASE( "weary_assorted_tasks", "[weary][activities]" )

SECTION( "Light tasks" ) {
INFO( "\nFirst Aid 8 hours:" );
INFO( guy.debug_weary_info() );
weariness_events info = do_activity( desk_8h );
INFO( info.summarize() );
INFO( guy.debug_weary_info() );
Expand All @@ -49,6 +50,7 @@ TEST_CASE( "weary_assorted_tasks", "[weary][activities]" )

SECTION( "Moderate tasks" ) {
INFO( "\nPlanting 8 hours:" );
INFO( guy.debug_weary_info() );
weariness_events info = do_activity( moderate_8h );
INFO( info.summarize() );
INFO( guy.debug_weary_info() );
Expand All @@ -59,6 +61,7 @@ TEST_CASE( "weary_assorted_tasks", "[weary][activities]" )

SECTION( "Heavy tasks" ) {
INFO( "\nDigging Pits 8 hours:" );
INFO( guy.debug_weary_info() );
weariness_events info = do_activity( soldier_8h );
INFO( info.summarize() );
INFO( guy.debug_weary_info() );
Expand Down Expand Up @@ -115,6 +118,7 @@ TEST_CASE( "weary_recovery", "[weary][activities]" )

SECTION( "Heavy tasks" ) {
INFO( "\nDigging Pits 8 hours, then waiting 8:" );
INFO( guy.debug_weary_info() );
weariness_events info = do_activity( soldier_8h );
INFO( info.summarize() );
INFO( guy.debug_weary_info() );
Expand All @@ -126,6 +130,7 @@ TEST_CASE( "weary_recovery", "[weary][activities]" )

SECTION( "1 day vehicle work" ) {
INFO( "\n3 meals, 10h vehicle work, 4h reading, 10h sleep, 16h waiting" );
INFO( guy.debug_weary_info() );
weariness_events info = do_activity( mechanic_day );
INFO( info.summarize() );
INFO( guy.debug_weary_info() );
Expand All @@ -148,6 +153,7 @@ TEST_CASE( "weary_24h_tasks", "[weary][activities]" )
digging_24h.enschedule( task_dig, 24_hours );

SECTION( "Waiting 24 hours" ) {
INFO( guy.debug_weary_info() );
weariness_events info = do_activity( waiting_24h );
INFO( info.summarize() );
INFO( guy.debug_weary_info() );
Expand All @@ -156,6 +162,7 @@ TEST_CASE( "weary_24h_tasks", "[weary][activities]" )
}

SECTION( "Digging 24 hours" ) {
INFO( guy.debug_weary_info() );
weariness_events info = do_activity( digging_24h );
INFO( info.summarize() );
INFO( guy.debug_weary_info() );
Expand Down

0 comments on commit 1582f28

Please sign in to comment.