Setup AdvancePond to run in OnItemReceive. (#4585)

This commit is contained in:
Malkierian 2024-11-26 18:28:50 -07:00 committed by GitHub
parent 13789a1dfb
commit c960433832
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 25 deletions

View File

@ -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<RandomizerCheck, LinkAge> Fishsanity::pondFishAgeMap;
std::vector<RandomizerCheck> Fishsanity::childPondFish;
std::vector<RandomizerCheck> 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

View File

@ -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 ////

View File

@ -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<GameInteractor::OnLoadGame>([](int32_t fileNum) {
randomizerQueuedChecks = std::queue<RandomizerCheck>();
@ -2146,10 +2146,10 @@ void RandomizerRegisterHooks() {
GameInteractor::Instance->UnregisterGameHook<GameInteractor::OnKaleidoscopeUpdate>(onKaleidoUpdateHook);
GameInteractor::Instance->UnregisterGameHook<GameInteractor::OnActorInit>(fishsanityOnActorInitHook);
GameInteractor::Instance->UnregisterGameHook<GameInteractor::OnFlagSet>(fishsanityOnFlagSetHook);
GameInteractor::Instance->UnregisterGameHook<GameInteractor::OnActorUpdate>(fishsanityOnActorUpdateHook);
GameInteractor::Instance->UnregisterGameHook<GameInteractor::OnSceneInit>(fishsanityOnSceneInitHook);
GameInteractor::Instance->UnregisterGameHook<GameInteractor::OnVanillaBehavior>(fishsanityOnVanillaBehaviorHook);
GameInteractor::Instance->UnregisterGameHook<GameInteractor::OnItemReceive>(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<GameInteractor::OnActorInit>(Rando::Fishsanity::OnActorInitHandler);
fishsanityOnFlagSetHook = GameInteractor::Instance->RegisterGameHook<GameInteractor::OnFlagSet>(Rando::Fishsanity::OnFlagSetHandler);
fishsanityOnActorUpdateHook = GameInteractor::Instance->RegisterGameHook<GameInteractor::OnActorUpdate>(Rando::Fishsanity::OnActorUpdateHandler);
fishsanityOnSceneInitHook = GameInteractor::Instance->RegisterGameHook<GameInteractor::OnSceneInit>(Rando::Fishsanity::OnSceneInitHandler);
fishsanityOnVanillaBehaviorHook = GameInteractor::Instance->RegisterGameHook<GameInteractor::OnVanillaBehavior>(Rando::Fishsanity::OnVanillaBehaviorHandler);
fishsanityOnItemReceiveHook = GameInteractor::Instance->RegisterGameHook<GameInteractor::OnItemReceive>(Rando::Fishsanity::OnItemReceiveHandler);
}
});
}