From 25ed66439e858cab50f60b06bd3aad2c67d02625 Mon Sep 17 00:00:00 2001 From: Garrett Cox Date: Fri, 2 Sep 2022 17:23:37 -0500 Subject: [PATCH] Fix repeatable purchases and bottles rendering incorrectly --- .../randomizer/3drando/spoiler_log.cpp | 2 +- .../Enhancements/randomizer/randomizer.cpp | 39 +++++++++- .../Enhancements/randomizer/randomizerTypes.h | 2 +- .../overlays/actors/ovl_En_GirlA/z_en_girla.c | 75 ++++++++++++------- 4 files changed, 90 insertions(+), 28 deletions(-) diff --git a/soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp b/soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp index 1c02564af..63230c2d1 100644 --- a/soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp +++ b/soh/soh/Enhancements/randomizer/3drando/spoiler_log.cpp @@ -684,7 +684,7 @@ static void WriteAllLocations(int language) { } // Eventually check for other things here like fake name - if (location->HasScrubsanityPrice() || location->HasShopsanityPrice() || location->GetPrice() > 0) { + if (location->HasScrubsanityPrice() || location->HasShopsanityPrice()) { jsonData["locations"][location->GetName()]["item"] = placedItemName; jsonData["locations"][location->GetName()]["price"] = location->GetPrice(); } else { diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index 0959f6be1..2eb7b3c63 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -751,6 +751,39 @@ std::vector shopItemRandomizerChecks = { RC_MARKET_BOMBCHU_SHOP_ITEM_8, }; +// Reference soh/src/overlays/actors/ovl_En_GirlA/z_en_girla.h +std::unordered_map randomizerGetToEnGirlShopItem = { + { RG_BUY_DEKU_NUT_5, 0x00 }, + { RG_BUY_ARROWS_30, 0x01 }, + { RG_BUY_ARROWS_50, 0x02 }, + { RG_BUY_BOMBS_525, 0x03 }, + { RG_BUY_DEKU_NUT_10, 0x04 }, + { RG_BUY_DEKU_STICK_1, 0x05 }, + { RG_BUY_BOMBS_10, 0x06 }, + { RG_BUY_FISH, 0x07 }, + { RG_BUY_RED_POTION_30, 0x08 }, + { RG_BUY_GREEN_POTION, 0x09 }, + { RG_BUY_BLUE_POTION, 0x0A }, + { RG_BUY_HYLIAN_SHIELD, 0x0C }, + { RG_BUY_DEKU_SHIELD, 0x0D }, + { RG_BUY_GORON_TUNIC, 0x0E }, + { RG_BUY_ZORA_TUNIC, 0x0F }, + { RG_BUY_HEART, 0x10 }, + { RG_BUY_BOMBCHU_10, 0x15 }, + { RG_BUY_BOMBCHU_20, 0x16 }, + { RG_BUY_DEKU_SEEDS_30, 0x1D }, + { RG_BUY_BLUE_FIRE, 0x27 }, + { RG_BUY_BOTTLE_BUG, 0x28 }, + { RG_BUY_POE, 0x2A }, + { RG_BUY_FAIRYS_SPIRIT, 0x2B }, + { RG_BUY_ARROWS_10, 0x2C }, + { RG_BUY_BOMBS_20, 0x2D }, + { RG_BUY_BOMBS_30, 0x2E }, + { RG_BUY_BOMBS_535, 0x2F }, + { RG_BUY_RED_POTION_40, 0x30 }, + { RG_BUY_RED_POTION_50, 0x31 }, +}; + void Randomizer::LoadShopMessages(const char* spoilerFileName) { if (strcmp(spoilerFileName, "") != 0) { ParseHintLocationsFile(spoilerFileName); @@ -2512,7 +2545,7 @@ ShopItemIdentity Randomizer::IdentifyShopItem(s32 sceneNum, s32 actorParams) { shopItemIdentity.randomizerCheck = RC_UNKNOWN_CHECK; shopItemIdentity.ogItemId = GI_NONE; shopItemIdentity.itemPrice = -1; - shopItemIdentity.isShuffled = GetRandoSettingValue(RSK_SHOPSANITY) > 0; + shopItemIdentity.enGirlAShopItem = -1; switch (sceneNum) { case SCENE_SHOP1: @@ -2871,6 +2904,10 @@ ShopItemIdentity Randomizer::IdentifyShopItem(s32 sceneNum, s32 actorParams) { break; } + if (randomizerGetToEnGirlShopItem.find(GetRandomizerGetFromKnownCheck(shopItemIdentity.randomizerCheck)) != randomizerGetToEnGirlShopItem.end()) { + shopItemIdentity.enGirlAShopItem = randomizerGetToEnGirlShopItem[GetRandomizerGetFromKnownCheck(shopItemIdentity.randomizerCheck)]; + } + if (randomizerMerchantPrices.find(shopItemIdentity.randomizerCheck) != randomizerMerchantPrices.end()) { shopItemIdentity.itemPrice = randomizerMerchantPrices[shopItemIdentity.randomizerCheck]; } diff --git a/soh/soh/Enhancements/randomizer/randomizerTypes.h b/soh/soh/Enhancements/randomizer/randomizerTypes.h index 5f6c310b3..29a04eb52 100644 --- a/soh/soh/Enhancements/randomizer/randomizerTypes.h +++ b/soh/soh/Enhancements/randomizer/randomizerTypes.h @@ -1042,6 +1042,6 @@ typedef struct ShopItemIdentity { RandomizerInf randomizerInf; RandomizerCheck randomizerCheck; GetItemID ogItemId; + int32_t enGirlAShopItem; int32_t itemPrice; - bool isShuffled; } ShopItemIdentity; diff --git a/soh/src/overlays/actors/ovl_En_GirlA/z_en_girla.c b/soh/src/overlays/actors/ovl_En_GirlA/z_en_girla.c index 27099fff4..c84098cc4 100644 --- a/soh/src/overlays/actors/ovl_En_GirlA/z_en_girla.c +++ b/soh/src/overlays/actors/ovl_En_GirlA/z_en_girla.c @@ -392,16 +392,21 @@ void EnGirlA_InitItem(EnGirlA* this, GlobalContext* globalCtx) { this->objBankIndex = Object_GetIndex(&globalCtx->objectCtx, shopItemEntries[params].objID); } else { ShopItemIdentity shopItemIdentity = Randomizer_IdentifyShopItem(globalCtx->sceneNum, this->actor.params); - if (shopItemIdentity.randomizerCheck != RC_UNKNOWN_CHECK) { - GetItemEntry getItemEntry = Randomizer_GetItemFromKnownCheckWithoutObtainabilityCheck(shopItemIdentity.randomizerCheck, shopItemIdentity.ogItemId); + s16 objectId = shopItemEntries[params].objID; - if (Object_IsLoaded(&globalCtx->objectCtx, getItemEntry.objectId)) { - this->objBankIndex = Object_GetIndex(&globalCtx->objectCtx, getItemEntry.objectId); + if (shopItemIdentity.randomizerCheck != RC_UNKNOWN_CHECK) { + if (shopItemIdentity.enGirlAShopItem == -1) { + GetItemEntry getItemEntry = Randomizer_GetItemFromKnownCheckWithoutObtainabilityCheck(shopItemIdentity.randomizerCheck, shopItemIdentity.ogItemId); + objectId = getItemEntry.objectId; } else { - this->objBankIndex = Object_Spawn(&globalCtx->objectCtx, getItemEntry.objectId); + objectId = shopItemEntries[shopItemIdentity.enGirlAShopItem].objID; } + } + + if (Object_IsLoaded(&globalCtx->objectCtx, objectId)) { + this->objBankIndex = Object_GetIndex(&globalCtx->objectCtx, objectId); } else { - this->objBankIndex = Object_GetIndex(&globalCtx->objectCtx, shopItemEntries[params].objID); + this->objBankIndex = Object_Spawn(&globalCtx->objectCtx, objectId); } } @@ -1023,7 +1028,11 @@ void EnGirlA_SetItemDescription(GlobalContext* globalCtx, EnGirlA* this) { if (gSaveContext.n64ddFlag && Randomizer_GetSettingValue(RSK_SHOPSANITY)) { ShopItemIdentity shopItemIdentity = Randomizer_IdentifyShopItem(globalCtx->sceneNum, this->actor.params); if (shopItemIdentity.randomizerCheck != RC_UNKNOWN_CHECK) { - this->actor.textId = 0x9100 + (shopItemIdentity.randomizerInf - RAND_INF_SHOP_ITEMS_KF_SHOP_ITEM_1); + if (shopItemIdentity.enGirlAShopItem == -1) { + this->actor.textId = 0x9100 + (shopItemIdentity.randomizerInf - RAND_INF_SHOP_ITEMS_KF_SHOP_ITEM_1); + } else { + this->actor.textId = &shopItemEntries[shopItemIdentity.enGirlAShopItem].itemDescTextId; + } } } @@ -1049,7 +1058,11 @@ void EnGirlA_UpdateStockedItem(GlobalContext* globalCtx, EnGirlA* this) { if (gSaveContext.n64ddFlag && Randomizer_GetSettingValue(RSK_SHOPSANITY)) { ShopItemIdentity shopItemIdentity = Randomizer_IdentifyShopItem(globalCtx->sceneNum, this->actor.params); if (shopItemIdentity.randomizerCheck != RC_UNKNOWN_CHECK) { - itemEntry->itemDescTextId = 0x9100 + (shopItemIdentity.randomizerInf - RAND_INF_SHOP_ITEMS_KF_SHOP_ITEM_1); + if (shopItemIdentity.enGirlAShopItem == -1) { + itemEntry->itemDescTextId = 0x9100 + (shopItemIdentity.randomizerInf - RAND_INF_SHOP_ITEMS_KF_SHOP_ITEM_1); + } else { + itemEntry->itemDescTextId = &shopItemEntries[shopItemIdentity.enGirlAShopItem].itemDescTextId; + } } } @@ -1079,23 +1092,6 @@ void EnGirlA_InitializeItemAction(EnGirlA* this, GlobalContext* globalCtx) { s16 params = this->actor.params; ShopItemEntry* itemEntry = &shopItemEntries[params]; - if (gSaveContext.n64ddFlag && Randomizer_GetSettingValue(RSK_SHOPSANITY)) { - ShopItemIdentity shopItemIdentity = Randomizer_IdentifyShopItem(globalCtx->sceneNum, this->actor.params); - if (shopItemIdentity.randomizerCheck != RC_UNKNOWN_CHECK) { - GetItemEntry getItemEntry = Randomizer_GetItemFromKnownCheckWithoutObtainabilityCheck(shopItemIdentity.randomizerCheck, shopItemIdentity.ogItemId); - itemEntry->objID = getItemEntry.objectId; - itemEntry->giDrawId = getItemEntry.gid; - itemEntry->getItemId = getItemEntry.getItemId; - itemEntry->count = 1; - itemEntry->price = shopItemIdentity.itemPrice; - itemEntry->itemDescTextId = 0x9100 + (shopItemIdentity.randomizerInf - RAND_INF_SHOP_ITEMS_KF_SHOP_ITEM_1); - itemEntry->itemBuyPromptTextId = 0x9100 + ((shopItemIdentity.randomizerInf - RAND_INF_SHOP_ITEMS_KF_SHOP_ITEM_1) + NUM_SHOP_ITEMS); - itemEntry->canBuyFunc = EnGirlA_CanBuy_Randomizer; - itemEntry->itemGiveFunc = EnGirlA_ItemGive_Randomizer; - itemEntry->buyEventFunc = EnGirlA_BuyEvent_Randomizer; - } - } - if (Object_IsLoaded(&globalCtx->objectCtx, this->objBankIndex)) { this->actor.flags &= ~ACTOR_FLAG_4; this->actor.objBankIndex = this->objBankIndex; @@ -1191,6 +1187,35 @@ void EnGirlA_InitializeItemAction(EnGirlA* this, GlobalContext* globalCtx) { this->isSelected = false; this->yRotation = 0; this->yRotationInit = this->actor.shape.rot.y; + + // TODO: This is pretty verbose, pointers are making this difficult + if (gSaveContext.n64ddFlag && Randomizer_GetSettingValue(RSK_SHOPSANITY)) { + ShopItemIdentity shopItemIdentity = Randomizer_IdentifyShopItem(globalCtx->sceneNum, this->actor.params); + if (shopItemIdentity.randomizerCheck != RC_UNKNOWN_CHECK) { + if (shopItemIdentity.enGirlAShopItem == -1) { + GetItemEntry getItemEntry = Randomizer_GetItemFromKnownCheckWithoutObtainabilityCheck(shopItemIdentity.randomizerCheck, shopItemIdentity.ogItemId); + this->actor.textId = 0x9100 + (shopItemIdentity.randomizerInf - RAND_INF_SHOP_ITEMS_KF_SHOP_ITEM_1); + this->itemBuyPromptTextId = 0x9100 + ((shopItemIdentity.randomizerInf - RAND_INF_SHOP_ITEMS_KF_SHOP_ITEM_1) + NUM_SHOP_ITEMS); + this->getItemId = getItemEntry.getItemId; + this->canBuyFunc = EnGirlA_CanBuy_Randomizer; + this->itemGiveFunc = EnGirlA_ItemGive_Randomizer; + this->buyEventFunc = EnGirlA_BuyEvent_Randomizer; + this->basePrice = shopItemIdentity.itemPrice; + this->itemCount = 1; + this->giDrawId = getItemEntry.gid; + } else { + this->actor.textId = (&shopItemEntries[shopItemIdentity.enGirlAShopItem])->itemDescTextId; + this->itemBuyPromptTextId = (&shopItemEntries[shopItemIdentity.enGirlAShopItem])->itemBuyPromptTextId; + this->getItemId = (&shopItemEntries[shopItemIdentity.enGirlAShopItem])->getItemId; + this->canBuyFunc = (&shopItemEntries[shopItemIdentity.enGirlAShopItem])->canBuyFunc; + this->itemGiveFunc = (&shopItemEntries[shopItemIdentity.enGirlAShopItem])->itemGiveFunc; + this->buyEventFunc = (&shopItemEntries[shopItemIdentity.enGirlAShopItem])->buyEventFunc; + this->basePrice = (&shopItemEntries[shopItemIdentity.enGirlAShopItem])->price; + this->itemCount = (&shopItemEntries[shopItemIdentity.enGirlAShopItem])->count; + this->giDrawId = (&shopItemEntries[shopItemIdentity.enGirlAShopItem])->giDrawId; + } + } + } } }