From 69086f58c2b6bb00a273eefed4744ad456bba6ba Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Sat, 13 Aug 2022 00:22:34 -0400 Subject: [PATCH] Cleanup, bugfixes, removing the `- 1`s from `z_player.c` --- .../Enhancements/randomizer/randomizer.cpp | 61 ++++++++++++++++++- .../Enhancements/randomizer/randomizerTypes.h | 3 +- soh/soh/OTRGlobals.cpp | 30 +++++---- soh/src/code/z_actor.c | 4 +- .../actors/ovl_player_actor/z_player.c | 16 ++--- 5 files changed, 86 insertions(+), 28 deletions(-) diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index 7c7476aff..e723fb871 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -2196,6 +2196,65 @@ bool Randomizer::IsItemVanilla(RandomizerGet randoGet) { case RG_PROGRESSIVE_GORONSWORD: case RG_EMPTY_BOTTLE: case RG_BOTTLE_WITH_MILK: + case RG_RECOVERY_HEART: + case RG_GREEN_RUPEE: + case RG_BLUE_RUPEE: + case RG_RED_RUPEE: + case RG_PURPLE_RUPEE: + case RG_HUGE_RUPEE: + case RG_PIECE_OF_HEART: + case RG_HEART_CONTAINER: + case RG_MILK: + case RG_BOMBS_5: + case RG_BOMBS_10: + case RG_BOMBS_20: + case RG_BOMBCHU_5: + case RG_BOMBCHU_10: + case RG_BOMBCHU_20: + case RG_BOMBCHU_DROP: + case RG_ARROWS_5: + case RG_ARROWS_10: + case RG_ARROWS_30: + case RG_DEKU_NUTS_5: + case RG_DEKU_NUTS_10: + case RG_DEKU_SEEDS_30: + case RG_DEKU_STICK_1: + case RG_RED_POTION_REFILL: + case RG_GREEN_POTION_REFILL: + case RG_BLUE_POTION_REFILL: + case RG_TREASURE_GAME_HEART: + case RG_TREASURE_GAME_GREEN_RUPEE: + case RG_BUY_DEKU_NUT_5: + case RG_BUY_ARROWS_30: + case RG_BUY_ARROWS_50: + case RG_BUY_BOMBS_525: + case RG_BUY_DEKU_NUT_10: + case RG_BUY_DEKU_STICK_1: + case RG_BUY_BOMBS_10: + case RG_BUY_FISH: + case RG_BUY_RED_POTION_30: + case RG_BUY_GREEN_POTION: + case RG_BUY_BLUE_POTION: + case RG_BUY_HYLIAN_SHIELD: + case RG_BUY_DEKU_SHIELD: + case RG_BUY_GORON_TUNIC: + case RG_BUY_ZORA_TUNIC: + case RG_BUY_HEART: + case RG_BUY_BOMBCHU_10: + case RG_BUY_BOMBCHU_20: + case RG_BUY_BOMBCHU_5: + case RG_BUY_DEKU_SEEDS_30: + case RG_SOLD_OUT: + case RG_BUY_BLUE_FIRE: + case RG_BUY_BOTTLE_BUG: + case RG_BUY_POE: + case RG_BUY_FAIRYS_SPIRIT: + case RG_BUY_ARROWS_10: + case RG_BUY_BOMBS_20: + case RG_BUY_BOMBS_30: + case RG_BUY_BOMBS_535: + case RG_BUY_RED_POTION_40: + case RG_BUY_RED_POTION_50: return true; default: return false; @@ -4641,7 +4700,7 @@ void InitRandoItemTable() { // These do not have ItemIDs or GetItemIDs from vanilla, so I'm using their // RandomizerGet enum values for both. GetItemEntry randoGetItemTable[] = { - GET_ITEM(RG_ICE_TRAP, OBJECT_GI_RUPY, GID_RUPEE_GOLD, 0, 0, CHEST_ANIM_SHORT), + GET_ITEM(RG_ICE_TRAP, OBJECT_GI_RUPY, GID_RUPEE_GOLD, 0, 0x80, CHEST_ANIM_SHORT), GET_ITEM(RG_MAGIC_SINGLE, OBJECT_GI_MAGICPOT, GID_MAGIC_SMALL, 0xE4, 0x80, CHEST_ANIM_LONG), GET_ITEM(RG_MAGIC_DOUBLE, OBJECT_GI_MAGICPOT, GID_MAGIC_LARGE, 0xE8, 0x80, CHEST_ANIM_LONG), GET_ITEM(RG_DOUBLE_DEFENSE, OBJECT_GI_HEARTS, GID_HEART_CONTAINER, 0xE9, 0x80, CHEST_ANIM_LONG), diff --git a/soh/soh/Enhancements/randomizer/randomizerTypes.h b/soh/soh/Enhancements/randomizer/randomizerTypes.h index e8206dac2..55e28845c 100644 --- a/soh/soh/Enhancements/randomizer/randomizerTypes.h +++ b/soh/soh/Enhancements/randomizer/randomizerTypes.h @@ -954,7 +954,8 @@ typedef enum { RG_BUY_RED_POTION_40, RG_BUY_RED_POTION_50, RG_TRIFORCE, - RG_HINT + RG_HINT, + RG_MAX } RandomizerGet; typedef enum { diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index fefd7f613..3d298fb71 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -288,7 +288,12 @@ extern "C" void VanillaItemTable_Init() { ItemTableManager::Instance->AddItemTable(MOD_NONE); for (uint8_t i = 0; i < ARRAY_COUNT(getItemTable); i++) { getItemTable[i].modIndex = MOD_NONE; - ItemTableManager::Instance->AddItemEntry(MOD_NONE, i, getItemTable[i]); + // The vanilla item table array started with ITEM_BOMBS_5, + // but the GetItemID enum started with GI_NONE. Then everywhere + // that table was accessed used `GetItemID - 1`. This allows the + // "first" item of the new map to start at 1, syncing it up with + // the GetItemID values and removing the need for the `- 1` + ItemTableManager::Instance->AddItemEntry(MOD_NONE, i+1, getItemTable[i]); } } @@ -1606,25 +1611,18 @@ extern "C" CustomMessageEntry Randomizer_GetHintFromCheck(RandomizerCheck check) } extern "C" GetItemEntry ItemTable_Retrieve(int16_t getItemID) { - if (OTRGlobals::Instance->getItemModIndex != MOD_NONE) { - getItemID++; // counteracts the - 1 offset used for vanilla table - } - return ItemTableManager::Instance->RetrieveItemEntry(OTRGlobals::Instance->getItemModIndex, getItemID); } extern "C" GetItemEntry ItemTable_RetrieveEntry(s16 tableID, s16 getItemID) { - if (tableID == MOD_NONE) { - getItemID--; // counteracts the - 1 offset used for vanilla table - } return ItemTableManager::Instance->RetrieveItemEntry(tableID, getItemID); } extern "C" s32 Randomizer_GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum) { if (OTRGlobals::Instance->gRandomizer->CheckContainsVanillaItem(OTRGlobals::Instance->gRandomizer->GetCheckFromActor(sceneNum, actorId, actorParams))) { - OTRGlobals::Instance->getItemModIndex = MOD_RANDOMIZER; - } else { OTRGlobals::Instance->getItemModIndex = MOD_NONE; + } else { + OTRGlobals::Instance->getItemModIndex = MOD_RANDOMIZER; } return OTRGlobals::Instance->gRandomizer->GetRandomizedItemId(ogId, actorId, actorParams, sceneNum); } @@ -1633,9 +1631,9 @@ extern "C" GetItemEntry Randomizer_GetRandomizedItem(GetItemID ogId, s16 actorId s16 getItemModIndex; if (OTRGlobals::Instance->gRandomizer->CheckContainsVanillaItem( OTRGlobals::Instance->gRandomizer->GetCheckFromActor(sceneNum, actorId, actorParams))) { - getItemModIndex = MOD_RANDOMIZER; - } else { getItemModIndex = MOD_NONE; + } else { + getItemModIndex = MOD_RANDOMIZER; } s16 itemID = OTRGlobals::Instance->gRandomizer->GetRandomizedItemId(ogId, actorId, actorParams, sceneNum); return ItemTable_RetrieveEntry(getItemModIndex, itemID); @@ -1643,9 +1641,9 @@ extern "C" GetItemEntry Randomizer_GetRandomizedItem(GetItemID ogId, s16 actorId extern "C" s32 Randomizer_GetItemIdFromKnownCheck(RandomizerCheck randomizerCheck, GetItemID ogId) { if (OTRGlobals::Instance->gRandomizer->CheckContainsVanillaItem(randomizerCheck)) { - OTRGlobals::Instance->getItemModIndex = MOD_RANDOMIZER; - } else { OTRGlobals::Instance->getItemModIndex = MOD_NONE; + } else { + OTRGlobals::Instance->getItemModIndex = MOD_RANDOMIZER; } return OTRGlobals::Instance->gRandomizer->GetRandomizedItemIdFromKnownCheck(randomizerCheck, ogId); } @@ -1653,9 +1651,9 @@ extern "C" s32 Randomizer_GetItemIdFromKnownCheck(RandomizerCheck randomizerChec extern "C" GetItemEntry Randomizer_GetItemFromKnownCheck(RandomizerCheck randomizerCheck, GetItemID ogId) { s16 getItemModIndex; if (OTRGlobals::Instance->gRandomizer->CheckContainsVanillaItem(randomizerCheck)) { - getItemModIndex = MOD_RANDOMIZER; - } else { getItemModIndex = MOD_NONE; + } else { + getItemModIndex = MOD_RANDOMIZER; } s16 itemID = OTRGlobals::Instance->gRandomizer->GetRandomizedItemIdFromKnownCheck(randomizerCheck, ogId); return ItemTable_RetrieveEntry(getItemModIndex, itemID); diff --git a/soh/src/code/z_actor.c b/soh/src/code/z_actor.c index 745524909..206b17be5 100644 --- a/soh/src/code/z_actor.c +++ b/soh/src/code/z_actor.c @@ -1977,8 +1977,8 @@ s32 func_8002F434(Actor* actor, GlobalContext* globalCtx, s32 getItemId, f32 xzR Player* player = GET_PLAYER(globalCtx); if (!(player->stateFlags1 & 0x3C7080) && Player_GetExplosiveHeld(player) < 0) { - if ((((player->heldActor != NULL) || (actor == player->targetActor)) && (getItemId > GI_NONE) && - (getItemId < GI_MAX)) || + if ((((player->heldActor != NULL) || (actor == player->targetActor)) && + ((!gSaveContext.n64ddFlag && ((getItemId > GI_NONE) && (getItemId < GI_MAX))) || (gSaveContext.n64ddFlag && ((getItemId > RG_NONE) && (getItemId < RG_MAX))))) || (!(player->stateFlags1 & 0x20000800))) { if ((actor->xzDistToPlayer < xzRange) && (fabsf(actor->yDistToPlayer) < yRange)) { s16 yawDiff = actor->yawTowardsPlayer - player->actor.shape.rot.y; diff --git a/soh/src/overlays/actors/ovl_player_actor/z_player.c b/soh/src/overlays/actors/ovl_player_actor/z_player.c index bf3c5b74b..a8b8dd71f 100644 --- a/soh/src/overlays/actors/ovl_player_actor/z_player.c +++ b/soh/src/overlays/actors/ovl_player_actor/z_player.c @@ -1410,7 +1410,7 @@ s32 func_808332E4(Player* this) { void func_808332F4(Player* this, GlobalContext* globalCtx) { GetItemEntry giEntry; if (this->getItemEntry.objectId == OBJECT_INVALID) { - giEntry = ItemTable_Retrieve(this->getItemId - 1); + giEntry = ItemTable_Retrieve(this->getItemId); } else { giEntry = this->getItemEntry; } @@ -4862,7 +4862,7 @@ s32 func_8083B040(Player* this, GlobalContext* globalCtx) { if (sp2C >= 0) { if (this->getItemEntry.objectId == OBJECT_INVALID) { - giEntry = ItemTable_Retrieve(D_80854528[sp2C] - 1); + giEntry = ItemTable_Retrieve(D_80854528[sp2C]); } else { giEntry = this->getItemEntry; } @@ -6100,10 +6100,10 @@ s32 func_8083E5A8(Player* this, GlobalContext* globalCtx) { this->getItemId = iREG(68); } - if (this->getItemId < GI_MAX) { + if (this->getItemId < GI_MAX || (gSaveContext.n64ddFlag && this->getItemId < RG_MAX)) { GetItemEntry giEntry; if (this->getItemEntry.objectId == OBJECT_INVALID) { - giEntry = ItemTable_Retrieve(this->getItemId - 1); + giEntry = ItemTable_Retrieve(this->getItemId); } else { giEntry = this->getItemEntry; } @@ -6160,7 +6160,7 @@ s32 func_8083E5A8(Player* this, GlobalContext* globalCtx) { if (this->getItemId != GI_NONE) { GetItemEntry giEntry; if (this->getItemEntry.objectId == OBJECT_INVALID) { - giEntry = ItemTable_Retrieve(-this->getItemId - 1); + giEntry = ItemTable_Retrieve(-this->getItemId); } else { giEntry = this->getItemEntry; } @@ -6173,7 +6173,7 @@ s32 func_8083E5A8(Player* this, GlobalContext* globalCtx) { if (((Item_CheckObtainability(giEntry.itemId) == ITEM_NONE) && (giEntry.field & 0x40)) || ((Item_CheckObtainability(giEntry.itemId) != ITEM_NONE) && (giEntry.field & 0x20))) { this->getItemId = -GI_RUPEE_BLUE; - giEntry = ItemTable_Retrieve(GI_RUPEE_BLUE - 1); + giEntry = ItemTable_Retrieve(GI_RUPEE_BLUE); } } @@ -12546,7 +12546,7 @@ s32 func_8084DFF4(GlobalContext* globalCtx, Player* this) { if (this->unk_84F == 0) { if (this->getItemEntry.objectId == OBJECT_INVALID) { - giEntry = ItemTable_Retrieve(this->getItemId - 1); + giEntry = ItemTable_Retrieve(this->getItemId); } else { giEntry = this->getItemEntry; } @@ -13192,7 +13192,7 @@ void func_8084F104(Player* this, GlobalContext* globalCtx) { func_80853148(globalCtx, targetActor); } else { - GetItemEntry giEntry = ItemTable_Retrieve(D_80854528[this->exchangeItemId - 1] - 1); + GetItemEntry giEntry = ItemTable_Retrieve(D_80854528[this->exchangeItemId - 1]); if (this->itemActionParam >= PLAYER_AP_LETTER_ZELDA) { if (giEntry.gi >= 0) {