get item refactor

This commit is contained in:
MelonSpeedruns 2022-05-29 16:42:10 -04:00
commit f96cfee16d
8 changed files with 37 additions and 66 deletions

View file

@ -782,22 +782,13 @@ void Randomizer::ParseItemLocations(const char* spoilerFileName) {
}
}
s32 Randomizer::GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 sceneNum, s16 actorParams, s32 homePosX, s32 homePosY, s32 homePosZ) {
if (actorId != -1) {
s32 itemId = GetItemFromActor(actorId, ogId);
return itemId;
} else {
s32 itemId = GetItemFromSceneParamsAndHomePos(sceneNum, actorParams, homePosX, homePosY, homePosZ, ogId);
return itemId;
}
s32 Randomizer::GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum) {
s32 itemId = GetItemFromActor(actorId, actorParams, sceneNum, ogId);
return itemId;
}
GetItemID Randomizer::GetItemFromActor(s16 actorId, GetItemID ogItemId) {
return GetItemFromGet(this->itemLocations[GetCheckFromActor(actorId, ogItemId)], ogItemId);
}
GetItemID Randomizer::GetItemFromSceneParamsAndHomePos(s16 sceneNum, s16 actorParams, s32 homePosX, s32 homePosY, s32 homePosZ, GetItemID ogItemId) {
return GetItemFromGet(this->itemLocations[GetCheckFromSceneAndParams(sceneNum, actorParams, homePosX, homePosY, homePosZ)], ogItemId);
GetItemID Randomizer::GetItemFromActor(s16 actorId, s16 actorParams, s16 sceneNum, GetItemID ogItemId) {
return GetItemFromGet(this->itemLocations[GetCheckFromActor(sceneNum, actorId, actorParams)], ogItemId);
}
GetItemID Randomizer::GetItemFromGet(RandomizerGet randoGet, GetItemID ogItemId) {
@ -998,30 +989,21 @@ GetItemID Randomizer::GetItemFromGet(RandomizerGet randoGet, GetItemID ogItemId)
}
}
RandomizerCheck Randomizer::GetCheckFromActor(s16 actorId, GetItemID ogItemId) {
if (!gSaveContext.n64ddFlag) {
return UNKNOWN_CHECK;
}
switch (actorId) {
case 316:
switch (ogItemId) {
case GI_BOTTLE:
return KAK_ANJU_AS_CHILD;
case GI_POCKET_EGG:
return KAK_ANJU_AS_ADULT;
}
}
return UNKNOWN_CHECK;
}
RandomizerCheck Randomizer::GetCheckFromSceneAndParams(s16 sceneNum, s16 actorParams, s32 homePosX, s32 homePosY, s32 homePosZ) {
RandomizerCheck Randomizer::GetCheckFromActor(s16 sceneNum, s16 actorId, s16 actorParams) {
if (!gSaveContext.n64ddFlag) {
return UNKNOWN_CHECK;
}
switch(sceneNum) {
case 82:
switch (actorId) {
case 316:
if (LINK_IS_ADULT) {
return KAK_ANJU_AS_ADULT;
} else {
return KAK_ANJU_AS_CHILD;
}
}
case 17:
switch (actorParams) {
case 0x1F:

View file

@ -11,10 +11,8 @@ class Randomizer {
private:
std::unordered_map<RandomizerCheck, RandomizerGet> itemLocations;
GetItemID GetItemFromGet(RandomizerGet randoGet, GetItemID ogItemId);
RandomizerCheck GetCheckFromActor(s16 actorId, GetItemID ogItemId);
RandomizerCheck GetCheckFromSceneAndParams(s16 sceneNum, s16 actorParams, s32 homePosX, s32 homePosY, s32 homePosZ);
GetItemID GetItemFromActor(s16 actorId, GetItemID ogItemId);
GetItemID GetItemFromSceneParamsAndHomePos(s16 sceneNum, s16 actorParams, s32 homePosX, s32 homePosY, s32 homePosZ, GetItemID ogItemId);
RandomizerCheck GetCheckFromActor(s16 actorId, s16 actorParams, s16 sceneNum);
GetItemID GetItemFromActor(s16 actorId, s16 actorParams, s16 sceneNum, GetItemID ogItemId);
public:
Randomizer();
@ -23,7 +21,7 @@ class Randomizer {
s16 GetItemModelFromId(s16 itemId);
void LoadItemLocations(const char* spoilerFileName);
void ParseItemLocations(const char* spoilerFileName);
s32 GetRandomizedItemId(GetItemID ogId, s16 actorId = -1, s16 sceneNum = -1, s16 actorParams = -1, s32 homePosX = 0, s32 homePosY = 0, s32 homePosZ = 0);
s32 GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum);
};
#endif

View file

@ -1036,16 +1036,6 @@ extern "C" void ParseItemLocations(const char* spoilerFileName) {
OTRGlobals::Instance->gRandomizer->ParseItemLocations(spoilerFileName);
}
extern "C" s32 GetRandomizedItemId(GetItemID ogId, s16 sceneNum, s16 actorParams) {
return OTRGlobals::Instance->gRandomizer->GetRandomizedItemId(ogId, -1, sceneNum, actorParams);
}
// the lack of optional params in c is frustrating
extern "C" s32 GetRandomizedItemIdFromActor(GetItemID ogId, s16 actorId ) {
return OTRGlobals::Instance->gRandomizer->GetRandomizedItemId(ogId, actorId);
}
// use an explicit (s32) cast on the position values from the Vec3f when calling
extern "C" s32 GetRandomizedItemIdFromPosition(GetItemID ogId, s16 sceneNum, s16 actorParams, s32 homePosX, s32 homePosY, s32 homePosZ) {
return OTRGlobals::Instance->gRandomizer->GetRandomizedItemId(ogId, -1, sceneNum, actorParams, homePosX, homePosY, homePosZ);
extern "C" s32 GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum) {
return OTRGlobals::Instance->gRandomizer->GetRandomizedItemId(ogId, actorId, actorParams, sceneNum);
}

View file

@ -76,9 +76,7 @@ void AudioMgr_CreateNextAudioBuffer(s16* samples, u32 num_samples);
int Controller_ShouldRumble(size_t i);
void LoadItemLocations(const char* spoilerFileName);
void ParseItemLocations(const char* spoilerfilename);
s32 GetRandomizedItemId(GetItemID ogId, s16 sceneNum, s16 actorParams);
s32 GetRandomizedItemIdFromActor(GetItemID ogId, s16 actorId);
s32 GetRandomizedItemIdFromPosition(GetItemID ogId, s16 sceneNum, s16 actorParams, s32 homePosX, s32 homePosY, s32 homePosZ);
s32 GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum);
#endif

View file

@ -692,7 +692,7 @@ void EnItem00_Init(Actor* thisx, GlobalContext* globalCtx) {
}
if ((getItemId != GI_NONE) && !Actor_HasParent(&this->actor, globalCtx)) {
getItemId = GetRandomizedItemId(this->getItemId, globalCtx->sceneNum, this->ogParams);
getItemId = GetRandomizedItemId(this->getItemId, this->actor.id, this->ogParams, globalCtx->sceneNum);
func_8002F554(&this->actor, globalCtx, getItemId);
}
@ -1053,7 +1053,7 @@ void EnItem00_Update(Actor* thisx, GlobalContext* globalCtx) {
if ((getItemId != GI_NONE) && !Actor_HasParent(&this->actor, globalCtx)) {
if (gSaveContext.n64ddFlag) {
getItemId = GetRandomizedItemId(this->getItemId, globalCtx->sceneNum, this->ogParams);
getItemId = GetRandomizedItemId(this->getItemId, this->actor.id, this->ogParams, globalCtx->sceneNum);
}
func_8002F554(&this->actor, globalCtx, getItemId);
}
@ -1325,7 +1325,8 @@ void EnItem00_DrawHeartPiece(EnItem00* this, GlobalContext* globalCtx) {
if (gSaveContext.n64ddFlag) {
f32 mtxScale = 16.0f;
Matrix_Scale(mtxScale, mtxScale, mtxScale, MTXMODE_APPLY);
GetItem_Draw(globalCtx, GetItemModelFromId(GetRandomizedItemId(this->getItemId, globalCtx->sceneNum, this->ogParams)));
GetItem_Draw(globalCtx, GetItemModelFromId(GetRandomizedItemId(this->getItemId, this->actor.id, this->ogParams,
globalCtx->sceneNum)));
} else {
s32 pad;

View file

@ -424,7 +424,8 @@ void EnBox_WaitOpen(EnBox* this, GlobalContext* globalCtx) {
func_8002DBD0(&this->dyna.actor, &sp4C, &player->actor.world.pos);
if (sp4C.z > -50.0f && sp4C.z < 0.0f && fabsf(sp4C.y) < 10.0f && fabsf(sp4C.x) < 20.0f &&
Player_IsFacingActor(&this->dyna.actor, 0x3000, globalCtx)) {
func_8002F554(&this->dyna.actor, globalCtx, 0 - GetRandomizedItemId(this->dyna.actor.params >> 5 & 0x7F, globalCtx->sceneNum, this->dyna.actor.params));
int32_t item = GetRandomizedItemId(this->dyna.actor.params >> 5 & 0x7F, this->dyna.actor.id, this->dyna.actor.params, globalCtx->sceneNum);
func_8002F554(&this->dyna.actor, globalCtx, 0 - item);
}
if (Flags_GetTreasure(globalCtx, this->dyna.actor.params & 0x1F)) {
EnBox_SetupAction(this, EnBox_Open);

View file

@ -304,8 +304,8 @@ void func_80ABA654(EnNiwLady* this, GlobalContext* globalCtx) {
if (!(gSaveContext.itemGetInf[0] & 0x1000)) {
this->actor.parent = NULL;
this->getItemId = GetRandomizedItemIdFromActor(GI_BOTTLE, this->actor.id);
func_8002F434(&this->actor, globalCtx, GetRandomizedItemIdFromActor(GI_BOTTLE, this->actor.id), 100.0f, 50.0f); //not sure if calling again makes sense here or if we should just use this->getItemId
this->getItemId = GetRandomizedItemId(GI_BOTTLE, this->actor.id, this->actor.params, globalCtx->sceneNum);
func_8002F434(&this->actor, globalCtx, this->getItemId, 100.0f, 50.0f);
this->actionFunc = func_80ABAC00;
return;
}
@ -387,8 +387,9 @@ void func_80ABA9B8(EnNiwLady* this, GlobalContext* globalCtx) {
case 0:
Message_CloseTextbox(globalCtx);
this->actor.parent = NULL;
func_8002F434(&this->actor, globalCtx, GetRandomizedItemIdFromActor(GI_POCKET_EGG, this->actor.id), 200.0f,
100.0f);
s32 itemId =
GetRandomizedItemId(GI_POCKET_EGG, this->actor.id, this->actor.params, globalCtx->sceneNum);
func_8002F434(&this->actor, globalCtx, itemId, 200.0f, 100.0f);
this->actionFunc = func_80ABAC00;
break;
case 1:
@ -440,8 +441,8 @@ void func_80ABAC00(EnNiwLady* this, GlobalContext* globalCtx) {
} else {
getItemId = this->getItemId;
if (LINK_IS_ADULT) {
getItemId =
!(gSaveContext.itemGetInf[2] & 0x1000) ? GetRandomizedItemIdFromActor(GI_POCKET_EGG, this->actor.id) : GI_COJIRO;
getItemId = !(gSaveContext.itemGetInf[2] & 0x1000)
? GetRandomizedItemId(GI_POCKET_EGG, this->actor.id, this->actor.params, globalCtx->sceneNum) : GI_COJIRO;
}
func_8002F434(&this->actor, globalCtx, getItemId, 200.0f, 100.0f);
}

View file

@ -60,7 +60,7 @@ void ItemBHeart_Update(Actor* thisx, GlobalContext* globalCtx) {
Actor_Kill(&this->actor);
} else {
if (gSaveContext.n64ddFlag) {
s16 getItemId = GetRandomizedItemId(GI_HEART_CONTAINER_2, globalCtx->sceneNum, 0x1F);
s16 getItemId = GetRandomizedItemId(GI_HEART_CONTAINER_2, this->actor.id, this->actor.params, globalCtx->sceneNum);
func_8002F434(&this->actor, globalCtx, getItemId, 30.0f, 40.0f);
} else {
func_8002F434(&this->actor, globalCtx, GI_HEART_CONTAINER_2, 30.0f, 40.0f);
@ -100,7 +100,7 @@ void ItemBHeart_Draw(Actor* thisx, GlobalContext* globalCtx) {
if (gSaveContext.n64ddFlag) {
GetItem_Draw(globalCtx,
GetItemModelFromId(GetRandomizedItemId(GI_HEART_CONTAINER_2, globalCtx->sceneNum, 0x1F)));
GetItemModelFromId(GetRandomizedItemId(GI_HEART_CONTAINER_2, this->actor.id, this->actor.params, globalCtx->sceneNum)));
} else {
if (flag) {
func_80093D84(globalCtx->state.gfxCtx);