Skip to content

Commit

Permalink
Use normal distribution to generate random height in new character sc…
Browse files Browse the repository at this point in the history
…reen (#49270)

* fix random height

* use Character::randomize_height

* use clamp() for limit the randomness, as @pehamm suggested

* astyle fix

* use std::round instead of round

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

* learning c++ in 21 days

Co-authored-by: John Bytheway <[email protected]>

* int instead of double

* use one distribution

* changed normal_roll to 168.35 mean, 15.5 sd

Co-authored-by: pehamm <[email protected]>
Co-authored-by: John Bytheway <[email protected]>
  • Loading branch information
3 people authored Jul 7, 2021
1 parent 6e829ef commit efcbdcc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,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 @@ -2136,6 +2136,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 @@ -199,8 +199,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 @@ -3306,7 +3305,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

0 comments on commit efcbdcc

Please sign in to comment.