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E2K2QN2EFLQC
6GDKXNFXPKQ6AVNOSMJECN7CLELM2KCMVRM2A7BARLK2NNILN6SAC
you.redraw_hit_points = 1;
you.redraw_magic_points = 1;
you.redraw_strength = 1;
you.redraw_intelligence = 1;
you.redraw_dexterity = 1;
you.redraw_armour_class = 1;
you.redraw_evasion = 1;
you.redraw_gold = 1;
you.redraw_experience = 1;
you.redraw_hit_points = true;
you.redraw_magic_points = true;
you.redraw_strength = true;
you.redraw_intelligence = true;
you.redraw_dexterity = true;
you.redraw_armour_class = true;
you.redraw_evasion = true;
you.redraw_gold = true;
you.redraw_experience = true;
shop_struct& the_shop = env.shop[shoppy];
cursor_control coff(false);
FixedVector < int, 20 > shop_items;
char st_pass[ ITEMNAME_SIZE ] = "";
unsigned char ft;
std::string purchasable;
clrscr();
int itty = 0;
int gp_value; // Should eliminate gotos instead of initializing here
ShopInfo &si = stashes.get_shop(the_shop.x, the_shop.y);
{
std::string welcome_message = "Welcome to ";
welcome_message += shop_name(the_shop.x, the_shop.y);
welcome_message += "!";
shop_print(welcome_message.c_str(), 20);
}
more3();
std::vector<int> result;
activate_notes(false); /* should do a better job here */
const bool id_stock = shoptype_identifies_stock(the_shop.type);
print_stock:
clrscr();
itty = igrd[0][5 + shoppy];
si.reset();
int itty = igrd[0][5 + shopidx];
purchasable.clear();
for (int i = 1; i < 18; i++)
static std::string shop_print_stock( const std::vector<int>& stock,
const shop_struct& shop )
{
ShopInfo &si = stashes.get_shop(shop.x, shop.y);
const bool id = shoptype_identifies_stock(shop.type);
std::string purchasable;
for (unsigned int i = 0; i < stock.size(); ++i)
const char c = i + 96;
gotoxy(1, i);
gp_value = the_shop.greed * item_value(mitm[itty], id_stock);
gp_value /= 10;
if ( you.duration[DUR_BARGAIN] ) // 20% discount
{
gp_value *= 8;
gp_value /= 10;
}
if (gp_value <= 1)
gp_value = 1;
const int gp_value = shop_item_value(mitm[stock[i]], shop.greed, id);
textcolor((i % 2) ? WHITE : LIGHTGREY);
cprintf("%s", mitm[itty].name(DESC_NOCAP_A, false, id_stock).c_str());
si.add_item(mitm[itty], gp_value);
gotoxy(60, i);
cprintf("%5d gold", gp_value);
if (mitm[itty].link == NON_ITEM)
break;
snprintf(st_pass, sizeof st_pass,
"What would you like to %s?",
purchasable.length()? "purchase" : "do");
shop_print(st_pass, 20);
textcolor(LIGHTGREY);
ft = get_ch();
if (ft == 'x' || ft == ESCAPE)
goto goodbye;
clrscr();
if ( stock.empty() )
{
shop_print("I'm sorry, my shop is empty now.", 20);
more3();
return;
}
const std::string purchasable = shop_print_stock(stock, shop);
list_shop_keys(purchasable);
snprintf( info, INFO_SIZE, "You have %d gold piece%s.", you.gold,
(you.gold == 1) ? "" : "s" );
textcolor(YELLOW);
shop_print(info, 19);
if (ft == '\\')
{
check_item_knowledge();
goto print_stock;
}
if (ft == 'v')
{
snprintf( info, INFO_SIZE, "What would you like to %s?",
purchasable.length()? "purchase" : "do");
if (shop_items[ft] == NON_ITEM)
// A hack to make the description more useful.
// In theory, the user could kill the process at this
// point and end up with valid ID for the item.
// That's not very useful, though, because it doesn't set
// type-ID and once you can access the item (by buying it)
// you have its full ID anyway. Worst case, it won't get
// noted when you buy it.
item_def& item = mitm[stock[ft]];
const unsigned long old_flags = item.flags;
if ( id_stock )
item.flags |= ISFLAG_IDENT_MASK;
describe_item(item);
if ( id_stock )
item.flags = old_flags;
}
else if (ft == '?' || ft == '*')
invent(-1, false);
else if ( !isalpha(ft) )
// A hack to make the description more useful.
// In theory, the user could kill the process at this
// point and end up with valid ID for the item.
// That's not very useful, though, because it doesn't set
// type-ID and once you can access the item (by buying it)
// you have its full ID anyway. Worst case, it won't get
// noted when you buy it.
item_def& item = mitm[shop_items[ft]];
const unsigned long old_flags = item.flags;
if ( id_stock )
item.flags |= ISFLAG_IDENT_MASK;
describe_item(item);
if ( id_stock )
item.flags = old_flags;
item_def& item = mitm[stock[ft]];
const int gp_value = shop_item_value(item, shop.greed, id_stock);
if (gp_value > you.gold)
{
shop_print("I'm sorry, you don't seem to have enough money.",
20);
more3();
}
else
{
snprintf(info, INFO_SIZE, "Purchase %s (%d gold)? [y/n]",
item.name(DESC_NOCAP_A).c_str(), gp_value);
shop_print(info, 20);
goto print_stock;
}
if (ft == '?' || ft == '*')
{
invent(-1, false);
goto print_stock;
}
if (ft < 'a' || ft > 'z') // see earlier comments re: uppercase {dlb}
{
huh:
shop_print("Huh?", 20);
more3();
goto purchase;
}
ft -= 'a'; // see earlier comments re: uppercase {dlb}
if (ft > 18)
goto huh;
if (shop_items[ft] == NON_ITEM)
{
shop_print("I'm sorry, you seem to be confused.", 20);
more3();
goto purchase;
}
gp_value = the_shop.greed*item_value(mitm[shop_items[ft]],id_stock)/10;
if ( you.duration[DUR_BARGAIN] ) // 20% discount
{
gp_value *= 8;
gp_value /= 10;
}
if (gp_value > you.gold)
{
shop_print("I'm sorry, you don't seem to have enough money.", 20);
more3();
goto purchase;
}
snprintf(info, INFO_SIZE, "Purchase %s (%d gold)? [y/n]",
mitm[shop_items[ft]].name(DESC_NOCAP_A).c_str(), gp_value);
shop_print(info, 20);
if ( yesno(NULL, true, 'n', false, false, true) )
{
if ( id_stock )
{
// Identify the item and its type.
item_def& pitem = mitm[shop_items[ft]];
set_ident_type(pitem.base_type, pitem.sub_type, ID_KNOWN_TYPE);
set_ident_flags(pitem, ISFLAG_IDENT_MASK);
if ( yesno(NULL, true, 'n', false, false, true) )
purchase( shopidx, stock[ft], gp_value, id_stock );
}
activate_notes(true);
take_note(Note(NOTE_ID_ITEM, 0, 0,
item.name(DESC_NOCAP_A).c_str(),
origin_desc(item).c_str()));
activate_notes(false);
// Identify the item and its type.
// This also takes the ID note if necessary.
set_ident_type(item.base_type, item.sub_type, ID_KNOWN_TYPE);
set_ident_flags(item, ISFLAG_IDENT_MASK);