From c90b181e5e1bc59b60c2176c0ecce3b4d64efb7e Mon Sep 17 00:00:00 2001 From: Jeremy Rose Date: Fri, 26 Jan 2024 08:00:10 -0800 Subject: [PATCH] remove talk_effect_fun declarations from header (#70898) * remove talkeffect_fun declarations from header * editor fail * astyle * fix build * missed trigger_event * Update src/condition.cpp * Update src/condition.cpp --------- Co-authored-by: Maleclypse <54345792+Maleclypse@users.noreply.github.com> --- src/condition.cpp | 11 +- src/dialogue_helpers.h | 35 + src/npctalk.cpp | 1771 +++++++++++++++++++++++++++++++++++++--- 3 files changed, 1706 insertions(+), 111 deletions(-) diff --git a/src/condition.cpp b/src/condition.cpp index 1488fe74a6cee..7a47250a54c47 100644 --- a/src/condition.cpp +++ b/src/condition.cpp @@ -21,6 +21,7 @@ #include "coordinates.h" #include "dialogue.h" #include "debug.h" +#include "dialogue_helpers.h" #include "enum_conversions.h" #include "field.h" #include "flag.h" @@ -128,9 +129,7 @@ dbl_or_var_part get_dbl_or_var_part( const JsonValue &jv, const std::string &mem JsonObject jo = jv.get_object(); jo.allow_omitted_members(); if( jo.has_array( "arithmetic" ) ) { - talk_effect_fun_t arith; - arith.set_arithmetic( jo, "arithmetic", true ); - ret_val.arithmetic_val = arith; + ret_val.arithmetic_val = talk_effect_fun_t::from_arithmetic( jo, "arithmetic", true ); } else if( jo.has_array( "math" ) ) { ret_val.math_val.emplace(); ret_val.math_val->from_json( jo, "math", eoc_math::type_t::ret ); @@ -182,9 +181,7 @@ duration_or_var_part get_duration_or_var_part( const JsonValue &jv, const std::s JsonObject jo = jv.get_object(); jo.allow_omitted_members(); if( jo.has_array( "arithmetic" ) ) { - talk_effect_fun_t arith; - arith.set_arithmetic( jo, "arithmetic", true ); - ret_val.arithmetic_val = arith; + ret_val.arithmetic_val = talk_effect_fun_t::from_arithmetic( jo, "arithmetic", true ); } else if( jo.has_array( "math" ) ) { ret_val.math_val.emplace(); ret_val.math_val->from_json( jo, "math", eoc_math::type_t::ret ); @@ -2247,7 +2244,7 @@ std::function conditional_t::get_get_dbl( J const &jo ) } else if( jo.has_array( "arithmetic" ) ) { talk_effect_fun_t arith; if constexpr( std::is_same_v ) { - arith.set_arithmetic( jo, "arithmetic", true ); + arith = talk_effect_fun_t::from_arithmetic( jo, "arithmetic", true ); } return [arith]( dialogue & d ) { arith( d ); diff --git a/src/dialogue_helpers.h b/src/dialogue_helpers.h index d5eae67481988..f45f524ef5e30 100644 --- a/src/dialogue_helpers.h +++ b/src/dialogue_helpers.h @@ -158,6 +158,41 @@ struct abstract_str_or_var { }; using str_or_var = abstract_str_or_var; +<<<<<<< HEAD +======= + +struct talk_effect_fun_t { + public: + using likely_reward_t = std::pair; + using likely_rewards_t = std::vector; + using func = std::function; + private: + func function; + likely_rewards_t likely_rewards; + + public: + talk_effect_fun_t() = default; + explicit talk_effect_fun_t( const talkfunction_ptr & ); + explicit talk_effect_fun_t( const std::function & ); + explicit talk_effect_fun_t( func && ); + static talk_effect_fun_t from_arithmetic( const JsonObject &jo, std::string_view member, + bool no_result ); + + likely_rewards_t &get_likely_rewards(); + void operator()( dialogue &d ) const { + if( !function ) { + return; + } + return function( d ); + } +}; + +std::string read_var_value( const var_info &info, const dialogue &d ); +std::optional maybe_read_var_value( const var_info &info, const dialogue &d ); + +var_info process_variable( const std::string &type ); + +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) using translation_or_var = abstract_str_or_var; struct eoc_math { diff --git a/src/npctalk.cpp b/src/npctalk.cpp index 48028578bdb9f..2f0490f97c36b 100644 --- a/src/npctalk.cpp +++ b/src/npctalk.cpp @@ -33,6 +33,7 @@ #include "coordinates.h" #include "creature_tracker.h" #include "debug.h" +#include "dialogue_helpers.h" #include "effect_on_condition.h" #include "enums.h" #include "event_bus.h" @@ -121,6 +122,110 @@ static const zone_type_id zone_type_NPC_NO_INVESTIGATE( "NPC_NO_INVESTIGATE" ); static std::map json_talk_topics; +<<<<<<< HEAD +======= +using item_menu = std::function; +using item_menu_mul = std::function; + +struct sub_effect_parser { + using f_t = talk_effect_fun_t::func( * )( const JsonObject &, std::string_view ); + using f_t_beta = talk_effect_fun_t::func( * )( const JsonObject &, std::string_view, bool ); + using f_t_effect = talk_effect_fun_t ( * )( const JsonObject &, std::string_view ); + using f_t_beta_effect = talk_effect_fun_t ( * )( const JsonObject &, std::string_view, bool ); + + sub_effect_parser( std::string_view key_alpha_, jarg arg_, f_t f_ ) : key_alpha( key_alpha_ ), + arg( arg_ ) { + f = [f_]( const JsonObject & jo, std::string_view key, bool ) { + return talk_effect_fun_t( f_( jo, key ) ); + }; + } + sub_effect_parser( std::string_view key_alpha_, std::string_view key_beta_, jarg arg_, + f_t_beta f_ ) : key_alpha( key_alpha_ ), key_beta( key_beta_ ), arg( arg_ ) { + f = [f_]( const JsonObject & jo, std::string_view key, bool beta ) { + return talk_effect_fun_t( f_( jo, key, beta ) ); + }; + has_beta = true; + } + sub_effect_parser( std::string_view key_alpha_, + jarg arg_, f_t_effect f_ ) + : key_alpha( key_alpha_ ), arg( arg_ ) { + f = [f_]( const JsonObject & jo, std::string_view key, bool ) { + return f_( jo, key ); + }; + } + + bool check( const JsonObject &jo, bool beta = false ) const { + std::string_view key = beta ? key_beta : key_alpha; + if( ( ( arg & jarg::member ) && jo.has_member( key ) ) || + ( ( arg & jarg::object ) && jo.has_object( key ) ) || + ( ( arg & jarg::string ) && jo.has_string( key ) ) || + ( ( arg & jarg::array ) && jo.has_array( key ) ) ) { + return true; + } + return false; + } + + bool has_beta = false; + std::string_view key_alpha; + std::string_view key_beta; + jarg arg; + std::function f; +}; + +struct item_search_data { + itype_id id; + item_category_id category; + material_id material; + std::vector flags; + std::vector excluded_flags; + bool worn_only; + bool wielded_only; + + explicit item_search_data( const JsonObject &jo ) { + id = itype_id( jo.get_string( "id", "" ) ); + category = item_category_id( jo.get_string( "category", "" ) ); + material = material_id( jo.get_string( "material", "" ) ); + for( std::string flag : jo.get_string_array( "flags" ) ) { + flags.emplace_back( flag ); + } + for( std::string flag : jo.get_string_array( "excluded_flags" ) ) { + excluded_flags.emplace_back( flag ); + } + worn_only = jo.get_bool( "worn_only", false ); + wielded_only = jo.get_bool( "wielded_only", false ); + } + + bool check( const Character *guy, const item_location &loc ) { + if( !id.is_empty() && id != loc->typeId() ) { + return false; + } + if( !category.is_empty() && category != loc->get_category_shallow().id ) { + return false; + } + if( !material.is_empty() && loc->made_of( material ) == 0 ) { + return false; + } + for( flag_id flag : flags ) { + if( !loc->has_flag( flag ) ) { + return false; + } + } + for( flag_id flag : excluded_flags ) { + if( loc->has_flag( flag ) ) { + return false; + } + } + if( worn_only && !guy->is_worn( *loc ) ) { + return false; + } + if( wielded_only && !guy->is_wielding( *loc ) ) { + return false; + } + return true; + } +}; + +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) #define dbg(x) DebugLog((x),D_GAME) << __FILE__ << ":" << __LINE__ << ": " static int topic_category( const talk_topic &the_topic ); @@ -2423,22 +2528,168 @@ talk_effect_fun_t::talk_effect_fun_t( const std::function &ptr ) }; } -talk_effect_fun_t::talk_effect_fun_t( const std::function &fun ) +talk_effect_fun_t::talk_effect_fun_t( func &&fun ) { - function = [fun]( dialogue const & d ) { - fun( d ); - }; + function = fun; } +<<<<<<< HEAD void talk_effect_fun_t::set_companion_mission( const std::string &role_id ) { function = [role_id]( dialogue const & d ) { +======= +talk_effect_fun_t::likely_rewards_t &talk_effect_fun_t::get_likely_rewards() +{ + return likely_rewards; +} + +static Character *get_character_from_id( const std::string &id_str, game *g ) +{ + // Return the character with character_id, return nullptr if counldn't find the character with character_id + Character *temp_guy = nullptr; + + character_id char_id; + try { + char_id = character_id( std::stoi( id_str ) ); + } catch( const std::exception & ) { + return nullptr; + } + + // Check Avatar + if( char_id == get_avatar().getID() ) { + return &get_avatar(); + } + + // Check visible NPC + for( npc *guy : g->get_npcs_if( [char_id]( const npc & guy ) { + return guy.getID() == char_id; + } ) ) { + temp_guy = guy; + } + + // Check NPC in the OverMapBuffer + if( temp_guy == nullptr ) { + temp_guy = g->find_npc( char_id ); + } + return temp_guy; +} + +static void run_item_eocs( const dialogue &d, bool is_npc, const std::vector &items, + std::string_view option, const std::vector &true_eocs, + const std::vector &false_eocs, const std::vector &data, + const item_menu &f, const item_menu_mul &f_mul ) +{ + Character *guy = d.actor( is_npc )->get_character(); + guy = guy ? guy : &get_player_character(); + std::vector true_items; + std::vector false_items; + for( const item_location &loc : items ) { + // Check if item matches any search_data. + bool true_tgt = data.empty(); + for( item_search_data datum : data ) { + if( datum.check( guy, loc ) ) { + true_tgt = true; + break; + } + } + if( true_tgt ) { + true_items.push_back( loc ); + } else { + false_items.push_back( loc ); + } + } + const auto run_eoc = [&d, is_npc]( item_location & loc, + const std::vector &eocs ) { + for( const effect_on_condition_id &eoc : eocs ) { + // Check if item is outdated. + if( loc.get_item() ) { + dialogue newDialog = dialogue( d.actor( is_npc )->clone(), get_talker_for( loc ), + d.get_conditionals(), d.get_context() ); + eoc->activate( newDialog ); + } + } + }; + auto filter = [true_items]( const item_location & it ) { + for( const item_location &true_it : true_items ) { + if( true_it == it ) { + return true; + } + } + return false; + }; + if( option == "all" ) { + for( item_location target : true_items ) { + run_eoc( target, true_eocs ); + } + for( item_location target : false_items ) { + run_eoc( target, false_eocs ); + } + } else if( option == "random" ) { + if( !true_items.empty() ) { + std::shuffle( true_items.begin(), true_items.end(), rng_get_engine() ); + run_eoc( true_items.back(), true_eocs ); + true_items.pop_back(); + } + + for( item_location target : true_items ) { + run_eoc( target, false_eocs ); + } + for( item_location target : false_items ) { + run_eoc( target, false_eocs ); + } + } else if( option == "manual" ) { + item_location selected = f( filter ); + run_eoc( selected, true_eocs ); + for( item_location target : true_items ) { + if( target != selected ) { + run_eoc( target, false_eocs ); + } + } + for( item_location target : false_items ) { + run_eoc( target, false_eocs ); + } + } else if( option == "manual_mult" ) { + const drop_locations &selected = f_mul( filter ); + for( item_location target : true_items ) { + bool true_eoc = false; + for( const drop_location &dloc : selected ) { + if( target == dloc.first ) { + true_eoc = true; + break; + } + } + if( true_eoc ) { + run_eoc( target, true_eocs ); + } else { + run_eoc( target, false_eocs ); + } + } + for( item_location target : false_items ) { + run_eoc( target, false_eocs ); + } + } +} +namespace talk_effect_fun +{ +namespace +{ +talk_effect_fun_t::func f_companion_mission( const JsonObject &jo, std::string_view member ) +{ + str_or_var id = get_str_or_var( jo.get_member( member ), member, true ); + return [id]( dialogue const & d ) { + std::string role_id = id.evaluate( d ); +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) d.actor( true )->set_companion_mission( role_id ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_add_effect( const JsonObject &jo, const std::string &member, bool is_npc ) +======= +talk_effect_fun_t::func f_add_effect( const JsonObject &jo, std::string_view member, + bool is_npc ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var new_effect = get_str_or_var( jo.get_member( member ), member, true ); bool permanent = false; @@ -2466,7 +2717,7 @@ void talk_effect_fun_t::set_add_effect( const JsonObject &jo, const std::string } else { target.str_val = "bp_null"; } - function = [is_npc, new_effect, dov_duration, target, permanent, force, + return [is_npc, new_effect, dov_duration, target, permanent, force, dov_intensity]( dialogue & d ) { d.actor( is_npc )->add_effect( efftype_id( new_effect.evaluate( d ) ), dov_duration.evaluate( d ), @@ -2475,6 +2726,7 @@ void talk_effect_fun_t::set_add_effect( const JsonObject &jo, const std::string }; } +<<<<<<< HEAD void talk_effect_fun_t::set_remove_effect( const JsonObject &jo, const std::string &member, bool is_npc ) { @@ -2494,91 +2746,190 @@ void talk_effect_fun_t::set_add_trait( const JsonObject &jo, const std::string & } void talk_effect_fun_t::set_activate_trait( const JsonObject &jo, const std::string &member, +======= +talk_effect_fun_t::func f_remove_effect( const JsonObject &jo, std::string_view member, bool is_npc ) +{ + str_or_var old_effect = get_str_or_var( jo.get_member( member ), member, true ); + + str_or_var target; + if( jo.has_member( "target_part" ) ) { + target = get_str_or_var( jo.get_member( "target_part" ), "target_part", false, "bp_null" ); + } else { + target.str_val = "bp_null"; + } + + return [is_npc, old_effect, target]( dialogue const & d ) { + d.actor( is_npc )->remove_effect( efftype_id( old_effect.evaluate( d ) ), target.evaluate( d ) ); + }; +} + +talk_effect_fun_t::func f_add_trait( const JsonObject &jo, std::string_view member, + bool is_npc ) { str_or_var new_trait = get_str_or_var( jo.get_member( member ), member, true ); - function = [is_npc, new_trait]( dialogue const & d ) { + str_or_var new_variant; + + if( jo.has_member( "variant" ) ) { + new_variant = get_str_or_var( jo.get_member( "variant" ), "variant", true ); + } else { + new_variant.str_val = ""; + } + + return [is_npc, new_trait, new_variant]( dialogue const & d ) { + const trait_id trait = trait_id( new_trait.evaluate( d ) ); + const mutation_variant *variant = trait->variant( new_variant.evaluate( d ) ); + + d.actor( is_npc )->set_mutation( trait, variant ); + }; +} + +talk_effect_fun_t::func f_activate_trait( const JsonObject &jo, std::string_view member, +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) + bool is_npc ) +{ + str_or_var new_trait = get_str_or_var( jo.get_member( member ), member, true ); + return [is_npc, new_trait]( dialogue const & d ) { d.actor( is_npc )->activate_mutation( trait_id( new_trait.evaluate( d ) ) ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_deactivate_trait( const JsonObject &jo, const std::string &member, +======= +talk_effect_fun_t::func f_deactivate_trait( const JsonObject &jo, std::string_view member, +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) bool is_npc ) { str_or_var new_trait = get_str_or_var( jo.get_member( member ), member, true ); - function = [is_npc, new_trait]( dialogue const & d ) { + return [is_npc, new_trait]( dialogue const & d ) { d.actor( is_npc )->deactivate_mutation( trait_id( new_trait.evaluate( d ) ) ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_remove_trait( const JsonObject &jo, const std::string &member, bool is_npc ) +======= +talk_effect_fun_t::func f_remove_trait( const JsonObject &jo, std::string_view member, + bool is_npc ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var old_trait = get_str_or_var( jo.get_member( member ), member, true ); - function = [is_npc, old_trait]( dialogue const & d ) { + return [is_npc, old_trait]( dialogue const & d ) { d.actor( is_npc )->unset_mutation( trait_id( old_trait.evaluate( d ) ) ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_learn_martial_art( const JsonObject &jo, const std::string &member, +======= +talk_effect_fun_t::func f_learn_martial_art( const JsonObject &jo, std::string_view member, +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) bool is_npc ) { str_or_var ma_to_learn = get_str_or_var( jo.get_member( member ), member, true ); - function = [is_npc, ma_to_learn]( dialogue const & d ) { + return [is_npc, ma_to_learn]( dialogue const & d ) { d.actor( is_npc )->learn_martial_art( matype_id( ma_to_learn.evaluate( d ) ) ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_forget_martial_art( const JsonObject &jo, const std::string &member, +======= +talk_effect_fun_t::func f_forget_martial_art( const JsonObject &jo, std::string_view member, +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) bool is_npc ) { str_or_var ma_to_forget = get_str_or_var( jo.get_member( member ), member, true ); - function = [is_npc, ma_to_forget]( dialogue const & d ) { + return [is_npc, ma_to_forget]( dialogue const & d ) { d.actor( is_npc )->forget_martial_art( matype_id( ma_to_forget.evaluate( d ) ) ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_mutate( const JsonObject &jo, const std::string &member, bool is_npc ) +======= +talk_effect_fun_t::func f_mutate( const JsonObject &jo, std::string_view member, + bool is_npc ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { dbl_or_var highest_cat = get_dbl_or_var( jo, member, true, 0 ); const bool use_vitamins = jo.get_bool( "use_vitamins", true ); - function = [is_npc, highest_cat, use_vitamins]( dialogue & d ) { + return [is_npc, highest_cat, use_vitamins]( dialogue & d ) { d.actor( is_npc )->mutate( highest_cat.evaluate( d ), use_vitamins ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_mutate_category( const JsonObject &jo, const std::string &member, +======= +talk_effect_fun_t::func f_mutate_category( const JsonObject &jo, std::string_view member, +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) bool is_npc ) { str_or_var mut_cat = get_str_or_var( jo.get_member( member ), member, true, "" ); const bool use_vitamins = jo.get_bool( "use_vitamins", true ); - function = [is_npc, mut_cat, use_vitamins]( dialogue const & d ) { + return [is_npc, mut_cat, use_vitamins]( dialogue const & d ) { d.actor( is_npc )->mutate_category( mutation_category_id( mut_cat.evaluate( d ) ), use_vitamins ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_add_bionic( const JsonObject &jo, const std::string &member, bool is_npc ) +======= +talk_effect_fun_t::func f_mutate_towards( const JsonObject &jo, std::string_view member, + bool is_npc ) +{ + str_or_var trait = get_str_or_var( jo.get_member( member ), member, true, "" ); + str_or_var mut_cat; + if( jo.has_member( "category" ) ) { + mut_cat = get_str_or_var( jo.get_member( "category" ), "category", false, "" ); + } else { + mut_cat.str_val = ""; + } + const bool use_vitamins = jo.get_bool( "use_vitamins", true ); + + return [is_npc, trait, mut_cat, use_vitamins]( dialogue const & d ) { + d.actor( is_npc )->mutate_towards( trait_id( trait.evaluate( d ) ), + mutation_category_id( mut_cat.evaluate( d ) ), use_vitamins ); + }; +} + +talk_effect_fun_t::func f_add_bionic( const JsonObject &jo, std::string_view member, + bool is_npc ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var new_bionic = get_str_or_var( jo.get_member( member ), member, true ); - function = [is_npc, new_bionic]( dialogue const & d ) { + return [is_npc, new_bionic]( dialogue const & d ) { d.actor( is_npc )->add_bionic( bionic_id( new_bionic.evaluate( d ) ) ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_lose_bionic( const JsonObject &jo, const std::string &member, bool is_npc ) +======= +talk_effect_fun_t::func f_lose_bionic( const JsonObject &jo, std::string_view member, + bool is_npc ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var old_bionic = get_str_or_var( jo.get_member( member ), member, true ); - function = [is_npc, old_bionic]( dialogue const & d ) { + return [is_npc, old_bionic]( dialogue const & d ) { d.actor( is_npc )->remove_bionic( bionic_id( old_bionic.evaluate( d ) ) ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_add_var( const JsonObject &jo, const std::string &member, bool is_npc ) +======= +talk_effect_fun_t::func f_add_var( const JsonObject &jo, std::string_view member, + bool is_npc ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { dbl_or_var empty; const std::string var_name = get_talk_varname( jo, member, false, empty ); @@ -2589,7 +2940,7 @@ void talk_effect_fun_t::set_add_var( const JsonObject &jo, const std::string &me const std::string value = time_check ? "" : jo.get_string( "value" ); possible_values.push_back( value ); } - function = [is_npc, var_name, possible_values, time_check, var_base_name]( dialogue const & d ) { + return [is_npc, var_name, possible_values, time_check, var_base_name]( dialogue const & d ) { talker *actor = d.actor( is_npc ); if( time_check ) { actor->set_value( var_name, string_format( "%d", to_turn( calendar::turn ) ) ); @@ -2601,24 +2952,34 @@ void talk_effect_fun_t::set_add_var( const JsonObject &jo, const std::string &me }; } +<<<<<<< HEAD void talk_effect_fun_t::set_remove_var( const JsonObject &jo, const std::string &member, bool is_npc ) +======= +talk_effect_fun_t::func f_remove_var( const JsonObject &jo, std::string_view member, + bool is_npc ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { dbl_or_var empty; const std::string var_name = get_talk_varname( jo, member, false, empty ); - function = [is_npc, var_name]( dialogue const & d ) { + return [is_npc, var_name]( dialogue const & d ) { d.actor( is_npc )->remove_value( var_name ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_adjust_var( const JsonObject &jo, const std::string &member, bool is_npc ) +======= +talk_effect_fun_t::func f_adjust_var( const JsonObject &jo, std::string_view member, + bool is_npc ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { dbl_or_var empty; const std::string var_name = get_talk_varname( jo, member, false, empty ); const std::string var_base_name = get_talk_var_basename( jo, member, false ); dbl_or_var dov = get_dbl_or_var( jo, "adjustment" ); - function = [is_npc, var_base_name, var_name, dov]( dialogue & d ) { + return [is_npc, var_base_name, var_name, dov]( dialogue & d ) { int adjusted_value = dov.evaluate( d ); const std::string &var = d.actor( is_npc )->get_value( var_name ); @@ -2631,8 +2992,27 @@ void talk_effect_fun_t::set_adjust_var( const JsonObject &jo, const std::string }; } +<<<<<<< HEAD static void receive_item( itype_id &item_name, int count, const std::string &container_name, const dialogue &d, bool use_item_group, bool suppress_message ) +======= +void map_add_item( item &it, tripoint_abs_ms target_pos ) +{ + if( get_map().inbounds( target_pos ) ) { + get_map().add_item_or_charges( get_map().getlocal( target_pos ), it ); + } else { + tinymap target_bay; + target_bay.load( project_to( target_pos ), false ); + target_bay.add_item_or_charges( target_bay.getlocal( target_pos ), it ); + } +} + +void receive_item( itype_id &item_name, int count, std::string_view container_name, + const dialogue &d, bool use_item_group, bool suppress_message, + const std::vector &flags, + bool add_talker = true, + const tripoint_abs_ms &p = tripoint_abs_ms(), bool force_equip = false ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { item new_item; if( use_item_group ) { @@ -2675,7 +3055,11 @@ static void receive_item( itype_id &item_name, int count, const std::string &con } } +<<<<<<< HEAD void talk_effect_fun_t::set_u_spawn_item( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t f_spawn_item( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var item_name = get_str_or_var( jo.get_member( member ), member, true ); str_or_var container_name; @@ -2692,6 +3076,7 @@ void talk_effect_fun_t::set_u_spawn_item( const JsonObject &jo, const std::strin } else { count = get_dbl_or_var( jo, "count", false, 0 ); } +<<<<<<< HEAD function = [item_name, count, container_name, use_item_group, suppress_message]( dialogue & d ) { itype_id iname = itype_id( item_name.evaluate( d ) ); @@ -2704,6 +3089,41 @@ void talk_effect_fun_t::set_u_spawn_item( const JsonObject &jo, const std::strin } void talk_effect_fun_t::set_u_buy_item( const JsonObject &jo, const std::string &member ) +======= + bool add_talker = true; + if( member == "u_spawn_item" ) { + add_talker = true; + } else if( member == "map_spawn_item" ) { + add_talker = false; + } + std::optional loc_var; + if( jo.has_object( "loc" ) ) { + loc_var = read_var_info( jo.get_object( "loc" ) ); + } + bool force_equip = jo.get_bool( "force_equip", false ); + + std::vector flags; + for( JsonValue jv : jo.get_array( "flags" ) ) { + flags.emplace_back( get_str_or_var( jv, "flags" ) ); + } + talk_effect_fun_t ret( [item_name, count, container_name, use_item_group, suppress_message, + add_talker, loc_var, force_equip, flags]( dialogue & d ) { + itype_id iname = itype_id( item_name.evaluate( d ) ); + const tripoint_abs_ms target_location = get_tripoint_from_var( loc_var, d ); + std::vector flags_str; + flags_str.reserve( flags.size() ); + for( const str_or_var &flat_sov : flags ) { + flags_str.emplace_back( flat_sov.evaluate( d ) ); + } + receive_item( iname, count.evaluate( d ), container_name.evaluate( d ), d, use_item_group, + suppress_message, flags_str, add_talker, target_location, force_equip ); + } ); + ret.get_likely_rewards().emplace_back( count, item_name ); + return ret; +} + +talk_effect_fun_t::func f_u_buy_item( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { std::vector true_eocs = load_eoc_vector( jo, "true_eocs" ); std::vector false_eocs = load_eoc_vector( jo, "false_eocs" ); @@ -2724,8 +3144,13 @@ void talk_effect_fun_t::set_u_buy_item( const JsonObject &jo, const std::string } str_or_var item_name = get_str_or_var( jo.get_member( member ), member, true ); +<<<<<<< HEAD function = [item_name, cost, count, container_name, true_eocs, false_eocs, use_item_group, suppress_message]( dialogue & d ) { +======= + return [item_name, cost, count, container_name, true_eocs, false_eocs, + use_item_group, suppress_message, flags]( dialogue & d ) { +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) if( !d.actor( true )->buy_from( cost.evaluate( d ) ) ) { popup( _( "You can't afford it!" ) ); run_eoc_vector( false_eocs, d ); @@ -2738,7 +3163,11 @@ void talk_effect_fun_t::set_u_buy_item( const JsonObject &jo, const std::string }; } +<<<<<<< HEAD void talk_effect_fun_t::set_u_sell_item( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_u_sell_item( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { std::vector true_eocs = load_eoc_vector( jo, "true_eocs" ); std::vector false_eocs = load_eoc_vector( jo, "false_eocs" ); @@ -2750,7 +3179,7 @@ void talk_effect_fun_t::set_u_sell_item( const JsonObject &jo, const std::string count = get_dbl_or_var( jo, "count", false, 0 ); } str_or_var item_name = get_str_or_var( jo.get_member( member ), member, true ); - function = [item_name, cost, count, true_eocs, false_eocs]( dialogue & d ) { + return [item_name, cost, count, true_eocs, false_eocs]( dialogue & d ) { int current_count = count.evaluate( d ); itype_id current_item_name = itype_id( item_name.evaluate( d ) ); if( item::count_by_charges( current_item_name ) && @@ -2784,8 +3213,13 @@ void talk_effect_fun_t::set_u_sell_item( const JsonObject &jo, const std::string }; } +<<<<<<< HEAD void talk_effect_fun_t::set_consume_item( const JsonObject &jo, const std::string &member, bool is_npc ) +======= +talk_effect_fun_t::func f_consume_item( const JsonObject &jo, std::string_view member, + bool is_npc ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var item_name = get_str_or_var( jo.get_member( member ), member, true ); dbl_or_var charges = get_dbl_or_var( jo, "charges", false, 0 ); @@ -2796,7 +3230,7 @@ void talk_effect_fun_t::set_consume_item( const JsonObject &jo, const std::strin count = get_dbl_or_var( jo, "count", false, 0 ); } const bool do_popup = jo.get_bool( "popup", false ); - function = [do_popup, is_npc, item_name, count, charges]( dialogue & d ) { + return [do_popup, is_npc, item_name, count, charges]( dialogue & d ) { // this is stupid, but I couldn't get the assignment to work int current_count = count.evaluate( d ); int current_charges = charges.evaluate( d ); @@ -2839,11 +3273,15 @@ void talk_effect_fun_t::set_consume_item( const JsonObject &jo, const std::strin }; } +<<<<<<< HEAD void talk_effect_fun_t::set_remove_item_with( const JsonObject &jo, const std::string &member, +======= +talk_effect_fun_t::func f_remove_item_with( const JsonObject &jo, std::string_view member, +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) bool is_npc ) { str_or_var item_name = get_str_or_var( jo.get_member( member ), member, true ); - function = [is_npc, item_name]( dialogue const & d ) { + return [is_npc, item_name]( dialogue const & d ) { itype_id item_id = itype_id( item_name.evaluate( d ) ); d.actor( is_npc )->remove_items_with( [item_id]( const item & it ) { return it.typeId() == item_id; @@ -2851,12 +3289,16 @@ void talk_effect_fun_t::set_remove_item_with( const JsonObject &jo, const std::s }; } +<<<<<<< HEAD void talk_effect_fun_t::set_u_spend_cash( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_u_spend_cash( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { dbl_or_var amount = get_dbl_or_var( jo, member ); std::vector true_eocs = load_eoc_vector( jo, "true_eocs" ); std::vector false_eocs = load_eoc_vector( jo, "false_eocs" ); - function = [amount, true_eocs, false_eocs]( dialogue & d ) { + return [amount, true_eocs, false_eocs]( dialogue & d ) { if( d.actor( true )->buy_from( amount.evaluate( d ) ) ) { run_eoc_vector( true_eocs, d ); } else { @@ -2865,33 +3307,58 @@ void talk_effect_fun_t::set_u_spend_cash( const JsonObject &jo, const std::strin }; } +<<<<<<< HEAD void talk_effect_fun_t::set_npc_change_faction( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_npc_change_faction( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var faction_name = get_str_or_var( jo.get_member( member ), member, true ); - function = [faction_name]( dialogue const & d ) { + return [faction_name]( dialogue const & d ) { d.actor( true )->set_fac( faction_id( faction_name.evaluate( d ) ) ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_npc_change_class( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_npc_change_class( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var class_name = get_str_or_var( jo.get_member( member ), member, true ); - function = [class_name]( dialogue const & d ) { + return [class_name]( dialogue const & d ) { d.actor( true )->set_class( npc_class_id( class_name.evaluate( d ) ) ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_change_faction_rep( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_change_faction_rep( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { dbl_or_var rep_change = get_dbl_or_var( jo, member ); - function = [rep_change]( dialogue & d ) { + return [rep_change]( dialogue & d ) { d.actor( true )->add_faction_rep( rep_change.evaluate( d ) ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_add_debt( const std::vector &debt_modifiers ) { function = [debt_modifiers]( dialogue const & d ) { +======= +talk_effect_fun_t::func f_add_debt( const JsonObject &jo, std::string_view member ) +{ + std::vector debt_modifiers; + for( JsonArray jmod : jo.get_array( member ) ) { + trial_mod this_modifier; + this_modifier.first = jmod.next_string(); + this_modifier.second = jmod.next_int(); + debt_modifiers.push_back( this_modifier ); + } + return [debt_modifiers]( dialogue const & d ) { +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) int debt = 0; for( const trial_mod &this_mod : debt_modifiers ) { if( this_mod.first == "TOTAL" ) { @@ -2904,66 +3371,101 @@ void talk_effect_fun_t::set_add_debt( const std::vector &debt_modifie }; } +<<<<<<< HEAD void talk_effect_fun_t::set_toggle_npc_rule( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_toggle_npc_rule( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var rule = get_str_or_var( jo.get_member( member ), member, true ); - function = [rule]( dialogue const & d ) { + return [rule]( dialogue const & d ) { d.actor( true )->toggle_ai_rule( "ally_rule", rule.evaluate( d ) ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_set_npc_rule( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_set_npc_rule( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var rule = get_str_or_var( jo.get_member( member ), member, true ); - function = [rule]( dialogue const & d ) { + return [rule]( dialogue const & d ) { d.actor( true )->set_ai_rule( "ally_rule", rule.evaluate( d ) ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_clear_npc_rule( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_clear_npc_rule( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var rule = get_str_or_var( jo.get_member( member ), member, true ); - function = [rule]( dialogue const & d ) { + return [rule]( dialogue const & d ) { d.actor( true )->clear_ai_rule( "ally_rule", rule.evaluate( d ) ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_npc_engagement_rule( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_npc_engagement_rule( const JsonObject &jo, + std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var rule = get_str_or_var( jo.get_member( member ), member, true ); - function = [rule]( dialogue const & d ) { + return [rule]( dialogue const & d ) { d.actor( true )->set_ai_rule( "engagement_rule", rule.evaluate( d ) ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_npc_aim_rule( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_npc_aim_rule( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var rule = get_str_or_var( jo.get_member( member ), member, true ); - function = [rule]( dialogue const & d ) { + return [rule]( dialogue const & d ) { d.actor( true )->set_ai_rule( "aim_rule", rule.evaluate( d ) ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_npc_cbm_reserve_rule( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_npc_cbm_reserve_rule( const JsonObject &jo, + std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var rule = get_str_or_var( jo.get_member( member ), member, true ); - function = [rule]( dialogue const & d ) { + return [rule]( dialogue const & d ) { d.actor( true )->set_ai_rule( "cbm_reserve_rule", rule.evaluate( d ) ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_npc_cbm_recharge_rule( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_npc_cbm_recharge_rule( const JsonObject &jo, + std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var rule = get_str_or_var( jo.get_member( member ), member, true ); - function = [rule]( dialogue const & d ) { + return [rule]( dialogue const & d ) { d.actor( true )->set_ai_rule( "cbm_recharge_rule", rule.evaluate( d ) ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_location_variable( const JsonObject &jo, const std::string_view member, +======= +talk_effect_fun_t::func f_location_variable( const JsonObject &jo, std::string_view member, +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) bool is_npc ) { dbl_or_var dov_min_radius = get_dbl_or_var( jo, "min_radius", false, 0 ); @@ -3021,9 +3523,15 @@ void talk_effect_fun_t::set_location_variable( const JsonObject &jo, const std:: std::vector true_eocs = load_eoc_vector( jo, "true_eocs" ); std::vector false_eocs = load_eoc_vector( jo, "false_eocs" ); +<<<<<<< HEAD function = [dov_min_radius, dov_max_radius, var_name, outdoor_only, target_params, is_npc, type, dov_x_adjust, dov_y_adjust, dov_z_adjust, z_override, true_eocs, false_eocs, search_target, search_type, dov_target_min_radius, dov_target_max_radius]( dialogue & d ) { +======= + return [dov_min_radius, dov_max_radius, var_name, outdoor_only, passable_only, target_params, + is_npc, type, dov_x_adjust, dov_y_adjust, dov_z_adjust, z_override, true_eocs, false_eocs, + search_target, search_type, dov_target_min_radius, dov_target_max_radius]( dialogue & d ) { +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) talker *target = d.actor( is_npc ); tripoint talker_pos = get_map().getabs( target->pos() ); tripoint target_pos = talker_pos; @@ -3145,8 +3653,13 @@ void talk_effect_fun_t::set_location_variable( const JsonObject &jo, const std:: }; } +<<<<<<< HEAD void talk_effect_fun_t::set_location_variable_adjust( const JsonObject &jo, const std::string_view member ) +======= +talk_effect_fun_t::func f_location_variable_adjust( const JsonObject &jo, + std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { dbl_or_var dov_z_adjust = get_dbl_or_var( jo, "z_adjust", false, 0 ); dbl_or_var dov_x_adjust = get_dbl_or_var( jo, "x_adjust", false, 0 ); @@ -3160,7 +3673,7 @@ void talk_effect_fun_t::set_location_variable_adjust( const JsonObject &jo, if( jo.has_member( "output_var" ) ) { output_var = read_var_info( jo.get_object( "output_var" ) ); } - function = [input_var, dov_x_adjust, dov_y_adjust, dov_z_adjust, z_override, + return [input_var, dov_x_adjust, dov_y_adjust, dov_z_adjust, z_override, output_var, overmap_tile ]( dialogue & d ) { tripoint_abs_ms target_pos = get_tripoint_from_var( input_var, d ); @@ -3186,7 +3699,11 @@ void talk_effect_fun_t::set_location_variable_adjust( const JsonObject &jo, }; } +<<<<<<< HEAD void talk_effect_fun_t::set_transform_radius( const JsonObject &jo, const std::string &member, +======= +talk_effect_fun_t::func f_transform_radius( const JsonObject &jo, std::string_view member, +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) bool is_npc ) { str_or_var transform = get_str_or_var( jo.get_member( "ter_furn_transform" ), @@ -3204,7 +3721,7 @@ void talk_effect_fun_t::set_transform_radius( const JsonObject &jo, const std::s } else { key.str_val = ""; } - function = [dov, transform, target_var, dov_time_in_future, key, is_npc]( dialogue & d ) { + return [dov, transform, target_var, dov_time_in_future, key, is_npc]( dialogue & d ) { tripoint_abs_ms target_pos = d.actor( is_npc )->global_pos(); if( target_var.has_value() ) { target_pos = get_tripoint_from_var( target_var, d ); @@ -3225,13 +3742,17 @@ void talk_effect_fun_t::set_transform_radius( const JsonObject &jo, const std::s }; } +<<<<<<< HEAD void talk_effect_fun_t::set_transform_line( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_transform_line( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var transform = get_str_or_var( jo.get_member( member ), member, true ); var_info first = read_var_info( jo.get_object( "first" ) ); var_info second = read_var_info( jo.get_object( "second" ) ); - function = [transform, first, second]( dialogue const & d ) { + return [transform, first, second]( dialogue const & d ) { tripoint_abs_ms const t_first = get_tripoint_from_var( first, d ); tripoint_abs_ms const t_second = get_tripoint_from_var( second, d ); tripoint_abs_ms const orig = coord_min( t_first, t_second ); @@ -3241,7 +3762,11 @@ void talk_effect_fun_t::set_transform_line( const JsonObject &jo, const std::str }; } +<<<<<<< HEAD void talk_effect_fun_t::set_place_override( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_place_override( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var new_place = get_str_or_var( jo.get_member( member ), member ); duration_or_var dov_length = get_duration_or_var( jo, "length", true ); @@ -3251,7 +3776,7 @@ void talk_effect_fun_t::set_place_override( const JsonObject &jo, const std::str } else { key.str_val = ""; } - function = [new_place, dov_length, key]( dialogue & d ) { + return [new_place, dov_length, key]( dialogue & d ) { get_timed_events().add( timed_event_type::OVERRIDE_PLACE, calendar::turn + dov_length.evaluate( d ) + 1_seconds, //Timed events happen before the player turn and eocs are during so we add a second here to sync them up using the same variable @@ -3259,7 +3784,11 @@ void talk_effect_fun_t::set_place_override( const JsonObject &jo, const std::str }; } +<<<<<<< HEAD void talk_effect_fun_t::set_mapgen_update( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_mapgen_update( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { mission_target_params target_params = mission_util::parse_mission_om_target( jo ); std::vector update_ids; @@ -3282,7 +3811,7 @@ void talk_effect_fun_t::set_mapgen_update( const JsonObject &jo, const std::stri } else { key.str_val = ""; } - function = [target_params, update_ids, target_var, dov_time_in_future, key]( dialogue & d ) { + return [target_params, update_ids, target_var, dov_time_in_future, key]( dialogue & d ) { tripoint_abs_omt omt_pos; if( target_var.has_value() ) { const tripoint_abs_ms abs_ms( get_tripoint_from_var( target_var, d ) ); @@ -3314,17 +3843,25 @@ void talk_effect_fun_t::set_mapgen_update( const JsonObject &jo, const std::stri }; } +<<<<<<< HEAD void talk_effect_fun_t::set_alter_timed_events( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_alter_timed_events( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var key = get_str_or_var( jo.get_member( member ), member, true ); duration_or_var time_in_future = get_duration_or_var( jo, "time_in_future", false, 0_seconds ); - function = [key, time_in_future]( dialogue & d ) { + return [key, time_in_future]( dialogue & d ) { get_timed_events().set_all( key.evaluate( d ), time_in_future.evaluate( d ) ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_revert_location( const JsonObject &jo, const std::string_view &member ) +======= +talk_effect_fun_t::func f_revert_location( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { duration_or_var dov_time_in_future = get_duration_or_var( jo, "time_in_future", true ); str_or_var key; @@ -3334,7 +3871,7 @@ void talk_effect_fun_t::set_revert_location( const JsonObject &jo, const std::st key.str_val = ""; } std::optional target_var = read_var_info( jo.get_object( member ) ); - function = [target_var, dov_time_in_future, key]( dialogue & d ) { + return [target_var, dov_time_in_future, key]( dialogue & d ) { const tripoint_abs_ms abs_ms( get_tripoint_from_var( target_var, d ) ); tripoint_abs_omt omt_pos = project_to( abs_ms ); time_point tif = calendar::turn + dov_time_in_future.evaluate( d ) + 1_seconds; @@ -3359,14 +3896,19 @@ void talk_effect_fun_t::set_revert_location( const JsonObject &jo, const std::st }; } +<<<<<<< HEAD void talk_effect_fun_t::set_npc_goal( const JsonObject &jo, const std::string_view member, bool is_npc ) +======= +talk_effect_fun_t::func f_npc_goal( const JsonObject &jo, std::string_view member, + bool is_npc ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { mission_target_params dest_params = mission_util::parse_mission_om_target( jo.get_object( member ) ); std::vector true_eocs = load_eoc_vector( jo, "true_eocs" ); std::vector false_eocs = load_eoc_vector( jo, "false_eocs" ); - function = [dest_params, true_eocs, false_eocs, is_npc]( dialogue & d ) { + return [dest_params, true_eocs, false_eocs, is_npc]( dialogue & d ) { npc *guy = d.actor( is_npc )->get_npc(); if( guy ) { tripoint_abs_omt destination = mission_util::get_om_terrain_pos( dest_params, d ); @@ -3390,12 +3932,17 @@ void talk_effect_fun_t::set_npc_goal( const JsonObject &jo, const std::string_vi }; } +<<<<<<< HEAD void talk_effect_fun_t::set_guard_pos( const JsonObject &jo, const std::string_view &member, bool is_npc ) +======= +talk_effect_fun_t::func f_guard_pos( const JsonObject &jo, std::string_view member, + bool is_npc ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { std::optional target_var = read_var_info( jo.get_object( member ) ); bool unique_id = jo.get_bool( "unique_id", false ); - function = [target_var, unique_id, is_npc]( dialogue const & d ) { + return [target_var, unique_id, is_npc]( dialogue const & d ) { npc *guy = d.actor( is_npc )->get_npc(); if( guy ) { var_info cur_var = target_var.value(); @@ -3409,7 +3956,11 @@ void talk_effect_fun_t::set_guard_pos( const JsonObject &jo, const std::string_v }; } +<<<<<<< HEAD void talk_effect_fun_t::set_bulk_trade_accept( const JsonObject &jo, const std::string &member, +======= +talk_effect_fun_t::func f_bulk_trade_accept( const JsonObject &jo, std::string_view member, +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) bool is_npc ) { dbl_or_var dov_quantity; @@ -3419,7 +3970,7 @@ void talk_effect_fun_t::set_bulk_trade_accept( const JsonObject &jo, const std:: dov_quantity.min.dbl_val = -1; } bool is_trade = member == "u_bulk_trade_accept" || member == "npc_bulk_trade_accept"; - function = [is_trade, is_npc, dov_quantity]( dialogue & d ) { + return [is_trade, is_npc, dov_quantity]( dialogue & d ) { talker *seller = d.actor( is_npc ); talker *buyer = d.actor( !is_npc ); item tmp( d.cur_item ); @@ -3482,27 +4033,35 @@ void talk_effect_fun_t::set_bulk_trade_accept( const JsonObject &jo, const std:: }; } -void talk_effect_fun_t::set_npc_gets_item( bool to_use ) +talk_effect_fun_t::func f_npc_gets_item( bool to_use ) { - function = [to_use]( dialogue const & d ) { + return [to_use]( dialogue const & d ) { d.reason = d.actor( true )->give_item_to( to_use ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_add_mission( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_add_mission( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var mission_id = get_str_or_var( jo.get_member( member ), member, true ); - function = [mission_id]( dialogue const & d ) { + return [mission_id]( dialogue const & d ) { d.actor( true )->add_mission( mission_type_id( mission_id.evaluate( d ) ) ); }; } +<<<<<<< HEAD const std::vector> &talk_effect_fun_t::get_likely_rewards() const { return likely_rewards; } void talk_effect_fun_t::set_u_buy_monster( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_u_buy_monster( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var monster_type_id = get_str_or_var( jo.get_member( member ), member, true ); dbl_or_var cost = get_dbl_or_var( jo, "cost", false, 0 ); @@ -3516,7 +4075,7 @@ void talk_effect_fun_t::set_u_buy_monster( const JsonObject &jo, const std::stri } std::vector true_eocs = load_eoc_vector( jo, "true_eocs" ); std::vector false_eocs = load_eoc_vector( jo, "false_eocs" ); - function = [monster_type_id, cost, count, pacified, name, true_eocs, + return [monster_type_id, cost, count, pacified, name, true_eocs, false_eocs]( dialogue & d ) { const mtype_id mtype( monster_type_id.evaluate( d ) ); translation translated_name = to_translation( _( name.evaluate( d ) ) ); @@ -3529,36 +4088,65 @@ void talk_effect_fun_t::set_u_buy_monster( const JsonObject &jo, const std::stri }; } +<<<<<<< HEAD void talk_effect_fun_t::set_learn_recipe( const JsonObject &jo, const std::string &member, bool is_npc ) +======= +talk_effect_fun_t::func f_learn_recipe( const JsonObject &jo, std::string_view member, + bool is_npc ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var learned_recipe_id = get_str_or_var( jo.get_member( member ), member, true ); - function = [learned_recipe_id, is_npc]( dialogue const & d ) { + return [learned_recipe_id, is_npc]( dialogue const & d ) { const recipe_id &r = recipe_id( learned_recipe_id.evaluate( d ) ); d.actor( is_npc )->learn_recipe( r ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_forget_recipe( const JsonObject &jo, const std::string &member, +======= +talk_effect_fun_t::func f_forget_recipe( const JsonObject &jo, std::string_view member, +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) bool is_npc ) { str_or_var forgotten_recipe_id = get_str_or_var( jo.get_member( member ), member, true ); - function = [forgotten_recipe_id, is_npc]( dialogue const & d ) { + return [forgotten_recipe_id, is_npc]( dialogue const & d ) { const recipe_id &r = recipe_id( forgotten_recipe_id.evaluate( d ) ); d.actor( is_npc )->forget_recipe( r ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_npc_first_topic( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_turn_cost( const JsonObject &jo, std::string_view member ) +{ + duration_or_var cost = get_duration_or_var( jo, member, true ); + return [cost]( dialogue & d ) { + Character *target = d.actor( false )->get_character(); + if( target ) { + target->moves -= to_moves( cost.evaluate( d ) ); + } + }; +} + +talk_effect_fun_t::func f_npc_first_topic( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var chat_topic = get_str_or_var( jo.get_member( member ), member, true ); - function = [chat_topic]( dialogue const & d ) { + return [chat_topic]( dialogue const & d ) { d.actor( true )->set_first_topic( chat_topic.evaluate( d ) ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_message( const JsonObject &jo, const std::string &member, bool is_npc ) +======= +talk_effect_fun_t::func f_message( const JsonObject &jo, std::string_view member, + bool is_npc ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var message = get_str_or_var( jo.get_member( member ), member ); const bool snippet = jo.get_bool( "snippet", false ); @@ -3579,8 +4167,13 @@ void talk_effect_fun_t::set_message( const JsonObject &jo, const std::string &me } else { type_string.str_val = "neutral"; } +<<<<<<< HEAD function = [message, outdoor_only, sound, snippet, same_snippet, type_string, popup_msg, popup_w_interrupt_query_msg, interrupt_type, +======= + return [message, outdoor_only, sound, snippet, same_snippet, type_string, popup_msg, + popup_w_interrupt_query_msg, interrupt_type, global, +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) is_npc]( dialogue const & d ) { Character *target = d.actor( is_npc )->get_character(); if( !target || target->is_npc() ) { @@ -3680,12 +4273,16 @@ void talk_effect_fun_t::set_message( const JsonObject &jo, const std::string &me }; } +<<<<<<< HEAD void talk_effect_fun_t::set_assign_activity( const JsonObject &jo, const std::string &member, +======= +talk_effect_fun_t::func f_assign_activity( const JsonObject &jo, std::string_view member, +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) bool is_npc ) { duration_or_var dov = get_duration_or_var( jo, "duration", true ); str_or_var act = get_str_or_var( jo.get_member( member ), member, true ); - function = [is_npc, dov, act]( dialogue & d ) { + return [is_npc, dov, act]( dialogue & d ) { Character *target = d.actor( is_npc )->get_character(); if( target ) { target->assign_activity( activity_id( act.evaluate( d ) ), to_moves( dov.evaluate( d ) ) ); @@ -3693,11 +4290,16 @@ void talk_effect_fun_t::set_assign_activity( const JsonObject &jo, const std::st }; } +<<<<<<< HEAD void talk_effect_fun_t::set_add_wet( const JsonObject &jo, const std::string &member, bool is_npc ) +======= +talk_effect_fun_t::func f_add_wet( const JsonObject &jo, std::string_view member, + bool is_npc ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { dbl_or_var dov = get_dbl_or_var( jo, member ); - function = [is_npc, dov]( dialogue & d ) { + return [is_npc, dov]( dialogue & d ) { Character *target = d.actor( is_npc )->get_character(); if( target ) { wet_character( *target, dov.evaluate( d ) ); @@ -3705,7 +4307,11 @@ void talk_effect_fun_t::set_add_wet( const JsonObject &jo, const std::string &me }; } +<<<<<<< HEAD void talk_effect_fun_t::set_open_dialogue( const JsonObject &jo, const std::string_view member ) +======= +talk_effect_fun_t::func f_open_dialogue( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { std::vector true_eocs; std::vector false_eocs; @@ -3718,7 +4324,7 @@ void talk_effect_fun_t::set_open_dialogue( const JsonObject &jo, const std::stri false_eocs = load_eoc_vector( innerJo, "false_eocs" ); topic = get_str_or_var( innerJo.get_member( "topic" ), "topic" ); } - function = [true_eocs, false_eocs, topic, has_member]( dialogue const & d ) { + return [true_eocs, false_eocs, topic, has_member]( dialogue const & d ) { std::string actual_topic; if( has_member ) { actual_topic = topic.evaluate( d ); @@ -3744,11 +4350,15 @@ void talk_effect_fun_t::set_open_dialogue( const JsonObject &jo, const std::stri }; } +<<<<<<< HEAD void talk_effect_fun_t::set_take_control( const JsonObject &jo ) +======= +talk_effect_fun_t::func f_take_control( const JsonObject &jo, std::string_view ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { std::vector true_eocs = load_eoc_vector( jo, "true_eocs" ); std::vector false_eocs = load_eoc_vector( jo, "false_eocs" ); - function = [true_eocs, false_eocs]( dialogue const & d ) { + return [true_eocs, false_eocs]( dialogue const & d ) { if( !d.actor( false )->get_character()->is_avatar() ) { //only take control if the avatar is alpha run_eoc_vector( false_eocs, d ); return; @@ -3759,14 +4369,18 @@ void talk_effect_fun_t::set_take_control( const JsonObject &jo ) }; } -void talk_effect_fun_t::set_take_control_menu() +talk_effect_fun_t::func f_take_control_menu() { - function = []( dialogue const &/* d */ ) { + return []( dialogue const &/* d */ ) { get_avatar().control_npc_menu(); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_sound_effect( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_sound_effect( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var variant = get_str_or_var( jo.get_member( member ), member, true ); str_or_var id = get_str_or_var( jo.get_member( "id" ), "id", true ); @@ -3777,7 +4391,7 @@ void talk_effect_fun_t::set_sound_effect( const JsonObject &jo, const std::strin } else { volume.min.dbl_val = -1; } - function = [variant, id, outdoor_event, volume]( dialogue & d ) { + return [variant, id, outdoor_event, volume]( dialogue & d ) { map &here = get_map(); int local_volume = volume.evaluate( d ); Character *target = &get_player_character(); //Only the player can hear sound effects. @@ -3800,11 +4414,15 @@ void talk_effect_fun_t::set_sound_effect( const JsonObject &jo, const std::strin }; } +<<<<<<< HEAD void talk_effect_fun_t::set_give_achievment( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_give_achievment( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var achieve = get_str_or_var( jo.get_member( member ), member, true ); - function = [achieve]( dialogue const & d ) { + return [achieve]( dialogue const & d ) { const achievement_id achievement_to_give( achieve.evaluate( d ) ); // make sure the achievement is being tracked and that it is currently pending std::vector all_achievements = get_achievements().valid_achievements(); @@ -3820,20 +4438,30 @@ void talk_effect_fun_t::set_give_achievment( const JsonObject &jo, const std::st }; } +<<<<<<< HEAD void talk_effect_fun_t::set_mod_healthy( const JsonObject &jo, const std::string &member, bool is_npc ) +======= +talk_effect_fun_t::func f_mod_healthy( const JsonObject &jo, std::string_view member, + bool is_npc ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { dbl_or_var dov_amount = get_dbl_or_var( jo, member ); dbl_or_var dov_cap = get_dbl_or_var( jo, "cap" ); - function = [is_npc, dov_amount, dov_cap]( dialogue & d ) { + return [is_npc, dov_amount, dov_cap]( dialogue & d ) { d.actor( is_npc )->mod_daily_health( dov_amount.evaluate( d ), dov_cap.evaluate( d ) ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_hp( const JsonObject &jo, const std::string &member, bool is_npc ) +======= +talk_effect_fun_t::func f_cast_spell( const JsonObject &jo, std::string_view member, + bool is_npc ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { dbl_or_var new_hp = get_dbl_or_var( jo, member, true ); std::optional target_part; @@ -3871,8 +4499,57 @@ void talk_effect_fun_t::set_cast_spell( const JsonObject &jo, const std::string_ fake_spell fake; std::vector true_eocs = load_eoc_vector( jo, "true_eocs" ); std::vector false_eocs = load_eoc_vector( jo, "false_eocs" ); +<<<<<<< HEAD mandatory( jo, false, member, fake ); function = [is_npc, fake, targeted, true_eocs, false_eocs]( dialogue const & d ) { +======= + bool targeted = jo.get_bool( "targeted", false ); + + std::optional loc_var; + if( jo.has_object( "loc" ) ) { + loc_var = read_var_info( jo.get_object( "loc" ) ); + } + JsonObject spell_jo = jo.get_object( member ); + str_or_var id = get_str_or_var( spell_jo.get_member( "id" ), "id" ); + bool hit_self = spell_jo.get_bool( "hit_self", false ); + + int trigger_once_in = spell_jo.get_int( "once_in", 1 ); + str_or_var trigger_message; + if( spell_jo.has_member( "message" ) ) { + trigger_message = get_str_or_var( spell_jo.get_member( "message" ), "message", true ); + } else { + trigger_message.str_val = ""; + } + str_or_var npc_trigger_message; + if( spell_jo.has_member( "npc_message" ) ) { + npc_trigger_message = get_str_or_var( spell_jo.get_member( "npc_message" ), "npc_message", true ); + } else { + npc_trigger_message.str_val = ""; + } + + dbl_or_var dov_max_level = get_dbl_or_var( spell_jo, "max_level", false, -1 ); + dbl_or_var level = get_dbl_or_var( spell_jo, "min_level", false ); + if( spell_jo.has_string( "level" ) ) { + debugmsg( "level member for fake_spell was renamed to min_level. id: %s", + id.str_val.value_or( "" ) ); + } + + return [is_npc, id, hit_self, dov_max_level, trigger_once_in, level, trigger_message, + npc_trigger_message, targeted, loc_var, true_eocs, + false_eocs]( dialogue & d ) { + std::optional max_level; + int max_level_int = dov_max_level.evaluate( d ); + if( max_level_int == -1 ) { + max_level = std::nullopt; + } else { + max_level = max_level_int; + } + fake_spell fake( spell_id( id.evaluate( d ) ), hit_self, max_level ); + fake.trigger_once_in = trigger_once_in; + fake.level = level.evaluate( d ); + fake.trigger_message = to_translation( trigger_message.evaluate( d ) ); + fake.npc_trigger_message = to_translation( npc_trigger_message.evaluate( d ) ); +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) Creature *caster = d.actor( is_npc )->get_creature(); if( !caster ) { debugmsg( "No valid caster for spell. %s", d.get_callstack() ); @@ -3899,15 +4576,20 @@ void talk_effect_fun_t::set_cast_spell( const JsonObject &jo, const std::string_ }; } +<<<<<<< HEAD void talk_effect_fun_t::set_attack( const JsonObject &jo, const std::string &member, bool is_npc ) +======= +talk_effect_fun_t::func f_attack( const JsonObject &jo, std::string_view member, + bool is_npc ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var force_technique = get_str_or_var( jo.get_member( member ), member, true ); bool allow_special = jo.get_bool( "allow_special", true ); bool allow_unarmed = jo.get_bool( "allow_unarmed", true );; dbl_or_var forced_movecost = get_dbl_or_var( jo, "forced_movecost", false, -1.0 ); - function = [is_npc, allow_special, force_technique, allow_unarmed, + return [is_npc, allow_special, force_technique, allow_unarmed, forced_movecost]( dialogue & d ) { // if beta is attacking then target is the alpha talker *target = d.actor( !is_npc ); @@ -3921,30 +4603,48 @@ void talk_effect_fun_t::set_attack( const JsonObject &jo, const std::string &mem }; } -void talk_effect_fun_t::set_die( bool is_npc ) +talk_effect_fun_t::func f_die( bool is_npc ) { - function = [is_npc]( dialogue const & d ) { + return [is_npc]( dialogue const & d ) { d.actor( is_npc )->die(); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_lightning() +======= +talk_effect_fun_t::func f_prevent_death( bool is_npc ) { - function = []( dialogue const &/* d */ ) { + return [is_npc]( dialogue const & d ) { + Character *ch = d.actor( is_npc )->get_character(); + if( ch ) { + ch->prevent_death(); + } + }; +} + +talk_effect_fun_t::func f_lightning() +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) +{ + return []( dialogue const &/* d */ ) { if( get_player_character().posz() >= 0 ) { get_weather().lightning_active = true; } }; } -void talk_effect_fun_t::set_next_weather() +talk_effect_fun_t::func f_next_weather() { - function = []( dialogue const &/* d */ ) { + return []( dialogue const &/* d */ ) { get_weather().set_nextweather( calendar::turn ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_set_string_var( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_set_string_var( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { std::vector values; if( jo.has_array( member ) ) { @@ -3955,29 +4655,41 @@ void talk_effect_fun_t::set_set_string_var( const JsonObject &jo, const std::str values.emplace_back( get_str_or_var( jo.get_member( member ), member ) ); } var_info var = read_var_info( jo.get_member( "target_var" ) ); +<<<<<<< HEAD function = [values, var]( dialogue & d ) { +======= + return [values, var, parse]( dialogue & d ) { +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) int index = rng( 0, values.size() - 1 ); write_var_value( var.type, var.name, d.actor( var.type == var_type::npc ), &d, values[index].evaluate( d ) ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_set_condition( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_set_condition( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var value; value = get_str_or_var( jo.get_member( member ), member ); std::function cond; read_condition( jo, "condition", cond, false ); - function = [value, cond]( dialogue & d ) { + return [value, cond]( dialogue & d ) { d.set_conditional( value.evaluate( d ), cond ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_assign_mission( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_assign_mission( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var mission_name = get_str_or_var( jo.get_member( member ), member, true ); - function = [mission_name]( dialogue const & d ) { + return [mission_name]( dialogue const & d ) { avatar &player_character = get_avatar(); const mission_type_id &mission_type = mission_type_id( mission_name.evaluate( d ) ); @@ -3986,7 +4698,11 @@ void talk_effect_fun_t::set_assign_mission( const JsonObject &jo, const std::str }; } +<<<<<<< HEAD void talk_effect_fun_t::set_finish_mission( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_finish_mission( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var mission_name = get_str_or_var( jo.get_member( member ), member, true ); bool success = false; @@ -3996,7 +4712,7 @@ void talk_effect_fun_t::set_finish_mission( const JsonObject &jo, const std::str } else { success = jo.get_bool( "success" ); } - function = [mission_name, success, step]( dialogue const & d ) { + return [mission_name, success, step]( dialogue const & d ) { avatar &player_character = get_avatar(); const mission_type_id &mission_type = mission_type_id( mission_name.evaluate( d ) ); std::vector missions = player_character.get_active_missions(); @@ -4016,11 +4732,16 @@ void talk_effect_fun_t::set_finish_mission( const JsonObject &jo, const std::str }; } +<<<<<<< HEAD void talk_effect_fun_t::set_remove_active_mission( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_remove_active_mission( const JsonObject &jo, + std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var mission_name = get_str_or_var( jo.get_member( member ), member, true ); - function = [mission_name]( dialogue const & d ) { + return [mission_name]( dialogue const & d ) { avatar &player_character = get_avatar(); const mission_type_id &mission_type = mission_type_id( mission_name.evaluate( d ) ); std::vector missions = player_character.get_active_missions(); @@ -4033,7 +4754,11 @@ void talk_effect_fun_t::set_remove_active_mission( const JsonObject &jo, }; } +<<<<<<< HEAD void talk_effect_fun_t::set_offer_mission( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_offer_mission( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { std::vector mission_names; @@ -4047,7 +4772,7 @@ void talk_effect_fun_t::set_offer_mission( const JsonObject &jo, const std::stri jo.throw_error( "Invalid input for set_offer_mission" ); } - function = [mission_names]( dialogue const & d ) { + return [mission_names]( dialogue const & d ) { // assume that the alpha is the npc if there isn't a beta npc *p = d.actor( d.has_beta )->get_npc(); @@ -4059,8 +4784,282 @@ void talk_effect_fun_t::set_offer_mission( const JsonObject &jo, const std::stri }; } +<<<<<<< HEAD void talk_effect_fun_t::set_make_sound( const JsonObject &jo, const std::string &member, bool is_npc ) +======= +talk_effect_fun_t::func f_set_flag( const JsonObject &jo, std::string_view member, + bool is_npc ) +{ + str_or_var flag = get_str_or_var( jo.get_member( member ), member, true ); + + return [is_npc, flag]( dialogue & d ) { + item_location *it = d.actor( is_npc )->get_item(); + + if( it && it->get_item() ) { + flag_id f_id( flag.evaluate( d ) ); + it->get_item()->set_flag( f_id ); + } else { + debugmsg( "No valid %s talker.", is_npc ? "beta" : "alpha" ); + } + }; +} + +talk_effect_fun_t::func f_unset_flag( const JsonObject &jo, std::string_view member, + bool is_npc ) +{ + str_or_var flag = get_str_or_var( jo.get_member( member ), member, true ); + + return [is_npc, flag]( dialogue & d ) { + item_location *it = d.actor( is_npc )->get_item(); + + if( it && it->get_item() ) { + flag_id f_id( flag.evaluate( d ) ); + it->get_item()->unset_flag( f_id ); + } else { + debugmsg( "No valid %s talker.", is_npc ? "beta" : "alpha" ); + } + }; +} + +talk_effect_fun_t::func f_activate( const JsonObject &jo, std::string_view member, + bool is_npc ) +{ + str_or_var method = get_str_or_var( jo.get_member( member ), member, true ); + std::optional target_var; + if( jo.has_member( "target_var" ) ) { + target_var = read_var_info( jo.get_object( "target_var" ) ); + } + + return [is_npc, method, target_var]( dialogue & d ) { + Character *guy = d.actor( is_npc )->get_character(); + item_location *it = d.actor( !is_npc )->get_item(); + + if( guy ) { + const std::string method_str = method.evaluate( d ); + if( it && it->get_item() ) { + if( !it->get_item()->get_usable_item( method_str ) ) { + add_msg_debug( debugmode::DF_NPC, "Invalid use action. %s", method_str ); + return; + } + if( target_var.has_value() ) { + tripoint_abs_ms target_pos = get_tripoint_from_var( target_var, d ); + if( get_map().inbounds( target_pos ) ) { + guy->invoke_item( it->get_item(), method_str, get_map().getlocal( target_pos ) ); + return; + } + } + guy->invoke_item( it->get_item(), method.evaluate( d ) ); + + } else { + debugmsg( "%s talker must be Item.", is_npc ? "alpha" : "beta" ); + } + } else { + debugmsg( "%s talker must be Character.", is_npc ? "beta" : "alpha" ); + } + }; +} + +talk_effect_fun_t::func f_arithmetic( const JsonObject &jo, std::string_view member, + bool no_result ) +{ + JsonArray objects = jo.get_array( member ); + std::optional min; + std::optional max; + if( jo.has_member( "min" ) ) { + min = get_dbl_or_var_part( jo.get_member( "min" ), "min" ); + } else if( jo.has_member( "min_time" ) ) { + dbl_or_var_part value; + time_duration min_time; + mandatory( jo, false, "min_time", min_time ); + value.dbl_val = to_turns( min_time ); + min = value; + } + if( jo.has_member( "max" ) ) { + max = get_dbl_or_var_part( jo.get_member( "max" ), "max" ); + } else if( jo.has_member( "max_time" ) ) { + dbl_or_var_part value; + time_duration max_time; + mandatory( jo, false, "max_time", max_time ); + value.dbl_val = to_turns( max_time ); + max = value; + } + std::string op = "none"; + std::string result = "none"; + std::function set_dbl = conditional_t::get_set_dbl( + objects.get_object( 0 ), min, + max, no_result ); + int no_result_mod = no_result ? 2 : 0; //In the case of a no result we have fewer terms. + // Normal full version + if( static_cast( objects.size() ) == 5 - no_result_mod ) { + op = objects.get_string( 3 - no_result_mod ); + if( !no_result ) { + result = objects.get_string( 1 ); + if( result != "=" ) { + jo.throw_error( "invalid result " + op + " in " + jo.str() ); + return []( dialogue const & ) { + return false; + }; + } + } + std::function get_first_dbl = conditional_t::get_get_dbl( + objects.get_object( 2 - no_result_mod ) ); + std::function get_second_dbl = conditional_t::get_get_dbl( + objects.get_object( 4 - no_result_mod ) ); + if( op == "*" ) { + return [get_first_dbl, get_second_dbl, set_dbl]( dialogue & d ) { + set_dbl( d, get_first_dbl( d ) * get_second_dbl( d ) ); + }; + } else if( op == "/" ) { + return [get_first_dbl, get_second_dbl, set_dbl]( dialogue & d ) { + set_dbl( d, get_first_dbl( d ) / get_second_dbl( d ) ); + }; + } else if( op == "+" ) { + return [get_first_dbl, get_second_dbl, set_dbl]( dialogue & d ) { + set_dbl( d, get_first_dbl( d ) + get_second_dbl( d ) ); + }; + } else if( op == "-" ) { + return [get_first_dbl, get_second_dbl, set_dbl]( dialogue & d ) { + set_dbl( d, get_first_dbl( d ) - get_second_dbl( d ) ); + }; + } else if( op == "%" ) { + return [get_first_dbl, get_second_dbl, set_dbl]( dialogue & d ) { + set_dbl( d, static_cast( get_first_dbl( d ) ) % static_cast( get_second_dbl( d ) ) ); + }; + } else if( op == "^" ) { + return [get_first_dbl, get_second_dbl, set_dbl]( dialogue & d ) { + set_dbl( d, pow( get_first_dbl( d ), get_second_dbl( d ) ) ); + }; + } else { + jo.throw_error( "unexpected operator " + op + " in " + jo.str() ); + return []( dialogue const & ) { + return false; + }; + } + // ~ + } else if( objects.size() == 4 && !no_result ) { + op = objects.get_string( 3 ); + result = objects.get_string( 1 ); + if( result != "=" ) { + jo.throw_error( "invalid result " + op + " in " + jo.str() ); + return []( dialogue const & ) { + return false; + }; + } + std::function get_first_dbl = conditional_t::get_get_dbl( + objects.get_object( 2 ) ); + if( op == "~" ) { + return [get_first_dbl, set_dbl]( dialogue & d ) { + set_dbl( d, ~static_cast( get_first_dbl( d ) ) ); + }; + } else { + jo.throw_error( "unexpected operator " + op + " in " + jo.str() ); + return []( dialogue const & ) { + return false; + }; + } + + // =, -=, +=, *=, and /= + } else if( objects.size() == 3 && !no_result ) { + result = objects.get_string( 1 ); + std::function get_first_dbl = conditional_t::get_get_dbl( + objects.get_object( 0 ) ); + std::function get_second_dbl = conditional_t::get_get_dbl( + objects.get_object( 2 ) ); + if( result == "+=" ) { + return [get_first_dbl, get_second_dbl, set_dbl]( dialogue & d ) { + set_dbl( d, get_first_dbl( d ) + get_second_dbl( d ) ); + }; + } else if( result == "-=" ) { + return [get_first_dbl, get_second_dbl, set_dbl]( dialogue & d ) { + set_dbl( d, get_first_dbl( d ) - get_second_dbl( d ) ); + }; + } else if( result == "*=" ) { + return [get_first_dbl, get_second_dbl, set_dbl]( dialogue & d ) { + set_dbl( d, get_first_dbl( d ) * get_second_dbl( d ) ); + }; + } else if( result == "/=" ) { + return [get_first_dbl, get_second_dbl, set_dbl]( dialogue & d ) { + set_dbl( d, get_first_dbl( d ) / get_second_dbl( d ) ); + }; + } else if( result == "%=" ) { + return [get_first_dbl, get_second_dbl, set_dbl]( dialogue & d ) { + set_dbl( d, static_cast( get_first_dbl( d ) ) % static_cast( get_second_dbl( d ) ) ); + }; + } else if( result == "=" ) { + return [get_second_dbl, set_dbl]( dialogue & d ) { + set_dbl( d, get_second_dbl( d ) ); + }; + } else { + jo.throw_error( "unexpected result " + result + " in " + jo.str() ); + return []( dialogue const & ) { + return false; + }; + } + // ++ and -- + } else if( objects.size() == 2 && !no_result ) { + op = objects.get_string( 1 ); + std::function get_first_dbl = conditional_t::get_get_dbl( + objects.get_object( 0 ) ); + if( op == "++" ) { + return [get_first_dbl, set_dbl]( dialogue & d ) { + set_dbl( d, get_first_dbl( d ) + 1 ); + }; + } else if( op == "--" ) { + return [get_first_dbl, set_dbl]( dialogue & d ) { + set_dbl( d, get_first_dbl( d ) - 1 ); + }; + } else { + jo.throw_error( "unexpected operator " + op + " in " + jo.str() ); + return []( dialogue const & ) { + return false; + }; + } + } else if( objects.size() == 1 && no_result ) { + std::function get_first_dbl = conditional_t::get_get_dbl( + objects.get_object( 0 ) ); + return [get_first_dbl, set_dbl]( dialogue & d ) { + set_dbl( d, get_first_dbl( d ) ); + }; + } else { + jo.throw_error( "Invalid number of args in " + jo.str() ); + return []( dialogue const & ) { + return false; + }; + } +} + +talk_effect_fun_t::func f_math( const JsonObject &jo, std::string_view member ) +{ + eoc_math math; + math.from_json( jo, member, eoc_math::type_t::assign ); + return [math = std::move( math )]( dialogue & d ) { + return math.act( d ); + }; +} + + +talk_effect_fun_t::func f_transform_item( const JsonObject &jo, std::string_view member ) +{ + str_or_var target_id = get_str_or_var( jo.get_member( member ), member, true ); + bool activate = jo.get_bool( "active", false ); + + return [target_id, activate]( dialogue & d ) { + item_location *it = d.actor( true )->get_item(); + + if( it && it->get_item() ) { + const std::string target_str = target_id.evaluate( d ); + ( *it )->convert( itype_id( target_str ), it->carrier() ); + ( *it )->active = activate || ( *it )->has_temperature(); + } else { + debugmsg( "beta talker must be Item." ); + } + }; +} + +talk_effect_fun_t::func f_make_sound( const JsonObject &jo, std::string_view member, + bool is_npc ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var message = get_str_or_var( jo.get_member( member ), member, true ); @@ -4101,8 +5100,13 @@ void talk_effect_fun_t::set_make_sound( const JsonObject &jo, const std::string if( jo.has_member( "target_var" ) ) { target_var = read_var_info( jo.get_object( "target_var" ) ); } +<<<<<<< HEAD function = [is_npc, message, volume, type, target_var, snippet, same_snippet]( dialogue const & d ) { +======= + return [is_npc, message, volume, ambient, type, target_var, snippet, + same_snippet]( dialogue & d ) { +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) tripoint_abs_ms target_pos = get_tripoint_from_var( target_var, d ); std::string translated_message; if( snippet ) { @@ -4126,21 +5130,38 @@ void talk_effect_fun_t::set_make_sound( const JsonObject &jo, const std::string }; } +<<<<<<< HEAD void talk_effect_fun_t::set_run_eocs( const JsonObject &jo, const std::string_view member ) +======= + + +talk_effect_fun_t::func f_run_eocs( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { std::vector eocs = load_eoc_vector( jo, member ); if( eocs.empty() ) { jo.throw_error( "Invalid input for run_eocs" ); } +<<<<<<< HEAD function = [eocs]( dialogue const & d ) { for( const effect_on_condition_id &eoc : eocs ) { +======= + return [eocs_entries]( dialogue const & d ) { + for( const eoc_entry &entry : eocs_entries ) { + effect_on_condition_id eoc_id = + entry.var ? effect_on_condition_id( entry.var->evaluate( d ) ) : entry.id; +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) dialogue newDialog( d ); eoc->activate( newDialog ); } }; } +<<<<<<< HEAD void talk_effect_fun_t::set_run_eoc_until( const JsonObject &jo, const std::string_view member ) +======= +talk_effect_fun_t::func f_run_eoc_until( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { effect_on_condition_id eoc = effect_on_conditions::load_inline_eoc( jo.get_member( member ), "" ); @@ -4148,8 +5169,12 @@ void talk_effect_fun_t::set_run_eoc_until( const JsonObject &jo, const std::stri dbl_or_var iteration_count = get_dbl_or_var( jo, "iteration_count", false, 100 ); +<<<<<<< HEAD function = [eoc, condition, iteration_count]( dialogue & d ) { +======= + return [eoc, condition, iteration_count]( dialogue & d ) { +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) auto itt = d.get_conditionals().find( condition.evaluate( d ) ); if( itt == d.get_conditionals().end() ) { debugmsg( string_format( "No condition with the name %s", condition.evaluate( d ) ) ); @@ -4172,7 +5197,11 @@ void talk_effect_fun_t::set_run_eoc_until( const JsonObject &jo, const std::stri }; } +<<<<<<< HEAD void talk_effect_fun_t::set_run_eoc_selector( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_run_eoc_selector( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { std::vector eocs; for( const JsonValue &jv : jo.get_array( member ) ) { @@ -4247,8 +5276,13 @@ void talk_effect_fun_t::set_run_eoc_selector( const JsonObject &jo, const std::s std::string title = jo.get_string( "title", _( "Select an option." ) ); +<<<<<<< HEAD function = [eocs, context, title, eoc_names, eoc_keys, eoc_descriptions, hide_failing]( dialogue & d ) { +======= + return [eocs, context, title, eoc_names, eoc_keys, eoc_descriptions, + hide_failing, allow_cancel]( dialogue & d ) { +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) uilist eoc_list; eoc_list.text = title; @@ -4310,7 +5344,12 @@ void talk_effect_fun_t::set_run_eoc_selector( const JsonObject &jo, const std::s }; } +<<<<<<< HEAD void talk_effect_fun_t::set_run_eoc_with( const JsonObject &jo, const std::string_view member ) +======= + +talk_effect_fun_t::func f_run_eoc_with( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { effect_on_condition_id eoc = effect_on_conditions::load_inline_eoc( jo.get_member( member ), "" ); @@ -4329,7 +5368,25 @@ void talk_effect_fun_t::set_run_eoc_with( const JsonObject &jo, const std::strin target_var = read_var_info( jo.get_object( "beta_loc" ) ); } +<<<<<<< HEAD function = [eoc, context, target_var]( dialogue const & d ) { +======= + if( jo.has_member( "alpha_loc" ) ) { + alpha_var = get_str_or_var( jo.get_member( "alpha_loc" ), "alpha_loc", has_beta_var, + "u" ); // alpha_talker is mandatory if beta_talker exists + is_alpha_loc = true; + } else if( jo.has_member( "alpha_talker" ) ) { + alpha_var = get_str_or_var( jo.get_member( "alpha_talker" ), "alpha_talker", false, "u" ); + } else { + alpha_var.str_val = "u"; + has_alpha_var = false; + } + + std::vector false_eocs = load_eoc_vector( jo, "false_eocs" ); + + return [eoc, context, alpha_var, beta_var, is_alpha_loc, is_beta_loc, has_alpha_var, + has_beta_var, false_eocs]( dialogue const & d ) { +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) dialogue newDialog( d ); tripoint_abs_ms target_location = get_tripoint_from_var( target_var, d ); @@ -4346,8 +5403,13 @@ void talk_effect_fun_t::set_run_eoc_with( const JsonObject &jo, const std::strin }; } +<<<<<<< HEAD void talk_effect_fun_t::set_run_npc_eocs( const JsonObject &jo, const std::string_view member, bool is_npc ) +======= +talk_effect_fun_t::func f_run_npc_eocs( const JsonObject &jo, + std::string_view member, bool is_npc ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { std::vector eocs = load_eoc_vector( jo, member ); std::vector unique_ids; @@ -4362,7 +5424,7 @@ void talk_effect_fun_t::set_run_npc_eocs( const JsonObject &jo, } bool npc_must_see = jo.get_bool( "npc_must_see", false ); if( local ) { - function = [eocs, unique_ids, npc_must_see, npc_range, is_npc]( dialogue const & d ) { + return [eocs, unique_ids, npc_must_see, npc_range, is_npc]( dialogue const & d ) { tripoint actor_pos = d.actor( is_npc )->pos(); std::vector ids( unique_ids.size() ); for( const str_or_var &id : unique_ids ) { @@ -4389,7 +5451,7 @@ void talk_effect_fun_t::set_run_npc_eocs( const JsonObject &jo, } }; } else { - function = [eocs, unique_ids]( dialogue const & d ) { + return [eocs, unique_ids]( dialogue const & d ) { for( const str_or_var &target : unique_ids ) { if( g->unique_npc_exists( target.evaluate( d ) ) ) { for( const effect_on_condition_id &eoc : eocs ) { @@ -4407,16 +5469,170 @@ void talk_effect_fun_t::set_run_npc_eocs( const JsonObject &jo, } } +<<<<<<< HEAD void talk_effect_fun_t::set_queue_eocs( const JsonObject &jo, const std::string_view member ) { std::vector eocs = load_eoc_vector( jo, member ); if( eocs.empty() ) { +======= + +talk_effect_fun_t::func f_run_inv_eocs( const JsonObject &jo, + std::string_view member, bool is_npc ) +{ + str_or_var option = get_str_or_var( jo.get_member( member ), member ); + std::vector true_eocs = load_eoc_vector( jo, "true_eocs" ); + std::vector false_eocs = load_eoc_vector( jo, "false_eocs" ); + std::vector data; + for( const JsonValue &search_data_jo : jo.get_array( "search_data" ) ) { + data.emplace_back( search_data_jo ); + } + str_or_var title; + if( jo.has_member( "title" ) ) { + title = get_str_or_var( jo.get_member( "title" ), "title", true ); + } else { + title.str_val = ""; + } + + return [option, true_eocs, false_eocs, data, is_npc, title]( dialogue & d ) { + Character *guy = d.actor( is_npc )->get_character(); + if( guy ) { + const auto f = [d, guy, title]( const item_location_filter & filter ) { + return game_menus::inv::titled_filter_menu( filter, *guy, title.evaluate( d ) ); + }; + const auto f_mul = [d, guy, title]( const item_location_filter & filter ) { + return game_menus::inv::titled_multi_filter_menu( filter, *guy, title.evaluate( d ) ); + }; + run_item_eocs( d, is_npc, guy->all_items_loc(), option.evaluate( d ), true_eocs, false_eocs, data, + f, f_mul ); + } + }; +} + +talk_effect_fun_t::func f_map_run_item_eocs( const JsonObject &jo, std::string_view member, + bool is_npc ) +{ + str_or_var option = get_str_or_var( jo.get_member( member ), member ); + std::vector true_eocs = load_eoc_vector( jo, "true_eocs" ); + std::vector false_eocs = load_eoc_vector( jo, "false_eocs" ); + std::vector data; + for( const JsonValue &search_data_jo : jo.get_array( "search_data" ) ) { + data.emplace_back( search_data_jo ); + } + str_or_var title; + if( jo.has_member( "title" ) ) { + title = get_str_or_var( jo.get_member( "title" ), "title", true ); + } else { + title.str_val = ""; + } + std::optional loc_var; + if( jo.has_object( "loc" ) ) { + loc_var = read_var_info( jo.get_object( "loc" ) ); + } + dbl_or_var dov_min_radius = get_dbl_or_var( jo, "min_radius", false, 0 ); + dbl_or_var dov_max_radius = get_dbl_or_var( jo, "max_radius", false, 0 ); + + return [is_npc, option, true_eocs, false_eocs, data, loc_var, dov_min_radius, dov_max_radius, + title]( dialogue & d ) { + tripoint_abs_ms target_location = get_tripoint_from_var( loc_var, d ); + std::vector items; + map &here = get_map(); + tripoint center = here.getlocal( target_location ); + int max_radius = dov_max_radius.evaluate( d ); + int min_radius = dov_min_radius.evaluate( d ); + for( const tripoint &pos : here.points_in_radius( center, max_radius ) ) { + if( rl_dist( center, pos ) >= min_radius && here.inbounds( pos ) ) { + for( item &it : here.i_at( pos ) ) { + items.emplace_back( map_cursor( pos ), &it ); + } + } + } + Character *guy = d.actor( is_npc )->get_character(); + guy = guy ? guy : &get_player_character(); + const auto f = [d, guy, title, center, min_radius, + max_radius]( const item_location_filter & filter ) { + inventory_filter_preset preset( filter ); + inventory_pick_selector inv_s( *guy, preset ); + inv_s.set_title( title.evaluate( d ) ); + inv_s.set_display_stats( false ); + inv_s.clear_items(); + for( const tripoint &pos : get_map().points_in_radius( center, max_radius ) ) { + if( rl_dist( center, pos ) >= min_radius ) { + inv_s.add_map_items( pos ); + } + } + if( inv_s.empty() ) { + popup( _( "You don't have the necessary item at hand." ), PF_GET_KEY ); + return item_location(); + } + return inv_s.execute(); + }; + const item_menu_mul f_mul = [d, guy, title, center, min_radius, + max_radius]( const item_location_filter & filter ) { + inventory_filter_preset preset( filter ); + inventory_multiselector inv_s( *guy, preset ); + inv_s.set_title( title.evaluate( d ) ); + inv_s.set_display_stats( false ); + inv_s.clear_items(); + for( const tripoint &pos : get_map().points_in_radius( center, max_radius ) ) { + if( rl_dist( center, pos ) >= min_radius ) { + inv_s.add_map_items( pos ); + } + } + if( inv_s.empty() ) { + popup( _( "You don't have the necessary item at hand." ), PF_GET_KEY ); + return drop_locations(); + } + return inv_s.execute(); + }; + run_item_eocs( d, is_npc, items, option.evaluate( d ), true_eocs, false_eocs, data, + f, f_mul ); + }; +} + +talk_effect_fun_t::func f_set_talker( const JsonObject &jo, std::string_view member, bool is_npc ) +{ + var_info var = read_var_info( jo.get_object( member ) ); + var_type type = var.type; + std::string var_name = var.name; + return [is_npc, var, type, var_name]( dialogue & d ) { + int id = d.actor( is_npc )->getID().get_value(); + write_var_value( type, var_name, d.actor( type == var_type::npc ), &d, id ); + }; +} + +void process_eoc( const effect_on_condition_id &eoc, dialogue &d, + time_duration time_in_future ) +{ + if( eoc->type == eoc_type::ACTIVATION ) { + Character *alpha = d.has_alpha ? d.actor( false )->get_character() : nullptr; + if( alpha ) { + effect_on_conditions::queue_effect_on_condition( time_in_future, eoc, *alpha, d.get_context() ); + } else if( eoc->global ) { + effect_on_conditions::queue_effect_on_condition( time_in_future, eoc, get_player_character(), + d.get_context() ); + } + // If the target is a monster or item and the eoc is non global it won't be queued and will silently "fail" + // this is so monster attacks against other monsters won't give error messages. + } else { + debugmsg( "Cannot queue a non activation effect_on_condition. %s", d.get_callstack() ); + } +} + +talk_effect_fun_t::func f_queue_eocs( const JsonObject &jo, std::string_view member ) +{ + std::vector eocs_entries = load_eoc_vector_id_and_var( jo, member ); + if( eocs_entries.empty() ) { +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) jo.throw_error( "Invalid input for queue_eocs" ); } duration_or_var dov_time_in_future = get_duration_or_var( jo, "time_in_future", false, 0_seconds ); +<<<<<<< HEAD function = [dov_time_in_future, eocs]( dialogue & d ) { +======= + return [dov_time_in_future, eocs_entries]( dialogue & d ) { +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) time_duration time_in_future = dov_time_in_future.evaluate( d ); for( const effect_on_condition_id &eoc : eocs ) { if( eoc->type == eoc_type::ACTIVATION ) { @@ -4436,7 +5652,11 @@ void talk_effect_fun_t::set_queue_eocs( const JsonObject &jo, const std::string_ }; } +<<<<<<< HEAD void talk_effect_fun_t::set_queue_eoc_with( const JsonObject &jo, const std::string_view member ) +======= +talk_effect_fun_t::func f_queue_eoc_with( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { effect_on_condition_id eoc = effect_on_conditions::load_inline_eoc( jo.get_member( member ), "" ); @@ -4451,7 +5671,7 @@ void talk_effect_fun_t::set_queue_eoc_with( const JsonObject &jo, const std::str duration_or_var dov_time_in_future = get_duration_or_var( jo, "time_in_future", false, 0_seconds ); - function = [dov_time_in_future, eoc, context]( dialogue & d ) { + return [dov_time_in_future, eoc, context]( dialogue & d ) { time_duration time_in_future = dov_time_in_future.evaluate( d ); if( eoc->type == eoc_type::ACTIVATION ) { @@ -4475,8 +5695,13 @@ void talk_effect_fun_t::set_queue_eoc_with( const JsonObject &jo, const std::str }; } +<<<<<<< HEAD void talk_effect_fun_t::set_weighted_list_eocs( const JsonObject &jo, const std::string_view member ) +======= +talk_effect_fun_t::func f_weighted_list_eocs( const JsonObject &jo, + std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { std::vector>> eoc_pairs; for( JsonArray ja : jo.get_array( member ) ) { @@ -4485,7 +5710,7 @@ void talk_effect_fun_t::set_weighted_list_eocs( const JsonObject &jo, eoc_pairs.emplace_back( effect_on_conditions::load_inline_eoc( eoc, "" ), conditional_t::get_get_dbl( weight ) ); } - function = [eoc_pairs]( dialogue & d ) { + return [eoc_pairs]( dialogue & d ) { weighted_int_list eocs; for( const std::pair> &eoc_pair : eoc_pairs ) { @@ -4497,7 +5722,31 @@ void talk_effect_fun_t::set_weighted_list_eocs( const JsonObject &jo, }; } +<<<<<<< HEAD void talk_effect_fun_t::set_switch( const JsonObject &jo, const std::string_view member ) +======= +talk_effect_fun_t::func f_if( const JsonObject &jo, std::string_view member ) +{ + std::function cond; + talk_effect_t then_effect; + talk_effect_t else_effect; + read_condition( jo, std::string( member ), cond, false ); + then_effect.load_effect( jo, "then" ); + if( jo.has_member( "else" ) || jo.has_array( "else" ) ) { + else_effect.load_effect( jo, "else" ); + } + + return [cond, then_effect, else_effect]( dialogue & d ) { + if( cond( d ) ) { + then_effect.apply( d ); + } else { + else_effect.apply( d ); + } + }; +} + +talk_effect_fun_t::func f_switch( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { std::function eoc_switch = jo.has_string( member ) ? conditional_t::get_get_dbl( jo.get_string( member.data() ), jo ) : @@ -4509,7 +5758,7 @@ void talk_effect_fun_t::set_switch( const JsonObject &jo, const std::string_view case_effect.load_effect( array_case, "effect" ); case_pairs.emplace_back( get_dbl_or_var( array_case, "case" ), case_effect ); } - function = [eoc_switch, case_pairs]( dialogue & d ) { + return [eoc_switch, case_pairs]( dialogue & d ) { const double switch_int = eoc_switch( d ); talk_effect_t case_effect; for( const std::pair &case_pair : @@ -4522,8 +5771,72 @@ void talk_effect_fun_t::set_switch( const JsonObject &jo, const std::string_view }; } +<<<<<<< HEAD void talk_effect_fun_t::set_roll_remainder( const JsonObject &jo, const std::string &member, bool is_npc ) +======= +talk_effect_fun_t::func f_foreach( const JsonObject &jo, std::string_view member ) +{ + std::string type = jo.get_string( member.data() ); + var_info itr = read_var_info( jo.get_object( "var" ) ); + talk_effect_t effect; + effect.load_effect( jo, "effect" ); + std::string target; + std::vector array; + if( jo.has_string( "target" ) ) { + target = jo.get_string( "target" ); + } else if( jo.has_array( "target" ) ) { + for( const JsonValue &jv : jo.get_array( "target" ) ) { + array.emplace_back( get_str_or_var( jv, "target" ) ); + } + } + return [type, itr, effect, target, array]( dialogue & d ) { + std::vector list; + + if( type == "ids" ) { + if( target == "bodypart" ) { + for( const body_part_type &bp : body_part_type::get_all() ) { + list.push_back( bp.id.str() ); + } + } else if( target == "flag" ) { + for( const json_flag &f : json_flag::get_all() ) { + list.push_back( f.id.str() ); + } + } else if( target == "trait" ) { + for( const mutation_branch &m : mutation_branch::get_all() ) { + list.push_back( m.id.str() ); + } + } else if( target == "vitamin" ) { + for( const std::pair &v : vitamin::all() ) { + list.push_back( v.first.str() ); + } + } + } else if( type == "item_group" ) { + item_group_id ig( target ); + for( const itype *type : item_group::every_possible_item_from( ig ) ) { + list.push_back( type->get_id().str() ); + } + } else if( type == "monstergroup" ) { + mongroup_id mg( target ); + for( const auto &m : MonsterGroupManager::GetMonstersFromGroup( mg, true ) ) { + list.push_back( m.str() ); + } + } else if( type == "array" ) { + for( const str_or_var &v : array ) { + list.emplace_back( v.evaluate( d ) ); + } + } + + for( std::string_view str : list ) { + write_var_value( itr.type, itr.name, d.actor( itr.type == var_type::npc ), &d, str.data() ); + effect.apply( d ); + } + }; +} + +talk_effect_fun_t::func f_roll_remainder( const JsonObject &jo, + std::string_view member, bool is_npc ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { std::vector list; for( JsonValue jv : jo.get_array( member ) ) { @@ -4539,7 +5852,7 @@ void talk_effect_fun_t::set_roll_remainder( const JsonObject &jo, std::vector true_eocs = load_eoc_vector( jo, "true_eocs" ); std::vector false_eocs = load_eoc_vector( jo, "false_eocs" ); - function = [list, type, is_npc, true_eocs, false_eocs, message]( dialogue const & d ) { + return [list, type, is_npc, true_eocs, false_eocs, message]( dialogue const & d ) { std::vector not_had; for( const str_or_var &cur_string : list ) { if( type.evaluate( d ) == "bionic" ) { @@ -4599,8 +5912,13 @@ void talk_effect_fun_t::set_roll_remainder( const JsonObject &jo, }; } +<<<<<<< HEAD void talk_effect_fun_t::set_add_morale( const JsonObject &jo, const std::string &member, bool is_npc ) +======= +talk_effect_fun_t::func f_add_morale( const JsonObject &jo, std::string_view member, + bool is_npc ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var new_type = get_str_or_var( jo.get_member( member ), member, true ); dbl_or_var dov_bonus = get_dbl_or_var( jo, "bonus" ); @@ -4608,7 +5926,7 @@ void talk_effect_fun_t::set_add_morale( const JsonObject &jo, const std::string duration_or_var dov_duration = get_duration_or_var( jo, "duration", false, 1_hours ); duration_or_var dov_decay_start = get_duration_or_var( jo, "decay_start", false, 30_minutes ); const bool capped = jo.get_bool( "capped", false ); - function = [is_npc, new_type, dov_bonus, dov_max_bonus, dov_duration, dov_decay_start, + return [is_npc, new_type, dov_bonus, dov_max_bonus, dov_duration, dov_decay_start, capped]( dialogue & d ) { d.actor( is_npc )->add_morale( morale_type( new_type.evaluate( d ) ), dov_bonus.evaluate( d ), @@ -4619,34 +5937,53 @@ void talk_effect_fun_t::set_add_morale( const JsonObject &jo, const std::string }; } +<<<<<<< HEAD void talk_effect_fun_t::set_lose_morale( const JsonObject &jo, const std::string &member, bool is_npc ) +======= +talk_effect_fun_t::func f_lose_morale( const JsonObject &jo, std::string_view member, + bool is_npc ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var old_morale = get_str_or_var( jo.get_member( member ), member, true ); - function = [is_npc, old_morale]( dialogue const & d ) { + return [is_npc, old_morale]( dialogue const & d ) { d.actor( is_npc )->remove_morale( morale_type( old_morale.evaluate( d ) ) ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_add_faction_trust( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_add_faction_trust( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { dbl_or_var dov = get_dbl_or_var( jo, member ); - function = [dov]( dialogue & d ) { + return [dov]( dialogue & d ) { d.actor( true )->get_faction()->trusts_u += dov.evaluate( d ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_lose_faction_trust( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_lose_faction_trust( const JsonObject &jo, + std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { dbl_or_var dov = get_dbl_or_var( jo, member ); - function = [dov]( dialogue & d ) { + return [dov]( dialogue & d ) { d.actor( true )->get_faction()->trusts_u -= dov.evaluate( d ); }; } +<<<<<<< HEAD void talk_effect_fun_t::set_custom_light_level( const JsonObject &jo, const std::string &member ) +======= +talk_effect_fun_t::func f_custom_light_level( const JsonObject &jo, + std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { dbl_or_var dov = get_dbl_or_var( jo, member, true ); duration_or_var dov_length = get_duration_or_var( jo, "length", false, 0_seconds ); @@ -4656,7 +5993,7 @@ void talk_effect_fun_t::set_custom_light_level( const JsonObject &jo, } else { key.str_val = ""; } - function = [dov_length, dov, key]( dialogue & d ) { + return [dov_length, dov, key]( dialogue & d ) { get_timed_events().add( timed_event_type::CUSTOM_LIGHT_LEVEL, calendar::turn + dov_length.evaluate( d ) + 1_seconds/*We add a second here because this will get ticked on the turn its applied before it has an effect*/, @@ -4664,7 +6001,11 @@ void talk_effect_fun_t::set_custom_light_level( const JsonObject &jo, }; } +<<<<<<< HEAD void talk_effect_fun_t::set_give_equipment( const JsonObject &jo, const std::string_view member ) +======= +talk_effect_fun_t::func f_give_equipment( const JsonObject &jo, std::string_view member ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { JsonObject jobj = jo.get_object( member ); int allowance = 0; @@ -4679,7 +6020,7 @@ void talk_effect_fun_t::set_give_equipment( const JsonObject &jo, const std::str debt_modifiers.push_back( this_modifier ); } } - function = [debt_modifiers, allowance]( dialogue const & d ) { + return [debt_modifiers, allowance]( dialogue const & d ) { int debt = allowance; for( const trial_mod &this_mod : debt_modifiers ) { if( this_mod.first == "TOTAL" ) { @@ -4694,7 +6035,11 @@ void talk_effect_fun_t::set_give_equipment( const JsonObject &jo, const std::str }; } +<<<<<<< HEAD void talk_effect_fun_t::set_spawn_monster( const JsonObject &jo, const std::string &member, +======= +talk_effect_fun_t::func f_spawn_monster( const JsonObject &jo, std::string_view member, +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) bool is_npc ) { bool group = jo.get_bool( "group", false ); @@ -4722,9 +6067,15 @@ void talk_effect_fun_t::set_spawn_monster( const JsonObject &jo, const std::stri std::string spawn_message_plural = jo.get_string( "spawn_message_plural", "" ); std::vector true_eocs = load_eoc_vector( jo, "true_eocs" ); std::vector false_eocs = load_eoc_vector( jo, "false_eocs" ); +<<<<<<< HEAD function = [monster_id, dov_target_range, dov_hallucination_count, dov_real_count, dov_min_radius, dov_max_radius, outdoor_only, indoor_only, group, dov_lifespan, target_var, spawn_message, spawn_message_plural, true_eocs, false_eocs, open_air_allowed, +======= + return [monster_id, dov_target_range, dov_hallucination_count, dov_real_count, dov_min_radius, + dov_max_radius, outdoor_only, indoor_only, group, single_target, dov_lifespan, target_var, + spawn_message, spawn_message_plural, true_eocs, false_eocs, open_air_allowed, +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) friendly, is_npc]( dialogue & d ) { monster target_monster; @@ -4814,8 +6165,13 @@ void talk_effect_fun_t::set_spawn_monster( const JsonObject &jo, const std::stri }; } +<<<<<<< HEAD void talk_effect_fun_t::set_spawn_npc( const JsonObject &jo, const std::string &member, bool is_npc ) +======= +talk_effect_fun_t::func f_spawn_npc( const JsonObject &jo, std::string_view member, + bool is_npc ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var sov_npc_class = get_str_or_var( jo.get_member( member ), member ); str_or_var unique_id; @@ -4851,9 +6207,9 @@ void talk_effect_fun_t::set_spawn_npc( const JsonObject &jo, const std::string & std::string spawn_message_plural = jo.get_string( "spawn_message_plural", "" ); std::vector true_eocs = load_eoc_vector( jo, "true_eocs" ); std::vector false_eocs = load_eoc_vector( jo, "false_eocs" ); - function = [sov_npc_class, unique_id, traits, dov_hallucination_count, dov_real_count, - dov_min_radius, - dov_max_radius, outdoor_only, indoor_only, dov_lifespan, target_var, spawn_message, + return [sov_npc_class, unique_id, traits, dov_hallucination_count, dov_real_count, + dov_min_radius, + dov_max_radius, outdoor_only, indoor_only, dov_lifespan, target_var, spawn_message, spawn_message_plural, true_eocs, false_eocs, open_air_allowed, is_npc]( dialogue & d ) { int min_radius = dov_min_radius.evaluate( d ); int max_radius = dov_max_radius.evaluate( d ); @@ -4925,8 +6281,13 @@ void talk_effect_fun_t::set_spawn_npc( const JsonObject &jo, const std::string & }; } +<<<<<<< HEAD void talk_effect_fun_t::set_field( const JsonObject &jo, const std::string &member, bool is_npc ) +======= +talk_effect_fun_t::func f_field( const JsonObject &jo, std::string_view member, + bool is_npc ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { str_or_var new_field = get_str_or_var( jo.get_member( member ), member, true ); dbl_or_var dov_intensity = get_dbl_or_var( jo, "intensity", false, 1 ); @@ -4941,7 +6302,7 @@ void talk_effect_fun_t::set_field( const JsonObject &jo, const std::string &memb if( jo.has_member( "target_var" ) ) { target_var = read_var_info( jo.get_object( "target_var" ) ); } - function = [new_field, dov_intensity, dov_age, dov_radius, outdoor_only, + return [new_field, dov_intensity, dov_age, dov_radius, outdoor_only, hit_player, target_var, is_npc, indoor_only]( dialogue & d ) { int radius = dov_radius.evaluate( d ); int intensity = dov_intensity.evaluate( d ); @@ -4962,8 +6323,13 @@ void talk_effect_fun_t::set_field( const JsonObject &jo, const std::string &memb }; } +<<<<<<< HEAD void talk_effect_fun_t::set_teleport( const JsonObject &jo, const std::string_view member, bool is_npc ) +======= +talk_effect_fun_t::func f_teleport( const JsonObject &jo, std::string_view member, + bool is_npc ) +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) { std::optional target_var = read_var_info( jo.get_object( member ) ); str_or_var fail_message; @@ -4980,7 +6346,7 @@ void talk_effect_fun_t::set_teleport( const JsonObject &jo, const std::string_vi success_message.str_val = ""; } bool force = jo.get_bool( "force", false ); - function = [is_npc, target_var, fail_message, success_message, force]( dialogue const & d ) { + return [is_npc, target_var, fail_message, success_message, force]( dialogue const & d ) { tripoint_abs_ms target_pos = get_tripoint_from_var( target_var, d ); Creature *teleporter = d.actor( is_npc )->get_creature(); if( teleporter ) { @@ -4991,9 +6357,67 @@ void talk_effect_fun_t::set_teleport( const JsonObject &jo, const std::string_vi teleporter->add_msg_if_player( _( fail_message.evaluate( d ) ) ); } } +<<<<<<< HEAD +======= + item_location *it = d.actor( is_npc )->get_item(); + if( it && it->get_item() ) { + map_add_item( *it->get_item(), target_pos ); + add_msg( _( success_message.evaluate( d ) ) ); + it->remove_item(); + } }; } +talk_effect_fun_t::func f_wants_to_talk( bool is_npc ) +{ + return [is_npc]( dialogue const & d ) { + npc *p = d.actor( is_npc )->get_npc(); + if( p ) { + if( p->get_attitude() == NPCATT_TALK ) { + return; + } + if( p->sees( get_player_character() ) ) { + add_msg( _( "%s wants to talk to you." ), p->get_name() ); + } + p->set_attitude( NPCATT_TALK ); + } + }; +} + +talk_effect_fun_t::func f_trigger_event( const JsonObject &jo, std::string_view member ) +{ + std::string const type_str = jo.get_string( member.data() ); + JsonArray const &jargs = jo.get_array( "args" ); + + event_type type = io::string_to_enum( type_str ); + std::vector args; + args.reserve( jargs.size() ); + for( JsonValue const &jv : jargs ) { + args.emplace_back( get_str_or_var( jv, "args" ) ); + } + + return [type, args]( dialogue & d ) { + std::vector args_str; + args_str.reserve( args.size() ); + std::transform( args.cbegin(), args.cend(), + std::back_inserter( args_str ), [&d]( str_or_var const & sov ) { + return sov.evaluate( d ); + } ); + get_event_bus().send( cata::event::make_dyn( type, args_str ) ); +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) + }; +} + +} // namespace +} // namespace talk_effect_fun + +// static +talk_effect_fun_t talk_effect_fun_t::from_arithmetic( const JsonObject &jo, std::string_view member, + bool no_result ) +{ + return talk_effect_fun_t( talk_effect_fun::f_arithmetic( jo, member, no_result ) ); +} + void talk_effect_t::set_effect_consequence( const talk_effect_fun_t &fun, dialogue_consequence con ) { @@ -5086,6 +6510,7 @@ talk_effect_t::talk_effect_t( const JsonObject &jo, const std::string &member_na } } +<<<<<<< HEAD void talk_effect_t::parse_sub_effect( const JsonObject &jo ) { bool handled = true; @@ -5376,6 +6801,130 @@ void talk_effect_t::parse_sub_effect( const JsonObject &jo ) subeffect_fun.set_take_control( jo ); } else { jo.throw_error( "invalid sub effect syntax: " + jo.str() ); +======= +static const +std::vector +parsers = { + { "u_add_effect", "npc_add_effect", jarg::member, &talk_effect_fun::f_add_effect }, + { "u_lose_effect", "npc_lose_effect", jarg::member, &talk_effect_fun::f_remove_effect }, + { "u_add_var", "npc_add_var", jarg::string, &talk_effect_fun::f_add_var }, + { "u_lose_var", "npc_lose_var", jarg::string, &talk_effect_fun::f_remove_var }, + { "u_adjust_var", "npc_adjust_var", jarg::string, &talk_effect_fun::f_adjust_var }, + { "u_add_trait", "npc_add_trait", jarg::member, &talk_effect_fun::f_add_trait }, + { "u_lose_trait", "npc_lose_trait", jarg::member, &talk_effect_fun::f_remove_trait }, + { "u_deactivate_trait", "npc_deactivate_trait", jarg::member, &talk_effect_fun::f_deactivate_trait }, + { "u_activate_trait", "npc_activate_trait", jarg::member, &talk_effect_fun::f_activate_trait }, + { "u_mutate", "npc_mutate", jarg::member | jarg::array, &talk_effect_fun::f_mutate }, + { "u_mutate_category", "npc_mutate_category", jarg::member, &talk_effect_fun::f_mutate_category }, + { "u_mutate_towards", "npc_mutate_towards", jarg::member, &talk_effect_fun::f_mutate_towards}, + { "u_learn_martial_art", "npc_learn_martial_art", jarg::member, &talk_effect_fun::f_learn_martial_art }, + { "u_forget_martial_art", "npc_forget_martial_art", jarg::member, &talk_effect_fun::f_forget_martial_art }, + { "u_location_variable", "npc_location_variable", jarg::object, &talk_effect_fun::f_location_variable }, + { "u_transform_radius", "npc_transform_radius", jarg::member | jarg::array, &talk_effect_fun::f_transform_radius }, + { "u_set_goal", "npc_set_goal", jarg::member, &talk_effect_fun::f_npc_goal }, + { "u_set_guard_pos", "npc_set_guard_pos", jarg::member, &talk_effect_fun::f_guard_pos }, + { "u_learn_recipe", "npc_learn_recipe", jarg::member, &talk_effect_fun::f_learn_recipe }, + { "u_forget_recipe", "npc_forget_recipe", jarg::member, &talk_effect_fun::f_forget_recipe }, + { "u_message", "npc_message", jarg::member, &talk_effect_fun::f_message }, + { "message", "message", jarg::member, &talk_effect_fun::f_message }, + { "u_add_wet", "npc_add_wet", jarg::member | jarg::array, &talk_effect_fun::f_add_wet }, + { "u_assign_activity", "npc_assign_activity", jarg::member, &talk_effect_fun::f_assign_activity }, + { "u_make_sound", "npc_make_sound", jarg::member, &talk_effect_fun::f_make_sound }, + { "u_run_npc_eocs", "npc_run_npc_eocs", jarg::array, &talk_effect_fun::f_run_npc_eocs }, + { "u_run_inv_eocs", "npc_run_inv_eocs", jarg::member, &talk_effect_fun::f_run_inv_eocs }, + { "u_roll_remainder", "npc_roll_remainder", jarg::member, &talk_effect_fun::f_roll_remainder }, + { "u_mod_healthy", "npc_mod_healthy", jarg::array | jarg::member, &talk_effect_fun::f_mod_healthy }, + { "u_add_morale", "npc_add_morale", jarg::member, &talk_effect_fun::f_add_morale }, + { "u_lose_morale", "npc_lose_morale", jarg::member, &talk_effect_fun::f_lose_morale }, + { "u_add_bionic", "npc_add_bionic", jarg::member, &talk_effect_fun::f_add_bionic }, + { "u_lose_bionic", "npc_lose_bionic", jarg::member, &talk_effect_fun::f_lose_bionic }, + { "u_attack", "npc_attack", jarg::member, &talk_effect_fun::f_attack }, + { "u_spawn_monster", "npc_spawn_monster", jarg::member, &talk_effect_fun::f_spawn_monster }, + { "u_spawn_npc", "npc_spawn_npc", jarg::member, &talk_effect_fun::f_spawn_npc }, + { "u_set_field", "npc_set_field", jarg::member, &talk_effect_fun::f_field }, + { "u_teleport", "npc_teleport", jarg::object, &talk_effect_fun::f_teleport }, + { "u_set_flag", "npc_set_flag", jarg::member, &talk_effect_fun::f_set_flag }, + { "u_unset_flag", "npc_unset_flag", jarg::member, &talk_effect_fun::f_unset_flag }, + { "u_activate", "npc_activate", jarg::member, &talk_effect_fun::f_activate }, + { "arithmetic", "arithmetic", jarg::array, &talk_effect_fun::f_arithmetic }, + { "u_consume_item", "npc_consume_item", jarg::member, &talk_effect_fun::f_consume_item }, + { "u_remove_item_with", "npc_remove_item_with", jarg::member, &talk_effect_fun::f_remove_item_with }, + { "u_bulk_trade_accept", "npc_bulk_trade_accept", jarg::member, &talk_effect_fun::f_bulk_trade_accept }, + { "u_bulk_donate", "npc_bulk_donate", jarg::member, &talk_effect_fun::f_bulk_trade_accept }, + { "u_cast_spell", "npc_cast_spell", jarg::member, &talk_effect_fun::f_cast_spell }, + { "u_map_run_item_eocs", "npc_map_run_item_eocs", jarg::member, &talk_effect_fun::f_map_run_item_eocs }, + { "companion_mission", jarg::string, &talk_effect_fun::f_companion_mission }, + { "u_spend_cash", jarg::member | jarg::array, &talk_effect_fun::f_u_spend_cash }, + { "npc_change_faction", jarg::member, &talk_effect_fun::f_npc_change_faction }, + { "npc_change_class", jarg::member, &talk_effect_fun::f_npc_change_class }, + { "u_faction_rep", jarg::member | jarg::array, &talk_effect_fun::f_change_faction_rep }, + { "add_mission", jarg::member, &talk_effect_fun::f_add_mission }, + { "u_sell_item", jarg::member, &talk_effect_fun::f_u_sell_item }, + { "u_buy_item", jarg::member, &talk_effect_fun::f_u_buy_item }, + { "u_spawn_item", jarg::member, &talk_effect_fun::f_spawn_item }, + { "toggle_npc_rule", jarg::member, &talk_effect_fun::f_toggle_npc_rule }, + { "set_npc_rule", jarg::member, &talk_effect_fun::f_set_npc_rule }, + { "clear_npc_rule", jarg::member, &talk_effect_fun::f_clear_npc_rule }, + { "set_npc_engagement_rule", jarg::member, &talk_effect_fun::f_npc_engagement_rule }, + { "set_npc_aim_rule", jarg::member, &talk_effect_fun::f_npc_aim_rule }, + { "set_npc_cbm_reserve_rule", jarg::member, &talk_effect_fun::f_npc_cbm_reserve_rule }, + { "set_npc_cbm_recharge_rule", jarg::member, &talk_effect_fun::f_npc_cbm_recharge_rule }, + { "map_spawn_item", jarg::member, &talk_effect_fun::f_spawn_item }, + { "mapgen_update", jarg::member, &talk_effect_fun::f_mapgen_update }, + { "alter_timed_events", jarg::member, &talk_effect_fun::f_alter_timed_events }, + { "revert_location", jarg::member, &talk_effect_fun::f_revert_location }, + { "place_override", jarg::member, &talk_effect_fun::f_place_override }, + { "transform_line", jarg::member, &talk_effect_fun::f_transform_line }, + { "location_variable_adjust", jarg::member, &talk_effect_fun::f_location_variable_adjust }, + { "u_buy_monster", jarg::member, &talk_effect_fun::f_u_buy_monster }, + { "u_add_faction_trust", jarg::member | jarg::array, &talk_effect_fun::f_add_faction_trust }, + { "u_lose_faction_trust", jarg::member | jarg::array, &talk_effect_fun::f_lose_faction_trust }, + { "npc_first_topic", jarg::member, &talk_effect_fun::f_npc_first_topic }, + { "sound_effect", jarg::member, &talk_effect_fun::f_sound_effect }, + { "give_achievement", jarg::member, &talk_effect_fun::f_give_achievment }, + { "assign_mission", jarg::member, &talk_effect_fun::f_assign_mission }, + { "finish_mission", jarg::member, &talk_effect_fun::f_finish_mission }, + { "remove_active_mission", jarg::member, &talk_effect_fun::f_remove_active_mission }, + { "offer_mission", jarg::array | jarg::string, &talk_effect_fun::f_offer_mission }, + { "run_eocs", jarg::member | jarg::array, &talk_effect_fun::f_run_eocs }, + { "run_eoc_until", jarg::member, &talk_effect_fun::f_run_eoc_until }, + { "run_eoc_with", jarg::member, &talk_effect_fun::f_run_eoc_with }, + { "run_eoc_selector", jarg::member, &talk_effect_fun::f_run_eoc_selector }, + { "queue_eocs", jarg::member | jarg::array, &talk_effect_fun::f_queue_eocs }, + { "queue_eoc_with", jarg::member, &talk_effect_fun::f_queue_eoc_with }, + { "weighted_list_eocs", jarg::array, &talk_effect_fun::f_weighted_list_eocs }, + { "if", jarg::member, &talk_effect_fun::f_if }, + { "switch", jarg::member, &talk_effect_fun::f_switch }, + { "foreach", jarg::string, &talk_effect_fun::f_foreach }, + { "math", jarg::array, &talk_effect_fun::f_math }, + { "custom_light_level", jarg::member | jarg::array, &talk_effect_fun::f_custom_light_level }, + { "give_equipment", jarg::object, &talk_effect_fun::f_give_equipment }, + { "set_string_var", jarg::member | jarg::array, &talk_effect_fun::f_set_string_var }, + { "set_condition", jarg::member, &talk_effect_fun::f_set_condition }, + { "open_dialogue", jarg::member, &talk_effect_fun::f_open_dialogue }, + { "take_control", jarg::member, &talk_effect_fun::f_take_control }, + { "trigger_event", jarg::member, &talk_effect_fun::f_trigger_event }, + { "add_debt", jarg::array, &talk_effect_fun::f_add_debt }, + { "u_set_talker", "npc_set_talker", jarg::member, &talk_effect_fun::f_set_talker }, + { "turn_cost", jarg::member, &talk_effect_fun::f_turn_cost }, + { "transform_item", jarg::member, &talk_effect_fun::f_transform_item }, +}; + +void talk_effect_t::parse_sub_effect( const JsonObject &jo ) +{ + for( const sub_effect_parser &p : parsers ) { + if( p.has_beta ) { + if( p.check( jo ) ) { + set_effect( p.f( jo, p.key_alpha, false ) ); + return; + } else if( p.check( jo, true ) ) { + set_effect( p.f( jo, p.key_beta, true ) ); + return; + } + } else if( p.check( jo ) ) { + set_effect( p.f( jo, p.key_alpha, false ) ); + return; +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) } } set_effect( subeffect_fun ); @@ -5477,61 +7026,75 @@ void talk_effect_t::parse_string_effect( const std::string &effect_id, const Jso return; } - talk_effect_fun_t subeffect_fun; if( effect_id == "u_bulk_trade_accept" || effect_id == "npc_bulk_trade_accept" || effect_id == "u_bulk_donate" || effect_id == "npc_bulk_donate" ) { bool is_npc = effect_id == "npc_bulk_trade_accept" || effect_id == "npc_bulk_donate"; - subeffect_fun.set_bulk_trade_accept( jo, effect_id, is_npc ); - set_effect( subeffect_fun ); + set_effect( talk_effect_fun_t( talk_effect_fun::f_bulk_trade_accept( jo, effect_id, is_npc ) ) ); return; } if( effect_id == "lightning" ) { - subeffect_fun.set_lightning(); - set_effect( subeffect_fun ); + set_effect( talk_effect_fun_t( talk_effect_fun::f_lightning() ) ); return; } if( effect_id == "u_die" ) { - subeffect_fun.set_die( false ); - set_effect( subeffect_fun ); + set_effect( talk_effect_fun_t( talk_effect_fun::f_die( false ) ) ); return; } if( effect_id == "npc_die" ) { - subeffect_fun.set_die( true ); - set_effect( subeffect_fun ); + set_effect( talk_effect_fun_t( talk_effect_fun::f_die( true ) ) ); + return; + } + +<<<<<<< HEAD +======= + if( effect_id == "u_prevent_death" ) { + set_effect( talk_effect_fun_t( talk_effect_fun::f_prevent_death( false ) ) ); + return; + } + + if( effect_id == "npc_prevent_death" ) { + set_effect( talk_effect_fun_t( talk_effect_fun::f_prevent_death( true ) ) ); return; } +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) if( effect_id == "next_weather" ) { - subeffect_fun.set_next_weather(); - set_effect( subeffect_fun ); + set_effect( talk_effect_fun_t( talk_effect_fun::f_next_weather() ) ); return; } if( effect_id == "npc_gets_item" || effect_id == "npc_gets_item_to_use" ) { bool to_use = effect_id == "npc_gets_item_to_use"; - subeffect_fun.set_npc_gets_item( to_use ); - set_effect( subeffect_fun ); + set_effect( talk_effect_fun_t( talk_effect_fun::f_npc_gets_item( to_use ) ) ); return; } if( effect_id == "open_dialogue" ) { - subeffect_fun.set_open_dialogue( jo, "" ); - set_effect( subeffect_fun ); + set_effect( talk_effect_fun_t( talk_effect_fun::f_open_dialogue( jo, "" ) ) ); return; } if( effect_id == "take_control" ) { - subeffect_fun.set_take_control( jo ); - set_effect( subeffect_fun ); + set_effect( talk_effect_fun_t( talk_effect_fun::f_take_control( jo, "" ) ) ); return; } if( effect_id == "take_control_menu" ) { - subeffect_fun.set_take_control_menu(); - set_effect( subeffect_fun ); + set_effect( talk_effect_fun_t( talk_effect_fun::f_take_control_menu() ) ); + return; + } +<<<<<<< HEAD +======= + if( effect_id == "u_wants_to_talk" ) { + set_effect( talk_effect_fun_t( talk_effect_fun::f_wants_to_talk( false ) ) ); + return; + } + if( effect_id == "npc_wants_to_talk" ) { + set_effect( talk_effect_fun_t( talk_effect_fun::f_wants_to_talk( true ) ) ); return; } +>>>>>>> 0f39e72180 (remove talk_effect_fun declarations from header (#70898)) jo.throw_error_at( effect_id, "unknown effect string" ); }