From 2c08fca46c05efc4172123b9572906c49ed80e55 Mon Sep 17 00:00:00 2001 From: Garrett Cox Date: Mon, 28 Oct 2024 10:25:15 -0500 Subject: [PATCH] Add faster rupee accumulator (#4490) --- .../TimeSavers/FasterRupeeAccumulator.cpp | 47 +++++++++++++++++++ .../Enhancements/TimeSavers/TimeSavers.cpp | 1 + soh/soh/Enhancements/TimeSavers/TimeSavers.h | 1 + soh/soh/SohMenuBar.cpp | 1 + 4 files changed, 50 insertions(+) create mode 100644 soh/soh/Enhancements/TimeSavers/FasterRupeeAccumulator.cpp diff --git a/soh/soh/Enhancements/TimeSavers/FasterRupeeAccumulator.cpp b/soh/soh/Enhancements/TimeSavers/FasterRupeeAccumulator.cpp new file mode 100644 index 000000000..b7b6587ba --- /dev/null +++ b/soh/soh/Enhancements/TimeSavers/FasterRupeeAccumulator.cpp @@ -0,0 +1,47 @@ +#include "soh/Enhancements/game-interactor/GameInteractor.h" +#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h" +#include "soh/OTRGlobals.h" +#include "spdlog/spdlog.h" + +extern "C" { + #include "z64save.h" + #include "macros.h" + #include "variables.h" + #include "functions.h" + extern PlayState* gPlayState; + extern SaveContext gSaveContext; +} + +void FasterRupeeAccumulator_Register() { + GameInteractor::Instance->RegisterGameHook([]() { + if (!CVarGetInteger(CVAR_ENHANCEMENT("TimeSavers.FasterRupeeAccumulator"), 0)) return; + + if (gSaveContext.rupeeAccumulator == 0) { + return; + } + + // Gaining rupees + if (gSaveContext.rupeeAccumulator > 0) { + // Wallet is full + if (gSaveContext.rupees >= CUR_CAPACITY(UPG_WALLET)) { + return; + } + + if (gSaveContext.rupeeAccumulator >= 10 && gSaveContext.rupees + 10 < CUR_CAPACITY(UPG_WALLET)) { + gSaveContext.rupeeAccumulator-= 10; + gSaveContext.rupees += 10; + } + // Losing rupees + } else if (gSaveContext.rupeeAccumulator < 0) { + // No rupees to lose + if (gSaveContext.rupees == 0) { + return; + } + + if (gSaveContext.rupeeAccumulator <= -10 && gSaveContext.rupees > 10) { + gSaveContext.rupeeAccumulator += 10; + gSaveContext.rupees -= 10; + } + } + }); +} diff --git a/soh/soh/Enhancements/TimeSavers/TimeSavers.cpp b/soh/soh/Enhancements/TimeSavers/TimeSavers.cpp index 68fe71da6..6814b9332 100644 --- a/soh/soh/Enhancements/TimeSavers/TimeSavers.cpp +++ b/soh/soh/Enhancements/TimeSavers/TimeSavers.cpp @@ -12,4 +12,5 @@ void TimeSavers_Register() { // SkipMiscInteractions MoveMidoInKokiriForest_Register(); FasterHeavyBlockLift_Register(); + FasterRupeeAccumulator_Register(); } diff --git a/soh/soh/Enhancements/TimeSavers/TimeSavers.h b/soh/soh/Enhancements/TimeSavers/TimeSavers.h index d45ed7f10..0cec3edfa 100644 --- a/soh/soh/Enhancements/TimeSavers/TimeSavers.h +++ b/soh/soh/Enhancements/TimeSavers/TimeSavers.h @@ -14,5 +14,6 @@ void TimeSavers_Register(); // SkipMiscInteractions void MoveMidoInKokiriForest_Register(); void FasterHeavyBlockLift_Register(); +void FasterRupeeAccumulator_Register(); #endif // TIME_SAVERS_H diff --git a/soh/soh/SohMenuBar.cpp b/soh/soh/SohMenuBar.cpp index 626bbcd1a..bec69cceb 100644 --- a/soh/soh/SohMenuBar.cpp +++ b/soh/soh/SohMenuBar.cpp @@ -711,6 +711,7 @@ void DrawEnhancementsMenu() { UIWidgets::PaddedEnhancementSliderInt("Crawl speed %dx", "##CRAWLSPEED", CVAR_ENHANCEMENT("CrawlSpeed"), 1, 4, "", 1, true, false, true); UIWidgets::PaddedEnhancementCheckbox("Faster Heavy Block Lift", CVAR_ENHANCEMENT("FasterHeavyBlockLift"), false, false); UIWidgets::Tooltip("Speeds up lifting silver rocks and obelisks"); + UIWidgets::PaddedEnhancementCheckbox("Faster Rupee Accumulator", CVAR_ENHANCEMENT("TimeSavers.FasterRupeeAccumulator"), false, false); UIWidgets::PaddedEnhancementCheckbox("Skip Pickup Messages", CVAR_ENHANCEMENT("FastDrops"), true, false); UIWidgets::Tooltip("Skip pickup messages for new consumable items and bottle swipes"); UIWidgets::PaddedEnhancementCheckbox("Fast Ocarina Playback", CVAR_ENHANCEMENT("FastOcarinaPlayback"), true, false);