From f4ac37f54ae6419933c549d2ba90ac736957bd45 Mon Sep 17 00:00:00 2001 From: Garrett Cox Date: Thu, 20 Oct 2022 21:01:54 -0500 Subject: [PATCH] Use macros for max key count (#1818) --- soh/include/macros.h | 10 ++++++++ .../Enhancements/randomizer/randomizer.cpp | 22 +++++++++--------- .../randomizer/randomizer_item_tracker.cpp | 23 ++++++++++--------- soh/soh/OTRGlobals.cpp | 12 ++++++++-- 4 files changed, 43 insertions(+), 24 deletions(-) diff --git a/soh/include/macros.h b/soh/include/macros.h index aad606a2d..4ff2b9a41 100644 --- a/soh/include/macros.h +++ b/soh/include/macros.h @@ -263,5 +263,15 @@ extern GraphicsContext* __gfxCtx; #define NUM_TRIALS 6 #define NUM_SHOP_ITEMS 64 #define NUM_SCRUBS 35 +#define FOREST_TEMPLE_SMALL_KEY_MAX (ResourceMgr_IsSceneMasterQuest(SCENE_BMORI1) ? 6 : 5) +#define FIRE_TEMPLE_SMALL_KEY_MAX (ResourceMgr_IsSceneMasterQuest(SCENE_HIDAN) ? 5 : 8) +#define WATER_TEMPLE_SMALL_KEY_MAX (ResourceMgr_IsSceneMasterQuest(SCENE_MIZUSIN) ? 2 : 6) +#define SPIRIT_TEMPLE_SMALL_KEY_MAX (ResourceMgr_IsSceneMasterQuest(SCENE_JYASINZOU) ? 7 : 5) +#define SHADOW_TEMPLE_SMALL_KEY_MAX (ResourceMgr_IsSceneMasterQuest(SCENE_HAKADAN) ? 6 : 5) +#define BOTTOM_OF_THE_WELL_SMALL_KEY_MAX (ResourceMgr_IsSceneMasterQuest(SCENE_HAKADANCH) ? 2 : 3) +#define GERUDO_TRAINING_GROUNDS_SMALL_KEY_MAX (ResourceMgr_IsSceneMasterQuest(SCENE_MEN) ? 3 : 9) +#define GERUDO_FORTRESS_SMALL_KEY_MAX 4 +#define GANONS_CASTLE_SMALL_KEY_MAX (ResourceMgr_IsSceneMasterQuest(SCENE_GANONTIKA) ? 3 : 2) +#define TREASURE_GAME_SMALL_KEY_MAX 6 #endif diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index b2c7d4dfd..e2f6d6779 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -24,6 +24,7 @@ #include "rando_hash.h" extern "C" uint32_t ResourceMgr_IsGameMasterQuest(); +extern "C" uint32_t ResourceMgr_IsSceneMasterQuest(s16 sceneNum); using json = nlohmann::json; using namespace std::literals::string_literals; @@ -1396,27 +1397,26 @@ ItemObtainability Randomizer::GetItemObtainabilityFromRandomizerGet(RandomizerGe return !CHECK_DUNGEON_ITEM(DUNGEON_KEY_BOSS, SCENE_HAKADAN) ? CAN_OBTAIN : CANT_OBTAIN_ALREADY_HAVE; case RG_GANONS_CASTLE_BOSS_KEY: return !CHECK_DUNGEON_ITEM(DUNGEON_KEY_BOSS, SCENE_GANON) ? CAN_OBTAIN : CANT_OBTAIN_ALREADY_HAVE; - // TODO: Handle MQ key counts case RG_FOREST_TEMPLE_SMALL_KEY: - return gSaveContext.inventory.dungeonKeys[SCENE_BMORI1] < 5 ? CAN_OBTAIN : CANT_OBTAIN_ALREADY_HAVE; + return gSaveContext.inventory.dungeonKeys[SCENE_BMORI1] < FOREST_TEMPLE_SMALL_KEY_MAX ? CAN_OBTAIN : CANT_OBTAIN_ALREADY_HAVE; case RG_FIRE_TEMPLE_SMALL_KEY: - return gSaveContext.inventory.dungeonKeys[SCENE_HIDAN] < 8 ? CAN_OBTAIN : CANT_OBTAIN_ALREADY_HAVE; + return gSaveContext.inventory.dungeonKeys[SCENE_HIDAN] < FIRE_TEMPLE_SMALL_KEY_MAX ? CAN_OBTAIN : CANT_OBTAIN_ALREADY_HAVE; case RG_WATER_TEMPLE_SMALL_KEY: - return gSaveContext.inventory.dungeonKeys[SCENE_MIZUSIN] < 6 ? CAN_OBTAIN : CANT_OBTAIN_ALREADY_HAVE; + return gSaveContext.inventory.dungeonKeys[SCENE_MIZUSIN] < WATER_TEMPLE_SMALL_KEY_MAX ? CAN_OBTAIN : CANT_OBTAIN_ALREADY_HAVE; case RG_SPIRIT_TEMPLE_SMALL_KEY: - return gSaveContext.inventory.dungeonKeys[SCENE_JYASINZOU] < 5 ? CAN_OBTAIN : CANT_OBTAIN_ALREADY_HAVE; + return gSaveContext.inventory.dungeonKeys[SCENE_JYASINZOU] < SPIRIT_TEMPLE_SMALL_KEY_MAX ? CAN_OBTAIN : CANT_OBTAIN_ALREADY_HAVE; case RG_SHADOW_TEMPLE_SMALL_KEY: - return gSaveContext.inventory.dungeonKeys[SCENE_HAKADAN] < 5 ? CAN_OBTAIN : CANT_OBTAIN_ALREADY_HAVE; + return gSaveContext.inventory.dungeonKeys[SCENE_HAKADAN] < SHADOW_TEMPLE_SMALL_KEY_MAX ? CAN_OBTAIN : CANT_OBTAIN_ALREADY_HAVE; case RG_BOTTOM_OF_THE_WELL_SMALL_KEY: - return gSaveContext.inventory.dungeonKeys[SCENE_HAKADANCH] < 3 ? CAN_OBTAIN : CANT_OBTAIN_ALREADY_HAVE; + return gSaveContext.inventory.dungeonKeys[SCENE_HAKADANCH] < BOTTOM_OF_THE_WELL_SMALL_KEY_MAX ? CAN_OBTAIN : CANT_OBTAIN_ALREADY_HAVE; case RG_GERUDO_TRAINING_GROUNDS_SMALL_KEY: - return gSaveContext.inventory.dungeonKeys[SCENE_MEN] < 9 ? CAN_OBTAIN : CANT_OBTAIN_ALREADY_HAVE; + return gSaveContext.inventory.dungeonKeys[SCENE_MEN] < GERUDO_TRAINING_GROUNDS_SMALL_KEY_MAX ? CAN_OBTAIN : CANT_OBTAIN_ALREADY_HAVE; case RG_GERUDO_FORTRESS_SMALL_KEY: - return gSaveContext.inventory.dungeonKeys[SCENE_GERUDOWAY] < 4 ? CAN_OBTAIN : CANT_OBTAIN_ALREADY_HAVE; + return gSaveContext.inventory.dungeonKeys[SCENE_GERUDOWAY] < GERUDO_FORTRESS_SMALL_KEY_MAX ? CAN_OBTAIN : CANT_OBTAIN_ALREADY_HAVE; case RG_GANONS_CASTLE_SMALL_KEY: - return gSaveContext.inventory.dungeonKeys[SCENE_GANONTIKA] < 2 ? CAN_OBTAIN : CANT_OBTAIN_ALREADY_HAVE; + return gSaveContext.inventory.dungeonKeys[SCENE_GANONTIKA] < GANONS_CASTLE_SMALL_KEY_MAX ? CAN_OBTAIN : CANT_OBTAIN_ALREADY_HAVE; case RG_TREASURE_GAME_SMALL_KEY: - return gSaveContext.inventory.dungeonKeys[SCENE_TAKARAYA] < 6 ? CAN_OBTAIN : CANT_OBTAIN_ALREADY_HAVE; + return gSaveContext.inventory.dungeonKeys[SCENE_TAKARAYA] < TREASURE_GAME_SMALL_KEY_MAX ? CAN_OBTAIN : CANT_OBTAIN_ALREADY_HAVE; // Dungeon Rewards case RG_KOKIRI_EMERALD: diff --git a/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp b/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp index 0e69f2206..cb55e6ce4 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp @@ -20,6 +20,7 @@ extern GlobalContext* gGlobalCtx; #include "textures/icon_item_static/icon_item_static.h" #include "textures/icon_item_24_static/icon_item_24_static.h" } +extern "C" uint32_t ResourceMgr_IsSceneMasterQuest(s16 sceneNum); void DrawEquip(ItemTrackerItem item); void DrawItem(ItemTrackerItem item); @@ -300,31 +301,31 @@ ItemTrackerNumbers GetItemCurrentAndMax(ItemTrackerItem item) { result.currentAmmo = MAX(gSaveContext.inventory.dungeonKeys[item.data], 0); switch (item.data) { case SCENE_BMORI1: - result.maxCapacity = result.currentCapacity = 5; + result.maxCapacity = result.currentCapacity = FOREST_TEMPLE_SMALL_KEY_MAX; break; case SCENE_HIDAN: - result.maxCapacity = result.currentCapacity = 8; + result.maxCapacity = result.currentCapacity = FIRE_TEMPLE_SMALL_KEY_MAX; break; case SCENE_MIZUSIN: - result.maxCapacity = result.currentCapacity = 6; + result.maxCapacity = result.currentCapacity = WATER_TEMPLE_SMALL_KEY_MAX; break; case SCENE_JYASINZOU: - result.maxCapacity = result.currentCapacity = 5; + result.maxCapacity = result.currentCapacity = SPIRIT_TEMPLE_SMALL_KEY_MAX; break; case SCENE_HAKADAN: - result.maxCapacity = result.currentCapacity = 5; + result.maxCapacity = result.currentCapacity = SHADOW_TEMPLE_SMALL_KEY_MAX; break; case SCENE_HAKADANCH: - result.maxCapacity = result.currentCapacity = 3; - break; - case SCENE_GANONTIKA: - result.maxCapacity = result.currentCapacity = 2; + result.maxCapacity = result.currentCapacity = BOTTOM_OF_THE_WELL_SMALL_KEY_MAX; break; case SCENE_MEN: - result.maxCapacity = result.currentCapacity = 9; + result.maxCapacity = result.currentCapacity = GERUDO_TRAINING_GROUNDS_SMALL_KEY_MAX; break; case SCENE_GERUDOWAY: - result.maxCapacity = result.currentCapacity = 4; + result.maxCapacity = result.currentCapacity = GERUDO_FORTRESS_SMALL_KEY_MAX; + break; + case SCENE_GANONTIKA: + result.maxCapacity = result.currentCapacity = GANONS_CASTLE_SMALL_KEY_MAX; break; } break; diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 7a5ba86cd..03d9fdb8b 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -638,7 +638,7 @@ extern "C" uint32_t ResourceMgr_GetGameVersion() return OTRGlobals::Instance->context->GetResourceManager()->GetGameVersion(); } -uint32_t IsGameMasterQuest() { +uint32_t IsSceneMasterQuest(s16 sceneNum) { uint32_t value = 0; if (OTRGlobals::Instance->HasMasterQuest()) { if (!OTRGlobals::Instance->HasOriginal()) { @@ -649,7 +649,7 @@ uint32_t IsGameMasterQuest() { value = 0; if (gSaveContext.n64ddFlag) { if (!OTRGlobals::Instance->gRandomizer->masterQuestDungeons.empty()) { - if (gGlobalCtx != NULL && OTRGlobals::Instance->gRandomizer->masterQuestDungeons.contains(gGlobalCtx->sceneNum)) { + if (gGlobalCtx != NULL && OTRGlobals::Instance->gRandomizer->masterQuestDungeons.contains(sceneNum)) { value = 1; } } @@ -659,6 +659,10 @@ uint32_t IsGameMasterQuest() { return value; } +uint32_t IsGameMasterQuest() { + return gGlobalCtx != NULL ? IsSceneMasterQuest(gGlobalCtx->sceneNum) : 0; +} + extern "C" uint32_t ResourceMgr_GameHasMasterQuest() { return OTRGlobals::Instance->HasMasterQuest(); } @@ -667,6 +671,10 @@ extern "C" uint32_t ResourceMgr_GameHasOriginal() { return OTRGlobals::Instance->HasOriginal(); } +extern "C" uint32_t ResourceMgr_IsSceneMasterQuest(s16 sceneNum) { + return IsSceneMasterQuest(sceneNum); +} + extern "C" uint32_t ResourceMgr_IsGameMasterQuest() { return IsGameMasterQuest(); }