Skip to content

Commit

Permalink
shop names: switch to pairs instead of tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
chucksellick committed May 24, 2024
1 parent 1ac2206 commit 4bec9dd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
4 changes: 2 additions & 2 deletions crawl-ref/source/god-abil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3144,9 +3144,9 @@ static void _setup_gozag_shop(int index, vector<shop_type> &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();
Expand Down
18 changes: 7 additions & 11 deletions crawl-ref/source/shopping.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ string generate_shopkeeper_name(bool fancy, bool gozag)
return name;
}

tuple<string, string> generate_shop_name(shop_type type, int shop_level, bool gozag)
pair<string, string> 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.
Expand All @@ -1578,7 +1578,7 @@ tuple<string, string> 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<string,string> 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.
Expand All @@ -1599,27 +1599,23 @@ tuple<string, string> 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)
{
// 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;
}
Expand Down
4 changes: 2 additions & 2 deletions crawl-ref/source/shopping.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<string,string> generate_shop_name(const shop_type type, int shop_level,
bool gozag);
pair<string,string> 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);

Expand Down

0 comments on commit 4bec9dd

Please sign in to comment.