Skip to content

Commit

Permalink
Clean up personality "magic numbers"-->defined constants
Browse files Browse the repository at this point in the history
  • Loading branch information
RenechCDDA committed Aug 10, 2024
1 parent 09410b2 commit af51f20
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
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
12 changes: 7 additions & 5 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
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

0 comments on commit af51f20

Please sign in to comment.