From ddc78831957abf24b4a6bbf321a9174dbf783993 Mon Sep 17 00:00:00 2001 From: GuardianDll Date: Thu, 7 Nov 2024 19:05:36 +0100 Subject: [PATCH] move NPC bye message to snippet --- doc/NPCs.md | 1 + src/dialogue_chatbin.h | 2 +- src/npc_class.cpp | 1 + src/npc_class.h | 2 ++ src/npctalk.cpp | 14 ++++++++++++-- 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/doc/NPCs.md b/doc/NPCs.md index 99ff1c97cf640..3e03c090324b6 100644 --- a/doc/NPCs.md +++ b/doc/NPCs.md @@ -57,6 +57,7 @@ Format: "carry_override": "NC_EXAMPLE_carried", // Optional. Defines an item group that replaces their carried items (in pockets, etc). Items which cannot // be carried will overflow(fall to the ground) when the NPC is loaded. "weapon_override": "NC_EXAMPLE_weapon", // Optional. Defines an item group that replaces their wielded weapon. + "bye_message_override": "", // Optional. If used, overrides the default bye message (picked from snippet) to any another custom snippet "shopkeeper_item_group": [ // Optional. See [Shopkeeper NPC configuration](#shopkeeper-npc-configuration) below. { "group": "example_shopkeeper_itemgroup1" }, { "group": "example_shopkeeper_itemgroup2", "trust": 10 }, diff --git a/src/dialogue_chatbin.h b/src/dialogue_chatbin.h index ebc9139a0eccc..77db389a39a06 100644 --- a/src/dialogue_chatbin.h +++ b/src/dialogue_chatbin.h @@ -132,7 +132,7 @@ struct dialogue_chatbin_snippets { // talk from npctalk.cpp(can use snippets in json) translation snip_acknowledged = no_translation( "" ); - translation snip_bye = to_translation( "Bye." ); + translation snip_bye = to_translation( "" ); // talk from talker_npc.cpp(can use snippets in json) translation snip_consume_cant_accept = diff --git a/src/npc_class.cpp b/src/npc_class.cpp index 1ee5ebf2bf8b1..5ad16b50be239 100644 --- a/src/npc_class.cpp +++ b/src/npc_class.cpp @@ -266,6 +266,7 @@ void npc_class::load( const JsonObject &jo, const std::string_view ) optional( jo, was_loaded, "worn_override", worn_override ); optional( jo, was_loaded, "carry_override", carry_override ); optional( jo, was_loaded, "weapon_override", weapon_override ); + optional( jo, was_loaded, "bye_message_override", bye_message_override ); if( jo.has_member( "traits" ) ) { traits = trait_group::load_trait_group( jo.get_member( "traits" ), "collection" ); diff --git a/src/npc_class.h b/src/npc_class.h index cb8cfb9ed653b..1f258651c5971 100644 --- a/src/npc_class.h +++ b/src/npc_class.h @@ -110,6 +110,8 @@ class npc_class item_group_id carry_override; item_group_id weapon_override; + translation bye_message_override; + std::map mutation_rounds; trait_group::Trait_group_tag traits = trait_group::Trait_group_tag( "EMPTY_GROUP" ); // the int is what level the spell starts at diff --git a/src/npctalk.cpp b/src/npctalk.cpp index 6e7e4458723f9..de48d0a597261 100644 --- a/src/npctalk.cpp +++ b/src/npctalk.cpp @@ -62,6 +62,7 @@ #include "npctalk.h" #include "npctalk_rules.h" #include "npctrade.h" +#include "npc_class.h" #include "output.h" #include "overmapbuffer.h" #include "pimpl.h" @@ -1567,7 +1568,11 @@ void avatar::talk_to( std::unique_ptr talk_with, bool radio_contact, if( next.id == "TALK_DONE" || d.topic_stack.empty() ) { npc *npc_actor = d.actor( true )->get_npc(); if( npc_actor ) { - d.actor( true )->say( npc_actor->chat_snippets().snip_bye.translated() ); + if( npc_actor->myclass->bye_message_override.empty() ) { + d.actor( true )->say( npc_actor->chat_snippets().snip_bye.translated() ); + } else { + d.actor( true )->say( npc_actor->myclass->bye_message_override.translated() ); + } } d.done = true; } else if( next.id != "TALK_NONE" ) { @@ -1689,7 +1694,12 @@ std::string dialogue::dynamic_line( const talk_topic &the_topic ) } if( topic == "TALK_NONE" || topic == "TALK_DONE" ) { - return actor( true )->get_npc()->chat_snippets().snip_bye.translated(); + npc *guy = actor( true )->get_npc(); + if( guy->myclass->bye_message_override.empty() ) { + return guy->chat_snippets().snip_bye.translated(); + } else { + return guy->myclass->bye_message_override.translated(); + } } else if( topic == "TALK_TRAIN" ) { if( !player_character.backlog.empty() && player_character.backlog.front().id() == ACT_TRAIN ) { return _( "Shall we resume?" );