From 5d3940a24182dde6e18cc25c4a8a4bf118b7f839 Mon Sep 17 00:00:00 2001 From: Hymore246 Date: Thu, 23 Nov 2023 19:42:26 -0500 Subject: [PATCH] Professions can start with specific recipes (#68818) * Professions can start with specific recipes * Trapper starts with Bear Trap recipe * Fixed clang error, hopefully * fixed static instance access error * Update src/newcharacter.cpp Co-authored-by: Anton Burmistrov * Update src/newcharacter.cpp Co-authored-by: Anton Burmistrov * Update data/json/professions.json * Update data/json/professions.json --------- Co-authored-by: Anton Burmistrov Co-authored-by: Maleclypse <54345792+Maleclypse@users.noreply.github.com> --- data/json/professions.json | 1 + src/newcharacter.cpp | 14 ++++++++++++++ src/profession.cpp | 6 ++++++ src/profession.h | 2 ++ 4 files changed, 23 insertions(+) diff --git a/data/json/professions.json b/data/json/professions.json index 3bb0da774ae7a..af72f96244e9d 100644 --- a/data/json/professions.json +++ b/data/json/professions.json @@ -3458,6 +3458,7 @@ "points": 3, "skills": [ { "level": 6, "name": "traps" }, { "level": 4, "name": "survival" } ], "proficiencies": [ "prof_fibers", "prof_fibers_rope", "prof_traps", "prof_trapsetting", "prof_knives_familiar" ], + "recipes": [ "beartrap" ], "items": { "both": { "items": [ diff --git a/src/newcharacter.cpp b/src/newcharacter.cpp index c2478b1cf826b..d7e04e59f2f8e 100644 --- a/src/newcharacter.cpp +++ b/src/newcharacter.cpp @@ -889,6 +889,12 @@ void Character::initialize( bool learn_recipes ) add_proficiency( pri ); } + // Add profession recipes + for( const recipe_id &id : prof->recipes() ) { + const recipe &r = recipe_dictionary::get_craft( id->result() ); + learn_recipe( &r ); + } + // Add hobby proficiencies set_proficiencies_from_hobbies(); @@ -2122,6 +2128,14 @@ static std::string assemble_profession_details( const avatar &u, const input_con assembled += prof->name() + "\n"; } } + // Recipes + std::vector prof_recipe = sorted_profs[cur_id]->recipes(); + if( !prof_recipe.empty() ) { + assembled += "\n" + colorize( _( "Profession recipes:" ), COL_HEADER ) + "\n"; + for( const recipe_id &prof : prof_recipe ) { + assembled += prof->result_name() + "\n"; + } + } // Profession pet if( !sorted_profs[cur_id]->pets().empty() ) { assembled += "\n" + colorize( _( "Profession pets:" ), COL_HEADER ) + "\n"; diff --git a/src/profession.cpp b/src/profession.cpp index c10ff5f84cdbc..513d6f5650d2e 100644 --- a/src/profession.cpp +++ b/src/profession.cpp @@ -256,6 +256,7 @@ void profession::load( const JsonObject &jo, const std::string_view ) // TODO: use string_id or so optional( jo, was_loaded, "CBMs", _starting_CBMs, string_id_reader<::bionic_data> {} ); optional( jo, was_loaded, "proficiencies", _starting_proficiencies ); + optional( jo, was_loaded, "recipes", _starting_recipes ); // TODO: use string_id or so optional( jo, was_loaded, "traits", _starting_traits ); optional( jo, was_loaded, "forbidden_traits", _forbidden_traits, @@ -553,6 +554,11 @@ std::vector profession::proficiencies() const return _starting_proficiencies; } +std::vector profession::recipes() const +{ + return _starting_recipes; +} + std::vector profession::ma_known() const { return _starting_martialarts; diff --git a/src/profession.h b/src/profession.h index 5e3b0d4b82eaa..3309041ad7d06 100644 --- a/src/profession.h +++ b/src/profession.h @@ -70,6 +70,7 @@ class profession std::vector _starting_addictions; std::vector _starting_CBMs; std::vector _starting_proficiencies; + std::vector _starting_recipes; std::vector _starting_traits; std::vector _starting_martialarts; std::vector _starting_martialarts_choices; @@ -118,6 +119,7 @@ class profession std::vector pets() const; std::vector CBMs() const; std::vector proficiencies() const; + std::vector recipes() const; std::vector ma_known() const; std::vector ma_choices() const; int ma_choice_amount;