decent start on consolidation

This commit is contained in:
briaguya 2022-05-28 17:34:37 -04:00
commit 857a7d87aa
7 changed files with 45 additions and 41 deletions

View file

@ -545,12 +545,18 @@ void Randomizer::ParseItemLocations(std::string spoilerFileName) {
} }
} }
GetItemID Randomizer::GetItemFromActor(s16 actorId, GetItemID ogItemId) { s32 Randomizer::GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 sceneNum, s16 actorParams, s32 homePosX, s32 homePosY, s32 homePosZ) {
return GetItemFromGet(this->itemLocations[GetCheckFromActor(actorId, ogItemId)], ogItemId); if (actorId != -1) {
s32 itemId = GetItemFromActor(actorId, ogId);
return itemId;
} else {
s32 itemId = GetItemFromSceneParamsAndHomePos(sceneNum, actorParams, homePosX, homePosY, homePosZ, ogId);
return itemId;
}
} }
GetItemID Randomizer::GetItemFromSceneAndParams(s16 sceneNum, s16 actorParams, GetItemID ogItemId) { GetItemID Randomizer::GetItemFromActor(s16 actorId, GetItemID ogItemId) {
return GetItemFromGet(this->itemLocations[GetCheckFromSceneAndParams(sceneNum, actorParams)], ogItemId); return GetItemFromGet(this->itemLocations[GetCheckFromActor(actorId, ogItemId)], ogItemId);
} }
GetItemID Randomizer::GetItemFromSceneParamsAndHomePos(s16 sceneNum, s16 actorParams, s32 homePosX, s32 homePosY, s32 homePosZ, GetItemID ogItemId) { GetItemID Randomizer::GetItemFromSceneParamsAndHomePos(s16 sceneNum, s16 actorParams, s32 homePosX, s32 homePosY, s32 homePosZ, GetItemID ogItemId) {

View file

@ -12,7 +12,9 @@ class Randomizer {
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, GetItemID ogItemId);
RandomizerCheck GetCheckFromSceneAndParams(s16 sceneNum, s16 actorParams, s32 homePosX = 0, s32 homePosY = 0, s32 homePosZ = 0); 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);
public: public:
Randomizer(); Randomizer();
@ -20,9 +22,7 @@ class Randomizer {
void LoadItemLocations(); void LoadItemLocations();
void ParseItemLocations(std::string spoilerfilename); void ParseItemLocations(std::string spoilerfilename);
GetItemID GetItemFromActor(s16 actorId, GetItemID ogItemId); s32 GetRandomizedItemId(GetItemID ogId, s16 actorId = -1, s16 sceneNum = -1, s16 actorParams = -1, s32 homePosX = 0, s32 homePosY = 0, s32 homePosZ = 0);
GetItemID GetItemFromSceneAndParams(s16 sceneNum, s16 actorParams, GetItemID ogItemId);
GetItemID GetItemFromSceneParamsAndHomePos(s16 sceneNum, s16 actorParams, s32 homePosX, s32 homePosY, s32 homePosZ, GetItemID ogItemId);
}; };
#endif #endif

View file

