mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-08-22 22:33:43 -07:00
Merge pull request #15 from MelonSpeedruns/melon-randomizer
get item refactor
This commit is contained in:
commit
4de0b10bf4
8 changed files with 37 additions and 66 deletions
|
@ -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) {
|
s32 Randomizer::GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum) {
|
||||||
if (actorId != -1) {
|
s32 itemId = GetItemFromActor(actorId, actorParams, sceneNum, ogId);
|
||||||
s32 itemId = GetItemFromActor(actorId, ogId);
|
|
||||||
return itemId;
|
|
||||||
} else {
|
|
||||||
s32 itemId = GetItemFromSceneParamsAndHomePos(sceneNum, actorParams, homePosX, homePosY, homePosZ, ogId);
|
|
||||||
return itemId;
|
return itemId;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
GetItemID Randomizer::GetItemFromActor(s16 actorId, GetItemID ogItemId) {
|
GetItemID Randomizer::GetItemFromActor(s16 actorId, s16 actorParams, s16 sceneNum, GetItemID ogItemId) {
|
||||||
return GetItemFromGet(this->itemLocations[GetCheckFromActor(actorId, ogItemId)], ogItemId);
|
return GetItemFromGet(this->itemLocations[GetCheckFromActor(sceneNum, actorId, actorParams)], 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::GetItemFromGet(RandomizerGet randoGet, GetItemID 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) {
|
RandomizerCheck Randomizer::GetCheckFromActor(s16 sceneNum, s16 actorId, s16 actorParams) {
|
||||||
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) {
|
|
||||||
if (!gSaveContext.n64ddFlag) {
|
if (!gSaveContext.n64ddFlag) {
|
||||||
return UNKNOWN_CHECK;
|
return UNKNOWN_CHECK;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(sceneNum) {
|
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:
|
case 17:
|
||||||
switch (actorParams) {
|
switch (actorParams) {
|
||||||
case 0x1F:
|
case 0x1F:
|
||||||
|
|
|
@ -11,10 +11,8 @@ class Randomizer {
|
||||||
private:
|
private:
|
||||||
std::unordered_map<RandomizerCheck, RandomizerGet> itemLocations;
|
std::unordered_map<RandomizerCheck, RandomizerGet> itemLocations;
|
||||||
GetItemID GetItemFromGet(RandomizerGet randoGet, GetItemID ogItemId);
|
GetItemID GetItemFromGet(RandomizerGet randoGet, GetItemID ogItemId);
|
||||||
RandomizerCheck GetCheckFromActor(s16 actorId, GetItemID ogItemId);
|
RandomizerCheck GetCheckFromActor(s16 actorId, s16 actorParams, s16 sceneNum);
|
||||||
RandomizerCheck GetCheckFromSceneAndParams(s16 sceneNum, s16 actorParams, s32 homePosX, s32 homePosY, s32 homePosZ);
|
GetItemID GetItemFromActor(s16 actorId, s16 actorParams, s16 sceneNum, GetItemID ogItemId);
|
||||||
GetItemID GetItemFromActor(s16 actorId, GetItemID ogItemId);
|
|
||||||
GetItemID GetItemFromSceneParamsAndHomePos(s16 sceneNum, s16 actorParams, s32 homePosX, s32 homePosY, s32 homePosZ, GetItemID ogItemId);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Randomizer();
|
Randomizer();
|
||||||
|
@ -23,7 +21,7 @@ class Randomizer {
|
||||||
s16 GetItemModelFromId(s16 itemId);
|
s16 GetItemModelFromId(s16 itemId);
|
||||||
void LoadItemLocations(const char* spoilerFileName);
|
void LoadItemLocations(const char* spoilerFileName);
|
||||||
void ParseItemLocations(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
|
#endif
|
||||||
|
|
|
@ -1036,16 +1036,6 @@ extern "C" void ParseItemLocations(const char* spoilerFileName) {
|
||||||
OTRGlobals::Instance->gRandomizer->ParseItemLocations(spoilerFileName);
|
OTRGlobals::Instance->gRandomizer->ParseItemLocations(spoilerFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" s32 GetRandomizedItemId(GetItemID ogId, s16 sceneNum, s16 actorParams) {
|
extern "C" s32 GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum) {
|
||||||
return OTRGlobals::Instance->gRandomizer->GetRandomizedItemId(ogId, -1, sceneNum, actorParams);
|
return OTRGlobals::Instance->gRandomizer->GetRandomizedItemId(ogId, actorId, actorParams, sceneNum);
|
||||||
}
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
}
|
|
@ -76,9 +76,7 @@ void AudioMgr_CreateNextAudioBuffer(s16* samples, u32 num_samples);
|
||||||
int Controller_ShouldRumble(size_t i);
|
int Controller_ShouldRumble(size_t i);
|
||||||
void LoadItemLocations(const char* spoilerFileName);
|
void LoadItemLocations(const char* spoilerFileName);
|
||||||
void ParseItemLocations(const char* spoilerfilename);
|
void ParseItemLocations(const char* spoilerfilename);
|
||||||
s32 GetRandomizedItemId(GetItemID ogId, s16 sceneNum, s16 actorParams);
|
s32 GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum);
|
||||||
s32 GetRandomizedItemIdFromActor(GetItemID ogId, s16 actorId);
|
|
||||||
s32 GetRandomizedItemIdFromPosition(GetItemID ogId, s16 sceneNum, s16 actorParams, s32 homePosX, s32 homePosY, s32 homePosZ);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -692,7 +692,7 @@ void EnItem00_Init(Actor* thisx, GlobalContext* globalCtx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((getItemId != GI_NONE) && !Actor_HasParent(&this->actor, 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);
|
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 ((getItemId != GI_NONE) && !Actor_HasParent(&this->actor, globalCtx)) {
|
||||||
if (gSaveContext.n64ddFlag) {
|
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);
|
func_8002F554(&this->actor, globalCtx, getItemId);
|
||||||
}
|
}
|
||||||
|
@ -1325,7 +1325,8 @@ void EnItem00_DrawHeartPiece(EnItem00* this, GlobalContext* globalCtx) {
|
||||||
if (gSaveContext.n64ddFlag) {
|
if (gSaveContext.n64ddFlag) {
|
||||||
f32 mtxScale = 16.0f;
|
f32 mtxScale = 16.0f;
|
||||||
Matrix_Scale(mtxScale, mtxScale, mtxScale, MTXMODE_APPLY);
|
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 {
|
} else {
|
||||||
s32 pad;
|
s32 pad;
|
||||||
|
|
||||||
|
|
|
@ -424,7 +424,8 @@ void EnBox_WaitOpen(EnBox* this, GlobalContext* globalCtx) {
|
||||||
func_8002DBD0(&this->dyna.actor, &sp4C, &player->actor.world.pos);
|
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 &&
|
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)) {
|
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)) {
|
if (Flags_GetTreasure(globalCtx, this->dyna.actor.params & 0x1F)) {
|
||||||
EnBox_SetupAction(this, EnBox_Open);
|
EnBox_SetupAction(this, EnBox_Open);
|
||||||
|
|
|
@ -304,8 +304,8 @@ void func_80ABA654(EnNiwLady* this, GlobalContext* globalCtx) {
|
||||||
if (!(gSaveContext.itemGetInf[0] & 0x1000)) {
|
if (!(gSaveContext.itemGetInf[0] & 0x1000)) {
|
||||||
this->actor.parent = NULL;
|
this->actor.parent = NULL;
|
||||||
|
|
||||||
this->getItemId = GetRandomizedItemIdFromActor(GI_BOTTLE, this->actor.id);
|
this->getItemId = GetRandomizedItemId(GI_BOTTLE, this->actor.id, this->actor.params, globalCtx->sceneNum);
|
||||||
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
|
func_8002F434(&this->actor, globalCtx, this->getItemId, 100.0f, 50.0f);
|
||||||
this->actionFunc = func_80ABAC00;
|
this->actionFunc = func_80ABAC00;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -387,8 +387,9 @@ void func_80ABA9B8(EnNiwLady* this, GlobalContext* globalCtx) {
|
||||||
case 0:
|
case 0:
|
||||||
Message_CloseTextbox(globalCtx);
|
Message_CloseTextbox(globalCtx);
|
||||||
this->actor.parent = NULL;
|
this->actor.parent = NULL;
|
||||||
func_8002F434(&this->actor, globalCtx, GetRandomizedItemIdFromActor(GI_POCKET_EGG, this->actor.id), 200.0f,
|
s32 itemId =
|
||||||
100.0f);
|
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;
|
this->actionFunc = func_80ABAC00;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -440,8 +441,8 @@ void func_80ABAC00(EnNiwLady* this, GlobalContext* globalCtx) {
|
||||||
} else {
|
} else {
|
||||||
getItemId = this->getItemId;
|
getItemId = this->getItemId;
|
||||||
if (LINK_IS_ADULT) {
|
if (LINK_IS_ADULT) {
|
||||||
getItemId =
|
getItemId = !(gSaveContext.itemGetInf[2] & 0x1000)
|
||||||
!(gSaveContext.itemGetInf[2] & 0x1000) ? GetRandomizedItemIdFromActor(GI_POCKET_EGG, this->actor.id) : GI_COJIRO;
|
? GetRandomizedItemId(GI_POCKET_EGG, this->actor.id, this->actor.params, globalCtx->sceneNum) : GI_COJIRO;
|
||||||
}
|
}
|
||||||
func_8002F434(&this->actor, globalCtx, getItemId, 200.0f, 100.0f);
|
func_8002F434(&this->actor, globalCtx, getItemId, 200.0f, 100.0f);
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ void ItemBHeart_Update(Actor* thisx, GlobalContext* globalCtx) {
|
||||||
Actor_Kill(&this->actor);
|
Actor_Kill(&this->actor);
|
||||||
} else {
|
} else {
|
||||||
if (gSaveContext.n64ddFlag) {
|
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);
|
func_8002F434(&this->actor, globalCtx, getItemId, 30.0f, 40.0f);
|
||||||
} else {
|
} else {
|
||||||
func_8002F434(&this->actor, globalCtx, GI_HEART_CONTAINER_2, 30.0f, 40.0f);
|
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) {
|
if (gSaveContext.n64ddFlag) {
|
||||||
GetItem_Draw(globalCtx,
|
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 {
|
} else {
|
||||||
if (flag) {
|
if (flag) {
|
||||||
func_80093D84(globalCtx->state.gfxCtx);
|
func_80093D84(globalCtx->state.gfxCtx);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue