Adds support for custom drawing functions, and adds one for Small Keys and Boss Keys.

This commit is contained in:
Christopher Leggett 2022-08-23 21:12:21 -04:00
parent b7e07bef2f
commit 28afbec341
No known key found for this signature in database
GPG Key ID: 7093AE5FF7037D79
7 changed files with 162 additions and 7 deletions

View File

@ -181,6 +181,7 @@ set(Header_Files__soh__Enhancements__randomizer
"soh/Enhancements/randomizer/randomizer_item_tracker.h"
"soh/Enhancements/randomizer/adult_trade_shuffle.h"
"soh/Enhancements/randomizer/randomizer_check_objects.h"
"soh/Enhancements/randomizer/draw.h"
)
source_group("Header Files\\soh\\Enhancements\\randomizer" FILES ${Header_Files__soh__Enhancements__randomizer})
@ -288,6 +289,7 @@ set(Source_Files__soh__Enhancements__randomizer
"soh/Enhancements/randomizer/randomizer_item_tracker.cpp"
"soh/Enhancements/randomizer/adult_trade_shuffle.c"
"soh/Enhancements/randomizer/randomizer_check_objects.cpp"
"soh/Enhancements/randomizer/draw.cpp"
)
source_group("Source Files\\soh\\Enhancements\\randomizer" FILES ${Source_Files__soh__Enhancements__randomizer})

View File

