Skip to content

Commit

Permalink
Merge pull request #76935 from ShnitzelX2/generalize-char-gen
Browse files Browse the repository at this point in the history
Obsolete generic NPC common classes; use the avatar character generator instead
  • Loading branch information
Maleclypse authored Oct 17, 2024
2 parents 655cdea + 21d13db commit cc3ab7f
Show file tree
Hide file tree
Showing 14 changed files with 461 additions and 108 deletions.
91 changes: 91 additions & 0 deletions data/json/npcs/BG_trait_groups.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,97 @@
{ "trait": "BGSS_Lab_1" }
]
},
{
"//": "This group is for NPCs that were left unusually emotionally or physically defenseless after the Cataclysm.",
"type": "trait_group",
"id": "BG_survival_story_VULNERABLE",
"subtype": "distribution",
"traits": [ { "trait": "BGSS_Confused_1" }, { "trait": "BGSS_No_Past_2" }, { "trait": "BGSS_No_Past_3" } ]
},
{
"//": "This group is for NPCs that were exploring a city.",
"type": "trait_group",
"id": "BG_survival_story_TOURIST",
"subtype": "distribution",
"traits": [ { "group": "BG_survival_story_UNIVERSAL" }, { "group": "BG_survival_story_STUCK_IN_TOWN" } ]
},
{
"//": "This group is for NPCs that retired prior to the Cataclysm.",
"type": "trait_group",
"id": "BG_survival_story_RETIRED",
"subtype": "distribution",
"traits": [ { "group": "BG_survival_story_UNIVERSAL" }, { "trait": "BGSS_Confused_1" }, { "trait": "BGSS_Codger" } ]
},
{
"//": "This group is for NPCs that are ambiguously unemployed and weirder than usual.",
"type": "trait_group",
"id": "BG_survival_story_ECCENTRIC",
"subtype": "distribution",
"traits": [ { "group": "BG_survival_story_EVACUEE" } ]
},
{
"//": "This group is for NPCs that prepared in advance and hunkered down after the Cataclysm.",
"type": "trait_group",
"id": "BG_survival_story_PREPPER",
"subtype": "distribution",
"traits": [ { "trait": "BGSS_Prepper_1" }, { "trait": "BGSS_Prepper_2" } ]
},
{
"//": "This group is for NPCs that are young and roam the streets.",
"type": "trait_group",
"id": "BG_survival_story_TEENAGER_TOUGH",
"subtype": "distribution",
"traits": [ { "group": "BG_survival_story_TEENAGER" } ]
},
{
"//": "This group is for NPCs that are particularly focused on a spiritual belief.",
"type": "trait_group",
"id": "BG_survival_story_SPIRITUAL",
"subtype": "distribution",
"traits": [ { "trait": "BGSS_Religious_1" }, { "trait": "BGSS_Religious_2" }, { "trait": "BGSS_Dreamer" } ]
},
{
"//": "This group is for NPCs that are particularly sporty.",
"type": "trait_group",
"id": "BG_survival_story_SPORTS",
"subtype": "distribution",
"traits": [ { "group": "BG_survival_story_EVACUEE" } ]
},
{
"//": "This group is for NPCs that were commercial workers before the Cataclysm.",
"type": "trait_group",
"id": "BG_survival_story_WORKER_COMMERCIAL",
"subtype": "distribution",
"traits": [ { "group": "BG_survival_story_EVACUEE" } ]
},
{
"//": "This group is for NPCs that were self-employed before the Cataclysm.",
"type": "trait_group",
"id": "BG_survival_story_WORKER_SELFEMP",
"subtype": "distribution",
"traits": [ { "group": "BG_survival_story_EVACUEE" } ]
},
{
"//": "This group is for NPCs that were public workers before the Cataclysm.",
"type": "trait_group",
"id": "BG_survival_story_WORKER_PUBLIC",
"subtype": "distribution",
"traits": [ { "group": "BG_survival_story_EVACUEE" } ]
},
{
"//": "This group is for NPCs that were firefighters before the Cataclysm.",
"type": "trait_group",
"id": "BG_survival_story_WORKER_FIREFIGHTER",
"subtype": "distribution",
"traits": [ { "group": "BG_survival_story_UNIVERSAL" } ]
},
{
"//": "This group is for NPCs that were prisoners before the Cataclysm.",
"type": "trait_group",
"id": "BG_survival_story_PRISONER",
"subtype": "distribution",
"traits": [ { "trait": "BGSS_Prisoner_1" } ]
},
{
"//": "This group is for Cyborgs rescued down in the Lab.",
"type": "trait_group",
Expand Down
198 changes: 198 additions & 0 deletions data/json/professions.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions doc/JSON_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -1990,6 +1990,7 @@ The following properties (mandatory, except if noted otherwise) are supported:
"name": { "male": "Groom", "female": "Bride" }, // String, either a single gender neutral (i.e. "Survivor") or object with members "male" and "female"
"description": "This is an example profession.", // In-game description
"points": 0, // Point cost of profession. Positive values cost points and negative values grant points. Has no effect as of 0.G
"npc_background": "BG_survival_story_LAB", // (optional) BG_trait_group ID, provides list of background stories. (see BG_trait_groups.json)
"addictions": [ { "intensity": 10, "type": "nicotine" } ], // (optional) Array of addictions. Requires "type" as the string ID of the addiction (see JSON_FLAGS.md) and "intensity"
"skills": [ { "name": "archery", "level": 2 } ], // (optional) Array of starting skills. Requires "name" as the string ID of the skill (see skills.json) and "level", which is a value added to the skill level after character creation
"missions": [ "MISSION_LAST_DELIVERY" ], // (optional) Array of starting mission IDs
Expand Down
37 changes: 0 additions & 37 deletions src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1810,43 +1810,6 @@ std::unique_ptr<talker> get_talker_for( avatar *me )
return std::make_unique<talker_avatar>( me );
}

