From 34556e40d6a3d102d9ad27ed906ce863895b73aa Mon Sep 17 00:00:00 2001 From: aMannus Date: Sun, 19 Nov 2023 20:45:09 +0100 Subject: [PATCH] Clean up Triforce Hunt U16's and GBK (#3355) * Clean up Triforce Hunt U16's and GBK * Apply suggestions from code review --- .../Enhancements/debugger/debugSaveEditor.cpp | 2 +- .../Enhancements/debugger/debugSaveEditor.h | 1 + soh/soh/Enhancements/mods.cpp | 20 +++++++++++-------- soh/soh/Enhancements/randomizer/draw.cpp | 6 +++--- .../Enhancements/randomizer/randomizer.cpp | 6 +++--- .../Enhancements/randomizer/randomizer_inf.h | 1 + soh/src/code/z_draw.c | 2 +- soh/src/code/z_parameter.c | 1 + 8 files changed, 23 insertions(+), 16 deletions(-) diff --git a/soh/soh/Enhancements/debugger/debugSaveEditor.cpp b/soh/soh/Enhancements/debugger/debugSaveEditor.cpp index 9af4eadb7..b357363ac 100644 --- a/soh/soh/Enhancements/debugger/debugSaveEditor.cpp +++ b/soh/soh/Enhancements/debugger/debugSaveEditor.cpp @@ -515,7 +515,7 @@ void DrawInfoTab() { UIWidgets::InsertHelpHoverText("Z-Targeting behavior"); if (IS_RANDO && OTRGlobals::Instance->gRandomizer->GetRandoSettingValue(RSK_TRIFORCE_HUNT)) { - ImGui::InputScalar("Triforce Pieces", ImGuiDataType_U16, &gSaveContext.triforcePiecesCollected); + ImGui::InputScalar("Triforce Pieces", ImGuiDataType_U8, &gSaveContext.triforcePiecesCollected); UIWidgets::InsertHelpHoverText("Currently obtained Triforce Pieces. For Triforce Hunt."); } diff --git a/soh/soh/Enhancements/debugger/debugSaveEditor.h b/soh/soh/Enhancements/debugger/debugSaveEditor.h index 42c9c91c0..01557efef 100644 --- a/soh/soh/Enhancements/debugger/debugSaveEditor.h +++ b/soh/soh/Enhancements/debugger/debugSaveEditor.h @@ -505,6 +505,7 @@ const std::vector flagTables = { { RAND_INF_CHILD_FISHING, "RAND_INF_CHILD_FISHING" }, { RAND_INF_ADULT_FISHING, "RAND_INF_ADULT_FISHING" }, { RAND_INF_10_BIG_POES, "RAND_INF_10_BIG_POES" }, + { RAND_INF_GRANT_GANONS_BOSSKEY, "RAND_INF_GRANT_GANONS_BOSSKEY" }, } }, }; diff --git a/soh/soh/Enhancements/mods.cpp b/soh/soh/Enhancements/mods.cpp index 45933b9a6..e9d62f63c 100644 --- a/soh/soh/Enhancements/mods.cpp +++ b/soh/soh/Enhancements/mods.cpp @@ -644,16 +644,19 @@ void RegisterTriforceHunt() { triforcePieceScale = 0.0f; GameInteractor::State::TriforceHuntPieceGiven = 0; } + } + }); +} - uint8_t currentPieces = gSaveContext.triforcePiecesCollected; - uint8_t requiredPieces = OTRGlobals::Instance->gRandomizer->GetRandoSettingValue(RSK_TRIFORCE_HUNT_PIECES_REQUIRED); - - // Give Boss Key when player loads back into the savefile. - if (currentPieces >= requiredPieces && gPlayState->transitionTrigger != TRANS_TRIGGER_START && - (1 << 0 & gSaveContext.inventory.dungeonItems[SCENE_GANONS_TOWER]) == 0) { - GetItemEntry getItemEntry = ItemTableManager::Instance->RetrieveItemEntry(MOD_RANDOMIZER, RG_GANONS_CASTLE_BOSS_KEY); +void RegisterGrantGanonsBossKey() { + GameInteractor::Instance->RegisterGameHook([]() { + // Triforce Hunt needs the check if the player isn't being teleported to the credits scene. + if (!GameInteractor::IsGameplayPaused() && + Flags_GetRandomizerInf(RAND_INF_GRANT_GANONS_BOSSKEY) && gPlayState->transitionTrigger != TRANS_TRIGGER_START && + (1 << 0 & gSaveContext.inventory.dungeonItems[SCENE_GANONS_TOWER]) == 0) { + GetItemEntry getItemEntry = + ItemTableManager::Instance->RetrieveItemEntry(MOD_RANDOMIZER, RG_GANONS_CASTLE_BOSS_KEY); GiveItemEntryWithoutActor(gPlayState, getItemEntry); - } } }); } @@ -1076,6 +1079,7 @@ void InitMods() { RegisterMenuPathFix(); RegisterMirrorModeHandler(); RegisterTriforceHunt(); + RegisterGrantGanonsBossKey(); RegisterEnemyDefeatCounts(); RegisterAltTrapTypes(); RegisterRandomizerSheikSpawn(); diff --git a/soh/soh/Enhancements/randomizer/draw.cpp b/soh/soh/Enhancements/randomizer/draw.cpp index eacc62725..570ac5801 100644 --- a/soh/soh/Enhancements/randomizer/draw.cpp +++ b/soh/soh/Enhancements/randomizer/draw.cpp @@ -214,7 +214,7 @@ extern "C" void Randomizer_DrawTriforcePiece(PlayState* play, GetItemEntry getIt Gfx_SetupDL_25Xlu(play->state.gfxCtx); - uint16_t current = gSaveContext.triforcePiecesCollected; + uint8_t current = gSaveContext.triforcePiecesCollected; Matrix_Scale(0.035f, 0.035f, 0.035f, MTXMODE_APPLY); @@ -238,8 +238,8 @@ extern "C" void Randomizer_DrawTriforcePieceGI(PlayState* play, GetItemEntry get Gfx_SetupDL_25Xlu(play->state.gfxCtx); - uint16_t current = gSaveContext.triforcePiecesCollected; - uint16_t required = OTRGlobals::Instance->gRandomizer->GetRandoSettingValue(RSK_TRIFORCE_HUNT_PIECES_REQUIRED); + uint8_t current = gSaveContext.triforcePiecesCollected; + uint8_t required = OTRGlobals::Instance->gRandomizer->GetRandoSettingValue(RSK_TRIFORCE_HUNT_PIECES_REQUIRED); Matrix_Scale(triforcePieceScale, triforcePieceScale, triforcePieceScale, MTXMODE_APPLY); diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index f879be4b8..6f5dafae9 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -5548,9 +5548,9 @@ void CreateTriforcePieceMessages() { CustomMessage Randomizer::GetTriforcePieceMessage() { // Item is only given after the textbox, so reflect that inside the textbox. - uint16_t current = gSaveContext.triforcePiecesCollected + 1; - uint16_t required = OTRGlobals::Instance->gRandomizer->GetRandoSettingValue(RSK_TRIFORCE_HUNT_PIECES_REQUIRED); - uint16_t remaining = required - current; + uint8_t current = gSaveContext.triforcePiecesCollected + 1; + uint8_t required = OTRGlobals::Instance->gRandomizer->GetRandoSettingValue(RSK_TRIFORCE_HUNT_PIECES_REQUIRED); + uint8_t remaining = required - current; float percentageCollected = (float)current / (float)required; uint8_t messageIndex; diff --git a/soh/soh/Enhancements/randomizer/randomizer_inf.h b/soh/soh/Enhancements/randomizer/randomizer_inf.h index 33c206b47..8d4ec9801 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_inf.h +++ b/soh/soh/Enhancements/randomizer/randomizer_inf.h @@ -159,6 +159,7 @@ typedef enum { RAND_INF_CHILD_FISHING, RAND_INF_ADULT_FISHING, RAND_INF_10_BIG_POES, + RAND_INF_GRANT_GANONS_BOSSKEY, // If you add anything to this list, you need to update the size of randomizerInf in z64save.h to be ceil(RAND_INF_MAX / 16) diff --git a/soh/src/code/z_draw.c b/soh/src/code/z_draw.c index cb28a498e..e9ab95398 100644 --- a/soh/src/code/z_draw.c +++ b/soh/src/code/z_draw.c @@ -1043,7 +1043,7 @@ void GetItem_DrawTriforcePiece(PlayState* play, s16 drawId) { Matrix_Scale(0.035f, 0.035f, 0.035f, MTXMODE_APPLY); - uint16_t index = gSaveContext.triforcePiecesCollected % 3; + uint8_t index = gSaveContext.triforcePiecesCollected % 3; Gfx* triforcePieceDL; switch (index) { diff --git a/soh/src/code/z_parameter.c b/soh/src/code/z_parameter.c index 8d98535df..04e806ede 100644 --- a/soh/src/code/z_parameter.c +++ b/soh/src/code/z_parameter.c @@ -2605,6 +2605,7 @@ u16 Randomizer_Item_Give(PlayState* play, GetItemEntry giEntry) { if (gSaveContext.triforcePiecesCollected == Randomizer_GetSettingValue(RSK_TRIFORCE_HUNT_PIECES_REQUIRED)) { gSaveContext.sohStats.itemTimestamp[TIMESTAMP_TRIFORCE_COMPLETED] = GAMEPLAYSTAT_TOTAL_TIME; gSaveContext.sohStats.gameComplete = 1; + Flags_SetRandomizerInf(RAND_INF_GRANT_GANONS_BOSSKEY); Play_PerformSave(play); GameInteractor_SetTriforceHuntCreditsWarpActive(true); }