Skip to content

Commit

Permalink
Merge pull request #77130 from ShnitzelX2/unify-name-suffix-profession-2
Browse files Browse the repository at this point in the history
Unify name suffix and profession
  • Loading branch information
Maleclypse authored Oct 21, 2024
2 parents 6345530 + 150549a commit 9617c39
Show file tree
Hide file tree
Showing 33 changed files with 102 additions and 60 deletions.
2 changes: 1 addition & 1 deletion data/json/npcs/prisoners/mi-go_prisoners.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "npc",
"id": "mi-go_prisoner",
"//": "A naked prisoner trapped in a horrifying cage, watching horrible things happen.",
"name_suffix": "prisoner",
"temp_suffix": "Prisoner",
"class": "NC_PRISONER",
"attitude": 0,
"mission": 7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"//": "Hungry beggar in the refugee center.",
"name_unique": "Reena Sandhu",
"gender": "female",
"name_suffix": "beggar",
"name_suffix": "Teacher",
"temp_suffix": "Beggar",
"class": "NC_BEGGAR_1",
"attitude": 0,
"mission": 7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"//": "Schizophrenic beggar in the refugee center.",
"name_unique": "Dino Dave",
"gender": "male",
"name_suffix": "beggar",
"temp_suffix": "Beggar",
"class": "NC_BEGGAR_2",
"attitude": 0,
"mission": 7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"//": "Angry beggar in the refugee center.",
"name_unique": "Luo Meizhen",
"gender": "female",
"name_suffix": "beggar",
"name_suffix": "Mycologist",
"temp_suffix": "Beggar",
"class": "NC_BEGGAR_3",
"attitude": 0,
"mission": 7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"//": "Sickly beggar in the refugee center.",
"name_unique": "Brandon Garder",
"gender": "male",
"name_suffix": "beggar",
"name_suffix": "Carpenter",
"temp_suffix": "Beggar",
"class": "NC_BEGGAR_4",
"attitude": 0,
"mission": 7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"//": "Mutant beggar in the refugee center.",
"name_unique": "Yusuke Taylor",
"gender": "male",
"name_suffix": "beggar",
"name_suffix": "Computer Technician",
"temp_suffix": "Beggar",
"class": "NC_BEGGAR_5",
"attitude": 0,
"mission": 7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id": "refugee_AleeshaSeward",
"name_unique": "Aleesha Seward",
"gender": "female",
"name_suffix": "refugee",
"name_suffix": "Refugee",
"class": "NC_REFUGEE_Aleesha",
"attitude": 0,
"mission": 7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id": "refugee_AlonsoLautrec",
"name_unique": "Alonso Lautrec",
"gender": "male",
"name_suffix": "refugee",
"name_suffix": "Refugee",
"class": "NC_REFUGEE_Alonso",
"attitude": 0,
"mission": 7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id": "refugee_BorisBorichenko",
"name_unique": "Boris Borichenko",
"gender": "male",
"name_suffix": "refugee",
"name_suffix": "Refugee",
"class": "NC_REFUGEE_Boris",
"attitude": 0,
"mission": 7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id": "refugee_DanaNunez",
"name_unique": "Dana Nunez",
"gender": "female",
"name_suffix": "refugee",
"name_suffix": "Refugee",
"class": "NC_REFUGEE_Dana",
"attitude": 0,
"mission": 7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"id": "refugee_DracoDune",
"name_unique": "Draco Dune",
"gender": "male",
"name_suffix": "refugee",
"name_suffix": "Refugee",
"class": "NC_REFUGEE_Draco",
"attitude": 0,
"mission": 7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id": "refugee_FatimaalJadir",
"name_unique": "Fatima al Jadir",
"gender": "female",
"name_suffix": "refugee",
"name_suffix": "Refugee",
"class": "NC_REFUGEE_Fatima",
"attitude": 0,
"mission": 7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id": "refugee_GarryVilleneuve",
"name_unique": "Garry Villeneuve",
"gender": "male",
"name_suffix": "refugee",
"name_suffix": "Refugee",
"class": "NC_REFUGEE_Garry",
"attitude": 0,
"mission": 7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id": "refugee_GuneetSingh",
"name_unique": "Guneet Singh",
"gender": "male",
"name_suffix": "refugee",
"name_suffix": "Refugee",
"class": "NC_REFUGEE_Guneet",
"attitude": 0,
"mission": 7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"id": "refugee_JennyForcette",
"name_unique": "Jenny Forcette",
"gender": "female",
"name_suffix": "refugee",
"name_suffix": "Refugee",
"class": "NC_REFUGEE_Jenny",
"attitude": 0,
"mission": 7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id": "refugee_JohnClemens",
"name_unique": "John Clemens",
"gender": "male",
"name_suffix": "refugee",
"name_suffix": "Refugee",
"class": "NC_REFUGEE_John",
"attitude": 0,
"mission": 7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id": "refugee_MandeepSingh",
"name_unique": "Mandeep Singh",
"gender": "male",
"name_suffix": "refugee",
"name_suffix": "Refugee",
"class": "NC_REFUGEE_Mandeep",
"attitude": 0,
"mission": 7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id": "refugee_MangalpreetSingh",
"name_unique": "Mangalpreet Singh",
"gender": "female",
"name_suffix": "refugee",
"name_suffix": "Refugee",
"class": "NC_REFUGEE_Mangalpreet",
"attitude": 0,
"mission": 7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id": "refugee_PabloNunez",
"name_unique": "Pablo Nunez",
"gender": "male",
"name_suffix": "refugee",
"name_suffix": "Refugee",
"class": "NC_REFUGEE_Pablo",
"attitude": 0,
"mission": 7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id": "refugee_RhyzaeaJohnny",
"name_unique": "Rhyzaea Johnny",
"gender": "female",
"name_suffix": "refugee",
"name_suffix": "Refugee",
"class": "NC_REFUGEE_Rhyzaea",
"attitude": 0,
"mission": 7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id": "refugee_StanBorichenko",
"name_unique": "Stan Borichenko",
"gender": "male",
"name_suffix": "refugee",
"name_suffix": "Refugee",
"class": "NC_REFUGEE_Stan",
"attitude": 0,
"mission": 7,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id": "refugee_UyenTran",
"name_unique": "Uyen Tran",
"gender": "female",
"name_suffix": "refugee",
"name_suffix": "Refugee",
"class": "NC_REFUGEE_Uyen",
"attitude": 0,
"mission": 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id": "refugee_VanessaToby",
"name_unique": "Vanessa Toby",
"gender": "female",
"name_suffix": "refugee",
"name_suffix": "Refugee",
"class": "NC_REFUGEE_Vanessa",
"attitude": 0,
"mission": 7,
Expand Down
9 changes: 9 additions & 0 deletions src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,15 @@ int avatar::print_info( const catacurses::window &w, int vStart, int, int column
get_name() ) - 1;
}

