Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
kphoenix137 committed Sep 29, 2024
1 parent 07b212e commit 8a054da
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 86 deletions.
131 changes: 57 additions & 74 deletions Source/stores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ int currentItemIndex;
std::array<int8_t, NumPlayerItems> playerItemIndexes;
std::vector<IndexedItem> playerItems;

void ExitStore()
{
activeStore = TalkID::Exit;
}

namespace {

constexpr int PaddingTop = 32;
Expand Down Expand Up @@ -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" }
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -274,9 +279,9 @@ int GetItemCount(TalkID talkId)

if (towner != nullptr) {
switch (talkId) {
case TalkID::SmithBuy:
case TalkID::SmithBasicBuy:
return towner->basicItems.size();

Check warning on line 283 in Source/stores.cpp

View workflow job for this annotation

GitHub Actions / build

'return': conversion from 'size_t' to 'int', possible loss of data
case TalkID::SmithPremiumBuy:
case TalkID::SmithBuy:
case TalkID::HealerBuy:
case TalkID::WitchBuy:
case TalkID::BoyBuy:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -880,10 +885,10 @@ void SetupItemList(TalkID talkId, std::vector<IndexedItem> &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:
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -1296,7 +1284,7 @@ void SmithPremiumBuyEnter()
return;
}

oldActiveStore = TalkID::SmithPremiumBuy;
oldActiveStore = TalkID::SmithBuy;
oldTextLine = currentTextLine;
oldScrollPos = scrollPos;

Expand Down Expand Up @@ -1668,7 +1656,7 @@ void HealerBuyItem(Item &item)
void BoyBuyEnter()
{
if (currentTextLine != 10) {
activeStore = TalkID::Exit;
ExitStore();
return;
}

Expand Down Expand Up @@ -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:
Expand All @@ -1752,7 +1740,7 @@ void ConfirmEnter(Item &item)
StorytellerIdentifyItem(item);
StartStore(TalkID::StorytellerIdentifyShow);
return;
case TalkID::SmithPremiumBuy:
case TalkID::SmithBuy:
SmithBuyPItem(item);
break;
default:
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -2084,7 +2072,7 @@ void StartStore(TalkID s)
if (hasAnyItems)
SetupTownerBuyScreen(s);
else {
activeStore = TalkID::SmithBuy;
activeStore = TalkID::SmithBasicBuy;
oldTextLine = 12;
StoreESC();
return;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -2559,9 +2547,4 @@ bool IsPlayerInStore()
return activeStore != TalkID::Exit;
}

void ExitStore()
{
activeStore = TalkID::Exit;
}

} // namespace devilution
Loading

0 comments on commit 8a054da

Please sign in to comment.