void avatar::randomize_hobbies()
{
hobbies.clear();
std::vector<profession_id> choices = get_scenario()->permitted_hobbies();
choices.erase( std::remove_if( choices.begin(), choices.end(),
[this]( const string_id<profession> &hobby ) {
return !prof->allows_hobby( hobby );
} ), choices.end() );
if( choices.empty() ) {
debugmsg( "Why would you blacklist all hobbies?" );
choices = profession::get_all_hobbies();
};

int random = rng( 0, 5 );

if( random >= 1 ) {
add_random_hobby( choices );
}
if( random >= 3 ) {
add_random_hobby( choices );
}
if( random >= 5 ) {
add_random_hobby( choices );
}
}

void avatar::add_random_hobby( std::vector<profession_id> &choices )
{
const profession_id hobby = random_entry_removed( choices );
hobbies.insert( &*hobby );

// Add or remove traits from hobby
for( const trait_and_var &cur : hobby->get_locked_traits() ) {
toggle_trait( cur.trait );
}
}

void avatar::reassign_item( item &it, int invlet )
{
bool remove_old = true;
Expand Down
5 changes: 0 additions & 5 deletions src/avatar.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ class avatar : public Character
bool create( character_type type, const std::string &tempname = "" );
// initialize avatar and avatar mocks
void initialize( character_type type );
void add_profession_items();
void randomize( bool random_scenario, bool play_now = false );
void randomize_cosmetics();
bool load_template( const std::string &template_name, pool_type & );
void save_template( const std::string &name, pool_type );
void character_to_template( const std::string &name );
Expand Down Expand Up @@ -372,8 +369,6 @@ class avatar : public Character
void log_activity_level( float level ) override;
std::string total_daily_calories_string() const;
//set 0-3 random hobbies, with 1 and 2 being twice as likely as 0 and 3
void randomize_hobbies();
void add_random_hobby( std::vector<profession_id> &choices );

int movecounter = 0;

Expand Down
27 changes: 27 additions & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ static const trait_id trait_DOWN( "DOWN" );
static const trait_id trait_EATHEALTH( "EATHEALTH" );
static const trait_id trait_ELFA_FNV( "ELFA_FNV" );
static const trait_id trait_ELFA_NV( "ELFA_NV" );
static const trait_id trait_FACIAL_HAIR_NONE( "FACIAL_HAIR_NONE" );
static const trait_id trait_FAERIECREATURE( "FAERIECREATURE" );
static const trait_id trait_FAT( "FAT" );
static const trait_id trait_FEL_NV( "FEL_NV" );
Expand Down Expand Up @@ -484,6 +485,12 @@ static const vitamin_id vitamin_iron( "iron" );

static const std::set<material_id> ferric = { material_iron, material_steel, material_budget_steel, material_ch_steel, material_hc_steel, material_lc_steel, material_mc_steel, material_qt_steel };

static const std::string type_hair_color( "hair_color" );
static const std::string type_hair_style( "hair_style" );
static const std::string type_skin_tone( "skin_tone" );
static const std::string type_facial_hair( "facial_hair" );
static const std::string type_eye_color( "eye_color" );

namespace io
{

Expand Down Expand Up @@ -740,6 +747,19 @@ void Character::randomize_blood()
my_blood_type = blood_type::blood_AB;
blood_rh_factor = false;
}
void Character::randomize_cosmetics()
{
randomize_cosmetic_trait( type_hair_color );
randomize_cosmetic_trait( type_hair_style );
randomize_cosmetic_trait( type_skin_tone );
randomize_cosmetic_trait( type_eye_color );
//arbitrary 50% chance to add beard to male characters
if( male && one_in( 2 ) ) {
randomize_cosmetic_trait( type_facial_hair );
} else {
set_mutation( trait_FACIAL_HAIR_NONE );
}
}

field_type_id Character::bloodType() const
{
Expand Down Expand Up @@ -3452,6 +3472,13 @@ std::vector<std::pair<std::string, std::string>> Character::get_overlay_ids_when
return rval;
}

void Character::zero_all_skills()
{
for( Skill &skill : Skill::skills ) {
set_skill_level( skill.ident(), 0 );
}
}

SkillLevelMap Character::get_all_skills() const
{
SkillLevelMap skills = *_skills;
Expand Down
10 changes: 9 additions & 1 deletion src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,9 @@ class Character : public Creature, public visitable

const profession *prof;
std::set<const profession *> hobbies;
void randomize_hobbies();
void add_random_hobby( std::vector<profession_id> &choices );


// Relative direction of a grab, add to posx, posy to get the coordinates of the grabbed thing.
tripoint_rel_ms grab_point;
Expand Down Expand Up @@ -773,6 +776,7 @@ class Character : public Creature, public visitable

//returns character's profession
const profession *get_profession() const;
void add_profession_items();
//returns the hobbies
std::set<const profession *> get_hobbies() const;

Expand Down Expand Up @@ -2421,6 +2425,9 @@ class Character : public Creature, public visitable
std::vector<std::pair<std::string, std::string>> get_overlay_ids_when_override_look() const;

// --------------- Skill Stuff ---------------

//sets all skills to 0 so that they're guaranteed to be in the map
void zero_all_skills();
float get_skill_level( const skill_id &ident ) const;
float get_skill_level( const skill_id &ident, const item &context ) const;
int get_knowledge_level( const skill_id &ident ) const;
Expand Down Expand Up @@ -2759,7 +2766,8 @@ class Character : public Creature, public visitable

int avg_nat_bpm;
void randomize_heartrate();

void randomize( bool random_scenario, bool play_now = false );
void randomize_cosmetics();
int get_focus() const {
return std::max( 1, focus_pool / 1000 );
}
Expand Down
Loading

0 comments on commit cc3ab7f

Please sign in to comment.