From 8a054da3ae1bcf6c2933c8efbcef2d188cb5fee7 Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Sun, 29 Sep 2024 19:25:52 -0400 Subject: [PATCH] Updated --- Source/stores.cpp | 131 ++++++++++++++++++++-------------------------- Source/stores.h | 38 +++++++++----- 2 files changed, 83 insertions(+), 86 deletions(-) diff --git a/Source/stores.cpp b/Source/stores.cpp index ecf7cb7c1e7..278f5de7ebe 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -40,6 +40,11 @@ int currentItemIndex; std::array playerItemIndexes; std::vector playerItems; +void ExitStore() +{ + activeStore = TalkID::Exit; +} + namespace { constexpr int PaddingTop = 32; @@ -116,8 +121,8 @@ const std::string SmithMenuHeader = "Welcome to the\n\nBlacksmith's shop"; const StoreMenuOption SmithMenuOptions[] = { { TalkID::Gossip, "Talk to Griswold" }, - { TalkID::SmithBuy, "Buy basic items" }, - { TalkID::SmithPremiumBuy, "Buy premium items" }, + { TalkID::SmithBasicBuy, "Buy basic items" }, + { TalkID::SmithBuy, "Buy premium items" }, { TalkID::SmithSell, "Sell items" }, { TalkID::SmithRepair, "Repair items" }, { TalkID::Exit, "Leave the shop" } @@ -210,11 +215,11 @@ std::unordered_map<_talker_id, TownerStore *> townerStores; void InitializeTownerStores() { - townerStores[TOWN_SMITH] = &Blacksmith; - townerStores[TOWN_HEALER] = &Healer; - townerStores[TOWN_WITCH] = &Witch; - townerStores[TOWN_PEGBOY] = &Boy; - townerStores[TOWN_STORY] = &Storyteller; + townerStores[Blacksmith.townerId] = &Blacksmith; + townerStores[Healer.townerId] = &Healer; + townerStores[Witch.townerId] = &Witch; + townerStores[Boy.townerId] = &Boy; + townerStores[Storyteller.townerId] = &Storyteller; } /** @@ -274,9 +279,9 @@ int GetItemCount(TalkID talkId) if (towner != nullptr) { switch (talkId) { - case TalkID::SmithBuy: + case TalkID::SmithBasicBuy: return towner->basicItems.size(); - case TalkID::SmithPremiumBuy: + case TalkID::SmithBuy: case TalkID::HealerBuy: case TalkID::WitchBuy: case TalkID::BoyBuy: @@ -479,9 +484,9 @@ void SetupConfirmScreen(Item &item) prompt = _("Are you sure you want to identify this item?"); break; case TalkID::HealerBuy: - case TalkID::SmithPremiumBuy: - case TalkID::WitchBuy: case TalkID::SmithBuy: + case TalkID::WitchBuy: + case TalkID::SmithBasicBuy: prompt = _("Are you sure you want to buy this item?"); break; case TalkID::WitchRecharge: @@ -880,10 +885,10 @@ void SetupItemList(TalkID talkId, std::vector &items, int idx, bool void SetupTownerItemList(TalkID talkId, int idx, bool selling = true) { switch (talkId) { - case TalkID::SmithBuy: + case TalkID::SmithBasicBuy: SetupItemList(talkId, Blacksmith.basicItems, idx, selling); break; - case TalkID::SmithPremiumBuy: + case TalkID::SmithBuy: SetupItemList(talkId, Blacksmith.items, idx, selling); break; case TalkID::HealerBuy: @@ -944,11 +949,11 @@ static void UpdateItemStatFlag(Item &item) void UpdateItemStatFlags(TalkID talkId) { switch (talkId) { - case TalkID::SmithBuy: + case TalkID::SmithBasicBuy: for (Item &item : Blacksmith.basicItems) UpdateItemStatFlag(item); break; - case TalkID::SmithPremiumBuy: + case TalkID::SmithBuy: for (Item &item : Blacksmith.items) UpdateItemStatFlag(item); break; @@ -1151,29 +1156,9 @@ void TownerMainEnter() { TalkID selectedAction = storeLineMapping[currentTextLine]; - if (selectedAction == TalkID::Exit) { - activeStore = selectedAction; - return; - } - - if (selectedAction == TalkID::Gossip) { - oldTextLine = currentTextLine; - oldActiveStore = activeStore; - } - - if (selectedAction == TalkID::BoyBuy) { - if (!CanPlayerAfford(50)) { - oldActiveStore = activeStore; - StartStore(TalkID::NoMoney); - return; - } else { - TakePlrsMoney(50); - } - } - switch (selectedAction) { case TalkID::Exit: - activeStore = selectedAction; + ExitStore(); return; case TalkID::Gossip: oldTextLine = currentTextLine; @@ -1182,14 +1167,13 @@ void TownerMainEnter() case TalkID::BoyBuy: if (!CanPlayerAfford(50)) { oldActiveStore = activeStore; - StartStore(TalkID::NoMoney); - return; + selectedAction = TalkID::NoMoney; } else { TakePlrsMoney(50); } break; case TalkID::BarmaidStash: - activeStore = TalkID::Exit; + ExitStore(); IsStashOpen = true; Stash.RefreshItemStatFlags(); invflag = true; @@ -1225,31 +1209,35 @@ void SmithBuyItem(Item &item) CalcPlrInv(*MyPlayer, true); } -void SmithBuyEnter() +bool ReturnToMainMenu() { if (currentTextLine == BackButtonLine()) { - StartStore(TalkID::SmithMain); - currentTextLine = 12; - return; + StartStore(oldActiveStore); // FIXME: Might not be correct + return true; } + return false; +} + +void SmithBuyEnter() +{ + if (ReturnToMainMenu()) + return; + oldTextLine = currentTextLine; oldScrollPos = scrollPos; - oldActiveStore = TalkID::SmithBuy; + oldActiveStore = TalkID::SmithBasicBuy; + + int idx = scrollPos + ((currentTextLine - previousScrollPos) / BuyLineSpace); - int idx = scrollPos + ((currentTextLine - previousScrollPos) / 4); if (!CanPlayerAfford(Blacksmith.basicItems[idx]._iIvalue)) { StartStore(TalkID::NoMoney); - return; - } - - if (!GiveItemToPlayer(Blacksmith.basicItems[idx], false)) { + } else if (!GiveItemToPlayer(Blacksmith.basicItems[idx], false)) { StartStore(TalkID::NoRoom); - return; + } else { + tempItem = Blacksmith.basicItems[idx]; + StartStore(TalkID::Confirm); } - - tempItem = Blacksmith.basicItems[idx]; - StartStore(TalkID::Confirm); } /** @@ -1296,7 +1284,7 @@ void SmithPremiumBuyEnter() return; } - oldActiveStore = TalkID::SmithPremiumBuy; + oldActiveStore = TalkID::SmithBuy; oldTextLine = currentTextLine; oldScrollPos = scrollPos; @@ -1668,7 +1656,7 @@ void HealerBuyItem(Item &item) void BoyBuyEnter() { if (currentTextLine != 10) { - activeStore = TalkID::Exit; + ExitStore(); return; } @@ -1726,7 +1714,7 @@ void ConfirmEnter(Item &item) { if (currentTextLine == 18) { switch (oldActiveStore) { - case TalkID::SmithBuy: + case TalkID::SmithBasicBuy: SmithBuyItem(item); break; case TalkID::SmithSell: @@ -1752,7 +1740,7 @@ void ConfirmEnter(Item &item) StorytellerIdentifyItem(item); StartStore(TalkID::StorytellerIdentifyShow); return; - case TalkID::SmithPremiumBuy: + case TalkID::SmithBuy: SmithBuyPItem(item); break; default: @@ -1908,7 +1896,7 @@ void InitStores() { int numSmithItems = gbIsHellfire ? NumSmithItemsHf : NumSmithItems; ClearTextLines(0, NumStoreLines); - activeStore = TalkID::Exit; + ExitStore(); isTextFullSize = false; hasItemList = false; Blacksmith.itemLevel = 1; @@ -1956,7 +1944,7 @@ void FreeStoreMem() if (*sgOptions.Gameplay.showItemGraphicsInStores) { FreeHalfSizeItemSprites(); } - activeStore = TalkID::Exit; + ExitStore(); for (STextStruct &entry : textLine) { entry.text.clear(); entry.text.shrink_to_fit(); @@ -2075,7 +2063,7 @@ void StartStore(TalkID s) townerId = TOWN_SMITH; SetupTownerMenuScreen(); break; - case TalkID::SmithBuy: { + case TalkID::SmithBasicBuy: { bool hasAnyItems = false; for (int i = 0; !Blacksmith.basicItems[i].isEmpty(); i++) { hasAnyItems = true; @@ -2084,7 +2072,7 @@ void StartStore(TalkID s) if (hasAnyItems) SetupTownerBuyScreen(s); else { - activeStore = TalkID::SmithBuy; + activeStore = TalkID::SmithBasicBuy; oldTextLine = 12; StoreESC(); return; @@ -2140,7 +2128,7 @@ void StartStore(TalkID s) case TalkID::StorytellerIdentify: SetupTownerIdentifyScreen(); break; - case TalkID::SmithPremiumBuy: + case TalkID::SmithBuy: SetupTownerBuyScreen(s); break; case TalkID::Gossip: @@ -2185,8 +2173,8 @@ void DrawSText(const Surface &out) if (hasItemList) { switch (activeStore) { - case TalkID::SmithBuy: - SetupTownerItemList(TalkID::SmithBuy, scrollPos); + case TalkID::SmithBasicBuy: + SetupTownerItemList(TalkID::SmithBasicBuy, scrollPos); break; case TalkID::SmithSell: case TalkID::SmithRepair: @@ -2201,7 +2189,7 @@ void DrawSText(const Surface &out) case TalkID::HealerBuy: SetupTownerItemList(activeStore, scrollPos); break; - case TalkID::SmithPremiumBuy: + case TalkID::SmithBuy: SetupTownerItemList(activeStore, scrollPos); break; default: @@ -2245,14 +2233,14 @@ void StoreESC() case TalkID::TavernMain: case TalkID::DrunkMain: case TalkID::BarmaidMain: - activeStore = TalkID::Exit; + ExitStore(); break; case TalkID::Gossip: StartStore(oldActiveStore); currentTextLine = oldTextLine; break; + case TalkID::SmithBasicBuy: case TalkID::SmithBuy: - case TalkID::SmithPremiumBuy: case TalkID::SmithSell: case TalkID::SmithRepair: StartStore(TalkID::SmithMain); @@ -2424,10 +2412,10 @@ void StoreEnter() case TalkID::BarmaidMain: TownerMainEnter(); break; - case TalkID::SmithPremiumBuy: + case TalkID::SmithBuy: SmithPremiumBuyEnter(); break; - case TalkID::SmithBuy: + case TalkID::SmithBasicBuy: SmithBuyEnter(); break; case TalkID::SmithSell: @@ -2559,9 +2547,4 @@ bool IsPlayerInStore() return activeStore != TalkID::Exit; } -void ExitStore() -{ - activeStore = TalkID::Exit; -} - } // namespace devilution diff --git a/Source/stores.h b/Source/stores.h index eea712b8f4d..18d0fa6a722 100644 --- a/Source/stores.h +++ b/Source/stores.h @@ -36,7 +36,11 @@ constexpr int NumStoreLines = 104; enum class TalkID : uint8_t { Exit, SmithMain, - SmithBuy, + Main, + BasicBuy, + Buy, + Sell, + SmithBasicBuy, SmithSell, SmithRepair, WitchMain, @@ -52,13 +56,14 @@ enum class TalkID : uint8_t { StorytellerMain, HealerBuy, StorytellerIdentify, - SmithPremiumBuy, + SmithBuy, Gossip, StorytellerIdentifyShow, TavernMain, DrunkMain, BarmaidMain, BarmaidStash, + Invalid, }; enum class ItemLocation { @@ -91,26 +96,36 @@ extern std::array playerItemIndexes; // Map of inventor extern DVL_API_FOR_TEST std::vector playerItems; // Pointers to player items, coupled with necessary information class TownerStore { - // public: - // Store(); +public: + TownerStore(_talker_id id, TalkID buyBasic, TalkID buy, TalkID sell, TalkID special) + : townerId(id) + , buyBasicAction(buyBasic) + , buyAction(buy) + , sellAction(sell) + , specialAction(special) + { + } + public: std::vector basicItems; // Used for the blacksmith store that only displays non-magical items std::vector items; uint8_t itemLevel; - //_talker_id townerId; + _talker_id townerId; + TalkID buyBasicAction; TalkID buyAction; - TalkID buyPremiumAction; TalkID sellAction; TalkID specialAction; }; -extern TownerStore Blacksmith; -extern TownerStore Healer; -extern TownerStore Witch; -extern TownerStore Boy; -extern TownerStore Storyteller; +extern TownerStore Blacksmith(TOWN_SMITH, TalkID::SmithBasicBuy, TalkID::SmithBuy, TalkID::SmithSell, TalkID::SmithRepair); +extern TownerStore Healer(TOWN_HEALER, TalkID::Invalid, TalkID::HealerBuy, TalkID::Invalid, TalkID::Invalid); +extern TownerStore Witch(TOWN_WITCH, TalkID::Invalid, TalkID::WitchBuy, TalkID::WitchSell, TalkID::WitchRecharge); +extern TownerStore Boy(TOWN_PEGBOY, TalkID::Invalid, TalkID::BoyBuy, TalkID::Invalid, TalkID::Invalid); +extern TownerStore Storyteller(TOWN_STORY, TalkID::Invalid, TalkID::Invalid, TalkID::Invalid, TalkID::StorytellerIdentify); +extern TownerStore Barmaid(TOWN_BMAID, TalkID::Invalid, TalkID::Invalid, TalkID::Invalid, TalkID::BarmaidStash); +void ExitStore(); /* Clears premium items sold by Griswold and Wirt. */ void InitStores(); /* Spawns items sold by vendors, including premium items sold by Griswold and Wirt. */ @@ -132,6 +147,5 @@ void StoreEnter(); void CheckStoreButton(); void ReleaseStoreButton(); bool IsPlayerInStore(); -void ExitStore(); } // namespace devilution