std::string avatar::display_name( bool possessive, bool capitalize_first ) const
{
if( !possessive ) {
return capitalize_first ? _( "You" ) : _( "you" );
} else {
return capitalize_first ? _( "Your" ) : _( "your" );
}
}

mfaction_id avatar::get_monster_faction() const
{
return monfaction_player.id();
Expand Down
1 change: 1 addition & 0 deletions src/avatar.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class avatar : public Character

nc_color basic_symbol_color() const override;
int print_info( const catacurses::window &w, int vStart, int vLines, int column ) const override;
std::string display_name( bool possessive = false, bool capitalize_first = false ) const;

/** Resets stats, and applies effects in an idempotent manner */
void reset_stats() override;
Expand Down
25 changes: 16 additions & 9 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,17 +840,24 @@ creature_size Character::get_size() const

std::string Character::disp_name( bool possessive, bool capitalize_first ) const
{
if( !possessive ) {
if( is_avatar() ) {
return capitalize_first ? _( "You" ) : _( "you" );
}
return get_name();
} else {
if( is_avatar() ) {
return capitalize_first ? _( "Your" ) : _( "your" );
return is_avatar() ? as_avatar()->display_name( possessive,
capitalize_first ) : as_npc()->display_name( possessive );
}

std::string Character::disp_profession() const
{
if( !custom_profession.empty() ) {
return custom_profession;
}
if( is_npc() && as_npc()->myclass != npc_class_id::NULL_ID() ) {
if( play_name_suffix ) {
return play_name_suffix.value();
}
return string_format( _( "%s's" ), get_name() );
}
if( prof != nullptr && prof != profession::generic() ) {
return prof->gender_appropriate_name( male );
}
return "";
}

std::string Character::name_and_maybe_activity() const
Expand Down
15 changes: 10 additions & 5 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -742,11 +742,13 @@ class Character : public Creature, public visitable
/** Recalculate size class of character **/
void recalculate_size();

/** Returns either "you" or the player's name. capitalize_first assumes
that the character's name is already upper case and uses it only for
possessive "your" and "you"
/** Displays character name with a npc_class/profession suffix
**/
std::string disp_name( bool possessive = false, bool capitalize_first = false ) const override;
/** Returns the player's profession or an NPC's suffix if they have one
* @param npc_override for now, professions don't display by default as suffixes. Set to true to get the profession name if it exists.
**/
std::string disp_profession() const;
virtual std::string name_and_maybe_activity() const;
/** Returns the name of the player's outer layer, e.g. "armor plates" */
std::string skin_name() const override;
Expand Down Expand Up @@ -1117,8 +1119,6 @@ class Character : public Creature, public visitable

double recoil = MAX_RECOIL;

std::string custom_profession;

/** Returns true if the player has quiet melee attacks */
bool is_quiet() const;

Expand Down Expand Up @@ -2709,6 +2709,11 @@ class Character : public Creature, public visitable
std::string name; // Pre-cataclysm name, invariable
// In-game name which you give to npcs or whoever asks, variable
std::optional<std::string> play_name;
// In-game name suffix, either a profession or npc class, variable
std::optional<std::string> play_name_suffix;
// In-game customized suffix, set by player OR temp professison for NPC
std::string custom_profession;

bool male = false;

std::vector<effect_on_condition_id> death_eocs;
Expand Down
2 changes: 2 additions & 0 deletions src/newcharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,9 @@ void Character::randomize( const bool random_scenario, bool play_now )

const scenario *scenario_from = is_avatar() ? get_scenario() : scenario::generic();
prof = scenario_from->weighted_random_profession();
play_name_suffix = prof->gender_appropriate_name( male );
zero_all_skills();

init_age = rng( this->prof->age_lower, this->prof->age_upper );
starting_city = std::nullopt;
world_origin = std::nullopt;
Expand Down
24 changes: 19 additions & 5 deletions src/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ void npc_template::load( const JsonObject &jsobj, const std::string_view src )
if( jsobj.has_string( "class" ) ) {
guy.myclass = npc_class_id( jsobj.get_string( "class" ) );
}

if( jsobj.has_string( "temp_suffix" ) ) {
jsobj.read( "temp_suffix", tem.temp_suffix );
}
guy.set_attitude( static_cast<npc_attitude>( jsobj.get_int( "attitude" ) ) );
guy.mission = static_cast<npc_mission>( jsobj.get_int( "mission" ) );
guy.chatbin.first_topic = jsobj.get_string( "chat" );
Expand Down Expand Up @@ -523,8 +525,10 @@ void npc::load_npc_template( const string_id<npc_template> &ident )
name = tem.name_unique.translated();
}
if( !tem.name_suffix.empty() ) {
//~ %1$s: npc name, %2$s: name suffix
name = string_format( pgettext( "npc name", "%1$s, %2$s" ), name, tem.name_suffix );
play_name_suffix = tem.name_suffix.translated();
}
if( !tem.temp_suffix.empty() ) {
custom_profession = tem.temp_suffix.translated();
}
fac_id = tguy.fac_id;
set_fac( fac_id );
Expand Down Expand Up @@ -3781,13 +3785,23 @@ std::string npc::describe_mission() const
} // switch (mission)
}

