Skip to content

Commit

Permalink
Merge pull request #16 from MelonSpeedruns/melon-randomizer
Browse files Browse the repository at this point in the history
warps work
  • Loading branch information
briaguya-ai authored May 30, 2022
2 parents bf4f4d3 + 974fa03 commit b2dac6c
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 16 deletions.
14 changes: 13 additions & 1 deletion soh/include/z64item.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,16 @@ typedef enum {
/* 0x7B */ GI_BULLET_BAG_50,
/* 0x7C */ GI_ICE_TRAP, // freezes link when opened from a chest
/* 0x7D */ GI_TEXT_0, // no model appears over Link, shows text id 0 (pocket egg)
/* 0x7E */ GI_MAX
/* 0x7E */ GI_MEDALLION_LIGHT,
/* 0x7F */ GI_MEDALLION_FOREST,
/* 0x80 */ GI_MEDALLION_FIRE,
/* 0x81 */ GI_MEDALLION_WATER,
/* 0x82 */ GI_MEDALLION_SHADOW,
/* 0x83 */ GI_MEDALLION_SPIRIT,
/* 0x81 */ GI_STONE_KOKIRI,
/* 0x82 */ GI_STONE_GORON,
/* 0x83 */ GI_STONE_ZORA,
/* 0x84 */ GI_MAX
} GetItemID;

typedef enum {
Expand Down Expand Up @@ -501,6 +510,9 @@ typedef enum {
/* 0x72 */ GID_BULLET_BAG_50,
/* 0x73 */ GID_SWORD_KOKIRI,
/* 0x74 */ GID_SKULL_TOKEN_2,
/* 0x74 */ GID_KOKIRI_EMERALD,
/* 0x74 */ GID_GORON_RUBY,
/* 0x74 */ GID_ZORA_SAPPHIRE,
/* 0x75 */ GID_MAX
} GetItemDrawID;

Expand Down
2 changes: 1 addition & 1 deletion soh/include/z64player.h
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ typedef struct Player {
/* 0x042D */ s8 doorDirection;
/* 0x042E */ s16 doorTimer;
/* 0x0430 */ Actor* doorActor;
/* 0x0434 */ s8 getItemId;
/* 0x0434 */ s16 getItemId;
/* 0x0436 */ u16 getItemDirection;
/* 0x0438 */ Actor* interactRangeActor;
/* 0x043C */ s8 mountSide;
Expand Down
53 changes: 49 additions & 4 deletions soh/soh/Enhancements/randomizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,15 +782,26 @@ void Randomizer::ParseItemLocations(const char* spoilerFileName) {
}
}

s32 Randomizer::GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum) {
s32 itemId = GetItemFromActor(actorId, actorParams, sceneNum, ogId);
GetItemID Randomizer::GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum) {
GetItemID itemId = GetItemFromActor(actorId, actorParams, sceneNum, ogId);
return itemId;
}

GetItemID Randomizer::GetItemFromActor(s16 actorId, s16 actorParams, s16 sceneNum, GetItemID ogItemId) {
return GetItemFromGet(this->itemLocations[GetCheckFromActor(sceneNum, actorId, actorParams)], ogItemId);
}

ItemID Randomizer::GetItemIdFromGetItem(GetItemID getItemId) {
return GetItemFromGetItem(getItemId);
}

ItemID Randomizer::GetItemFromGetItem(GetItemID getItemId) {
switch (getItemId) {
case GI_MEDALLION_FIRE:
return ITEM_MEDALLION_FIRE;
}
}

