From 4bec9ddf3186441d8f4f05434f1a9ac84e3c1d5a Mon Sep 17 00:00:00 2001 From: mumra Date: Fri, 24 May 2024 23:52:07 +0100 Subject: [PATCH] shop names: switch to pairs instead of tuples --- crawl-ref/source/god-abil.cc | 4 ++-- crawl-ref/source/shopping.cc | 18 +++++++----------- crawl-ref/source/shopping.h | 4 ++-- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/crawl-ref/source/god-abil.cc b/crawl-ref/source/god-abil.cc index a0199d72a5f..8a85bf48b04 100644 --- a/crawl-ref/source/god-abil.cc +++ b/crawl-ref/source/god-abil.cc @@ -3144,9 +3144,9 @@ static void _setup_gozag_shop(int index, vector &valid_shops) auto names = generate_shop_name(type, you.experience_level, true); you.props[make_stringf(GOZAG_SHOP_NAME_KEY, index)] - = std::get<0>(names); + = names.first; you.props[make_stringf(GOZAG_SHOPKEEPER_NAME_KEY, index)] - = std::get<1>(names); + = names.second; you.props[make_stringf(GOZAG_SHOP_COST_KEY, index)].get_int() = gozag_price_for_shop(); diff --git a/crawl-ref/source/shopping.cc b/crawl-ref/source/shopping.cc index 1592367dab9..b7c7da6b6f6 100644 --- a/crawl-ref/source/shopping.cc +++ b/crawl-ref/source/shopping.cc @@ -1567,7 +1567,7 @@ string generate_shopkeeper_name(bool fancy, bool gozag) return name; } -tuple generate_shop_name(shop_type type, int shop_level, bool gozag) +pair generate_shop_name(shop_type type, int shop_level, bool gozag) { // Generate an appropriately long name for the level. Level is (2 * (absdepth || XL)) // depending on how it was generated, so it can get up to 54 with Gozag. @@ -1578,7 +1578,7 @@ tuple generate_shop_name(shop_type type, int shop_level, bool go // string key = (gozag ? "gozag " : fancy ? "fancy " : "") // + shop_type_name(type) + " shop"; string key = shop_type_name(type) + " shop name"; - std::tuple best = {"", ""}; + auto best = make_pair(string(""), string("")); size_t best_name_size = 0; // Have 10 tries, and veto the lengths we don't like. Aiming to get the // closest to the desired length without actually being longer. @@ -1599,7 +1599,7 @@ tuple generate_shop_name(shop_type type, int shop_level, bool go if (name.size() == target_length) { // Exact length, can't do any better, stop here - best = { name, keeper_name }; + best = make_pair(name, keeper_name); break; } else if (name.size() > target_length) @@ -1607,19 +1607,15 @@ tuple generate_shop_name(shop_type type, int shop_level, bool go // Keep the name if it's the first or it's shorter than the best // we found so far if (best_name_size == 0 || name.size() < best_name_size) - { - best = { name, keeper_name }; - } + best = make_pair(name, keeper_name); } + // Name is within target but longer than best so prefer this one else if (name.size() > best_name_size) - { - // Name is within target but longer than best so prefer this one - best = { name, keeper_name }; - } + best = make_pair(name, keeper_name); best_name_size = name.size(); } - mprf("Final: %s", std::get<0>(best).c_str()); + mprf("Final: %s", best.first.c_str()); return best; } diff --git a/crawl-ref/source/shopping.h b/crawl-ref/source/shopping.h index 49d3eabd78d..57d5af13df7 100644 --- a/crawl-ref/source/shopping.h +++ b/crawl-ref/source/shopping.h @@ -35,8 +35,8 @@ shop_struct *shop_at(const coord_def& where); void destroy_shop_at(coord_def p); string generate_shopkeeper_name(bool fancy, bool gozag); -tuple generate_shop_name(const shop_type type, int shop_level, - bool gozag); +pair generate_shop_name(const shop_type type, int shop_level, + bool gozag); string shop_name(const shop_struct& shop); string shop_type_name(shop_type type);