Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use normal distribution to generate random height in new character screen #49270

Merged
merged 9 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,15 @@ character_id Character::getID() const
return this->id;
}

void Character::randomize_height()
{
// Height distribution data is taken from CDC distributes statistics for the US population
// https://github.com/CleverRaven/Cataclysm-DDA/pull/49270#issuecomment-861339732
const int x = std::round( normal_roll( 168.35, 15.50 ) );
// clamping to 145..200 because this is the bounds of what player can set, see newplayer.cpp
init_height = clamp( x, 145, 200 );
}

void Character::randomize_blood()
{
// Blood type distribution data is taken from this study on blood types of
Expand Down
2 changes: 2 additions & 0 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -2119,6 +2119,8 @@ class Character : public Creature, public visitable
std::string height_string() const;
// returns the height of the player character in cm
int height() const;
// Randomizes characters' height
void randomize_height();
// returns bodyweight of the Character
units::mass bodyweight() const;
// returns total weight of installed bionics
Expand Down
5 changes: 2 additions & 3 deletions src/newcharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ void avatar::randomize( const bool random_scenario, points_left &points, bool pl
}
// if adjusting min and max age from 16 and 55, make sure to see set_description()
init_age = rng( 16, 55 );
// if adjusting min and max height from 145 and 200, make sure to see set_description()
init_height = rng( 145, 200 );
randomize_height();
randomize_blood();
bool cities_enabled = world_generator->active_world->WORLD_OPTIONS["CITY_SIZE"].getValue() != "0";
if( random_scenario ) {
Expand Down Expand Up @@ -3298,7 +3297,7 @@ tab_direction set_description( avatar &you, const bool allow_reroll,
no_name_entered = you.name.empty();
}
you.set_base_age( rng( 16, 55 ) );
you.set_base_height( rng( 145, 200 ) );
you.randomize_height();
you.randomize_blood();
} else if( action == "CHANGE_GENDER" ) {
you.male = !you.male;
Expand Down