diff --git a/data/json/hobbies.json b/data/json/hobbies.json index db3025eed3b71..9b03f3196feef 100644 --- a/data/json/hobbies.json +++ b/data/json/hobbies.json @@ -1,4 +1,59 @@ [ + { + "type": "profession", + "subtype": "hobby", + "id": "driving_license", + "name": "Driving License", + "description": "You got your driving license and know how to drive a car, change the oil and tires, and other basics.", + "points": 0, + "skills": [ { "level": 2, "name": "driving" }, { "level": 1, "name": "mechanics" } ] + }, + { + "type": "profession", + "subtype": "hobby", + "id": "simple_home_cooking", + "name": "Simple Home Cooking", + "description": "You've been living on your own long enough that you know how to cook basic dishes and feed yourself.", + "points": 0, + "skills": [ { "level": 1, "name": "cooking" } ], + "proficiencies": [ "prof_food_prep" ] + }, + { + "type": "profession", + "subtype": "hobby", + "id": "computer_literate", + "name": "Computer Literate", + "description": "Either through school, your job, or from your family, you've learned the basics of how to use a computer.", + "points": 0, + "skills": [ { "level": 1, "name": "computer" } ] + }, + { + "type": "profession", + "subtype": "hobby", + "id": "social_skills", + "name": "Social Skills", + "description": "You've spent a significant portion of your life living among other people and are familiar with social norms. You know how to talk with other people, and how to convey your emotions and understand those of others.", + "points": 0, + "skills": [ { "level": 1, "name": "speech" } ] + }, + { + "type": "profession", + "subtype": "hobby", + "id": "high_school_graduate", + "name": "High School Graduate", + "description": "You've graduated from high school and thus know a little bit about applied science and electronics.", + "points": 0, + "skills": [ { "level": 1, "name": "chemistry" }, { "level": 1, "name": "electronics" } ] + }, + { + "type": "profession", + "subtype": "hobby", + "id": "mundane_survival", + "name": "Mundane Survival", + "description": "You've managed to survive modern life in a first world country. Through your ordeals you've learned how to treat scraps and bruises and how to assemble basic furniture.", + "points": 0, + "skills": [ { "level": 1, "name": "fabrication" }, { "level": 1, "name": "firstaid" } ] + }, { "type": "profession", "subtype": "hobby", diff --git a/data/json/profession_groups.json b/data/json/profession_groups.json new file mode 100644 index 0000000000000..5bd16f79565a6 --- /dev/null +++ b/data/json/profession_groups.json @@ -0,0 +1,14 @@ +[ + { + "type": "profession_group", + "id": "adult_basic_background", + "professions": [ + "driving_license", + "simple_home_cooking", + "computer_literate", + "social_skills", + "high_school_graduate", + "mundane_survival" + ] + } +] diff --git a/lang/string_extractor/parser.py b/lang/string_extractor/parser.py index fe6909098a370..01e09281a7ad7 100644 --- a/lang/string_extractor/parser.py +++ b/lang/string_extractor/parser.py @@ -198,6 +198,7 @@ def dummy_parser(json, origin): "playlist": dummy_parser, "practice": parse_practice, "profession": parse_profession, + "profession_group": dummy_parser, "profession_item_substitutions": dummy_parser, "proficiency": parse_proficiency, "proficiency_category": parse_proficiency_category, diff --git a/src/avatar.h b/src/avatar.h index 38909b803841a..554252a8e18f2 100644 --- a/src/avatar.h +++ b/src/avatar.h @@ -108,6 +108,7 @@ class avatar : public Character 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 ); + void add_default_background(); bool is_avatar() const override { return true; diff --git a/src/init.cpp b/src/init.cpp index 38ff52dc69fd3..3b29a92d62ff2 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -80,6 +80,7 @@ #include "overmap_location.h" #include "path_info.h" #include "profession.h" +#include "profession_group.h" #include "proficiency.h" #include "recipe_dictionary.h" #include "recipe_groups.h" @@ -266,6 +267,7 @@ void DynamicDataLoader::initialize() add( "bionic", &bionic_data::load_bionic ); add( "bionic_migration", &bionic_data::load_bionic_migration ); add( "profession", &profession::load_profession ); + add( "profession_group", &profession_group::load_profession_group ); add( "profession_item_substitutions", &profession::load_item_substitutions ); add( "proficiency", &proficiency::load_proficiencies ); add( "proficiency_category", &proficiency_category::load_proficiency_categories ); @@ -815,6 +817,7 @@ void DynamicDataLoader::check_consistency( loading_ui &ui ) { _( "Constructions" ), &check_constructions }, { _( "Crafting recipes" ), &recipe_dictionary::check_consistency }, { _( "Professions" ), &profession::check_definitions }, + { _( "Profession groups" ), &profession_group::check_profession_group_consistency }, { _( "Scenarios" ), &scenario::check_definitions }, { _( "Martial arts" ), &check_martialarts }, { _( "Mutations" ), &mutation_branch::check_consistency }, diff --git a/src/newcharacter.cpp b/src/newcharacter.cpp index 5035d8617cd35..7f6eb8a7187e2 100644 --- a/src/newcharacter.cpp +++ b/src/newcharacter.cpp @@ -50,6 +50,7 @@ #include "pimpl.h" #include "player_difficulty.h" #include "profession.h" +#include "profession_group.h" #include "proficiency.h" #include "recipe.h" #include "recipe_dictionary.h" @@ -76,6 +77,8 @@ 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" ); +static const profession_group_id prof_group_id_adult_basic_background( "adult_basic_background" ); + static const flag_id json_flag_auto_wield( "auto_wield" ); static const flag_id json_flag_no_auto_equip( "no_auto_equip" ); @@ -713,6 +716,8 @@ bool avatar::create( character_type type, const std::string &tempname ) break; } + add_default_background(); + auto nameExists = [&]( const std::string & name ) { return world_generator->active_world->save_exists( save_t::from_save_id( name ) ) && !query_yn( _( "A save with the name '%s' already exists in this world.\n" @@ -4514,6 +4519,17 @@ void avatar::character_to_template( const std::string &name ) save_template( name, pool_type::TRANSFER ); } +void avatar::add_default_background() +{ + for( const profession_group &prof_grp : profession_group::get_all() ) { + if( prof_grp.get_id() == prof_group_id_adult_basic_background ) { + for( const profession_id &hobb : prof_grp.get_professions() ) { + hobbies.insert( &hobb.obj() ); + } + } + } +} + void avatar::save_template( const std::string &name, pool_type pool ) { write_to_file( PATH_INFO::templatedir() + name + ".template", [&]( std::ostream & fout ) { diff --git a/src/profession_group.cpp b/src/profession_group.cpp new file mode 100644 index 0000000000000..cf1a9414f6ca7 --- /dev/null +++ b/src/profession_group.cpp @@ -0,0 +1,60 @@ +#include "profession_group.h" + +#include "assign.h" +#include "generic_factory.h" + +namespace +{ +generic_factory profession_group_factory( "profession_group" ); +} // namespace + +template<> +const profession_group &string_id::obj() const +{ + return profession_group_factory.obj( *this ); +} + +template<> +bool string_id::is_valid() const +{ + return profession_group_factory.is_valid( *this ); +} + +void profession_group::load_profession_group( const JsonObject &jo, const std::string &src ) +{ + profession_group_factory.load( jo, src ); +} + +void profession_group::load( const JsonObject &jo, const std::string & ) +{ + assign( jo, "id", id ); + assign( jo, "professions", profession_list ); + +} + +const std::vector &profession_group::get_all() +{ + return profession_group_factory.get_all(); +} + +void profession_group::check_profession_group_consistency() +{ + for( const profession_group &prof_grp : get_all() ) { + for( const profession_id prof : prof_grp.profession_list ) { + if( !prof.is_valid() ) { + debugmsg( "profession_group %s contains invalid profession_id %s", prof_grp.id.c_str(), + prof.c_str() ); + } + } + } +} + +std::vector profession_group::get_professions() const +{ + return profession_list; +} + +profession_group_id profession_group::get_id() const +{ + return id; +} diff --git a/src/profession_group.h b/src/profession_group.h new file mode 100644 index 0000000000000..62f01744431b0 --- /dev/null +++ b/src/profession_group.h @@ -0,0 +1,25 @@ +#pragma once +#ifndef CATA_SRCPROFESSION_GROUP_H +#define CATA_SRCPROFESSION_GROUP_H + +#include "type_id.h" +#include "json.h" + +struct profession_group { + + static void load_profession_group( const JsonObject &jo, const std::string &src ); + void load( const JsonObject &jo, const std::string & ); + static const std::vector &get_all(); + static void check_profession_group_consistency(); + bool was_loaded; + + std::vector get_professions() const; + profession_group_id get_id() const; + + profession_group_id id; + + private: + std::vector profession_list; + +}; +#endif diff --git a/src/type_id.h b/src/type_id.h index a6315b1beb785..2dd48a52bb731 100644 --- a/src/type_id.h +++ b/src/type_id.h @@ -200,6 +200,9 @@ using overmap_special_migration_id = string_id; class profession; using profession_id = string_id; +struct profession_group; +using profession_group_id = string_id; + class recipe; using recipe_id = string_id;