From 4729eef7c8a21804e1a04262c39561e8edc0830e Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 29 Mar 2026 03:34:59 -0400 Subject: [PATCH] Make item category adjustments more consistent (#6434) --- .../Enhancements/randomizer/ShuffleCrates.cpp | 39 ++----------------- .../Enhancements/randomizer/ShuffleGrass.cpp | 3 +- .../Enhancements/randomizer/ShufflePots.cpp | 3 +- .../Enhancements/randomizer/ShuffleTrees.cpp | 20 +--------- .../randomizer/item_category_adj.cpp | 28 +++++++++++++ .../randomizer/item_category_adj.h | 18 +++++++++ soh/src/overlays/actors/ovl_En_Box/z_en_box.c | 17 +------- 7 files changed, 57 insertions(+), 71 deletions(-) create mode 100644 soh/soh/Enhancements/randomizer/item_category_adj.cpp create mode 100644 soh/soh/Enhancements/randomizer/item_category_adj.h diff --git a/soh/soh/Enhancements/randomizer/ShuffleCrates.cpp b/soh/soh/Enhancements/randomizer/ShuffleCrates.cpp index aed35dfa7..a1216ce01 100644 --- a/soh/soh/Enhancements/randomizer/ShuffleCrates.cpp +++ b/soh/soh/Enhancements/randomizer/ShuffleCrates.cpp @@ -4,6 +4,7 @@ #include #include "global.h" #include "soh/ObjectExtension/ObjectExtension.h" +#include "item_category_adj.h" extern "C" { #include "variables.h" @@ -35,24 +36,7 @@ extern "C" void ObjKibako2_RandomizerDraw(Actor* thisx, PlayState* play) { GetItemEntry crateItem = Rando::Context::GetInstance()->GetFinalGIEntry(crateIdentity->randomizerCheck, true, GI_NONE); - getItemCategory = crateItem.getItemCategory; - - // If they have bombchus, don't consider the bombchu item major - if (INV_CONTENT(ITEM_BOMBCHU) == ITEM_BOMBCHU && - ((crateItem.modIndex == MOD_RANDOMIZER && crateItem.getItemId == RG_PROGRESSIVE_BOMBCHU_BAG) || - (crateItem.modIndex == MOD_NONE && - (crateItem.getItemId == GI_BOMBCHUS_5 || crateItem.getItemId == GI_BOMBCHUS_10 || - crateItem.getItemId == GI_BOMBCHUS_20)))) { - getItemCategory = ITEM_CATEGORY_JUNK; - // If it's a bottle and they already have one, consider the item lesser - } else if ((crateItem.modIndex == MOD_RANDOMIZER && crateItem.getItemId >= RG_BOTTLE_WITH_RED_POTION && - crateItem.getItemId <= RG_BOTTLE_WITH_POE) || - (crateItem.modIndex == MOD_NONE && - (crateItem.getItemId == GI_BOTTLE || crateItem.getItemId == GI_MILK_BOTTLE))) { - if (gSaveContext.inventory.items[SLOT_BOTTLE_1] != ITEM_NONE) { - getItemCategory = ITEM_CATEGORY_LESSER; - } - } + getItemCategory = Randomizer_AdjustItemCategory(crateItem); // Change texture switch (getItemCategory) { @@ -102,24 +86,7 @@ extern "C" void ObjKibako_RandomizerDraw(Actor* thisx, PlayState* play) { GetItemEntry smallCrateItem = Rando::Context::GetInstance()->GetFinalGIEntry(crateIdentity->randomizerCheck, true, GI_NONE); - getItemCategory = smallCrateItem.getItemCategory; - - // If they have bombchus, don't consider the bombchu item major - if (INV_CONTENT(ITEM_BOMBCHU) == ITEM_BOMBCHU && - ((smallCrateItem.modIndex == MOD_RANDOMIZER && smallCrateItem.getItemId == RG_PROGRESSIVE_BOMBCHU_BAG) || - (smallCrateItem.modIndex == MOD_NONE && - (smallCrateItem.getItemId == GI_BOMBCHUS_5 || smallCrateItem.getItemId == GI_BOMBCHUS_10 || - smallCrateItem.getItemId == GI_BOMBCHUS_20)))) { - getItemCategory = ITEM_CATEGORY_JUNK; - // If it's a bottle and they already have one, consider the item lesser - } else if ((smallCrateItem.modIndex == MOD_RANDOMIZER && smallCrateItem.getItemId >= RG_BOTTLE_WITH_RED_POTION && - smallCrateItem.getItemId <= RG_BOTTLE_WITH_POE) || - (smallCrateItem.modIndex == MOD_NONE && - (smallCrateItem.getItemId == GI_BOTTLE || smallCrateItem.getItemId == GI_MILK_BOTTLE))) { - if (gSaveContext.inventory.items[SLOT_BOTTLE_1] != ITEM_NONE) { - getItemCategory = ITEM_CATEGORY_LESSER; - } - } + getItemCategory = Randomizer_AdjustItemCategory(smallCrateItem); // Change texture switch (getItemCategory) { diff --git a/soh/soh/Enhancements/randomizer/ShuffleGrass.cpp b/soh/soh/Enhancements/randomizer/ShuffleGrass.cpp index 351cbda26..14053bff5 100644 --- a/soh/soh/Enhancements/randomizer/ShuffleGrass.cpp +++ b/soh/soh/Enhancements/randomizer/ShuffleGrass.cpp @@ -1,6 +1,7 @@ #include #include "soh_assets.h" #include "static_data.h" +#include "item_category_adj.h" #include "soh/ObjectExtension/ObjectExtension.h" extern "C" { @@ -38,7 +39,7 @@ extern "C" void EnKusa_RandomizerDraw(Actor* thisx, PlayState* play) { if (csmc && (!requiresStoneAgony || (requiresStoneAgony && CHECK_QUEST_ITEM(QUEST_STONE_OF_AGONY)))) { auto itemEntry = Rando::Context::GetInstance()->GetFinalGIEntry(grassIdentity->randomizerCheck, true, GI_NONE); - GetItemCategory getItemCategory = itemEntry.getItemCategory; + GetItemCategory getItemCategory = Randomizer_AdjustItemCategory(itemEntry); switch (getItemCategory) { case ITEM_CATEGORY_JUNK: diff --git a/soh/soh/Enhancements/randomizer/ShufflePots.cpp b/soh/soh/Enhancements/randomizer/ShufflePots.cpp index 08b7a7c0c..3dd2c4383 100644 --- a/soh/soh/Enhancements/randomizer/ShufflePots.cpp +++ b/soh/soh/Enhancements/randomizer/ShufflePots.cpp @@ -1,6 +1,7 @@ #include "soh/OTRGlobals.h" #include "soh_assets.h" #include "static_data.h" +#include "item_category_adj.h" #include "soh/ObjectExtension/ObjectExtension.h" extern "C" { @@ -28,7 +29,7 @@ extern "C" void ObjTsubo_RandomizerDraw(Actor* thisx, PlayState* play) { if (csmc && (!requiresStoneAgony || (requiresStoneAgony && CHECK_QUEST_ITEM(QUEST_STONE_OF_AGONY)))) { auto itemEntry = Rando::Context::GetInstance()->GetFinalGIEntry(potIdentity->randomizerCheck, true, GI_NONE); - GetItemCategory getItemCategory = itemEntry.getItemCategory; + GetItemCategory getItemCategory = Randomizer_AdjustItemCategory(itemEntry); switch (getItemCategory) { case ITEM_CATEGORY_LESSER: diff --git a/soh/soh/Enhancements/randomizer/ShuffleTrees.cpp b/soh/soh/Enhancements/randomizer/ShuffleTrees.cpp index fb8f922a9..da99a2dd6 100644 --- a/soh/soh/Enhancements/randomizer/ShuffleTrees.cpp +++ b/soh/soh/Enhancements/randomizer/ShuffleTrees.cpp @@ -2,6 +2,7 @@ #include "soh_assets.h" #include "static_data.h" #include "soh/ObjectExtension/ObjectExtension.h" +#include "item_category_adj.h" extern "C" { #include "variables.h" @@ -60,24 +61,7 @@ extern "C" void EnWood02_RandomizerDraw(Actor* thisx, PlayState* play) { getItemCategory = ITEM_CATEGORY_JUNK; } else { treeItem = Rando::Context::GetInstance()->GetFinalGIEntry(treeIdentity->randomizerCheck, true, GI_NONE); - getItemCategory = treeItem.getItemCategory; - - // If they have bombchus, don't consider the bombchu item major - if (INV_CONTENT(ITEM_BOMBCHU) == ITEM_BOMBCHU && - ((treeItem.modIndex == MOD_RANDOMIZER && treeItem.getItemId == RG_PROGRESSIVE_BOMBCHU_BAG) || - (treeItem.modIndex == MOD_NONE && - (treeItem.getItemId == GI_BOMBCHUS_5 || treeItem.getItemId == GI_BOMBCHUS_10 || - treeItem.getItemId == GI_BOMBCHUS_20)))) { - getItemCategory = ITEM_CATEGORY_JUNK; - // If it's a bottle and they already have one, consider the item lesser - } else if ((treeItem.modIndex == MOD_RANDOMIZER && treeItem.getItemId >= RG_BOTTLE_WITH_RED_POTION && - treeItem.getItemId <= RG_BOTTLE_WITH_POE) || - (treeItem.modIndex == MOD_NONE && - (treeItem.getItemId == GI_BOTTLE || treeItem.getItemId == GI_MILK_BOTTLE))) { - if (gSaveContext.inventory.items[SLOT_BOTTLE_1] != ITEM_NONE) { - getItemCategory = ITEM_CATEGORY_LESSER; - } - } + getItemCategory = Randomizer_AdjustItemCategory(treeItem); } GraphicsContext* gfxCtx = play->state.gfxCtx; diff --git a/soh/soh/Enhancements/randomizer/item_category_adj.cpp b/soh/soh/Enhancements/randomizer/item_category_adj.cpp new file mode 100644 index 000000000..a64f1ca83 --- /dev/null +++ b/soh/soh/Enhancements/randomizer/item_category_adj.cpp @@ -0,0 +1,28 @@ +#include +#include "item_category_adj.h" +#include "z64item.h" +#include "variables.h" +#include "macros.h" + +GetItemCategory Randomizer_AdjustItemCategory(GetItemEntry item) { + GetItemCategory category = item.getItemCategory; + + // Downgrade bombchus to lesser if the player already has bombchus + if (INV_CONTENT(ITEM_BOMBCHU) == ITEM_BOMBCHU && + ((item.modIndex == MOD_RANDOMIZER && item.getItemId == RG_PROGRESSIVE_BOMBCHU_BAG) || + (item.modIndex == MOD_NONE && + (item.getItemId == GI_BOMBCHUS_5 || item.getItemId == GI_BOMBCHUS_10 || item.getItemId == GI_BOMBCHUS_20)))) { + category = ITEM_CATEGORY_LESSER; + } + + // Downgrade bottles to lesser if the player already has a bottle + if ((item.modIndex == MOD_RANDOMIZER && item.getItemId >= RG_BOTTLE_WITH_RED_POTION && + item.getItemId <= RG_BOTTLE_WITH_POE) || + (item.modIndex == MOD_NONE && (item.getItemId == GI_BOTTLE || item.getItemId == GI_MILK_BOTTLE))) { + if (gSaveContext.inventory.items[SLOT_BOTTLE_1] != ITEM_NONE) { + category = ITEM_CATEGORY_LESSER; + } + } + + return category; +} diff --git a/soh/soh/Enhancements/randomizer/item_category_adj.h b/soh/soh/Enhancements/randomizer/item_category_adj.h new file mode 100644 index 000000000..53a57e7d4 --- /dev/null +++ b/soh/soh/Enhancements/randomizer/item_category_adj.h @@ -0,0 +1,18 @@ +#pragma once + +#ifndef ITEM_CATEGORY_ADJ_H +#define ITEM_CATEGORY_ADJ_H + +#include "../item-tables/ItemTableTypes.h" + +#ifdef __cplusplus +extern "C" { +#endif + +GetItemCategory Randomizer_AdjustItemCategory(GetItemEntry item); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/soh/src/overlays/actors/ovl_En_Box/z_en_box.c b/soh/src/overlays/actors/ovl_En_Box/z_en_box.c index 7e0f762e9..fb4f09d2b 100644 --- a/soh/src/overlays/actors/ovl_En_Box/z_en_box.c +++ b/soh/src/overlays/actors/ovl_En_Box/z_en_box.c @@ -5,6 +5,7 @@ #include "soh/OTRGlobals.h" #include "soh/ResourceManagerHelpers.h" #include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h" +#include "soh/Enhancements/randomizer/item_category_adj.h" #define FLAGS 0 @@ -580,21 +581,7 @@ void EnBox_UpdateTexture(EnBox* this, PlayState* play) { this->dyna.actor.room != 6); // Exclude treasure game chests except for the final room if (!isVanilla) { - getItemCategory = chestItem.getItemCategory; - // If they have bombchus, don't consider the bombchu item major - if ((INV_CONTENT(ITEM_BOMBCHU) == ITEM_BOMBCHU && - ((chestItem.modIndex == MOD_RANDOMIZER && chestItem.getItemId == RG_PROGRESSIVE_BOMBCHU_BAG) || - (chestItem.modIndex == MOD_NONE && - (chestItem.getItemId == GI_BOMBCHUS_5 || chestItem.getItemId == GI_BOMBCHUS_10 || - chestItem.getItemId == GI_BOMBCHUS_20)))) || - // If it's a bottle and they already have one, consider the item lesser - ((chestItem.modIndex == MOD_RANDOMIZER && chestItem.getItemId >= RG_BOTTLE_WITH_RED_POTION && - chestItem.getItemId <= RG_BOTTLE_WITH_POE) || - (chestItem.modIndex == MOD_NONE && - (chestItem.getItemId == GI_BOTTLE || chestItem.getItemId == GI_MILK_BOTTLE)) && - gSaveContext.inventory.items[SLOT_BOTTLE_1] != ITEM_NONE)) { - getItemCategory = ITEM_CATEGORY_LESSER; - } + getItemCategory = Randomizer_AdjustItemCategory(chestItem); } switch (this->type) {