diff --git a/src/avatar.cpp b/src/avatar.cpp index 2aab09ba85c75..973376ecc0d8b 100644 --- a/src/avatar.cpp +++ b/src/avatar.cpp @@ -60,6 +60,7 @@ #include "pimpl.h" #include "player.h" #include "player_activity.h" +#include "profession.h" #include "ret_val.h" #include "rng.h" #include "skill.h" @@ -1595,3 +1596,30 @@ std::string points_left::to_string() return _( "Freeform" ); } } + +int avatar::randomize_hobbies() +{ + hobbies.clear(); + std::vector choices = profession::get_all_hobbies(); + + int random = rng( 0, 5 ); + int points = 0; + + if( random >= 1 ) { + const profession_id hobby = random_entry_removed( choices ); + points += hobby->point_cost(); + hobbies.insert( &*hobby ); + } + if( random >= 3 ) { + const profession_id hobby = random_entry_removed( choices ); + points += hobby->point_cost(); + hobbies.insert( &*hobby ); + } + if( random >= 5 ) { + const profession_id hobby = random_entry_removed( choices ); + points += hobby->point_cost(); + hobbies.insert( &*hobby ); + } + + return points; +} diff --git a/src/avatar.h b/src/avatar.h index a1e5091519b7d..72a37586eb466 100644 --- a/src/avatar.h +++ b/src/avatar.h @@ -293,6 +293,8 @@ class avatar : public player void add_gained_calories( int cal ) override; void log_activity_level( float level ) override; std::string total_daily_calories_string() const; + //set 0-3 random hobbies, with 1 and 2 being twice as likely as 0 and 3 + int randomize_hobbies(); private: std::unique_ptr player_map_memory; diff --git a/src/newcharacter.cpp b/src/newcharacter.cpp index 89dcd0511c52c..04be68a33ec12 100644 --- a/src/newcharacter.cpp +++ b/src/newcharacter.cpp @@ -218,6 +218,7 @@ void avatar::randomize( const bool random_scenario, points_left &points, bool pl } prof = get_scenario()->weighted_random_profession(); + int hobby_point_cost = randomize_hobbies(); random_start_location = true; str_max = rng( 6, HIGH_STAT - 2 ); @@ -225,7 +226,8 @@ void avatar::randomize( const bool random_scenario, points_left &points, bool pl int_max = rng( 6, HIGH_STAT - 2 ); per_max = rng( 6, HIGH_STAT - 2 ); points.stat_points = points.stat_points - str_max - dex_max - int_max - per_max; - points.skill_points = points.skill_points - prof->point_cost() - get_scenario()->point_cost(); + points.skill_points = points.skill_points - prof->point_cost() - get_scenario()->point_cost() - + hobby_point_cost; // The default for each stat is 8, and that default does not cost any points. // Values below give points back, values above require points. The line above has removed // to many points, therefore they are added back.