@ -7,12 +7,20 @@
#define CHEST_ANIM_LONG 1
#define GET_ITEM(itemId, objectId, drawId, textId, field, chestAnim, modIndex, getItemId) \
{ itemId, field, (chestAnim != CHEST_ANIM_SHORT ? 1 : -1) * (drawId + 1), textId, objectId, modIndex, getItemId, drawId, true }
{ itemId, field, (chestAnim != CHEST_ANIM_SHORT ? 1 : -1) * (drawId + 1), textId, objectId, modIndex, getItemId, drawId, true, NULL }
#define GET_ITEM_NONE \
{ ITEM_NONE, 0, 0, 0, 0, 0, 0, 0, false }
{ ITEM_NONE, 0, 0, 0, 0, 0, 0, 0, false, NULL }
typedef struct {
#define GET_ITEM_CUSTOM_DRAW(itemId, objectId, drawId, textId, field, chestAnim, modIndex, getItemId, drawFunc) \
{ itemId, field (chestAnim != CHEST_ANIM_SHORT ? 1 : -1) * (drawId + 1), textId, objectId, modIndex, getItemId, drawId, true, drawFunc }
typedef struct GlobalContext GlobalContext;
typedef struct GetItemEntry GetItemEntry;
typedef void (*CustomDrawFunc)(GlobalContext* globalCtx, GetItemEntry* getItemEntry);
typedef struct GetItemEntry {
/* 0x00 */ uint16_t itemId;
/* 0x01 */ uint16_t field; // various bit-packed data
/* 0x02 */ int16_t gi; // defines the draw id and chest opening animation
@ -22,4 +30,5 @@ typedef struct {
/* 0x08 */ int16_t getItemId;
/* 0x0A */ uint16_t gid; // Stores the GID value unmodified for future reference.
/* 0x0C */ uint16_t collectable; // determines whether the item can be collected on the overworld. Will be true in most cases.
} GetItemEntry; // size = 0x0F
CustomDrawFunc drawFunc;
}; // size = 0x0F

View File

@ -0,0 +1,114 @@
#include "draw.h"
#include "z64.h"
#include "macros.h"
#include "functions.h"
#include "randomizerTypes.h"
#include <array>
#include "objects/object_gi_key/object_gi_key.h"
#include "objects/object_gi_bosskey/object_gi_bosskey.h"
extern "C" void Randomizer_DrawSmallKey(GlobalContext* globalCtx, GetItemEntry* getItemEntry) {
s32 pad;
std::array<s16, 3> color;
switch(getItemEntry->getItemId) {
case RG_FOREST_TEMPLE_SMALL_KEY:
color = {4, 195, 46};
break;
case RG_FIRE_TEMPLE_SMALL_KEY:
color = {237, 95, 95};
break;
case RG_WATER_TEMPLE_SMALL_KEY:
color = {85, 180, 223};
break;
case RG_SPIRIT_TEMPLE_SMALL_KEY:
color = {222, 158, 47};
break;
case RG_SHADOW_TEMPLE_SMALL_KEY:
color = {126, 16, 177};
break;
case RG_GERUDO_TRAINING_GROUNDS_SMALL_KEY:
color = {221, 212, 60};
break;
case RG_BOTTOM_OF_THE_WELL_SMALL_KEY:
color = {227, 110, 255};
break;
case RG_GANONS_CASTLE_SMALL_KEY:
color = {80, 80, 80};
break;
}
OPEN_DISPS(globalCtx->state.gfxCtx);
func_80093D18(globalCtx->state.gfxCtx);
gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, (char*)__FILE__, __LINE__),
G_MTX_MODELVIEW | G_MTX_LOAD);
gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, (char*)__FILE__, __LINE__),
G_MTX_MODELVIEW | G_MTX_LOAD);
gsDPSetGrayscaleColor(POLY_OPA_DISP++, color[0], color[1], color[2], 255);
gsSPGrayscale(POLY_OPA_DISP++, true);
gSPDisplayList(POLY_OPA_DISP++, (Gfx*)gGiSmallKeyDL);
gsSPGrayscale(POLY_OPA_DISP++, false);
CLOSE_DISPS(globalCtx->state.gfxCtx);
}
extern "C" void Randomizer_DrawBossKey(GlobalContext* globalCtx, GetItemEntry* getItemEntry) {
s32 pad;
s16 color_slot;
color_slot = getItemEntry->getItemId - RG_FOREST_TEMPLE_BOSS_KEY;
s16 colors[6][3] = {
{ 4, 195, 46 }, // Forest Temple
{ 237, 95, 95 }, // Fire Temple
{ 85, 180, 223 }, // Water Temple
{ 222, 158, 47 }, // Spirit Temple
{ 126, 16, 177 }, // Shadow Temple
{ 210, 0, 0 } // Ganon's Castle
};
OPEN_DISPS(globalCtx->state.gfxCtx);
func_80093D18(globalCtx->state.gfxCtx);
gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, (char*)__FILE__, __LINE__),
G_MTX_MODELVIEW | G_MTX_LOAD);
gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, (char*)__FILE__, __LINE__),
G_MTX_MODELVIEW | G_MTX_LOAD);
if (color_slot == 5) { // Ganon's Boss Key
gsDPSetGrayscaleColor(POLY_OPA_DISP++, 80, 80, 80, 255);
gsSPGrayscale(POLY_OPA_DISP++, true);
}
gSPDisplayList(POLY_OPA_DISP++, (Gfx*)gGiBossKeyDL);
if (color_slot == 5) { // Ganon's Boss Key
gsSPGrayscale(POLY_OPA_DISP++, false);
}
func_80093D84(globalCtx->state.gfxCtx);
gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, (char*)__FILE__, __LINE__),
G_MTX_MODELVIEW | G_MTX_LOAD);
gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, (char*)__FILE__, __LINE__),
G_MTX_MODELVIEW | G_MTX_LOAD);
if (color_slot >= 0) {
gsDPSetGrayscaleColor(POLY_XLU_DISP++, colors[color_slot][0], colors[color_slot][1], colors[color_slot][2],
255);
gsSPGrayscale(POLY_XLU_DISP++, true);
}
gSPDisplayList(POLY_XLU_DISP++, (Gfx*)gGiBossKeyGemDL);
if (color_slot >= 0) {
gsSPGrayscale(POLY_XLU_DISP++, false);
}
CLOSE_DISPS(globalCtx->state.gfxCtx);
}

View File

