From 945eba941dcea177681d7d63722e836bb5d79132 Mon Sep 17 00:00:00 2001 From: Maleclypse <54345792+Maleclypse@users.noreply.github.com> Date: Sun, 24 Sep 2023 22:22:29 -0500 Subject: [PATCH 1/7] Achievements conditional c++ --- .../Xedra_Evolved/achievements/achievements.json | 14 ++++++++++++++ src/condition.cpp | 14 ++++++++++++-- src/condition.h | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/data/mods/Xedra_Evolved/achievements/achievements.json b/data/mods/Xedra_Evolved/achievements/achievements.json index 3890a382746f5..5368bff8cab1e 100644 --- a/data/mods/Xedra_Evolved/achievements/achievements.json +++ b/data/mods/Xedra_Evolved/achievements/achievements.json @@ -225,5 +225,19 @@ "stat_type": "count", "event_transformation": "avatar_gains_deduction_level_5", "description": { "str_sp": "Investigation skill level 5 gained" } + }, + { + "id": "achievement_find_border_patrol_office", + "type": "achievement", + "name": "Do borders even matter now?", + "requirements": [ + { + "event_statistic": "last_oter_type_avatar_entered", + "is": "==", + "target": [ "oter_type_str_id", "field_office_3" ], + "visible": "when_achievement_completed", + "description": "Enter a Border Patrol Office" + } + ] } ] diff --git a/src/condition.cpp b/src/condition.cpp index ee8eba59cc5bd..8ffec566f29bb 100644 --- a/src/condition.cpp +++ b/src/condition.cpp @@ -556,6 +556,14 @@ void conditional_t::set_u_has_mission( const JsonObject &jo, const std::string & }; } +void conditional_t::set_u_has_achievement(const JsonObject& jo, const std::string& member) +{ + str_or_var u_achievement = get_str_or_var(jo.get_member(member), member, true); + condition = [u_achievement](dialogue const& d) { + return get_avatar().has_achievement(achievement_id(u_achievement.evaluate(d))); + }; +} + void conditional_t::set_u_monsters_in_direction( const JsonObject &jo, const std::string &member ) { @@ -3277,8 +3285,10 @@ conditional_t::conditional_t( const JsonObject &jo ) set_has_activity( is_npc ); } else if( jo.has_string( "npc_is_riding" ) ) { set_is_riding( is_npc ); - } else if( jo.has_member( "u_has_mission" ) ) { - set_u_has_mission( jo, "u_has_mission" ); + } else if (jo.has_member("u_has_mission")) { + set_u_has_mission(jo, "u_has_mission"); + } else if (jo.has_member("u_has_achievement")) { + set_u_has_achievement(jo, "u_has_achievement"); } else if( jo.has_member( "u_monsters_in_direction" ) ) { set_u_monsters_in_direction( jo, "u_monsters_in_direction" ); } else if( jo.has_member( "u_safe_mode_trigger" ) ) { diff --git a/src/condition.h b/src/condition.h index 14d3c9646e2be..34f6d18d60da5 100644 --- a/src/condition.h +++ b/src/condition.h @@ -121,6 +121,7 @@ struct conditional_t { void set_is_riding( bool is_npc = false ); void set_npc_has_class( const JsonObject &jo, const std::string &member, bool is_npc ); void set_u_has_mission( const JsonObject &jo, const std::string &member ); + void set_u_has_achievement(const JsonObject& jo, const std::string& member); void set_u_monsters_in_direction( const JsonObject &jo, const std::string &member ); void set_u_safe_mode_trigger( const JsonObject &jo, const std::string &member ); void set_has_strength( const JsonObject &jo, const std::string &member, bool is_npc = false ); From 22c941975b4bb49ea800f8042450535855f3c01d Mon Sep 17 00:00:00 2001 From: Maleclypse <54345792+Maleclypse@users.noreply.github.com> Date: Sun, 24 Sep 2023 22:30:30 -0500 Subject: [PATCH 2/7] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/condition.cpp | 16 ++++++++-------- src/condition.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/condition.cpp b/src/condition.cpp index 8ffec566f29bb..ee2fbf3f4805b 100644 --- a/src/condition.cpp +++ b/src/condition.cpp @@ -556,11 +556,11 @@ void conditional_t::set_u_has_mission( const JsonObject &jo, const std::string & }; } -void conditional_t::set_u_has_achievement(const JsonObject& jo, const std::string& member) +void conditional_t::set_u_has_achievement( const JsonObject &jo, const std::string &member ) { - str_or_var u_achievement = get_str_or_var(jo.get_member(member), member, true); - condition = [u_achievement](dialogue const& d) { - return get_avatar().has_achievement(achievement_id(u_achievement.evaluate(d))); + str_or_var u_achievement = get_str_or_var( jo.get_member( member ), member, true ); + condition = [u_achievement]( dialogue const & d ) { + return get_avatar().has_achievement( achievement_id( u_achievement.evaluate( d ) ) ); }; } @@ -3285,10 +3285,10 @@ conditional_t::conditional_t( const JsonObject &jo ) set_has_activity( is_npc ); } else if( jo.has_string( "npc_is_riding" ) ) { set_is_riding( is_npc ); - } else if (jo.has_member("u_has_mission")) { - set_u_has_mission(jo, "u_has_mission"); - } else if (jo.has_member("u_has_achievement")) { - set_u_has_achievement(jo, "u_has_achievement"); + } else if( jo.has_member( "u_has_mission" ) ) { + set_u_has_mission( jo, "u_has_mission" ); + } else if( jo.has_member( "u_has_achievement" ) ) { + set_u_has_achievement( jo, "u_has_achievement" ); } else if( jo.has_member( "u_monsters_in_direction" ) ) { set_u_monsters_in_direction( jo, "u_monsters_in_direction" ); } else if( jo.has_member( "u_safe_mode_trigger" ) ) { diff --git a/src/condition.h b/src/condition.h index 34f6d18d60da5..b518f2301206b 100644 --- a/src/condition.h +++ b/src/condition.h @@ -121,7 +121,7 @@ struct conditional_t { void set_is_riding( bool is_npc = false ); void set_npc_has_class( const JsonObject &jo, const std::string &member, bool is_npc ); void set_u_has_mission( const JsonObject &jo, const std::string &member ); - void set_u_has_achievement(const JsonObject& jo, const std::string& member); + void set_u_has_achievement( const JsonObject &jo, const std::string &member ); void set_u_monsters_in_direction( const JsonObject &jo, const std::string &member ); void set_u_safe_mode_trigger( const JsonObject &jo, const std::string &member ); void set_has_strength( const JsonObject &jo, const std::string &member, bool is_npc = false ); From 048a2568165f53ae69c856880892b9c34cba4616 Mon Sep 17 00:00:00 2001 From: Maleclypse <54345792+Maleclypse@users.noreply.github.com> Date: Sun, 24 Sep 2023 23:29:10 -0500 Subject: [PATCH 3/7] I think copilot is leading me astray --- src/avatar.cpp | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/src/avatar.cpp b/src/avatar.cpp index 0a69884ffb7cf..b4d9a3b9c69db 100644 --- a/src/avatar.cpp +++ b/src/avatar.cpp @@ -295,6 +295,88 @@ void avatar::memorize_clear_decoration( const tripoint_abs_ms &p, std::string_vi player_map_memory->clear_tile_decoration( p, prefix ); } +std::vector avatar::has_achievement() const +{ + std::vector ret; + for (auto& elem : achievements) { + if (elem.second) { + ret.push_back(elem.second.get()); + } + } + return ret; +} + +void avatar::gain_achievement(const std::string& id) +{ + if (has_achievement(id)) { + return; + } + achievements[id] = std::make_unique(id); +} + +bool avatar::has_achievement(const std::string& id) const +{ + return achievements.count(id) > 0; +} + +void avatar::set_achievement(const std::string& id, const bool achieved) +{ + if (!has_achievement(id)) { + return; + } + achievements[id]->set_achieved(achieved); +} + +void avatar::set_achievement(const std::string& id, const int progress) +{ + if (!has_achievement(id)) { + return; + } + achievements[id]->set_progress(progress); +} + +void avatar::set_achievement(const std::string& id, const std::string& progress) +{ + if (!has_achievement(id)) { + return; + } + achievements[id]->set_progress(progress); +} + +void avatar::set_achievement(const std::string& id, const std::string& progress, + const bool achieved) +{ + if (!has_achievement(id)) { + return; + } + achievements[id]->set_progress(progress); + achievements[id]->set_achieved(achieved); +} + +void avatar::set_achievement(const std::string& id, const int progress, + const bool achieved) +{ + if (!has_achievement(id)) { + return; + } + achievements[id]->set_progress(progress); + achievements[id]->set_achieved(achieved); +} + +void avatar::set_achievement(const std::string& id, const std::string& progress, + const std::string& progress_max, const bool achieved) +{ + if (!has_achievement(id)) { + return; + } + achievements[id]->set_progress(progress); + achievements[id]->set_progress_max(progress_max); + achievements[id]->set_achieved(achieved); +} + +void avatar::set_achievement(const std::string& id, const int progress, + const int progress_max + std::vector avatar::get_active_missions() const { return active_missions; From 0f130afd52909e3b61ffc653a08f6e1ee047e92c Mon Sep 17 00:00:00 2001 From: Maleclypse <54345792+Maleclypse@users.noreply.github.com> Date: Sun, 24 Sep 2023 23:34:19 -0500 Subject: [PATCH 4/7] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/avatar.cpp | 76 +++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/src/avatar.cpp b/src/avatar.cpp index b4d9a3b9c69db..7c4049a058b92 100644 --- a/src/avatar.cpp +++ b/src/avatar.cpp @@ -295,89 +295,89 @@ void avatar::memorize_clear_decoration( const tripoint_abs_ms &p, std::string_vi player_map_memory->clear_tile_decoration( p, prefix ); } -std::vector avatar::has_achievement() const +std::vector avatar::has_achievement() const { - std::vector ret; - for (auto& elem : achievements) { - if (elem.second) { - ret.push_back(elem.second.get()); + std::vector ret; + for( auto &elem : achievements ) { + if( elem.second ) { + ret.push_back( elem.second.get() ); } } return ret; } -void avatar::gain_achievement(const std::string& id) +void avatar::gain_achievement( const std::string &id ) { - if (has_achievement(id)) { + if( has_achievement( id ) ) { return; } - achievements[id] = std::make_unique(id); + achievements[id] = std::make_unique( id ); } -bool avatar::has_achievement(const std::string& id) const +bool avatar::has_achievement( const std::string &id ) const { - return achievements.count(id) > 0; + return achievements.count( id ) > 0; } -void avatar::set_achievement(const std::string& id, const bool achieved) +void avatar::set_achievement( const std::string &id, const bool achieved ) { - if (!has_achievement(id)) { + if( !has_achievement( id ) ) { return; } - achievements[id]->set_achieved(achieved); + achievements[id]->set_achieved( achieved ); } -void avatar::set_achievement(const std::string& id, const int progress) +void avatar::set_achievement( const std::string &id, const int progress ) { - if (!has_achievement(id)) { + if( !has_achievement( id ) ) { return; } - achievements[id]->set_progress(progress); + achievements[id]->set_progress( progress ); } -void avatar::set_achievement(const std::string& id, const std::string& progress) +void avatar::set_achievement( const std::string &id, const std::string &progress ) { - if (!has_achievement(id)) { + if( !has_achievement( id ) ) { return; } - achievements[id]->set_progress(progress); + achievements[id]->set_progress( progress ); } -void avatar::set_achievement(const std::string& id, const std::string& progress, - const bool achieved) +void avatar::set_achievement( const std::string &id, const std::string &progress, + const bool achieved ) { - if (!has_achievement(id)) { + if( !has_achievement( id ) ) { return; } - achievements[id]->set_progress(progress); - achievements[id]->set_achieved(achieved); + achievements[id]->set_progress( progress ); + achievements[id]->set_achieved( achieved ); } -void avatar::set_achievement(const std::string& id, const int progress, - const bool achieved) +void avatar::set_achievement( const std::string &id, const int progress, + const bool achieved ) { - if (!has_achievement(id)) { + if( !has_achievement( id ) ) { return; } - achievements[id]->set_progress(progress); - achievements[id]->set_achieved(achieved); + achievements[id]->set_progress( progress ); + achievements[id]->set_achieved( achieved ); } -void avatar::set_achievement(const std::string& id, const std::string& progress, - const std::string& progress_max, const bool achieved) +void avatar::set_achievement( const std::string &id, const std::string &progress, + const std::string &progress_max, const bool achieved ) { - if (!has_achievement(id)) { + if( !has_achievement( id ) ) { return; } - achievements[id]->set_progress(progress); - achievements[id]->set_progress_max(progress_max); - achievements[id]->set_achieved(achieved); + achievements[id]->set_progress( progress ); + achievements[id]->set_progress_max( progress_max ); + achievements[id]->set_achieved( achieved ); } -void avatar::set_achievement(const std::string& id, const int progress, - const int progress_max +void avatar::set_achievement( const std::string &id, const int progress, + const int progress_max -std::vector avatar::get_active_missions() const + std::vector avatar::get_active_missions() const { return active_missions; } From 11506191d522d97a8973003ccb2bac88257ee590 Mon Sep 17 00:00:00 2001 From: Maleclypse <54345792+Maleclypse@users.noreply.github.com> Date: Mon, 25 Sep 2023 08:01:13 -0500 Subject: [PATCH 5/7] Update src/avatar.cpp --- src/avatar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/avatar.cpp b/src/avatar.cpp index 7c4049a058b92..9aa6b286332e3 100644 --- a/src/avatar.cpp +++ b/src/avatar.cpp @@ -298,7 +298,7 @@ void avatar::memorize_clear_decoration( const tripoint_abs_ms &p, std::string_vi std::vector avatar::has_achievement() const { std::vector ret; - for( auto &elem : achievements ) { + for( auto &elem : achievement ) { if( elem.second ) { ret.push_back( elem.second.get() ); } From 05d4a69e250d75fc043a94287ebcc7953f98be7d Mon Sep 17 00:00:00 2001 From: Maleclypse <54345792+Maleclypse@users.noreply.github.com> Date: Mon, 25 Sep 2023 08:43:40 -0500 Subject: [PATCH 6/7] Update avatar.cpp --- src/avatar.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/avatar.cpp b/src/avatar.cpp index 9aa6b286332e3..e8b286d78bd42 100644 --- a/src/avatar.cpp +++ b/src/avatar.cpp @@ -392,7 +392,7 @@ std::vector avatar::get_failed_missions() const return failed_missions; } -mission *avatar::get_active_mission() const +mission * avatar::get_active_mission() const { return active_mission; } @@ -477,7 +477,7 @@ void avatar::remove_active_mission( mission &cur_mission ) } } -diary *avatar::get_avatar_diary() +diary * avatar::get_avatar_diary() { if( a_diary == nullptr ) { a_diary = std::make_unique(); @@ -1262,7 +1262,7 @@ void avatar::upgrade_stat_prompt( const character_stat &stat ) } } -faction *avatar::get_faction() const +faction * avatar::get_faction() const { return g->faction_manager_ptr->get( faction_your_followers ); } @@ -2069,7 +2069,7 @@ void avatar::set_location( const tripoint_abs_ms &loc ) Creature::set_location( loc ); } -npc &avatar::get_shadow_npc() +npc & avatar::get_shadow_npc() { if( !shadow_npc ) { shadow_npc = std::make_unique(); From 2a976917ad3634b364eee91b9f14df486a2bf26c Mon Sep 17 00:00:00 2001 From: Zhilkin Serg Date: Fri, 15 Nov 2024 13:36:45 +0300 Subject: [PATCH 7/7] Update condition.cpp --- src/condition.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/condition.cpp b/src/condition.cpp index 6096f71e76f8a..9606931572b45 100644 --- a/src/condition.cpp +++ b/src/condition.cpp @@ -774,7 +774,7 @@ conditional_t::func f_u_has_mission( const JsonObject &jo, std::string_view memb }; } -void conditional_t::f_u_has_achievement( const JsonObject &jo, std::string_view member ) +conditional_t::func f_u_has_achievement( const JsonObject &jo, std::string_view member ) { str_or_var u_achievement = get_str_or_var( jo.get_member( member ), member, true ); condition = [u_achievement]( dialogue const & d ) {