GetItemID Randomizer::GetItemFromGet(RandomizerGet randoGet, GetItemID ogItemId) {
switch(randoGet) {
case UNKNOWN_GET:
Expand Down Expand Up @@ -984,6 +995,24 @@ GetItemID Randomizer::GetItemFromGet(RandomizerGet randoGet, GetItemID ogItemId)
return GI_ARROWS_LARGE;
case DEKU_STICK_1:
return GI_STICKS_1;
case LIGHT_MEDALLION:
return GI_MEDALLION_LIGHT;
case FOREST_MEDALLION:
return GI_MEDALLION_FOREST;
case FIRE_MEDALLION:
return GI_MEDALLION_FIRE;
case WATER_MEDALLION:
return GI_MEDALLION_WATER;
case SHADOW_MEDALLION:
return GI_MEDALLION_SHADOW;
case SPIRIT_MEDALLION:
return GI_MEDALLION_SPIRIT;
case KOKIRI_EMERALD:
return GI_STONE_KOKIRI;
case GORON_RUBY:
return GI_STONE_GORON;
case ZORA_SAPPHIRE:
return GI_STONE_ZORA;
default:
return ogItemId;
}
Expand All @@ -1005,9 +1034,25 @@ RandomizerCheck Randomizer::GetCheckFromActor(s16 sceneNum, s16 actorId, s16 act
}
}
case 17:
switch (actorParams) {
case 0x1F:
switch (actorId) {
case 95:
return DEKU_TREE_QUEEN_GOHMA_HEART;
case 93:
return QUEEN_GOHMA;
}
case 18:
switch (actorId) {
case 95:
return DODONGOS_CAVERN_KING_DODONGO_HEART;
case 93:
return KING_DODONGO;
}
case 19:
switch (actorId) {
case 95:
return JABU_JABUS_BELLY_BARINADE_HEART;
case 93:
return BARINADE;
}
case 40:
switch(actorParams) {
Expand Down
4 changes: 3 additions & 1 deletion soh/soh/Enhancements/randomizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class Randomizer {
s16 GetItemModelFromId(s16 itemId);
void LoadItemLocations(const char* spoilerFileName);
void ParseItemLocations(const char* spoilerFileName);
s32 GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum);
ItemID GetItemIdFromGetItem(GetItemID getItemId);
ItemID GetItemFromGetItem(GetItemID getItemId);
GetItemID GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum);
};

#endif
8 changes: 8 additions & 0 deletions soh/soh/OTRGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,4 +1038,12 @@ extern "C" void ParseItemLocations(const char* spoilerFileName) {

extern "C" s32 GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum) {
return OTRGlobals::Instance->gRandomizer->GetRandomizedItemId(ogId, actorId, actorParams, sceneNum);
}

extern "C" ItemID GetItemIdFromGetItem(GetItemID getItemId) {
return OTRGlobals::Instance->gRandomizer->GetItemIdFromGetItem(getItemId);
}

extern "C" ItemID GetItemFromGetItem(GetItemID getItemId) {
return OTRGlobals::Instance->gRandomizer->GetItemFromGetItem(getItemId);
}
3 changes: 3 additions & 0 deletions soh/soh/OTRGlobals.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ void AudioMgr_CreateNextAudioBuffer(s16* samples, u32 num_samples);
int Controller_ShouldRumble(size_t i);
void LoadItemLocations(const char* spoilerFileName);
void ParseItemLocations(const char* spoilerfilename);
ItemID GetItemIdFromGetItem(GetItemID getItemId);
s16 GetItemModelFromId(s16 itemId);
ItemID GetItemFromGetItem(GetItemID getItemId);
s32 GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum);

#endif
Expand Down
6 changes: 6 additions & 0 deletions soh/src/code/z_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,12 @@ DrawItemTableEntry sDrawItemTable[] = {
{ GetItem_DrawOpa0, { gGiKokiriSwordDL } },
// gold skulltula token, OBJECT_ST
{ GetItem_DrawSkullToken, { object_st_DL_004DB0, object_st_DL_004EB8 } },

{ GetItem_DrawOpa0Xlu1, { gGiKokiriEmeraldGemDL, gGiKokiriEmeraldSettingDL } },
// fire medallion, OBJECT_GI_MEDAL
{ GetItem_DrawOpa0Xlu1, { gGiGoronRubySettingDL, gGiGoronRubyGemDL } },
// water medallion, OBJECT_GI_MEDAL
{ GetItem_DrawOpa0Xlu1, { gGiZoraSapphireSettingDL, gGiZoraSapphireGemDL, } },
};

