Remove the 30-item limit in shops

This commit is contained in:
2019-12-02 01:16:34 -05:00
parent fd8bd913cc
commit 6f96222c37
10 changed files with 88 additions and 86 deletions

View File

@@ -81,6 +81,8 @@ bool cStack::setPage(size_t n) {
for(auto p : controls) {
const std::string& id = p.first;
cControl& ctrl = *p.second;
// Only trigger focus handlers if the current page still exists.
if(curPage < nPages) {
storage[curPage][id] = ctrl.store();
if(!ctrl.triggerFocusHandler(*parent, id, true))
failed = true;
@@ -92,6 +94,7 @@ bool cStack::setPage(size_t n) {
}
}
}
}
if(!failed) curPage = n;
return !failed;
}

View File

@@ -558,13 +558,9 @@ static void readShopFromXml(ticpp::Element& data, cShop& shop) {
} else if(type == "entries") {
cItem dummy_item;
dummy_item.variety = eItemType::GOLD;
int entries_found = 0;
Iterator<Element> entry;
for(entry = entry.begin(elem.Get()); entry != entry.end(); entry++) {
entry->GetValue(&type);
if(entries_found >= 30)
throw xBadNode(type, entry->Row(), entry->Column(), fname);
entries_found++;
if(type == "item") {
int amount = -1, num, chance = 100;
std::string title, descr;

View File

@@ -93,7 +93,7 @@ rectangle bottom_help_rects[4] = {{356,6,368,250},{374,6,386,270},{386,6,398,250
rectangle shop_name_str = {44,6,56,200};
rectangle shop_frame = {62,10,352,269};
rectangle shop_done_rect = {388,212,411,275};
short shop_array[30];
std::vector<int> shop_array;
cShop active_shop;
short active_shop_num;
@@ -125,9 +125,9 @@ void start_shop_mode(short which,short cost_adj,std::string store_name) {
for(auto p : univ.party.store_limited_stock[active_shop_num]) {
int which_item, quant_left;
std::tie(which_item, quant_left) = p;
if(which_item < 0 || which_item >= 30) continue;
if(which_item < 0 || which_item >= active_shop.size()) continue;
cShopItem entry = active_shop.getItem(which_item);
if(entry.quantity == 0) continue; // Just in case a stray entry accidentally gets put in for an infinite stock item
if(entry.quantity == 0) continue; // Just in case a stray entry accidentally gets put in for an infinite stock item (or an item was changed from finite to infinite)
if(quant_left == 0)
entry.type = eShopItemType::EMPTY;
else if(entry.type == eShopItemType::OPT_ITEM)
@@ -184,15 +184,16 @@ void end_shop_mode() {
// If it was a random shop, we need to update the stored list of items so that bought items don't reappear
if(active_shop.getType() == eShopType::RANDOM) {
for(int i = 0; i < 30; i++) {
auto& this_shop = univ.party.magic_store_items[active_shop_num];
this_shop.clear();
for(int i = 0; i < active_shop.size(); i++) {
cShopItem item = active_shop.getItem(i);
if(item.type != eShopItemType::EMPTY && univ.party.magic_store_items[active_shop_num][i].variety != eItemType::NO_ITEM)
univ.party.magic_store_items[active_shop_num][i] = item.item;
else univ.party.magic_store_items[active_shop_num][i].variety = eItemType::NO_ITEM;
if(item.type == eShopItemType::TREASURE || item.type == eShopItemType::CLASS || item.type == eShopItemType::OPT_ITEM)
this_shop[i] = item.item;
}
}
// We also need to save any limited stock
for(int i = 0; i < 30; i++) {
for(int i = 0; i < active_shop.size(); i++) {
cShopItem item = active_shop.getItem(i);
if(item.quantity > 0) {
// This means the stock is limited.
@@ -203,8 +204,6 @@ void end_shop_mode() {
}
void handle_shop_event(location p) {
unsigned long store_what_picked;
if(p.in(talk_help_rect)) {
if(!help_btn->handleClick(p))
return;
@@ -222,18 +221,18 @@ void handle_shop_event(location p) {
p.y -= 5;
for(short i = 0; i < 8; i++) {
store_what_picked = shop_array[i + shop_sbar->getPosition()];
if(store_what_picked >= 30) break;
if(active_shop.getItem(store_what_picked).type == eShopItemType::EMPTY)
unsigned long what_picked = shop_array[i + shop_sbar->getPosition()];
if(what_picked >= active_shop.size()) break;
if(active_shop.getItem(what_picked).type == eShopItemType::EMPTY)
break;
if(p.in(shopping_rects[i][SHOPRECT_ACTIVE_AREA])) {
click_shop_rect(shopping_rects[i][SHOPRECT_ACTIVE_AREA]);
handle_sale(active_shop.getItem(store_what_picked), store_what_picked);
handle_sale(active_shop.getItem(what_picked), what_picked);
set_up_shop_array();
draw_shop_graphics(false, {});
} else if(p.in(shopping_rects[i][SHOPRECT_ITEM_HELP])){
click_shop_rect(shopping_rects[i][SHOPRECT_ITEM_HELP]);
handle_info_request(active_shop.getItem(store_what_picked));
handle_info_request(active_shop.getItem(what_picked));
}
}
}
@@ -386,8 +385,6 @@ void handle_sale(cShopItem item, int i) {
play_sound(62);
ASB("You learn a little...");
active_shop.takeOne(i);
if(active_shop.size() != size_before)
shop_sbar->setMaximum(shop_sbar->getMaximum() - 1);
univ.current_pc().skills[skill]++;
}
break;
@@ -397,6 +394,8 @@ void handle_sale(cShopItem item, int i) {
beep();
ASB("Shop error 1. Report This!");
}
// Maybe that was the last of that item, so re-init the shop array just in case.
set_up_shop_array();
draw_shop_graphics(0,dummy_rect);
print_buf();
put_pc_screen();
@@ -465,12 +464,8 @@ void handle_info_request(cShopItem item) {
}
void set_up_shop_array() {
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable:4258)
#endif
int i = 0;
for(int j = 0; i < 30 && j < 30; j++) {
shop_array.clear();
for(int j = 0; j < active_shop.size(); j++) {
cShopItem entry = active_shop.getItem(j);
switch(entry.type) {
case eShopItemType::ITEM:
@@ -478,55 +473,55 @@ void set_up_shop_array() {
case eShopItemType::PRIEST_SPELL:
case eShopItemType::ALCHEMY:
case eShopItemType::SKILL:
shop_array[i++] = j;
shop_array.push_back(j);
break;
case eShopItemType::HEAL_WOUNDS:
if(univ.current_pc().cur_health < univ.current_pc().max_health)
shop_array[i++] = j;
shop_array.push_back(j);
break;
case eShopItemType::CURE_POISON:
if(univ.current_pc().status[eStatus::POISON] > 0)
shop_array[i++] = j;
shop_array.push_back(j);
break;
case eShopItemType::CURE_DISEASE:
if(univ.current_pc().status[eStatus::DISEASE] > 0)
shop_array[i++] = j;
shop_array.push_back(j);
break;
case eShopItemType::CURE_ACID:
if(univ.current_pc().status[eStatus::ACID] > 0)
shop_array[i++] = j;
shop_array.push_back(j);
break;
case eShopItemType::CURE_PARALYSIS:
if(univ.current_pc().status[eStatus::PARALYZED] > 0)
shop_array[i++] = j;
shop_array.push_back(j);
break;
case eShopItemType::CURE_DUMBFOUNDING:
if(univ.current_pc().status[eStatus::DUMB] > 0)
shop_array[i++] = j;
shop_array.push_back(j);
break;
case eShopItemType::DESTONE:
if(univ.current_pc().main_status == eMainStatus::STONE)
shop_array[i++] = j;
shop_array.push_back(j);
break;
case eShopItemType::RAISE_DEAD:
if(univ.current_pc().main_status == eMainStatus::DEAD)
shop_array[i++] = j;
shop_array.push_back(j);
break;
case eShopItemType::RESURRECT:
if(univ.current_pc().main_status == eMainStatus::DUST)
shop_array[i++] = j;
shop_array.push_back(j);
break;
case eShopItemType::REMOVE_CURSE:
for(int i = 0; i < univ.current_pc().items.size(); i++) {
if((univ.current_pc().equip[i]) && (univ.current_pc().items[i].cursed)) {
shop_array[i++] = j;
shop_array.push_back(j);
break;
}
}
break;
case eShopItemType::CALL_SPECIAL:
if(PSD[entry.item.abil_data[0]][entry.item.abil_data[1]])
shop_array[i++] = j;
shop_array.push_back(j);
break;
case eShopItemType::OPT_ITEM:
entry.quantity %= 1000;
@@ -536,7 +531,7 @@ void set_up_shop_array() {
entry.item = univ.party.magic_store_items[active_shop_num][j];
if(entry.item.variety == eItemType::NO_ITEM)
entry.type = eShopItemType::EMPTY;
else shop_array[i++] = j;
else shop_array.push_back(j);
entry.quantity = 1;
active_shop.replaceItem(j, entry);
break;
@@ -544,11 +539,7 @@ void set_up_shop_array() {
break;
}
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif
shop_sbar->setMaximum(i - 8);
std::fill(shop_array + i, shop_array + 30, -1);
shop_sbar->setMaximum(shop_array.size() - 8);
}
void start_talk_mode(short m_num,short personality,mon_num_t monst_type,short store_face_pic) {

View File

@@ -96,7 +96,7 @@ extern rectangle shop_frame ;
extern rectangle shop_done_rect;
extern char *heal_types[];
extern short heal_costs[8];
extern short shop_array[30];
extern std::vector<int> shop_array;
// Missile anim vars
struct store_missile_type {
@@ -726,8 +726,8 @@ void draw_shop_graphics(bool pressed,rectangle clip_area_rect) {
// Place all the items
for(short i = 0; i < 8; i++) {
current_pos = i + shop_sbar->getPosition();
if(shop_array[current_pos] < 0)
break; // theoretically, this shouldn't happen
if(current_pos >= shop_array.size() || shop_array[current_pos] < 0)
break; // theoretically, the second condition shouldn't happen
cShopItem item = active_shop.getItem(shop_array[current_pos]);
eSpell spell;
cur_cost = item.getCost(active_shop.getCostAdjust());

View File

@@ -93,15 +93,21 @@ size_t cShop::firstEmpty() {
return items.size();
}
size_t cShop::size() {
return std::count_if(items.begin(), items.end(), [](cShopItem& item) {
size_t cShop::size() const {
return items.size();
}
size_t cShop::num_items() const {
return std::count_if(items.begin(), items.end(), [](const cShopItem& item) {
return item.type != eShopItemType::EMPTY;
});
}
void cShop::addItem(size_t n, cItem item, size_t quantity, int chance) {
size_t i = firstEmpty();
if(i >= items.size()) return;
if(i >= items.size()) {
items.resize(i + 1);
}
if(item.variety == eItemType::NO_ITEM) return;
items[i].type = chance == 100 ? eShopItemType::ITEM : eShopItemType::OPT_ITEM;
items[i].item = item;
@@ -196,7 +202,9 @@ void cShop::replaceSpecial(size_t i, eShopItemType type, int n) {
if(type == eShopItemType::ITEM) return;
if(type == eShopItemType::OPT_ITEM) return;
if(type == eShopItemType::CALL_SPECIAL) return;
if(i >= items.size()) return;
if(i >= items.size()) {
items.resize(i + 1);
}
items[i].type = type;
if(type >= eShopItemType::HEAL_WOUNDS)
items[i].index = int(type) - int(eShopItemType::HEAL_WOUNDS);
@@ -232,7 +240,9 @@ void cShop::replaceSpecial(size_t i, eShopItemType type, int n) {
void cShop::addSpecial(std::string name, std::string descr, pic_num_t pic, int node, int cost, int quantity) {
size_t i = firstEmpty();
if(i >= items.size()) return;
if(i >= items.size()) {
items.resize(i + 1);
}
items[i].type = eShopItemType::CALL_SPECIAL;
items[i].quantity = quantity;
items[i].item.full_name = name;
@@ -243,6 +253,7 @@ void cShop::addSpecial(std::string name, std::string descr, pic_num_t pic, int n
}
cShopItem cShop::getItem(size_t i) const {
if(i >= items.size()) return cShopItem();
return items[i];
}
@@ -294,17 +305,18 @@ void cShop::takeOne(size_t i) {
}
void cShop::replaceItem(size_t i, cShopItem newItem) {
if(i >= 30) return;
if(i >= items.size()) {
items.resize(i + 1);
}
items[i] = newItem;
}
void cShop::clearItem(size_t i) {
std::copy(items.begin() + i + 1, items.end(), items.begin() + i);
items.back().type = eShopItemType::EMPTY;
items.erase(items.begin() + i);
}
void cShop::clear() {
std::fill(items.begin(), items.end(), cShopItem());
items.clear();
}
int cShopItem::getCost(int adj) {

View File

@@ -57,7 +57,7 @@ struct cShopItem {
};
class cShop {
std::array<cShopItem,30> items;
std::vector<cShopItem> items;
int cost_adj;
std::string name;
eShopType type;
@@ -79,7 +79,8 @@ public:
void replaceItem(size_t i, cShopItem newItem);
void replaceSpecial(size_t i, eShopItemType type, int n = 0);
void refreshItems(std::vector<cItem>& fromList);
size_t size();
size_t size() const;
size_t num_items() const;
cShopItem getItem(size_t i) const;
eShopType getType() const;
int getCostAdjust() const;

View File

@@ -2191,7 +2191,8 @@ static void put_shop_in_dlog(cDialog& me, const cShop& shop, size_t which_shop)
dynamic_cast<cLedGroup&>(me["prompt"]).setSelected("p" + std::to_string(int(shop.getPrompt()) + 1));
cStack& items = dynamic_cast<cStack&>(me["items"]);
for(int i = 0; i < 6; i++) {
items.setPageCount(std::max<int>(1, ceil(shop.size() / 5.0)));
for(int i = 0; i < items.getPageCount(); i++) {
items.setPage(i);
for(int j = 0; j < 5; j++) {
std::string id = std::to_string(j + 1);
@@ -2208,6 +2209,14 @@ static void put_shop_in_dlog(cDialog& me, const cShop& shop, size_t which_shop)
}
}
items.setPage(0);
if(items.getPageCount() <= 1) {
dynamic_cast<cButton&>(me["up"]).hide();
dynamic_cast<cButton&>(me["down"]).hide();
} else {
dynamic_cast<cButton&>(me["up"]).show();
dynamic_cast<cButton&>(me["down"]).show();
}
}
static bool save_shop_from_dlog(cDialog& me, cShop& shop, size_t which_shop, bool close) {
@@ -2391,16 +2400,14 @@ static bool delete_shop_entry(cDialog& me, std::string which, cShop& shop, size_
int page = items.getPage();
shop.clearItem((which[3] - '1') + 5 * page);
put_shop_in_dlog(me, shop, which_shop);
if(page == items.getPageCount())
page--;
items.setPage(page);
change_shop_dlog_items_page(me, "stay", shop);
return true;
}
static bool add_shop_entry(cDialog& me, std::string type, cShop& shop, size_t which_shop) {
if(shop.size() == 30) {
showError("There is no more room in this shop to add another item. Each shop can only have up to 30 items.", &me);
return true;
}
if(type == "item" || type == "opt") {
size_t which_item = 0, amount = 0;
edit_shop_item(me, which_item, amount, type == "opt");
@@ -2491,7 +2498,6 @@ bool edit_shop(size_t which_shop, cDialog* parent) {
shop_dlg.attachClickHandlers(std::bind(change_shop_dlog_page, _1, _2, std::ref(shop), std::ref(which_shop)), {"left", "right"});
}
dynamic_cast<cStack&>(shop_dlg["items"]).setPageCount(6);
put_shop_in_dlog(shop_dlg, shop, which_shop);
shop_dlg.run();
return shop_dlg.accepted();

View File

@@ -37,9 +37,6 @@ cParty::cParty(long party_preset) {
in_boat = -1;
in_horse = -1;
std::fill(magic_ptrs.begin(), magic_ptrs.end(), 0);
for(int i = 0; i < 5; i++)
for(int j = 0; j < 10; j++)
magic_store_items[i][j].variety = eItemType::NO_ITEM;
for(int i = 0; i < 10; i++)
out_c[i].exists = false;
for(int i = 0; i < 6; i++)
@@ -773,10 +770,10 @@ void cParty::writeTo(std::ostream& file, const cScenario& scen) const {
}
file << '\f';
for(auto& p : magic_store_items) {
for(int j = 0; j < p.second.size(); j++)
if(p.second[j].variety != eItemType::NO_ITEM){
file << "MAGICSTORE " << p.first << ' ' << j << '\n';
p.second[j].writeTo(file);
for(auto& p2 : p.second)
if(p2.second.variety != eItemType::NO_ITEM){
file << "MAGICSTORE " << p.first << ' ' << p2.first << '\n';
p2.second.writeTo(file);
file << '\f';
}
}
@@ -1030,7 +1027,6 @@ void cParty::readFrom(std::istream& file, cScenario& scen){
} else if(cur == "MAGICSTORE") {
int i,j;
bin >> i >> j;
if(j < 0 || j >= 30) continue;
magic_store_items[i][j].readFrom(bin);
} else if(cur == "ENCOUNTER") {
int i;

View File

@@ -101,7 +101,7 @@ public:
short in_boat;
short in_horse;
std::array<cOutdoors::cCreature,10> out_c;
std::map<int,std::array<cItem,30>> magic_store_items;
std::map<int,std::map<int,cItem>> magic_store_items;
std::map<int,std::map<int,int>> store_limited_stock;
std::vector<job_bank_t> job_banks;
std::array<mon_num_t,4> imprisoned_monst; // Soul Crystal

View File

@@ -1348,9 +1348,7 @@ void cUniverse::enter_scenario(const std::string& name) {
pop.which_town = 200;
for(short i = 0; i < 10; i++)
party.out_c[i].exists = false;
for(short i = 0; i < 5; i++)
for(short j = 0; j < 10; j++)
party.magic_store_items[i][j].variety = eItemType::NO_ITEM;
party.magic_store_items.clear();
// TODO: Now uncertain if the journal should really persist
// univ.party.journal.clear();
party.special_notes.clear();
@@ -1419,7 +1417,7 @@ void cUniverse::refresh_store_items() {
for(size_t i = 0; i < scenario.shops.size(); i++) {
if(scenario.shops[i].getType() != eShopType::RANDOM)
continue;
for(int j = 0; j < 30; j++) {
for(int j = 0; j < scenario.shops[i].size(); j++) {
cShopItem entry = scenario.shops[i].getItem(j);
if(entry.type == eShopItemType::TREASURE) {
party.magic_store_items[i][j] = get_random_store_item(entry.item.item_level, entry.item.item_level == 0);
@@ -1444,7 +1442,6 @@ void cUniverse::refresh_store_items() {
continue;
}
}
party.magic_store_items[i][j] = cItem();
}
}