Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New characters start with basic life skills #67663

Merged
merged 9 commits into from
Aug 15, 2023
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions data/json/hobbies.json
Original file line number Diff line number Diff line change
@@ -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.",
Fris0uman marked this conversation as resolved.
Show resolved Hide resolved
"points": 0,
"skills": [ { "level": 1, "name": "driving" } ]
},
{
"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": "socially_adequate",
"name": "Socially Adequate",
Fris0uman marked this conversation as resolved.
Show resolved Hide resolved
"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",
1 change: 1 addition & 0 deletions src/avatar.h
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 3 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
@@ -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 },
16 changes: 16 additions & 0 deletions src/newcharacter.cpp
Original file line number Diff line number Diff line change
@@ -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 ) {
60 changes: 60 additions & 0 deletions src/profession_group.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include "profession_group.h"

#include "assign.h"
#include "generic_factory.h"

namespace
{
generic_factory<profession_group> profession_group_factory( "profession_group" );
} // namespace

template<>
const profession_group &string_id<profession_group>::obj() const
{
return profession_group_factory.obj( *this );
}

template<>
bool string_id<profession_group>::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> &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_id> profession_group::get_professions() const
{
return profession_list;
}

profession_group_id profession_group::get_id() const
{
return id;
}
25 changes: 25 additions & 0 deletions src/profession_group.h
Original file line number Diff line number Diff line change
@@ -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<profession_group> &get_all();
static void check_profession_group_consistency();
bool was_loaded;
Fris0uman marked this conversation as resolved.
Show resolved Hide resolved

std::vector<profession_id> get_professions() const;
profession_group_id get_id() const;

profession_group_id id;

private:
std::vector<profession_id> profession_list;

};
#endif
3 changes: 3 additions & 0 deletions src/type_id.h
Original file line number Diff line number Diff line change
@@ -200,6 +200,9 @@ using overmap_special_migration_id = string_id<overmap_special_migration>;
class profession;
using profession_id = string_id<profession>;

class profession_group;
using profession_group_id = string_id<profession_group>;

class recipe;
using recipe_id = string_id<recipe>;