@ -1004,15 +1004,28 @@ extern "C" void ParseItemLocations(const char* spoilerfilename) {
OTRGlobals::Instance->gRandomizer->ParseItemLocations(spoilerfilename); OTRGlobals::Instance->gRandomizer->ParseItemLocations(spoilerfilename);
} }
extern "C" GetItemID GetItemFromActor(s16 actorId, GetItemID ogItemId) { extern "C" s32 GetRandomizedItemId(GetItemID ogId, s16 sceneNum, s16 actorParams) {
return OTRGlobals::Instance->gRandomizer->GetItemFromActor(actorId, ogItemId); return OTRGlobals::Instance->gRandomizer->GetRandomizedItemId(ogId, -1, sceneNum, actorParams);
} }
extern "C" GetItemID GetItemFromSceneAndParams(s16 sceneNum, s16 actorParams, GetItemID ogItemId) { // the lack of optional params in c is frustrating
return OTRGlobals::Instance->gRandomizer->GetItemFromSceneAndParams(sceneNum, actorParams, ogItemId); 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) {
extern "C" GetItemID GetItemFromSceneParamsAndHomePos(s16 sceneNum, s16 actorParams, s32 homePosX, s32 homePosY, s32 homePosZ, GetItemID ogItemId) { return OTRGlobals::Instance->gRandomizer->GetRandomizedItemId(ogId, -1, sceneNum, actorParams, homePosX, homePosY, homePosZ);
return OTRGlobals::Instance->gRandomizer->GetItemFromSceneParamsAndHomePos(sceneNum, actorParams, homePosX, homePosY, homePosZ, ogItemId);
} }
// extern "C" GetItemID GetItemFromActor(s16 actorId, GetItemID ogItemId) {
// return OTRGlobals::Instance->gRandomizer->GetItemFromActor(actorId, ogItemId);
// }
// extern "C" GetItemID GetItemFromSceneAndParams(s16 sceneNum, s16 actorParams, GetItemID ogItemId) {
// return OTRGlobals::Instance->gRandomizer->GetItemFromSceneAndParams(sceneNum, actorParams, ogItemId);
// }
// // use an explicit (s32) cast on the position values from the Vec3f when calling
// extern "C" GetItemID GetItemFromSceneParamsAndHomePos(s16 sceneNum, s16 actorParams, s32 homePosX, s32 homePosY, s32 homePosZ, GetItemID ogItemId) {
// return OTRGlobals::Instance->gRandomizer->GetItemFromSceneParamsAndHomePos(sceneNum, actorParams, homePosX, homePosY, homePosZ, ogItemId);
// }

View file

@ -75,8 +75,10 @@ void AudioPlayer_Play(const uint8_t* buf, uint32_t len);
void AudioMgr_CreateNextAudioBuffer(s16* samples, u32 num_samples); void AudioMgr_CreateNextAudioBuffer(s16* samples, u32 num_samples);
int Controller_ShouldRumble(size_t i); int Controller_ShouldRumble(size_t i);
void ParseItemLocations(const char* spoilerfilename); void ParseItemLocations(const char* spoilerfilename);
GetItemID GetItemFromActor(s16 actorId, GetItemID ogItemId); s32 GetRandomizedItemId(GetItemID ogId, s16 sceneNum, s16 actorParams);
GetItemID GetItemFromSceneAndParams(s16 sceneNum, s16 actorParams, GetItemID ogItemId); s32 GetRandomizedItemIdFromActor(GetItemID ogId, s16 actorId);
s32 GetRandomizedItemIdFromPosition(GetItemID ogId, s16 sceneNum, s16 actorParams, s32 homePosX, s32 homePosY, s32 homePosZ);
#endif #endif
#endif #endif

View file

@ -332,11 +332,6 @@ void EnItem00_SetupAction(EnItem00* this, EnItem00ActionFunc actionFunc) {
this->actionFunc = actionFunc; this->actionFunc = actionFunc;
} }
s32 Item00_GetRandomizedItemId(EnItem00* this, s16 sceneNum, s16 actorParams) {
s32 itemId = GetItemFromSceneAndParams(sceneNum, this->actor.params, this->getItemId);
return itemId;
}
void EnItem00_Init(Actor* thisx, GlobalContext* globalCtx) { void EnItem00_Init(Actor* thisx, GlobalContext* globalCtx) {
EnItem00* this = (EnItem00*)thisx; EnItem00* this = (EnItem00*)thisx;
s32 pad; s32 pad;
@ -695,7 +690,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 = Item00_GetRandomizedItemId(this, globalCtx->sceneNum, this->actor.params); getItemId = GetRandomizedItemId(globalCtx->sceneNum, this->actor.params, this->getItemId);
func_8002F554(&this->actor, globalCtx, getItemId); func_8002F554(&this->actor, globalCtx, getItemId);
} }
@ -1056,7 +1051,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 = Item00_GetRandomizedItemId(this, globalCtx->sceneNum, this->actor.params); getItemId = GetRandomizedItemId(globalCtx->sceneNum, this->actor.params, this->getItemId);
} }
func_8002F554(&this->actor, globalCtx, getItemId); func_8002F554(&this->actor, globalCtx, getItemId);
} }