/**
Expand Down
53 changes: 46 additions & 7 deletions soh/src/overlays/actors/ovl_Door_Warp1/z_door_warp1.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,13 +461,40 @@ s32 DoorWarp1_PlayerInRange(DoorWarp1* this, GlobalContext* globalCtx) {
return ret;
}

u8 success = 0;

void GivePlayerRandoReward(DoorWarp1* this, Player* player, GlobalContext* globalCtx) {
GetItemID getItemId = GetRandomizedItemId(GI_NONE, this->actor.id, this->actor.params, globalCtx->sceneNum);

if (success && !Player_InBlockingCsMode(globalCtx, GET_PLAYER(globalCtx))) {
Audio_PlaySoundGeneral(NA_SE_EV_LINK_WARP, &player->actor.projectedPos, 4, &D_801333E0, &D_801333E0,
&D_801333E8);
OnePointCutscene_Init(globalCtx, 0x25E7, 999, &this->actor, MAIN_CAM);
func_8002DF54(globalCtx, &this->actor, 10);

player->unk_450.x = this->actor.world.pos.x;
player->unk_450.z = this->actor.world.pos.z;
this->unk_1B2 = 1;
DoorWarp1_SetupAction(this, DoorWarp1_ChildWarpOut);

success = 0;
} else if (!success) {
success = func_8002F434(&this->actor, globalCtx, getItemId, 10000.0f, 100.0f);
}
}

void DoorWarp1_ChildWarpIdle(DoorWarp1* this, GlobalContext* globalCtx) {
Player* player;

Audio_PlayActorSound2(&this->actor, NA_SE_EV_WARP_HOLE - SFX_FLAG);

if (DoorWarp1_PlayerInRange(this, globalCtx)) {
player = GET_PLAYER(globalCtx);

if (gSaveContext.n64ddFlag) {
GivePlayerRandoReward(this, player, globalCtx);
return;
}

Audio_PlaySoundGeneral(NA_SE_EV_LINK_WARP, &player->actor.projectedPos, 4, &D_801333E0, &D_801333E0,
&D_801333E8);
Expand Down Expand Up @@ -503,9 +530,14 @@ void DoorWarp1_ChildWarpOut(DoorWarp1* this, GlobalContext* globalCtx) {
if (globalCtx->sceneNum == SCENE_DDAN_BOSS) {
if (!Flags_GetEventChkInf(0x25)) {
Flags_SetEventChkInf(0x25);
Item_Give(globalCtx, ITEM_GORON_RUBY);
globalCtx->nextEntranceIndex = 0x13D;
gSaveContext.nextCutsceneIndex = 0xFFF1;
if (gSaveContext.n64ddFlag) {
globalCtx->nextEntranceIndex = 0x47A;
gSaveContext.nextCutsceneIndex = 0;
} else {
Item_Give(globalCtx, ITEM_GORON_RUBY);
globalCtx->nextEntranceIndex = 0x13D;
gSaveContext.nextCutsceneIndex = 0xFFF1;
}
} else {
globalCtx->nextEntranceIndex = 0x47A;
gSaveContext.nextCutsceneIndex = 0;
Expand All @@ -514,11 +546,11 @@ void DoorWarp1_ChildWarpOut(DoorWarp1* this, GlobalContext* globalCtx) {
if (!Flags_GetEventChkInf(7)) {
Flags_SetEventChkInf(7);
Flags_SetEventChkInf(9);
Item_Give(globalCtx, ITEM_KOKIRI_EMERALD);
if (gSaveContext.n64ddFlag) {
globalCtx->nextEntranceIndex = 0x0457;
gSaveContext.nextCutsceneIndex = 0;
} else {
Item_Give(globalCtx, ITEM_KOKIRI_EMERALD);
globalCtx->nextEntranceIndex = 0xEE;
gSaveContext.nextCutsceneIndex = 0xFFF1;
}
Expand Down Expand Up @@ -613,9 +645,16 @@ void DoorWarp1_RutoWarpOut(DoorWarp1* this, GlobalContext* globalCtx) {

if (this->warpTimer > sWarpTimerTarget && gSaveContext.nextCutsceneIndex == 0xFFEF) {
gSaveContext.eventChkInf[3] |= 0x80;
Item_Give(globalCtx, ITEM_ZORA_SAPPHIRE);
globalCtx->nextEntranceIndex = 0x10E;
gSaveContext.nextCutsceneIndex = 0xFFF0;

if (gSaveContext.n64ddFlag) {
globalCtx->nextEntranceIndex = 0x10E;
gSaveContext.nextCutsceneIndex = 0;
} else {
Item_Give(globalCtx, ITEM_ZORA_SAPPHIRE);
globalCtx->nextEntranceIndex = 0x10E;
gSaveContext.nextCutsceneIndex = 0xFFF0;
}

globalCtx->sceneLoadFlag = 0x14;
globalCtx->fadeTransition = 7;
}
Expand Down
2 changes: 1 addition & 1 deletion soh/src/overlays/actors/ovl_En_Cow/z_en_cow.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void func_809DF778(EnCow* this, GlobalContext* globalCtx) {
this->actor.parent = NULL;
this->actionFunc = func_809DF730;
} else {
func_8002F434(&this->actor, globalCtx, GI_MILK, 10000.0f, 100.0f);
func_8002F434(&this->actor, globalCtx, GID_MEDALLION_FIRE, 10000.0f, 100.0f);
}
}

Expand Down
2 changes: 1 addition & 1 deletion soh/src/overlays/actors/ovl_Item_B_Heart/z_item_b_heart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, this->actor.id, this->actor.params, globalCtx->sceneNum);
s32 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);
Expand Down
11 changes: 11 additions & 0 deletions soh/src/overlays/actors/ovl_player_actor/z_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,17 @@ static GetItemEntry sGetItemTable[] = {
GET_ITEM(ITEM_NUT_UPGRADE_30, OBJECT_GI_NUTS, GID_NUTS, 0xA7, 0x80, CHEST_ANIM_SHORT),
GET_ITEM(ITEM_NUT_UPGRADE_40, OBJECT_GI_NUTS, GID_NUTS, 0xA8, 0x80, CHEST_ANIM_SHORT),
GET_ITEM(ITEM_BULLET_BAG_50, OBJECT_GI_DEKUPOUCH, GID_BULLET_BAG_50, 0x6C, 0x80, CHEST_ANIM_LONG),
GET_ITEM(ITEM_ARROW_ICE, OBJECT_GI_M_ARROW, GID_ARROW_ICE, 0x3C, 0x80, CHEST_ANIM_LONG), // Ice Traps
GET_ITEM_NONE,
GET_ITEM(ITEM_MEDALLION_LIGHT, OBJECT_GI_MEDAL, GID_MEDALLION_LIGHT, 0x40, 0x80, CHEST_ANIM_LONG),
GET_ITEM(ITEM_MEDALLION_FOREST, OBJECT_GI_MEDAL, GID_MEDALLION_FOREST, 0x3E, 0x80, CHEST_ANIM_LONG),
GET_ITEM(ITEM_MEDALLION_FIRE, OBJECT_GI_MEDAL, GID_MEDALLION_FIRE, 0x3C, 0x80, CHEST_ANIM_LONG),
GET_ITEM(ITEM_MEDALLION_WATER, OBJECT_GI_MEDAL, GID_MEDALLION_WATER, 0x3D, 0x80, CHEST_ANIM_LONG),
GET_ITEM(ITEM_MEDALLION_SHADOW, OBJECT_GI_MEDAL, GID_MEDALLION_SHADOW, 0x41, 0x80, CHEST_ANIM_LONG),
GET_ITEM(ITEM_MEDALLION_SPIRIT, OBJECT_GI_MEDAL, GID_MEDALLION_SPIRIT, 0x3F, 0x80, CHEST_ANIM_LONG),
GET_ITEM(ITEM_KOKIRI_EMERALD, OBJECT_GI_COIN, GID_NCOIN_GREEN, 0x80, 0x80, CHEST_ANIM_LONG),
GET_ITEM(ITEM_GORON_RUBY, OBJECT_GI_COIN, GID_NCOIN_RED, 0x81, 0x80, CHEST_ANIM_LONG),
GET_ITEM(ITEM_ZORA_SAPPHIRE, OBJECT_GI_COIN, GID_NCOIN_BLUE, 0x82, 0x80, CHEST_ANIM_LONG),
GET_ITEM_NONE,
GET_ITEM_NONE,
};
Expand Down

0 comments on commit b2dac6c

Please sign in to comment.