From d33709f4a2dbc655376040e7dc41047b7e5eab6d Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Sun, 12 Nov 2023 00:01:09 -0800 Subject: [PATCH] make quests appear in the menu even if they don't exist in player's language --- src/Quest.cc | 12 ++++++++---- src/Quest.hh | 3 ++- src/ReceiveCommands.cc | 4 ++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Quest.cc b/src/Quest.cc index fe4325a2..3f8aeb46 100644 --- a/src/Quest.cc +++ b/src/Quest.cc @@ -416,6 +416,12 @@ bool Quest::has_version(QuestScriptVersion v, uint8_t language) const { return this->versions.count(this->versions_key(v, language)); } +bool Quest::has_version_any_language(QuestScriptVersion v) const { + uint16_t k = this->versions_key(v, 0); + auto it = this->versions.lower_bound(k); + return ((it != this->versions.end()) && ((it->first & 0xFF00) == k)); +} + shared_ptr Quest::version(QuestScriptVersion v, uint8_t language) const { // Return the requested version, if it exists try { @@ -727,12 +733,10 @@ shared_ptr QuestIndex::get_gba(const string& name) const { } } -vector> QuestIndex::filter(uint32_t category_id, QuestScriptVersion version, uint8_t language) const { +vector> QuestIndex::filter(uint32_t category_id, QuestScriptVersion version) const { vector> ret; for (auto it : this->quests_by_number) { - // Show English quests, and quests that exist in the player's language - if ((it.second->category_id == category_id) && - (it.second->has_version(version, language) || it.second->has_version(version, 1))) { + if ((it.second->category_id == category_id) && it.second->has_version_any_language(version)) { ret.emplace_back(it.second); } } diff --git a/src/Quest.hh b/src/Quest.hh index 30e5728a..161e61e1 100644 --- a/src/Quest.hh +++ b/src/Quest.hh @@ -98,6 +98,7 @@ public: void add_version(std::shared_ptr vq); bool has_version(QuestScriptVersion v, uint8_t language) const; + bool has_version_any_language(QuestScriptVersion v) const; std::shared_ptr version(QuestScriptVersion v, uint8_t language) const; static uint16_t versions_key(QuestScriptVersion v, uint8_t language); @@ -124,7 +125,7 @@ struct QuestIndex { std::shared_ptr get(uint32_t quest_number) const; std::shared_ptr get_gba(const std::string& name) const; - std::vector> filter(uint32_t category_id, QuestScriptVersion version, uint8_t language) const; + std::vector> filter(uint32_t category_id, QuestScriptVersion version) const; }; std::string encode_download_quest_data( diff --git a/src/ReceiveCommands.cc b/src/ReceiveCommands.cc index 6fa7c74c..f26dc784 100644 --- a/src/ReceiveCommands.cc +++ b/src/ReceiveCommands.cc @@ -1979,7 +1979,7 @@ static void on_10(shared_ptr c, uint16_t, uint32_t, string& data) { if (num_ep3_categories == 1) { auto quest_index = s->quest_index_for_client(c); if (quest_index) { - auto quests = quest_index->filter(ep3_category_id, c->quest_version(), c->language()); + auto quests = quest_index->filter(ep3_category_id, c->quest_version()); send_quest_menu(c, MenuID::QUEST, quests, true); } else { send_lobby_message_box(c, "$C6Quests are not available."); @@ -2233,7 +2233,7 @@ static void on_10(shared_ptr c, uint16_t, uint32_t, string& data) { break; } shared_ptr l = c->lobby.lock(); - auto quests = quest_index->filter(item_id, c->quest_version(), c->language()); + auto quests = quest_index->filter(item_id, c->quest_version()); // Hack: Assume the menu to be sent is the download quest menu if the // client is not in any lobby