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

Clean up personality "magic numbers"-->defined constants #75382

Merged
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
16 changes: 8 additions & 8 deletions src/mutation_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ bool mut_personality_score::load( const JsonObject &jsobj, const std::string_vie
{
JsonObject j = jsobj.get_object( member );

optional( j, false, "min_aggression", min_aggression, -10 );
optional( j, false, "max_aggression", max_aggression, 10 );
optional( j, false, "min_bravery", min_bravery, -10 );
optional( j, false, "max_bravery", max_bravery, 10 );
optional( j, false, "min_collector", min_collector, -10 );
optional( j, false, "max_collector", max_collector, 10 );
optional( j, false, "min_altruism", min_altruism, -10 );
optional( j, false, "max_altruism", max_altruism, 10 );
optional( j, false, "min_aggression", min_aggression, NPC_PERSONALITY_MIN );
optional( j, false, "max_aggression", max_aggression, NPC_PERSONALITY_MAX );
optional( j, false, "min_bravery", min_bravery, NPC_PERSONALITY_MIN );
optional( j, false, "max_bravery", max_bravery, NPC_PERSONALITY_MAX );
optional( j, false, "min_collector", min_collector, NPC_PERSONALITY_MIN );
optional( j, false, "max_collector", max_collector, NPC_PERSONALITY_MAX );
optional( j, false, "min_altruism", min_altruism, NPC_PERSONALITY_MIN );
optional( j, false, "max_altruism", max_altruism, NPC_PERSONALITY_MAX );

return true;
}
Expand Down
26 changes: 15 additions & 11 deletions src/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,16 +559,18 @@ void npc::randomize( const npc_class_id &type, const npc_template_id &tem_id )

set_wielded_item( item( "null", calendar::turn_zero ) );
inv->clear();
personality.aggression = rng( -10, 10 );
personality.bravery = rng( -3, 10 );
personality.collector = rng( -1, 10 );
// Normal distribution. Mean = 0, stddev = 3, clamp at -10 and 10. Rounded to return integer value.
personality.altruism = std::round( std::max( -10.0, std::min( normal_roll( 0, 3 ), 10.0 ) ) );
personality.aggression = rng( NPC_PERSONALITY_MIN, NPC_PERSONALITY_MAX );
personality.bravery = rng( -3, NPC_PERSONALITY_MAX );
personality.collector = rng( -1, NPC_PERSONALITY_MAX );
// Normal distribution. Mean = 0, stddev = 3, clamp at NPC_PERSONALITY_MIN and NPC_PERSONALITY_MAX. Rounded to return integer value.
personality.altruism = std::round( std::clamp( normal_roll( 0, 3 ),
static_cast<double>( NPC_PERSONALITY_MIN ), static_cast<double>( NPC_PERSONALITY_MAX ) ) );
moves = 100;
mission = NPC_MISSION_NULL;
male = one_in( 2 );
pick_name();
randomize_height();
// Normally 16-55, but potential violence towards *underage* NPCs is a more problematic than towards adults.
set_base_age( rng( 18, 55 ) );
str_max = dice( 4, 3 );
dex_max = dice( 4, 3 );
Expand Down Expand Up @@ -622,12 +624,14 @@ void npc::randomize( const npc_class_id &type, const npc_template_id &tem_id )
personality.collector += myclass->roll_collector();
personality.altruism += myclass->roll_altruism();

personality.aggression = std::clamp( personality.aggression, NPC_PERSONALITY_MIN,
NPC_PERSONALITY_MAX );
personality.bravery = std::clamp( personality.bravery, NPC_PERSONALITY_MIN, NPC_PERSONALITY_MAX );
personality.collector = std::clamp( personality.collector, NPC_PERSONALITY_MIN,
NPC_PERSONALITY_MAX );
personality.altruism = std::clamp( personality.altruism, NPC_PERSONALITY_MIN, NPC_PERSONALITY_MAX );
personality.aggression = std::clamp<int8_t>( personality.aggression,
NPC_PERSONALITY_MIN, NPC_PERSONALITY_MAX );
personality.bravery = std::clamp<int8_t>( personality.bravery,
NPC_PERSONALITY_MIN, NPC_PERSONALITY_MAX );
personality.collector = std::clamp<int8_t>( personality.collector,
NPC_PERSONALITY_MIN, NPC_PERSONALITY_MAX );
personality.altruism = std::clamp<int8_t>( personality.altruism,
NPC_PERSONALITY_MIN, NPC_PERSONALITY_MAX );

for( Skill &skill : Skill::skills ) {
int level = myclass->roll_skill( skill.ident() );
Expand Down
4 changes: 2 additions & 2 deletions src/npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class npc_class;
class talker;
class vehicle;

constexpr int8_t NPC_PERSONALITY_MIN = -10;
constexpr int8_t NPC_PERSONALITY_MAX = 10;
constexpr int NPC_PERSONALITY_MIN = -10;
constexpr int NPC_PERSONALITY_MAX = 10;
constexpr float NPC_DANGER_VERY_LOW = 5.0f;
constexpr float NPC_MONSTER_DANGER_MAX = 150.0f;
constexpr float NPC_CHARACTER_DANGER_MAX = 250.0f;
Expand Down
2 changes: 1 addition & 1 deletion src/npc_attack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ void npc_attack_melee::use( npc &source, const tripoint &location ) const
}
} else if( source.mem_combat.formation_distance != -1 &&
source.mem_combat.formation_distance <= target_distance &&
rng( -10, 10 ) > source.personality.aggression ) {
rng( NPC_PERSONALITY_MIN, NPC_PERSONALITY_MAX ) > source.personality.aggression ) {
add_msg_debug( debugmode::DF_NPC_MOVEAI,
"<color_light_gray>%s decided to fall back to formation with allies.</color>", source.name );
source.look_for_player( get_player_character() );
Expand Down
3 changes: 2 additions & 1 deletion src/npctalk_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,8 @@ void talk_function::npc_thankful( npc &p )
if( p.chatbin.first_topic != p.chatbin.talk_friend ) {
p.chatbin.first_topic = p.chatbin.talk_stranger_friendly;
}
p.personality.aggression -= 1;
int8_t &aggro = p.personality.aggression;
aggro = std::clamp<int8_t>( aggro - 1, NPC_PERSONALITY_MIN, NPC_PERSONALITY_MAX );

}

Expand Down
Loading