std::string npc::display_name( bool possessive ) const
{
const std::string profession = disp_profession();
if( profession.empty() ) {
return possessive ? string_format( _( "%1$s's" ), get_name() ) : get_name();
}
return possessive ? string_format( _( "%1$s, %2$s's" ), get_name(),
profession ) : string_format( _( "%1$s, %2$s" ), get_name(), profession );
}

std::string npc::name_and_activity() const
{
if( current_activity_id ) {
//~ %1$s - npc name, %2$s - npc current activity name.
return string_format( _( "%1$s (%2$s)" ), get_name(), get_current_activity() );
return string_format( _( "%1$s (%2$s)" ), disp_name(), get_current_activity() );
} else {
return get_name();
return disp_name();
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@ class npc : public Character
std::string opinion_text() const;
int faction_display( const catacurses::window &fac_w, int width ) const;
std::string describe_mission() const;
std::string display_name( bool possessive = false ) const;
std::string name_and_activity() const;
std::string name_and_maybe_activity() const override;
/// Returns current status (Sleeping, Guarding, In Combat, etc.), or current activity
Expand Down Expand Up @@ -1463,6 +1464,7 @@ class npc_template
dialogue_chatbin_snippets snippets;
translation name_unique;
translation name_suffix;
translation temp_suffix;
enum class gender : int {
random,
male,
Expand Down
3 changes: 3 additions & 0 deletions src/npctalk_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,9 @@ void talk_function::follow( npc &p )
p.set_fac( faction_your_followers );
get_player_character().cash += p.cash;
p.cash = 0;
if( !p.custom_profession.empty() ) {
p.custom_profession.clear();
}
}

void talk_function::follow_only( npc &p )
Expand Down
Loading

0 comments on commit 9617c39

Please sign in to comment.