@ -0,0 +1,12 @@
#ifndef RANDODRAW_H
#define RANDODRAW_H
#pragma once
#include "../item-tables/ItemTableTypes.h"
typedef struct GlobalContext GlobalContext;
extern "C" void Randomizer_DrawSmallKey(GlobalContext* globalCtx, GetItemEntry* getItemEntry);
extern "C" void Randomizer_DrawBossKey(GlobalContext* globalCtx, GetItemEntry* getItemEntry);
#endif

View File

@ -20,6 +20,7 @@
#include <stdexcept>
#include "randomizer_check_objects.h"
#include <sstream>
#include "draw.h"
using json = nlohmann::json;
using namespace std::literals::string_literals;
@ -3889,6 +3890,11 @@ void InitRandoItemTable() {
ItemTableManager::Instance->AddItemEntry(MOD_RANDOMIZER, extendedVanillaGetItemTable[i].getItemId, extendedVanillaGetItemTable[i]);
}
for (int i = 0; i < ARRAY_COUNT(randoGetItemTable); i++) {
if (randoGetItemTable[i].itemId >= RG_FOREST_TEMPLE_SMALL_KEY && randoGetItemTable[i].itemId <= RG_GANONS_CASTLE_SMALL_KEY) {
randoGetItemTable[i].drawFunc = (CustomDrawFunc)Randomizer_DrawSmallKey;
} else if (randoGetItemTable[i].itemId >= RG_FOREST_TEMPLE_BOSS_KEY && randoGetItemTable[i].itemId <= RG_GANONS_CASTLE_BOSS_KEY) {
randoGetItemTable[i].drawFunc = (CustomDrawFunc)Randomizer_DrawBossKey;
}
ItemTableManager::Instance->AddItemEntry(MOD_RANDOMIZER, randoGetItemTable[i].itemId, randoGetItemTable[i]);
}
}

View File

@ -1360,7 +1360,11 @@ void EnItem00_DrawCollectible(EnItem00* this, GlobalContext* globalCtx) {
GetItemEntry randoGetItemEntry =
Randomizer_GetRandomizedItem(this->getItemId, this->actor.id, this->ogParams, globalCtx->sceneNum);
EnItem00_CustomItemsParticles(&this->actor, globalCtx, randoGetItemEntry);
if (randoGetItemEntry.drawFunc != NULL) {
randoGetItemEntry.drawFunc(globalCtx, &randoGetItemEntry);
} else {
GetItem_Draw(globalCtx, randoGetItemEntry.gid);
}
} else {
s32 texIndex = this->actor.params - 3;
@ -1419,7 +1423,11 @@ void EnItem00_DrawHeartPiece(EnItem00* this, GlobalContext* globalCtx) {
GetItemEntry randoGetItemEntry =
Randomizer_GetRandomizedItem(GI_HEART_PIECE, this->actor.id, this->ogParams, globalCtx->sceneNum);
EnItem00_CustomItemsParticles(&this->actor, globalCtx, randoGetItemEntry);
if (randoGetItemEntry.drawFunc != NULL) {
randoGetItemEntry.drawFunc(globalCtx, &randoGetItemEntry);
} else {
GetItem_Draw(globalCtx, randoGetItemEntry.gid);
}
} else {
s32 pad;

View File

@ -1170,7 +1170,11 @@ void Player_DrawGetItemImpl(GlobalContext* globalCtx, Player* this, Vec3f* refPo
Matrix_RotateZYX(0, globalCtx->gameplayFrames * 1000, 0, MTXMODE_APPLY);
Matrix_Scale(0.2f, 0.2f, 0.2f, MTXMODE_APPLY);
if(this->getItemEntry.drawFunc != NULL) {
this->getItemEntry.drawFunc(globalCtx, &this->getItemEntry);
} else {
GetItem_Draw(globalCtx, drawIdPlusOne - 1);
}
CLOSE_DISPS(globalCtx->state.gfxCtx);
}