From 3fc40fa3ffd608c3e2429f1d301e7dc26728a090 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Sat, 10 Feb 2024 15:58:53 -0500 Subject: [PATCH] Sets up hook to override silver rupee behavior. --- soh/soh/Enhancements/mods.cpp | 22 +++++++++++ .../randomizer/actors/z_en_g_switch_rando.c | 37 +++++++++++++++++++ .../randomizer/actors/z_en_g_switch_rando.h | 17 +++++++++ 3 files changed, 76 insertions(+) create mode 100644 soh/soh/Enhancements/randomizer/actors/z_en_g_switch_rando.c create mode 100644 soh/soh/Enhancements/randomizer/actors/z_en_g_switch_rando.h diff --git a/soh/soh/Enhancements/mods.cpp b/soh/soh/Enhancements/mods.cpp index 26adf611d..d10077758 100644 --- a/soh/soh/Enhancements/mods.cpp +++ b/soh/soh/Enhancements/mods.cpp @@ -27,6 +27,7 @@ #include "src/overlays//actors/ovl_Fishing/z_fishing.h" #include "objects/object_link_boy/object_link_boy.h" #include "objects/object_link_child/object_link_child.h" +#include "soh/Enhancements/randomizer/actors/z_en_g_switch_rando.h" extern "C" { #include @@ -1151,6 +1152,26 @@ void RegisterRandomizerSheikSpawn() { }); } +//Changes silver rupee update and draw functions, if silver rupees shuffle is enabled +void RegisterSilverRupeeShuffle() { + GameInteractor::Instance->RegisterGameHook([](void* refActor) { + if (!gPlayState) { + return; + } + if (!IS_RANDO || OTRGlobals::Instance->gRandoContext->GetOption(RSK_SHUFFLE_SILVER_RUPEES).Is(RO_SILVER_SHUFFLE_VANILLA)) { + return; + } + auto* actor = static_cast(refActor); + if (actor->id == ACTOR_EN_G_SWITCH) { + auto* silverRupee = reinterpret_cast(actor); + if (silverRupee->type == ENGSWITCH_SILVER_RUPEE) { + silverRupee->actionFunc = EnGSwitch_Randomizer_SilverRupeeIdle; + silverRupee->actor.draw = EnGSwitch_Randomizer_Draw; + } + } + }); +} + //Boss souls require an additional item (represented by a RAND_INF) to spawn a boss in a particular lair void RegisterBossSouls() { GameInteractor::Instance->RegisterGameHook([](void* actor) { @@ -1627,6 +1648,7 @@ void InitMods() { RegisterAltTrapTypes(); RegisterRandomizerSheikSpawn(); RegisterBossSouls(); + RegisterSilverRupeeShuffle(); RegisterRandomizedEnemySizes(); RegisterToTMedallions(); RegisterNoSwim(); diff --git a/soh/soh/Enhancements/randomizer/actors/z_en_g_switch_rando.c b/soh/soh/Enhancements/randomizer/actors/z_en_g_switch_rando.c new file mode 100644 index 000000000..b78bce33e --- /dev/null +++ b/soh/soh/Enhancements/randomizer/actors/z_en_g_switch_rando.c @@ -0,0 +1,37 @@ +#include "z_en_g_switch_rando.h" + +void EnGSwitch_Kill(EnGSwitch* this, PlayState* play); + +void EnGSwitch_Randomizer_SilverRupeeIdle(EnGSwitch* self, PlayState* play) { + Player* player = GET_PLAYER(play); + + self->actor.shape.rot.y += 0x800; + if (self->actor.xyzDistToPlayerSq < 900.0f) { + if (IS_RANDO && Randomizer_GetSettingValue(RSK_SHUFFLE_SILVER_RUPEES) != RO_SILVER_SHUFFLE_VANILLA) { + GetItemEntry getItem = ItemTable_RetrieveEntry(MOD_NONE, GI_NUTS_5); + if (getItem.modIndex == MOD_NONE) { + // RANDOTOD: Move this into Item_Give() or some other more central location + if (getItem.getItemId == GI_SWORD_BGS) { + gSaveContext.bgsFlag = true; + } + Item_Give(play, getItem.itemId); + } else if (getItem.modIndex == MOD_RANDOMIZER) { + Randomizer_Item_Give(play, getItem); + } + self->killTimer = 0; + self->actionFunc = EnGSwitch_Kill; + } + } +} + +void EnGSwitch_Randomizer_Draw(Actor* thisx, PlayState* play) { + EnGSwitch* this = (EnGSwitch*)thisx; + if (IS_RANDO && Randomizer_GetSettingValue(RSK_SHUFFLE_SILVER_RUPEES) != RO_SILVER_SHUFFLE_VANILLA && + this->type == ENGSWITCH_SILVER_RUPEE) { + OPEN_DISPS(play->state.gfxCtx); + Matrix_Scale(17.5f, 17.5f, 17.5f, MTXMODE_APPLY); + GetItemEntry getItem = ItemTable_RetrieveEntry(MOD_NONE, GI_NUTS_5); + GetItemEntry_Draw(play, getItem); + CLOSE_DISPS(play->state.gfxCtx); + } +} diff --git a/soh/soh/Enhancements/randomizer/actors/z_en_g_switch_rando.h b/soh/soh/Enhancements/randomizer/actors/z_en_g_switch_rando.h new file mode 100644 index 000000000..d725a8749 --- /dev/null +++ b/soh/soh/Enhancements/randomizer/actors/z_en_g_switch_rando.h @@ -0,0 +1,17 @@ +#ifndef SHIP_Z_EN_G_SWITCH_RANDO_H +#define SHIP_Z_EN_G_SWITCH_RANDO_H + +#include "overlays/actors/ovl_En_G_Switch/z_en_g_switch.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void EnGSwitch_Randomizer_SilverRupeeIdle(EnGSwitch *self, PlayState *play); +void EnGSwitch_Randomizer_Draw(Actor *thisx, PlayState *play); + +#ifdef __cplusplus +}; +#endif + +#endif //SHIP_Z_EN_G_SWITCH_RANDO_H