From a1a6c07549b232fb8c98c86e7f65b2bcdf86a121 Mon Sep 17 00:00:00 2001 From: aMannus Date: Wed, 21 Dec 2022 05:32:01 +0100 Subject: [PATCH] Rando - Fix ice traps & get item logic (#2210) * Fix ice traps & get item logic * Fix shop keepers & more draw logic cleanup --- soh/include/variables.h | 1 + soh/soh/Enhancements/randomizer/draw.cpp | 50 +++++++------------ .../Enhancements/randomizer/randomizer.cpp | 6 +-- soh/src/code/z_actor.c | 4 ++ soh/src/code/z_draw.c | 4 +- soh/src/code/z_player_lib.c | 50 +++++++++++++++++-- .../overlays/gamestates/ovl_title/z_title.c | 17 +++++++ 7 files changed, 90 insertions(+), 42 deletions(-) diff --git a/soh/include/variables.h b/soh/include/variables.h index 816a7d631..13e4dce95 100644 --- a/soh/include/variables.h +++ b/soh/include/variables.h @@ -168,6 +168,7 @@ extern "C" extern s32 __osPfsLastChannel; extern u8 gWalkSpeedToggle1; extern u8 gWalkSpeedToggle2; + extern f32 iceTrapScale; extern const s16 D_8014A6C0[]; #define gTatumsPerBeat (D_8014A6C0[1]) diff --git a/soh/soh/Enhancements/randomizer/draw.cpp b/soh/soh/Enhancements/randomizer/draw.cpp index 559927f9c..46b717801 100644 --- a/soh/soh/Enhancements/randomizer/draw.cpp +++ b/soh/soh/Enhancements/randomizer/draw.cpp @@ -12,7 +12,7 @@ extern "C" void Randomizer_DrawSmallKey(PlayState* play, GetItemEntry* getItemEntry) { s32 pad; - + s8 isColoredKeysEnabled = CVar_GetS32("gRandoMatchKeyColors", 0); s16 color_slot = getItemEntry->getItemId - RG_FOREST_TEMPLE_SMALL_KEY; s16 colors[9][3] = { { 4, 195, 46 }, // Forest Temple @@ -33,18 +33,23 @@ extern "C" void Randomizer_DrawSmallKey(PlayState* play, GetItemEntry* getItemEn gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx, (char*)__FILE__, __LINE__), G_MTX_MODELVIEW | G_MTX_LOAD); - gDPSetGrayscaleColor(POLY_OPA_DISP++, colors[color_slot][0], colors[color_slot][1], colors[color_slot][2], 255); - gSPGrayscale(POLY_OPA_DISP++, true); + if (isColoredKeysEnabled) { + gDPSetGrayscaleColor(POLY_OPA_DISP++, colors[color_slot][0], colors[color_slot][1], colors[color_slot][2], 255); + gSPGrayscale(POLY_OPA_DISP++, true); + } gSPDisplayList(POLY_OPA_DISP++, (Gfx*)gGiSmallKeyDL); - gSPGrayscale(POLY_OPA_DISP++, false); + if (isColoredKeysEnabled) { + gSPGrayscale(POLY_OPA_DISP++, false); + } CLOSE_DISPS(play->state.gfxCtx); } extern "C" void Randomizer_DrawBossKey(PlayState* play, GetItemEntry* getItemEntry) { s32 pad; + s8 isColoredKeysEnabled = CVar_GetS32("gRandoMatchKeyColors", 0); s16 color_slot; color_slot = getItemEntry->getItemId - RG_FOREST_TEMPLE_BOSS_KEY; s16 colors[6][3] = { @@ -63,14 +68,14 @@ extern "C" void Randomizer_DrawBossKey(PlayState* play, GetItemEntry* getItemEnt gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx, (char*)__FILE__, __LINE__), G_MTX_MODELVIEW | G_MTX_LOAD); - if (color_slot == 5) { // Ganon's Boss Key + if (color_slot == 5 && isColoredKeysEnabled) { // Ganon's Boss Key gDPSetGrayscaleColor(POLY_OPA_DISP++, 80, 80, 80, 255); gSPGrayscale(POLY_OPA_DISP++, true); } gSPDisplayList(POLY_OPA_DISP++, (Gfx*)gGiBossKeyDL); - if (color_slot == 5) { // Ganon's Boss Key + if (color_slot == 5 && isColoredKeysEnabled) { // Ganon's Boss Key gSPGrayscale(POLY_OPA_DISP++, false); } @@ -79,13 +84,16 @@ extern "C" void Randomizer_DrawBossKey(PlayState* play, GetItemEntry* getItemEnt gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(play->state.gfxCtx, (char*)__FILE__, __LINE__), G_MTX_MODELVIEW | G_MTX_LOAD); - gDPSetGrayscaleColor(POLY_XLU_DISP++, colors[color_slot][0], colors[color_slot][1], colors[color_slot][2], - 255); - gSPGrayscale(POLY_XLU_DISP++, true); + if (isColoredKeysEnabled) { + gDPSetGrayscaleColor(POLY_XLU_DISP++, colors[color_slot][0], colors[color_slot][1], colors[color_slot][2], 255); + gSPGrayscale(POLY_XLU_DISP++, true); + } gSPDisplayList(POLY_XLU_DISP++, (Gfx*)gGiBossKeyGemDL); - gSPGrayscale(POLY_XLU_DISP++, false); + if (isColoredKeysEnabled) { + gSPGrayscale(POLY_XLU_DISP++, false); + } CLOSE_DISPS(play->state.gfxCtx); } @@ -157,25 +165,3 @@ extern "C" void Randomizer_DrawDoubleDefense(PlayState* play, GetItemEntry getIt CLOSE_DISPS(play->state.gfxCtx); } - - -extern "C" void Randomizer_DrawIceTrap(PlayState* play, GetItemEntry getItemEntry) { - s32 pad; - OPEN_DISPS(play->state.gfxCtx); - - if (CVar_GetS32("gLetItSnow", 0)) { - Gfx_SetupDL_25Opa(play->state.gfxCtx); - - Matrix_Scale(0.2f, 0.2f, 0.2f, MTXMODE_APPLY); - gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx, (char*)__FILE__, __LINE__), G_MTX_MODELVIEW | G_MTX_LOAD); - - gDPSetGrayscaleColor(POLY_OPA_DISP++, 100, 100, 100, 255); - gSPGrayscale(POLY_OPA_DISP++, true); - - gSPDisplayList(POLY_OPA_DISP++, (Gfx*)gSilverRockDL); - - gSPGrayscale(POLY_OPA_DISP++, false); - } - - CLOSE_DISPS(play->state.gfxCtx); -} diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index 0f38f64bf..e67cb031c 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -4568,8 +4568,8 @@ void CreateIceTrapRandoMessages() { // We only use this ice trap message for christmas, so we don't want it in the normal ice trap messages rotation customMessageManager->CreateMessage(Randomizer::IceTrapRandoMessageTableID, NUM_ICE_TRAP_MESSAGES + 1, { TEXTBOX_TYPE_BLACK, TEXTBOX_POS_BOTTOM, - "This year for Christmas, all&you get is %BCOAL", - "This year for Christmas, all&you get is %BCOAL", + "This year for Christmas, all&you get is %BCOAL%w!", + "This year for Christmas, all&you get is %BCOAL%w!", "Pour Noël, cette année, tu&n'auras que du %BCHARBON!&%rJoyeux Noël%w!" }); } @@ -4928,8 +4928,6 @@ void InitRandoItemTable() { randoGetItemTable[i].drawFunc = (CustomDrawFunc)Randomizer_DrawBossKey; } else if (randoGetItemTable[i].itemId == RG_DOUBLE_DEFENSE) { randoGetItemTable[i].drawFunc = (CustomDrawFunc)Randomizer_DrawDoubleDefense; - } else if (randoGetItemTable[i].itemId == RG_ICE_TRAP) { - randoGetItemTable[i].drawFunc = (CustomDrawFunc)Randomizer_DrawIceTrap; } ItemTableManager::Instance->AddItemEntry(MOD_RANDOMIZER, randoGetItemTable[i].itemId, randoGetItemTable[i]); } diff --git a/soh/src/code/z_actor.c b/soh/src/code/z_actor.c index 74dd031b2..c4e89adf7 100644 --- a/soh/src/code/z_actor.c +++ b/soh/src/code/z_actor.c @@ -78,6 +78,9 @@ static CollisionPoly* sCurCeilingPoly; static s32 sCurCeilingBgId; +// Used for animating the ice trap on the "Get Item" model. +f32 iceTrapScale; + void ActorShape_Init(ActorShape* shape, f32 yOffset, ActorShadowFunc shadowDraw, f32 shadowScale) { shape->yOffset = yOffset; shape->shadowDraw = shadowDraw; @@ -2030,6 +2033,7 @@ s32 GiveItemEntryFromActor(Actor* actor, PlayState* play, GetItemEntry getItemEn s32 absYawDiff = ABS(yawDiff); if ((getItemEntry.getItemId != GI_NONE) || (player->getItemDirection < absYawDiff)) { + iceTrapScale = 0.0f; player->getItemEntry = getItemEntry; player->getItemId = getItemEntry.getItemId; player->interactRangeActor = actor; diff --git a/soh/src/code/z_draw.c b/soh/src/code/z_draw.c index 17deffad2..140ee399a 100644 --- a/soh/src/code/z_draw.c +++ b/soh/src/code/z_draw.c @@ -400,9 +400,7 @@ void GetItem_Draw(PlayState* play, s16 drawId) { * Uses the Custom Draw Function if it exists, or just calls `GetItem_Draw` */ void GetItemEntry_Draw(PlayState* play, GetItemEntry getItemEntry) { - // RANDOTODO: Make this more flexible for easier toggling of individual item recolors in the future. - if (getItemEntry.drawFunc != NULL && - (CVar_GetS32("gRandoMatchKeyColors", 0) || getItemEntry.getItemId == RG_DOUBLE_DEFENSE)) { + if (getItemEntry.drawFunc != NULL) { getItemEntry.drawFunc(play, &getItemEntry); } else { GetItem_Draw(play, getItemEntry.gid); diff --git a/soh/src/code/z_player_lib.c b/soh/src/code/z_player_lib.c index 625a53bee..617cf274e 100644 --- a/soh/src/code/z_player_lib.c +++ b/soh/src/code/z_player_lib.c @@ -1,5 +1,6 @@ #include "global.h" #include "objects/gameplay_keep/gameplay_keep.h" +#include "objects/gameplay_field_keep/gameplay_field_keep.h" #include "objects/object_link_boy/object_link_boy.h" #include "objects/object_link_child/object_link_child.h" #include "objects/object_triforce_spot/object_triforce_spot.h" @@ -1172,6 +1173,49 @@ void func_800906D4(PlayState* play, Player* this, Vec3f* newTipPos) { } } +void Player_DrawGetItemIceTrap(PlayState* play, Player* this, Vec3f* refPos, s32 drawIdPlusOne, f32 height) { + OPEN_DISPS(play->state.gfxCtx); + + if (CVar_GetS32("gLetItSnow", 0)) { + Gfx_SetupDL_25Opa(play->state.gfxCtx); + + Matrix_Scale(0.2f, 0.2f, 0.2f, MTXMODE_APPLY); + gSPMatrix(POLY_OPA_DISP++, MATRIX_NEWMTX(play->state.gfxCtx), G_MTX_MODELVIEW | G_MTX_LOAD); + + gDPSetGrayscaleColor(POLY_OPA_DISP++, 75, 75, 75, 255); + gSPGrayscale(POLY_OPA_DISP++, true); + + gSPDisplayList(POLY_OPA_DISP++, (Gfx*)gSilverRockDL); + + gSPGrayscale(POLY_OPA_DISP++, false); + } else { + if (iceTrapScale < 0.01) { + iceTrapScale += 0.001f; + } else if (iceTrapScale < 0.8f) { + iceTrapScale += 0.2f; + } + gSPSegment(POLY_XLU_DISP++, 0x08, + Gfx_TwoTexScroll(play->state.gfxCtx, 0, 0, (0 - play->gameplayFrames) % 128, 32, 32, 1, 0, + (play->gameplayFrames * -2) % 128, 32, 32)); + + Matrix_Translate(0.0f, -40.0f, 0.0f, MTXMODE_APPLY); + Matrix_Scale(iceTrapScale, iceTrapScale, iceTrapScale, MTXMODE_APPLY); + gSPMatrix(POLY_XLU_DISP++, MATRIX_NEWMTX(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gDPSetEnvColor(POLY_XLU_DISP++, 0, 50, 100, 255); + gSPDisplayList(POLY_XLU_DISP++, gEffIceFragment3DL); + + // Reset matrix for the fake item model because we're animating the size of the ice block around it before this. + Matrix_Translate(refPos->x + (3.3f * Math_SinS(this->actor.shape.rot.y)), refPos->y + height, + refPos->z + ((3.3f + (IREG(90) / 10.0f)) * Math_CosS(this->actor.shape.rot.y)), MTXMODE_NEW); + Matrix_RotateZYX(0, play->gameplayFrames * 1000, 0, MTXMODE_APPLY); + Matrix_Scale(0.2f, 0.2f, 0.2f, MTXMODE_APPLY); + // Draw fake item model. + GetItem_Draw(play, drawIdPlusOne - 1); + } + + CLOSE_DISPS(play->state.gfxCtx); +} + void Player_DrawGetItemImpl(PlayState* play, Player* this, Vec3f* refPos, s32 drawIdPlusOne) { f32 height = (this->exchangeItemId != EXCH_ITEM_NONE) ? 6.0f : 14.0f; @@ -1187,9 +1231,9 @@ void Player_DrawGetItemImpl(PlayState* play, Player* this, Vec3f* refPos, s32 dr Matrix_RotateZYX(0, play->gameplayFrames * 1000, 0, MTXMODE_APPLY); Matrix_Scale(0.2f, 0.2f, 0.2f, MTXMODE_APPLY); - // RANDOTODO: Make this more flexible for easier toggling of individual item recolors in the future. - if (this->getItemEntry.drawFunc != NULL && - (CVar_GetS32("gRandoMatchKeyColors", 0) || this->getItemEntry.getItemId == RG_DOUBLE_DEFENSE || this->getItemEntry.getItemId == RG_ICE_TRAP)) { + if (this->getItemEntry.modIndex == MOD_RANDOMIZER && this->getItemEntry.getItemId == RG_ICE_TRAP) { + Player_DrawGetItemIceTrap(play, this, refPos, drawIdPlusOne, height); + } else if (this->getItemEntry.drawFunc != NULL) { this->getItemEntry.drawFunc(play, &this->getItemEntry); } else { GetItem_Draw(play, drawIdPlusOne - 1); diff --git a/soh/src/overlays/gamestates/ovl_title/z_title.c b/soh/src/overlays/gamestates/ovl_title/z_title.c index 21859edbe..6f3446b62 100644 --- a/soh/src/overlays/gamestates/ovl_title/z_title.c +++ b/soh/src/overlays/gamestates/ovl_title/z_title.c @@ -9,6 +9,7 @@ #include "global.h" #include "alloca.h" #include "textures/nintendo_rogo_static/nintendo_rogo_static.h" +#include "assets/objects/gameplay_keep/gameplay_keep.h" #include #include #include @@ -234,6 +235,22 @@ void Title_Draw(TitleContext* this) { gSPTextureRectangle(POLY_OPA_DISP++, 388, y << 2, 1156, (y + 2) << 2, G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10); } + // Draw ice cube around N64 logo. + if (CVar_GetS32("gLetItSnow", 0)) { + f32 scale = 0.4f; + + gSPSegment(POLY_OPA_DISP++, 0x08, + Gfx_TwoTexScroll(this->state.gfxCtx, 0, 0, (0 - 1) % 128, 32, 32, 1, + 0, (1 * -2) % 128, 32, 32)); + + Matrix_Translate(0.0f, -10.0f, 0.0f, MTXMODE_APPLY); + Matrix_Scale(scale, scale, scale, MTXMODE_APPLY); + gSPMatrix(POLY_OPA_DISP++, MATRIX_NEWMTX(this->state.gfxCtx), + G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gDPSetEnvColor(POLY_OPA_DISP++, 0, 50, 100, 255); + gSPDisplayList(POLY_OPA_DISP++, gEffIceFragment3DL); + } + Environment_FillScreen(this->state.gfxCtx, 0, 0, 0, (s16)this->coverAlpha, FILL_SCREEN_XLU); sTitleRotY += (300 * CVar_GetFloat("gCosmetics.N64Logo_SpinSpeed", 1.0f));