From fe231147d5b1942c2b700640f25d5faddc672dad Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Tue, 9 Apr 2024 23:46:11 -0400 Subject: [PATCH] vb underwater item (#104) * underwater working pre func_80B858B4 replacement * underwater item update handled by hookhandlers * remove commented out code * remove unused should --- .../Enhancements/randomizer/hook_handlers.cpp | 39 +++++++++++++++++++ .../ovl_Item_Etcetera/z_item_etcetera.c | 35 ++--------------- .../ovl_Item_Etcetera/z_item_etcetera.h | 3 ++ 3 files changed, 45 insertions(+), 32 deletions(-) diff --git a/soh/soh/Enhancements/randomizer/hook_handlers.cpp b/soh/soh/Enhancements/randomizer/hook_handlers.cpp index 788701b9c..31ba23427 100644 --- a/soh/soh/Enhancements/randomizer/hook_handlers.cpp +++ b/soh/soh/Enhancements/randomizer/hook_handlers.cpp @@ -25,6 +25,7 @@ extern "C" { #include "src/overlays/actors/ovl_En_Fr/z_en_fr.h" #include "src/overlays/actors/ovl_En_Syateki_Man/z_en_syateki_man.h" #include "src/overlays/actors/ovl_En_Sth/z_en_sth.h" +#include "src/overlays/actors/ovl_Item_Etcetera/z_item_etcetera.h" #include "adult_trade_shuffle.h" extern SaveContext gSaveContext; extern PlayState* gPlayState; @@ -274,6 +275,27 @@ void ItemBHeart_UpdateRandomizedItem(Actor* actor, PlayState* play) { } } +void ItemEtcetera_DrawRandomizedItem(ItemEtcetera* itemEtcetera, PlayState* play) { + EnItem00_CustomItemsParticles(&itemEtcetera->actor, play, itemEtcetera->sohItemEntry); + GetItemEntry_Draw(play, itemEtcetera->sohItemEntry); +} + +void ItemEtcetera_func_80B858B4_Randomized(ItemEtcetera* itemEtcetera, PlayState* play) { + if (itemEtcetera->actor.xzDistToPlayer < 30.0f && + fabsf(itemEtcetera->actor.yDistToPlayer) < 50.0f) { + if ((itemEtcetera->actor.params & 0xFF) == 1) { + Flags_SetEventChkInf(EVENTCHKINF_OBTAINED_RUTOS_LETTER); + Flags_SetSwitch(play, 0xB); + } + + Actor_Kill(&itemEtcetera->actor); + } else { + if ((play->gameplayFrames & 0xD) == 0) { + EffectSsBubble_Spawn(play, &itemEtcetera->actor.world.pos, 0.0f, 0.0f, 10.0f, 0.13f); + } + } +} + void EnCow_MoveForRandomizer(EnCow* enCow, PlayState* play) { bool moved = false; @@ -954,6 +976,23 @@ void RandomizerOnActorInitHandler(void* actorRef) { } } } + + if (actor->id == ACTOR_ITEM_ETCETERA) { + ItemEtcetera* itemEtcetera = static_cast(actorRef); + RandomizerCheck rc = OTRGlobals::Instance->gRandomizer->GetCheckFromActor(itemEtcetera->actor.id, gPlayState->sceneNum, itemEtcetera->actor.params); + if (rc != RC_UNKNOWN_CHECK) { + itemEtcetera->sohItemEntry = Rando::Context::GetInstance()->GetFinalGIEntry(rc, true, (GetItemID)Rando::StaticData::GetLocation(rc)->GetVanillaItem()); + itemEtcetera->drawFunc = (ActorFunc)ItemEtcetera_DrawRandomizedItem; + } + + int32_t type = itemEtcetera->actor.params & 0xFF; + switch (type) { + case ITEM_ETC_LETTER: { + itemEtcetera->futureActionFunc = (ItemEtceteraActionFunc)ItemEtcetera_func_80B858B4_Randomized; + break; + } + } + } } void RandomizerRegisterHooks() { diff --git a/soh/src/overlays/actors/ovl_Item_Etcetera/z_item_etcetera.c b/soh/src/overlays/actors/ovl_Item_Etcetera/z_item_etcetera.c index 6fdf162db..db42bc15b 100644 --- a/soh/src/overlays/actors/ovl_Item_Etcetera/z_item_etcetera.c +++ b/soh/src/overlays/actors/ovl_Item_Etcetera/z_item_etcetera.c @@ -83,8 +83,7 @@ void ItemEtcetera_Init(Actor* thisx, PlayState* play) { case ITEM_ETC_LETTER: Actor_SetScale(&this->actor, 0.5f); this->futureActionFunc = func_80B858B4; - if ((Flags_GetEventChkInf(EVENTCHKINF_OBTAINED_RUTOS_LETTER) && !IS_RANDO) || - (IS_RANDO && Flags_GetTreasure(play, 0x1E))) { + if (Flags_GetEventChkInf(EVENTCHKINF_OBTAINED_RUTOS_LETTER)) { Actor_Kill(&this->actor); } break; @@ -147,21 +146,11 @@ void func_80B858B4(ItemEtcetera* this, PlayState* play) { if ((this->actor.params & 0xFF) == 1) { Flags_SetEventChkInf(EVENTCHKINF_OBTAINED_RUTOS_LETTER); Flags_SetSwitch(play, 0xB); - - if (IS_RANDO) { - Flags_SetTreasure(play, 0x1E); - } } + Actor_Kill(&this->actor); } else { - if (0) {} // Necessary to match - - if (!IS_RANDO) { - Actor_OfferGetItem(&this->actor, play, this->getItemId, 30.0f, 50.0f); - } else { - GetItemEntry getItemEntry = Randomizer_GetItemFromKnownCheck(RC_LH_UNDERWATER_ITEM, GI_LETTER_RUTO); - GiveItemEntryFromActor(&this->actor, play, getItemEntry, 30.0f, 50.0f); - } + Actor_OfferGetItem(&this->actor, play, this->getItemId, 30.0f, 50.0f); if ((play->gameplayFrames & 0xD) == 0) { EffectSsBubble_Spawn(play, &this->actor.world.pos, 0.0f, 0.0f, 10.0f, 0.13f); @@ -246,24 +235,6 @@ void ItemEtcetera_Draw(Actor* thisx, PlayState* play) { ItemEtcetera* this = (ItemEtcetera*)thisx; s32 type = this->actor.params & 0xFF; - if (IS_RANDO) { - GetItemEntry randoGetItem = (GetItemEntry)GET_ITEM_NONE; - if (type == ITEM_ETC_ARROW_FIRE) { - randoGetItem = Randomizer_GetItemFromKnownCheck(RC_LH_SUN, GI_ARROW_FIRE); - } else if (type == ITEM_ETC_LETTER) { - randoGetItem = Randomizer_GetItemFromKnownCheck(RC_LH_UNDERWATER_ITEM, GI_LETTER_RUTO); - } - - EnItem00_CustomItemsParticles(&this->actor, play, randoGetItem); - - if (randoGetItem.itemId != ITEM_NONE) { - func_8002EBCC(&this->actor, play, 0); - func_8002ED80(&this->actor, play, 0); - GetItemEntry_Draw(play, randoGetItem); - return; - } - } - func_8002EBCC(&this->actor, play, 0); func_8002ED80(&this->actor, play, 0); GetItem_Draw(play, this->giDrawId); diff --git a/soh/src/overlays/actors/ovl_Item_Etcetera/z_item_etcetera.h b/soh/src/overlays/actors/ovl_Item_Etcetera/z_item_etcetera.h index 3ec33b926..ceec9c8b1 100644 --- a/soh/src/overlays/actors/ovl_Item_Etcetera/z_item_etcetera.h +++ b/soh/src/overlays/actors/ovl_Item_Etcetera/z_item_etcetera.h @@ -16,6 +16,9 @@ typedef struct ItemEtcetera { /* 0x0154 */ u8 objBankIndex; /* 0x0158 */ ActorFunc drawFunc; /* 0x015C */ ItemEtceteraActionFunc actionFunc; + // #region SOH [Randomizer] Caching the get item entry for the draw function for performance + /* */ GetItemEntry sohItemEntry; + // #endregion } ItemEtcetera; // size = 0x0160 typedef enum {