From c9604338329364b1a13d9bcfdc839eacc3530d1c Mon Sep 17 00:00:00 2001 From: Malkierian Date: Tue, 26 Nov 2024 18:28:50 -0700 Subject: [PATCH] Setup AdvancePond to run in OnItemReceive. (#4585) --- .../Enhancements/randomizer/fishsanity.cpp | 25 +++++++------------ soh/soh/Enhancements/randomizer/fishsanity.h | 8 +++--- .../Enhancements/randomizer/hook_handlers.cpp | 8 +++--- 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/soh/soh/Enhancements/randomizer/fishsanity.cpp b/soh/soh/Enhancements/randomizer/fishsanity.cpp index 5fa2974ae..46b01e2d3 100644 --- a/soh/soh/Enhancements/randomizer/fishsanity.cpp +++ b/soh/soh/Enhancements/randomizer/fishsanity.cpp @@ -59,6 +59,7 @@ namespace Rando { const FishIdentity Fishsanity::defaultIdentity = { RAND_INF_MAX, RC_UNKNOWN_CHECK }; bool Fishsanity::fishsanityHelpersInit = false; s16 Fishsanity::fishGroupCounter = 0; + bool Fishsanity::enableAdvance = false; std::unordered_map Fishsanity::pondFishAgeMap; std::vector Fishsanity::childPondFish; std::vector Fishsanity::adultPondFish; @@ -395,22 +396,6 @@ namespace Rando { } } - void Fishsanity::OnFlagSetHandler(int16_t flagType, int16_t flag) { - if (flagType != FLAG_RANDOMIZER_INF) { - return; - } - RandomizerCheck rc = OTRGlobals::Instance->gRandomizer->GetCheckFromRandomizerInf((RandomizerInf)flag); - FishsanityCheckType fsType = Rando::Fishsanity::GetCheckType(rc); - if (fsType == FSC_NONE) { - return; - } - - // When a pond fish is caught, advance the pond. - if (fsType == FSC_POND) { - OTRGlobals::Instance->gRandoContext->GetFishsanity()->AdvancePond(); - } - } - void Fishsanity::OnActorUpdateHandler(void* refActor) { if (gPlayState->sceneNum != SCENE_GROTTOS && gPlayState->sceneNum != SCENE_ZORAS_DOMAIN && gPlayState->sceneNum != SCENE_FISHING_POND) { return; @@ -428,6 +413,7 @@ namespace Rando { FishIdentity identity = OTRGlobals::Instance->gRandomizer->IdentifyFish(gPlayState->sceneNum, actor->params); if (identity.randomizerCheck != RC_UNKNOWN_CHECK) { Flags_SetRandomizerInf(identity.randomizerInf); + enableAdvance = true; // Remove uncaught effect if (actor->shape.shadowDraw != NULL) { actor->shape.shadowDraw = NULL; @@ -483,6 +469,13 @@ namespace Rando { } } } + + void Fishsanity::OnItemReceiveHandler(GetItemEntry itemEntry) { + if (enableAdvance) { + enableAdvance = false; + OTRGlobals::Instance->gRandoContext->GetFishsanity()->AdvancePond(); + } + } } // namespace Rando // C interface diff --git a/soh/soh/Enhancements/randomizer/fishsanity.h b/soh/soh/Enhancements/randomizer/fishsanity.h index c98e9ab9c..91d021157 100644 --- a/soh/soh/Enhancements/randomizer/fishsanity.h +++ b/soh/soh/Enhancements/randomizer/fishsanity.h @@ -133,11 +133,6 @@ class Fishsanity { */ static void OnActorInitHandler(void* refActor); - /** - * @brief FlagSet hook handler for fishsanity - */ - static void OnFlagSetHandler(int16_t flagType, int16_t flag); - /** * @brief PlayerUpdate hook handler for fishsanity */ @@ -158,6 +153,8 @@ class Fishsanity { */ static void OnVanillaBehaviorHandler(GIVanillaBehavior id, bool* should, va_list originalArgs); + static void OnItemReceiveHandler(GetItemEntry itemEntry); + private: /** * @brief Initialize helper statics if they have not been initialized yet @@ -184,6 +181,7 @@ class Fishsanity { static bool fishsanityHelpersInit; static s16 fishGroupCounter; + static bool enableAdvance; ///////////////////////////////////////////////////////// //// Helper data structures derived from static data //// diff --git a/soh/soh/Enhancements/randomizer/hook_handlers.cpp b/soh/soh/Enhancements/randomizer/hook_handlers.cpp index 35badbce6..c98dabf74 100644 --- a/soh/soh/Enhancements/randomizer/hook_handlers.cpp +++ b/soh/soh/Enhancements/randomizer/hook_handlers.cpp @@ -2119,10 +2119,10 @@ void RandomizerRegisterHooks() { static uint32_t onKaleidoUpdateHook = 0; static uint32_t fishsanityOnActorInitHook = 0; - static uint32_t fishsanityOnFlagSetHook = 0; static uint32_t fishsanityOnActorUpdateHook = 0; static uint32_t fishsanityOnSceneInitHook = 0; static uint32_t fishsanityOnVanillaBehaviorHook = 0; + static uint32_t fishsanityOnItemReceiveHook = 0; GameInteractor::Instance->RegisterGameHook([](int32_t fileNum) { randomizerQueuedChecks = std::queue(); @@ -2146,10 +2146,10 @@ void RandomizerRegisterHooks() { GameInteractor::Instance->UnregisterGameHook(onKaleidoUpdateHook); GameInteractor::Instance->UnregisterGameHook(fishsanityOnActorInitHook); - GameInteractor::Instance->UnregisterGameHook(fishsanityOnFlagSetHook); GameInteractor::Instance->UnregisterGameHook(fishsanityOnActorUpdateHook); GameInteractor::Instance->UnregisterGameHook(fishsanityOnSceneInitHook); GameInteractor::Instance->UnregisterGameHook(fishsanityOnVanillaBehaviorHook); + GameInteractor::Instance->UnregisterGameHook(fishsanityOnItemReceiveHook); onFlagSetHook = 0; onSceneFlagSetHook = 0; @@ -2168,10 +2168,10 @@ void RandomizerRegisterHooks() { onKaleidoUpdateHook = 0; fishsanityOnActorInitHook = 0; - fishsanityOnFlagSetHook = 0; fishsanityOnActorUpdateHook = 0; fishsanityOnSceneInitHook = 0; fishsanityOnVanillaBehaviorHook = 0; + fishsanityOnItemReceiveHook = 0; if (!IS_RANDO) return; @@ -2203,10 +2203,10 @@ void RandomizerRegisterHooks() { OTRGlobals::Instance->gRandoContext->GetFishsanity()->InitializeFromSave(); fishsanityOnActorInitHook = GameInteractor::Instance->RegisterGameHook(Rando::Fishsanity::OnActorInitHandler); - fishsanityOnFlagSetHook = GameInteractor::Instance->RegisterGameHook(Rando::Fishsanity::OnFlagSetHandler); fishsanityOnActorUpdateHook = GameInteractor::Instance->RegisterGameHook(Rando::Fishsanity::OnActorUpdateHandler); fishsanityOnSceneInitHook = GameInteractor::Instance->RegisterGameHook(Rando::Fishsanity::OnSceneInitHandler); fishsanityOnVanillaBehaviorHook = GameInteractor::Instance->RegisterGameHook(Rando::Fishsanity::OnVanillaBehaviorHandler); + fishsanityOnItemReceiveHook = GameInteractor::Instance->RegisterGameHook(Rando::Fishsanity::OnItemReceiveHandler); } }); }