* Changed to ShipInit (might be missing something?)

* Corrected Should in z_en_kusa.c to use original draw func when setting is Off
This commit is contained in:
Fredrik Andréasson 2025-01-28 20:10:01 +01:00
parent fbf1b49c3e
commit 10e4b70bc9
3 changed files with 21 additions and 32 deletions

View File

@ -10,8 +10,9 @@ extern "C" {
extern PlayState* gPlayState;
}
extern void EnItem00_DrawRandomizedItem(EnItem00* enItem00, PlayState* play);
#define RAND_GET_OPTION(option) Rando::Context::GetInstance()->GetOption(option).Get()
extern void EnItem00_DrawRandomizedItem(EnItem00* enItem00, PlayState* play);
extern "C" void EnKusa_RandomizerDraw(Actor* thisx, PlayState* play) {
static Gfx* dLists[] = { (Gfx*)gFieldBushDL, (Gfx*)object_kusa_DL_000140, (Gfx*)object_kusa_DL_000140 };
@ -21,7 +22,8 @@ extern "C" void EnKusa_RandomizerDraw(Actor* thisx, PlayState* play) {
Gfx_SetupDL_25Opa(play->state.gfxCtx);
gDPSetGrayscaleColor(POLY_OPA_DISP++, 175, 255, 0, 255);
if (grassActor->grassIdentity.randomizerCheck != RC_MAX && Flags_GetRandomizerInf(grassActor->grassIdentity.randomizerInf) == 0) {
if (grassActor->grassIdentity.randomizerCheck != RC_MAX &&
Flags_GetRandomizerInf(grassActor->grassIdentity.randomizerInf) == 0) {
gSPGrayscale(POLY_OPA_DISP++, true);
}
@ -59,7 +61,8 @@ uint8_t EnKusa_RandomizerHoldsItem(EnKusa* grassActor, PlayState* play) {
void EnKusa_RandomizerSpawnCollectible(EnKusa* grassActor, PlayState* play) {
EnItem00* item00 = (EnItem00*)Item_DropCollectible2(play, &grassActor->actor.world.pos, ITEM00_SOH_DUMMY);
item00->randoInf = grassActor->grassIdentity.randomizerInf;
item00->itemEntry = Rando::Context::GetInstance()->GetFinalGIEntry(grassActor->grassIdentity.randomizerCheck, true, GI_NONE);
item00->itemEntry =
Rando::Context::GetInstance()->GetFinalGIEntry(grassActor->grassIdentity.randomizerCheck, true, GI_NONE);
item00->actor.draw = (ActorFunc)EnItem00_DrawRandomizedItem;
item00->actor.velocity.y = 8.0f;
item00->actor.speedXZ = 2.0f;
@ -69,20 +72,22 @@ void EnKusa_RandomizerSpawnCollectible(EnKusa* grassActor, PlayState* play) {
void EnKusa_RandomizerInit(void* actorRef) {
Actor* actor = static_cast<Actor*>(actorRef);
if (actor->id != ACTOR_EN_KUSA) return;
if (actor->id != ACTOR_EN_KUSA)
return;
EnKusa* grassActor = static_cast<EnKusa*>(actorRef);
s16 respawnData = gSaveContext.respawn[RESPAWN_MODE_RETURN].data & ((1 << 8) - 1);
grassActor->grassIdentity = OTRGlobals::Instance->gRandomizer->IdentifyGrass(gPlayState->sceneNum, (s16)actor->world.pos.x, (s16)actor->world.pos.z, respawnData, gPlayState->linkAgeOnLoad);
grassActor->grassIdentity = OTRGlobals::Instance->gRandomizer->IdentifyGrass(
gPlayState->sceneNum, (s16)actor->world.pos.x, (s16)actor->world.pos.z, respawnData, gPlayState->linkAgeOnLoad);
}
void ShuffleGrass_OnVanillaBehaviorHandler(GIVanillaBehavior id, bool* should, va_list originalArgs) {
va_list args;
va_copy(args, originalArgs);
void RegisterGrassanity() {
bool shouldRegister = IS_RANDO && RAND_GET_OPTION(RSK_GRASSANITY);
// Draw custom model for grass to indicate it holding a randomized item.
if (id == VB_GRASS_SETUP_DRAW) {
COND_ID_HOOK(OnActorInit, ACTOR_EN_KUSA, shouldRegister, EnKusa_RandomizerInit);
COND_VB_SHOULD(VB_GRASS_SETUP_DRAW, shouldRegister, {
EnKusa* grassActor = va_arg(args, EnKusa*);
if (EnKusa_RandomizerHoldsItem(grassActor, gPlayState)) {
grassActor->actor.draw = (ActorFunc)EnKusa_RandomizerDraw;
@ -90,10 +95,9 @@ void ShuffleGrass_OnVanillaBehaviorHandler(GIVanillaBehavior id, bool* should, v
} else {
*should = true;
}
}
});
// Do not spawn vanilla item from grass, instead spawn the randomized item.
if (id == VB_GRASS_DROP_ITEM) {
COND_VB_SHOULD(VB_GRASS_DROP_ITEM, shouldRegister, {
EnKusa* grassActor = va_arg(args, EnKusa*);
if (EnKusa_RandomizerHoldsItem(grassActor, gPlayState)) {
EnKusa_RandomizerSpawnCollectible(grassActor, gPlayState);
@ -103,7 +107,7 @@ void ShuffleGrass_OnVanillaBehaviorHandler(GIVanillaBehavior id, bool* should, v
} else {
*should = true;
}
}
va_end(args);
});
}
static RegisterShipInitFunc initFunc(RegisterGrassanity, { "IS_RANDO" });

View File

@ -16,7 +16,6 @@
#include "soh/Notification/Notification.h"
#include "soh/SaveManager.h"
#include "soh/Enhancements/randomizer/ShuffleFairies.h"
#include "soh/Enhancements/randomizer/grassanity.h"
extern "C" {
#include "macros.h"
@ -2372,9 +2371,6 @@ void RandomizerRegisterHooks() {
static uint32_t shuffleFreestandingOnVanillaBehaviorHook = 0;
static uint32_t shuffleGrassOnActorInitHook = 0;
static uint32_t shuffleGrassOnVanillaBehaviorHook = 0;
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnLoadGame>([](int32_t fileNum) {
ShipInit::Init("IS_RANDO");
@ -2410,9 +2406,6 @@ void RandomizerRegisterHooks() {
GameInteractor::Instance->UnregisterGameHook<GameInteractor::OnVanillaBehavior>(shuffleFreestandingOnVanillaBehaviorHook);
GameInteractor::Instance->UnregisterGameHook<GameInteractor::OnActorInit>(shuffleGrassOnActorInitHook);
GameInteractor::Instance->UnregisterGameHook<GameInteractor::OnVanillaBehavior>(shuffleGrassOnVanillaBehaviorHook);
onFlagSetHook = 0;
onSceneFlagSetHook = 0;
onPlayerUpdateForRCQueueHook = 0;
@ -2441,9 +2434,6 @@ void RandomizerRegisterHooks() {
shuffleFreestandingOnVanillaBehaviorHook = 0;
shuffleGrassOnActorInitHook = 0;
shuffleGrassOnVanillaBehaviorHook = 0;
ShuffleFairies_UnregisterHooks();
if (!IS_RANDO) return;
@ -2496,10 +2486,5 @@ void RandomizerRegisterHooks() {
if (RAND_GET_OPTION(RSK_SHUFFLE_FAIRIES)) {
ShuffleFairies_RegisterHooks();
}
if (RAND_GET_OPTION(RSK_GRASSANITY)) {
shuffleGrassOnActorInitHook = GameInteractor::Instance->RegisterGameHook<GameInteractor::OnActorInit>(EnKusa_RandomizerInit);
shuffleGrassOnVanillaBehaviorHook = GameInteractor::Instance->RegisterGameHook<GameInteractor::OnVanillaBehavior>(ShuffleGrass_OnVanillaBehaviorHandler);
}
});
}

View File

@ -292,7 +292,7 @@ void EnKusa_WaitObject(EnKusa* this, PlayState* play) {
EnKusa_SetupMain(this);
}
if (!GameInteractor_Should(VB_GRASS_SETUP_DRAW, false, this)) {
if (!GameInteractor_Should(VB_GRASS_SETUP_DRAW, true, this)) {
return;
}