Skip to content

Commit

Permalink
Merge pull request CleverRaven#50349 from mqrause/random_hobbies
Browse files Browse the repository at this point in the history
Random characters have hobbies
  • Loading branch information
ZhilkinSerg authored Aug 3, 2021
2 parents 6827cfc + 03abafd commit 08378ce
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1595,3 +1596,30 @@ std::string points_left::to_string()
return _( "Freeform" );
}
}

int avatar::randomize_hobbies()
{
hobbies.clear();
std::vector<profession_id> 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;
}
2 changes: 2 additions & 0 deletions src/avatar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<map_memory> player_map_memory;
Expand Down
4 changes: 3 additions & 1 deletion src/newcharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,16 @@ 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 );
dex_max = rng( 6, HIGH_STAT - 2 );
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.
Expand Down

0 comments on commit 08378ce

Please sign in to comment.