View file

@ -383,11 +383,6 @@ void EnBox_AppearAnimation(EnBox* this, GlobalContext* globalCtx) {
} }
} }
s32 EnBox_GetRandomizedItemId(s16 actorParams, s16 sceneNum) {
s32 itemId = GetItemFromSceneAndParams(sceneNum, actorParams, actorParams >> 5 & 0x7F);
return 0 - itemId;
}
/** /**
* Chest is ready to be open * Chest is ready to be open
*/ */
@ -429,8 +424,7 @@ 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, func_8002F554(&this->dyna.actor, globalCtx, GetRandomizedItemId(this->dyna.actor.params >> 5 & 0x7F, globalCtx->sceneNum, this->dyna.actor.params));
EnBox_GetRandomizedItemId(this->dyna.actor.params, globalCtx->sceneNum));
} }
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);

View file

@ -294,11 +294,6 @@ void func_80ABA244(EnNiwLady* this, GlobalContext* globalCtx) {
} }
} }
s32 NiwLady_GetRandomizedItemId(EnNiwLady* this, GetItemID ogId) {
s32 itemId = GetItemFromActor(this->actor.id, ogId);
return itemId;
}
void func_80ABA654(EnNiwLady* this, GlobalContext* globalCtx) { void func_80ABA654(EnNiwLady* this, GlobalContext* globalCtx) {
if (this->unk_262 == Message_GetState(&globalCtx->msgCtx) && Message_ShouldAdvance(globalCtx)) { if (this->unk_262 == Message_GetState(&globalCtx->msgCtx) && Message_ShouldAdvance(globalCtx)) {
Message_CloseTextbox(globalCtx); Message_CloseTextbox(globalCtx);
@ -309,9 +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 = NiwLady_GetRandomizedItemId(this, GI_BOTTLE); 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
func_8002F434(&this->actor, globalCtx, NiwLady_GetRandomizedItemId(this, GI_BOTTLE), 100.0f, 50.0f);
this->actionFunc = func_80ABAC00; this->actionFunc = func_80ABAC00;
return; return;
} }
@ -393,7 +387,7 @@ 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, NiwLady_GetRandomizedItemId(this, GI_POCKET_EGG), 200.0f, func_8002F434(&this->actor, globalCtx, GetRandomizedItemIdFromActor(GI_POCKET_EGG, this->actor.id), 200.0f,
100.0f); 100.0f);
this->actionFunc = func_80ABAC00; this->actionFunc = func_80ABAC00;
break; break;
@ -447,7 +441,7 @@ void func_80ABAC00(EnNiwLady* this, GlobalContext* globalCtx) {
getItemId = this->getItemId; getItemId = this->getItemId;
if (LINK_IS_ADULT) { if (LINK_IS_ADULT) {
getItemId = getItemId =
!(gSaveContext.itemGetInf[2] & 0x1000) ? NiwLady_GetRandomizedItemId(this, GI_POCKET_EGG) : GI_COJIRO; !(gSaveContext.itemGetInf[2] & 0x1000) ? GetRandomizedItemIdFromActor(GI_POCKET_EGG, this->actor.id) : GI_COJIRO;
} }
func_8002F434(&this->actor, globalCtx, getItemId, 200.0f, 100.0f); func_8002F434(&this->actor, globalCtx, getItemId, 200.0f, 100.0f);
} }