diff --git a/src/npc.cpp b/src/npc.cpp index b5f2949d38a70..1bf2255ff3e98 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -838,7 +838,12 @@ void npc::randomize( const npc_class_id &type ) set_body(); recalc_hp(); - + randomize_height(); + int days_since_cata = to_days( calendar::turn - calendar::start_of_cataclysm ); + double time_influence = days_since_cata >= 180 ? 3.0 : 6.0 - 3.0 * days_since_cata / 180.0; + double weight_percent = std::clamp( chi_squared_roll( time_influence ) / 5.0, + 0.2, 5.0 ); + set_stored_kcal( weight_percent * get_healthy_kcal() ); starting_weapon( myclass ); starting_clothes( *this, myclass, male ); starting_inv( *this, myclass ); @@ -882,7 +887,6 @@ void npc::randomize( const npc_class_id &type ) } set_base_age( rng( 18, 55 ) ); - randomize_height(); // Add eocs effect_on_conditions::load_new_character( *this ); diff --git a/src/rng.cpp b/src/rng.cpp index 1d0f1bb9600cb..425510e7626b3 100644 --- a/src/rng.cpp +++ b/src/rng.cpp @@ -55,6 +55,13 @@ double exponential_roll( double lambda ) std::exponential_distribution<>::param_type( lambda ) ); } +double chi_squared_roll( double trial_num ) +{ + static std::chi_squared_distribution rng_chi_squared_dist; + return rng_chi_squared_dist( rng_get_engine(), + std::chi_squared_distribution<>::param_type( trial_num ) ); +} + double rng_exponential( double min, double mean ) { const double adjusted_mean = mean - min; diff --git a/src/rng.h b/src/rng.h index 59e9123b4f677..89a8f4916b911 100644 --- a/src/rng.h +++ b/src/rng.h @@ -72,6 +72,8 @@ inline double rng_normal( double hi ) double normal_roll( double mean, double stddev ); +double chi_squared_roll( double trial_num ); + double rng_exponential( double min, double mean ); inline double rng_exponential( double mean )