Rework Get Item Table to be more flexible for adding custom items (#1050)

* Adds ItemTableManager class.

* Implements new getItem table in game.

* Adds rando item table and way to differentiate tables in GetItemEntry.

* Adds rough ability to differentiate between rando and vanilla items.merge stashed changes from before develop-zhora merge

* Change ItemTableID to be uint16_t so we can use ModIndex for it.

* Should fix switch build

* Should fix switch build pt 2

* Adds new files to CMakeLists.

* Implements fixes for competing getItem calls.

* Correctly renders freestanding items

Particle effects are probably broken, need to fix them still, I pretty
much know how I would do that.

* Fixed Particle effects in the new getItem system.

* Fixes item fanfares

* Partially fixes Ice Traps

Obtaining a freestanding Ice Trap causes link to slide forward
and receiving one from an NPC plays the sound effect and damage
animation but doesn't freeze link.

* Some more partial ice trap fixing that wasn't pushed earlier

* Removes unused function override

* Replaces ::find with ::at and adds exception handling

* Removes some commented out code.

* Refactors rando's GetItemEntry array into two arrays.

One array is for the vanilla items that don't have GetItemEntries in
vanilla, the other is for rando exclusive items. They are stored in
separate arrays before getting added to the table so that we can apply
different modIndexes. The items in the first table have are handled
by the vanilla Item_Give, and the second table needed a custom
`Randomizer_Item_Give` function.

* Renames, relocates, and implements ModIndex enum.

* Removes now unused ItemIDs and GetItemIDs

Also makes all the necessary changes to other code that was still
using them indirectly through the GI to GID map that was removed.
There's quite a lot of changes here and I haven't had time to test them
yet.

* Re-implements GIMESSAGE_UNTRANSLATED as macro

* Removes commented out function.

* Throws exception if an invalid itemID is used

Addresses https://github.com/HarbourMasters/Shipwright/pull/1050#discussion_r943694857

* Removes ARRAY_SIZE in favor of ARRAY_COUNT

ARRAY_COUNT already exists in `macros.h`, I just didn't find it before.

Addresses https://github.com/HarbourMasters/Shipwright/pull/1050#discussion_r943153833

* Inverts CheckContainsRandoItem to CheckContainsVanillaItem.

Addresses https://github.com/HarbourMasters/Shipwright/pull/1050#discussion_r940895135

* Cleanup, bugfixes, removing the `- 1`s from `z_player.c`

* Fixes some funky formatting that got committed earlier.

* Adds else if to added fanfare sound cases.

Addresses https://github.com/HarbourMasters/Shipwright/pull/1050#discussion_r940112924 and https://github.com/HarbourMasters/Shipwright/pull/1050#discussion_r940113492

* Extends GetItemEntry to include getItemId

Also adapts some existing calls for both the entry and the id to only
get the entry.

* Extends GetItemEntry to include GID.

This allows for using it later when drawing freestanding items.

Addresses https://github.com/HarbourMasters/Shipwright/pull/1050#discussion_r943168136

* Rando-specific items use new textId again.

This got lost when merging develop-zhora in because I didn't have custom
messages merged when I started this.

* Sets global modIndex to MOD_NONE on scene load

Fixes a crash when buying items in shops due to them
not triggering the rando code that normally sets these items.
May have also been crashing vanilla playthroughs.

* Realized I had the bgm conditions wrong.

* Fixes "static drops" (i.e. sticks from withered babas)

* Fixes LACS/Prelude situation... again.

* Fixes too many arguments error.

Not sure why this didn't fail to build on Windows before.

* Fixes Link's Pocket items.

* Simplifies sram init for rando-specific items

* Fixes issues with approaching bottleable items.

* Fixes Ruto's Letter.

It was accidentally getting classified as a rando item.

* Should re-fix freestanding ice traps

* Makes freestanding items set player->getItemEntry.

This prevents freestanding items from setting the global modIndex.
This is part of a larger transition that needs to happen to switch
to setting getItemEntries for all of the rando items. This prevents
some things that set getItemId of GI_MAX from granting a Fire Medallion
when the global modIndex is MOD_RANDOMIZER.

* Makes sure we aren't using getItemEntry when not randoed.

* Replace Randomizer_GetRandomizedItemId with Randomizer_GetRandomizedItem and Randomizer_GetItemIdFromKnownCheck with Randomizer_GetItemFromKnownCheck

* Introduce some new methods and migrate most actors to them

* Fixes ocarina game skull kids to set player->getItemEntry

* Sets `z_en_box.c` to set `player->getItemEntry`

* Fix logical errors and migrate most of the rest of the rando checks to GiveItemEntryFromActor

* Use GiveItemEntryFromActorWithFixedRange in item00

* Fixes Anju to set player->getItemEntry.

* Add a few missing cases

* Additional fix for Skull Kid

* Fixes vanilla ice traps and randomized ice smoke

* Fixes rendering of treasure chest game items.

* Removes unused `Randomizer_GetItemIdFromGetItemId`.

* Cleans up an if statement for item00.

* Cleans up another if statement in item00

* This should fix a bug with the Gerudo Archery minigame.

I wasn't able to get the bug to happen after making this change.

* Documents our new GiveItemEntry fuctions.

* Uses more descriptive type name for ItemIDs for creating custom messages.

* Fixes potential issue with if statement.

* Fixes missed type change.

Co-authored-by: Garrett Cox <garrettjcox@gmail.com>
This commit is contained in:
Christopher Leggett 2022-08-23 20:11:38 -04:00 committed by GitHub
parent ed1708508a
commit 168e84498f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
64 changed files with 1439 additions and 1087 deletions

View file

@ -1956,14 +1956,25 @@ u32 Actor_HasParent(Actor* actor, GlobalContext* globalCtx) {
}
}
s32 GiveItemWithoutActor(GlobalContext* globalCtx, s32 getItemId) {
/**
* Uses the given `GetItemEntry` to prepare the player to receive an item via the animation
* where Link holds an item over his head. This function does not require an actor for giving
* the player an item, instead setting the player as their own interactRangeActor and getItemDirection.
*
* \param globalCtx the Global Context
* \param getItemEntry the GetItemEntry for the item you want the player to receive.
* \return true if the player can receive an item, false if not.
*/
s32 GiveItemEntryWithoutActor(GlobalContext* globalCtx, GetItemEntry getItemEntry) {
Player* player = GET_PLAYER(globalCtx);
if (!(player->stateFlags1 & 0x3C7080) && Player_GetExplosiveHeld(player) < 0) {
if (((player->heldActor != NULL) && (getItemId > GI_NONE) && (getItemId < GI_MAX)) ||
if (((player->heldActor != NULL) && ((getItemEntry.getItemId > GI_NONE) && (getItemEntry.getItemId < GI_MAX)) ||
(gSaveContext.n64ddFlag && (getItemEntry.getItemId > RG_NONE) && (getItemEntry.getItemId < RG_MAX))) ||
(!(player->stateFlags1 & 0x20000800))) {
if ((getItemId != GI_NONE)) {
player->getItemId = getItemId;
if ((getItemEntry.getItemId != GI_NONE)) {
player->getItemEntry = getItemEntry;
player->getItemId = getItemEntry.getItemId;
player->interactRangeActor = &player->actor;
player->getItemDirection = player->actor.shape.rot.y;
return true;
@ -1974,12 +1985,69 @@ s32 GiveItemWithoutActor(GlobalContext* globalCtx, s32 getItemId) {
return false;
}
/**
* Uses the given `GetItemEntry` to prepare the player to receive an item via the animation
* where Link holds an item over his head. This uses data from the actor link is receiving
* the item from to set the player's interactRangeActor and getItemDirection. It also checks
* a range from which Link must be from said actor in order to receive the item.
*
* \param actor the actor link is receiving an item from. Will usually be a chest but can also
* be an npc.
* \param globalCtx the Global Context
* \param getItemEntry the GetItemEntry for the item you want the player to receive.
* \param xzRange the distance on the x and z axes that the player can be from the target
* actor to receive the item.
* \param yRange the distance on the y axis that the player can be from the target actor
* to receive the item.
* \return true if the player can receive an item, false if not.
*/
s32 GiveItemEntryFromActor(Actor* actor, GlobalContext* globalCtx, GetItemEntry getItemEntry, f32 xzRange, f32 yRange) {
Player* player = GET_PLAYER(globalCtx);
if (!(player->stateFlags1 & 0x3C7080) && Player_GetExplosiveHeld(player) < 0) {
if ((((player->heldActor != NULL) || (actor == player->targetActor)) &&
((!gSaveContext.n64ddFlag && ((getItemEntry.getItemId > GI_NONE) && (getItemEntry.getItemId < GI_MAX))) ||
(gSaveContext.n64ddFlag && ((getItemEntry.getItemId > RG_NONE) && (getItemEntry.getItemId < RG_MAX))))) ||
(!(player->stateFlags1 & 0x20000800))) {
if ((actor->xzDistToPlayer < xzRange) && (fabsf(actor->yDistToPlayer) < yRange)) {
s16 yawDiff = actor->yawTowardsPlayer - player->actor.shape.rot.y;
s32 absYawDiff = ABS(yawDiff);
if ((getItemEntry.getItemId != GI_NONE) || (player->getItemDirection < absYawDiff)) {
player->getItemEntry = getItemEntry;
player->getItemId = getItemEntry.getItemId;
player->interactRangeActor = actor;
player->getItemDirection = absYawDiff;
return true;
}
}
}
}
return false;
}
/**
* Uses the given `GetItemEntry` to prepare the player to receive an item via the animation
* where Link holds an item over his head. This is a wrapper function around `GiveItemEntryFromActor`
* that supplies a fixed xzRange of 50.0f and a fixed yRange of 10.0f.
*
* \param actor the target actor that link is receiving an item from.
* \param globalCtx the Global Context
* \param getItemEntry the GetItemEntry for the item you want the player to receive.
*/
void GiveItemEntryFromActorWithFixedRange(Actor* actor, GlobalContext* globalCtx, GetItemEntry getItemEntry) {
GiveItemEntryFromActor(actor, globalCtx, getItemEntry, 50.0f, 10.0f);
}
// TODO: Rename to GiveItemIdFromActor or similar
// If you're doing something for randomizer, you're probably looking for GiveItemEntryFromActor
s32 func_8002F434(Actor* actor, GlobalContext* globalCtx, s32 getItemId, f32 xzRange, f32 yRange) {
Player* player = GET_PLAYER(globalCtx);
if (!(player->stateFlags1 & 0x3C7080) && Player_GetExplosiveHeld(player) < 0) {
if ((((player->heldActor != NULL) || (actor == player->targetActor)) && (getItemId > GI_NONE) &&
(getItemId < GI_MAX)) ||
if ((((player->heldActor != NULL) || (actor == player->targetActor)) &&
((!gSaveContext.n64ddFlag && ((getItemId > GI_NONE) && (getItemId < GI_MAX))) || (gSaveContext.n64ddFlag && ((getItemId > RG_NONE) && (getItemId < RG_MAX))))) ||
(!(player->stateFlags1 & 0x20000800))) {
if ((actor->xzDistToPlayer < xzRange) && (fabsf(actor->yDistToPlayer) < yRange)) {
s16 yawDiff = actor->yawTowardsPlayer - player->actor.shape.rot.y;
@ -1998,6 +2066,8 @@ s32 func_8002F434(Actor* actor, GlobalContext* globalCtx, s32 getItemId, f32 xzR
return false;
}
// TODO: Rename to GiveItemIdFromActorWithFixedRange or similar
// If you're doing something for randomizer, you're probably looking for GiveItemEntryFromActorWithFixedRange
void func_8002F554(Actor* actor, GlobalContext* globalCtx, s32 getItemId) {
func_8002F434(actor, globalCtx, getItemId, 50.0f, 10.0f);
}
@ -5995,7 +6065,7 @@ s32 func_80038290(GlobalContext* globalCtx, Actor* actor, Vec3s* arg2, Vec3s* ar
return true;
}
s32 GetChestGameRandoGetItemId(s8 room, s16 ogDrawId, GlobalContext* globalCtx) {
GetItemEntry GetChestGameRandoGetItem(s8 room, s16 ogDrawId, GlobalContext* globalCtx) {
if (Randomizer_GetSettingValue(RSK_SHUFFLE_CHEST_MINIGAME)) {
// RANDOTODO update this logic when we implement keysanity
// because 3drando replaces the keys not the rupees
@ -6006,27 +6076,27 @@ s32 GetChestGameRandoGetItemId(s8 room, s16 ogDrawId, GlobalContext* globalCtx)
switch(room) {
case 1:
if(!Flags_GetCollectible(globalCtx, 0x1B)) {
return Randomizer_GetItemIdFromKnownCheck(RC_MARKET_TREASURE_CHEST_GAME_ITEM_1, GI_RUPEE_GREEN);
return Randomizer_GetItemFromKnownCheck(RC_MARKET_TREASURE_CHEST_GAME_ITEM_1, GI_RUPEE_GREEN);
}
break;
case 2:
if(!Flags_GetCollectible(globalCtx, 0x1C)) {
return Randomizer_GetItemIdFromKnownCheck(RC_MARKET_TREASURE_CHEST_GAME_ITEM_2, GI_RUPEE_GREEN);
return Randomizer_GetItemFromKnownCheck(RC_MARKET_TREASURE_CHEST_GAME_ITEM_2, GI_RUPEE_GREEN);
}
break;
case 3:
if(!Flags_GetCollectible(globalCtx, 0x1D)) {
return Randomizer_GetItemIdFromKnownCheck(RC_MARKET_TREASURE_CHEST_GAME_ITEM_3, GI_RUPEE_BLUE);
return Randomizer_GetItemFromKnownCheck(RC_MARKET_TREASURE_CHEST_GAME_ITEM_3, GI_RUPEE_BLUE);
}
break;
case 4:
if(!Flags_GetCollectible(globalCtx, 0x1E)) {
return Randomizer_GetItemIdFromKnownCheck(RC_MARKET_TREASURE_CHEST_GAME_ITEM_4, GI_RUPEE_BLUE);
return Randomizer_GetItemFromKnownCheck(RC_MARKET_TREASURE_CHEST_GAME_ITEM_4, GI_RUPEE_BLUE);
}
break;
case 5:
if(!Flags_GetCollectible(globalCtx, 0x1F)) {
return Randomizer_GetItemIdFromKnownCheck(RC_MARKET_TREASURE_CHEST_GAME_ITEM_5, GI_RUPEE_RED);
return Randomizer_GetItemFromKnownCheck(RC_MARKET_TREASURE_CHEST_GAME_ITEM_5, GI_RUPEE_RED);
}
break;
}
@ -6034,17 +6104,17 @@ s32 GetChestGameRandoGetItemId(s8 room, s16 ogDrawId, GlobalContext* globalCtx)
}
if(ogDrawId == GID_HEART_PIECE) {
return Randomizer_GetItemIdFromKnownCheck(RC_MARKET_TREASURE_CHEST_GAME_REWARD, GI_HEART_PIECE);
return Randomizer_GetItemFromKnownCheck(RC_MARKET_TREASURE_CHEST_GAME_REWARD, GI_HEART_PIECE);
}
return GI_NONE;
return (GetItemEntry)GET_ITEM_NONE;
}
s16 GetChestGameRandoGiDrawId(s8 room, s16 ogDrawId, GlobalContext* globalCtx) {
s32 randoGetItemId = GetChestGameRandoGetItemId(room, ogDrawId, globalCtx);
GetItemEntry randoGetItem = GetChestGameRandoGetItem(room, ogDrawId, globalCtx);
if(randoGetItemId != GI_NONE) {
return Randomizer_GetItemModelFromId(randoGetItemId);
if (randoGetItem.itemId != RG_NONE) {
return randoGetItem.gid;
}
return ogDrawId;

View file

@ -335,6 +335,7 @@ void EnItem00_Init(Actor* thisx, GlobalContext* globalCtx) {
f32 yOffset = 980.0f;
f32 shadowScale = 6.0f;
s32 getItemId = GI_NONE;
GetItemEntry getItem = (GetItemEntry)GET_ITEM_NONE;
s16 spawnParam8000 = this->actor.params & 0x8000;
s32 pad1;
@ -508,9 +509,15 @@ void EnItem00_Init(Actor* thisx, GlobalContext* globalCtx) {
break;
}
if ((gSaveContext.n64ddFlag || getItemId != GI_NONE) && !Actor_HasParent(&this->actor, globalCtx)) {
getItemId = Randomizer_GetRandomizedItemId(getItemId, this->actor.id, this->ogParams, globalCtx->sceneNum);
func_8002F554(&this->actor, globalCtx, getItemId);
if (!Actor_HasParent(&this->actor, globalCtx)) {
if (!gSaveContext.n64ddFlag) {
if (getItemId != GI_NONE) {
func_8002F554(&this->actor, globalCtx, getItemId);
}
} else {
getItem = Randomizer_GetRandomizedItem(getItemId, this->actor.id, this->ogParams, globalCtx->sceneNum);
GiveItemEntryFromActorWithFixedRange(&this->actor, globalCtx, getItem);
}
}
EnItem00_SetupAction(this, func_8001E5C8);
@ -666,10 +673,15 @@ void func_8001E304(EnItem00* this, GlobalContext* globalCtx) {
void func_8001E5C8(EnItem00* this, GlobalContext* globalCtx) {
Player* player = GET_PLAYER(globalCtx);
if (this->getItemId != GI_NONE) {
if (!Actor_HasParent(&this->actor, globalCtx)) {
func_8002F434(&this->actor, globalCtx, this->getItemId, 50.0f, 80.0f);
if (!gSaveContext.n64ddFlag) {
func_8002F434(&this->actor, globalCtx, this->getItemId, 50.0f, 80.0f);
} else {
GetItemEntry getItemEntry =
Randomizer_GetRandomizedItem(this->getItemId, this->actor.id, this->ogParams, globalCtx->sceneNum);
GiveItemEntryFromActor(&this->actor, globalCtx, getItemEntry, 50.0f, 80.0f);
}
this->unk_15A++;
} else {
this->getItemId = GI_NONE;
@ -703,6 +715,7 @@ void EnItem00_Update(Actor* thisx, GlobalContext* globalCtx) {
s16* params;
Actor* dynaActor;
s32 getItemId = GI_NONE;
GetItemEntry getItem = (GetItemEntry)GET_ITEM_NONE;
s16 sp3A = 0;
s16 i;
u32* temp;
@ -883,10 +896,13 @@ void EnItem00_Update(Actor* thisx, GlobalContext* globalCtx) {
params = &this->actor.params;
if ((getItemId != GI_NONE) && !Actor_HasParent(&this->actor, globalCtx)) {
if (gSaveContext.n64ddFlag) {
getItemId = Randomizer_GetRandomizedItemId(getItemId, this->actor.id, this->ogParams, globalCtx->sceneNum);
if (!gSaveContext.n64ddFlag) {
func_8002F554(&this->actor, globalCtx, getItemId);
} else {
getItem = Randomizer_GetRandomizedItem(getItemId, this->actor.id, this->ogParams, globalCtx->sceneNum);
getItemId = getItem.getItemId;
GiveItemEntryFromActorWithFixedRange(&this->actor, globalCtx, getItem);
}
func_8002F554(&this->actor, globalCtx, getItemId);
}
switch (*params) {
@ -1214,38 +1230,56 @@ void EnItem00_Draw(Actor* thisx, GlobalContext* globalCtx) {
}
}
void EnItem00_CustomItemsParticles(Actor* Parent, GlobalContext* globalCtx, s16 getItemId) {
void EnItem00_CustomItemsParticles(Actor* Parent, GlobalContext* globalCtx, GetItemEntry giEntry) {
s16 color_slot;
switch (getItemId) {
case GI_MINUET_OF_FOREST:
case GI_SINGLE_MAGIC:
case GI_DOUBLE_MAGIC:
color_slot = 0;
switch (giEntry.modIndex) {
case MOD_NONE:
switch (giEntry.itemId) {
case ITEM_SONG_MINUET:
color_slot = 0;
break;
case ITEM_SONG_BOLERO:
color_slot = 1;
break;
case ITEM_SONG_SERENADE:
color_slot = 2;
break;
case ITEM_SONG_REQUIEM:
color_slot = 3;
break;
case ITEM_SONG_NOCTURNE:
color_slot = 4;
break;
case ITEM_SONG_PRELUDE:
color_slot = 5;
break;
case ITEM_STICK_UPGRADE_20:
case ITEM_STICK_UPGRADE_30:
color_slot = 6;
break;
case ITEM_NUT_UPGRADE_30:
case ITEM_NUT_UPGRADE_40:
color_slot = 7;
break;
default:
return;
}
break;
case GI_BOLERO_OF_FIRE:
case GI_DOUBLE_DEFENSE:
color_slot = 1;
break;
case GI_SERENADE_OF_WATER:
color_slot = 2;
break;
case GI_REQUIEM_OF_SPIRIT:
color_slot = 3;
break;
case GI_NOCTURNE_OF_SHADOW:
color_slot = 4;
break;
case GI_PRELUDE_OF_LIGHT:
color_slot = 5;
break;
case GI_STICK_UPGRADE_20:
case GI_STICK_UPGRADE_30:
color_slot = 6;
break;
case GI_NUT_UPGRADE_30:
case GI_NUT_UPGRADE_40:
color_slot = 7;
case MOD_RANDOMIZER:
switch (giEntry.itemId) {
case RG_MAGIC_SINGLE:
case RG_MAGIC_DOUBLE:
color_slot = 0;
break;
case RG_DOUBLE_DEFENSE:
color_slot = 1;
break;
default:
return;
}
break;
default:
return;
}
s16* colors[9][3] = {
@ -1323,12 +1357,10 @@ void EnItem00_DrawCollectible(EnItem00* this, GlobalContext* globalCtx) {
if (gSaveContext.n64ddFlag && (this->getItemId != GI_NONE || this->actor.params == ITEM00_SMALL_KEY)) {
f32 mtxScale = 16.0f;
Matrix_Scale(mtxScale, mtxScale, mtxScale, MTXMODE_APPLY);
s32 randoGetItemId = Randomizer_GetRandomizedItemId(this->getItemId, this->actor.id, this->ogParams, globalCtx->sceneNum);
if ((randoGetItemId >= GI_MINUET_OF_FOREST && randoGetItemId <= GI_DOUBLE_DEFENSE) ||
(randoGetItemId >= GI_STICK_UPGRADE_20 && randoGetItemId <= GI_NUT_UPGRADE_40)) {
EnItem00_CustomItemsParticles(&this->actor, globalCtx, randoGetItemId);
}
GetItem_Draw(globalCtx, Randomizer_GetItemModelFromId(randoGetItemId));
GetItemEntry randoGetItemEntry =
Randomizer_GetRandomizedItem(this->getItemId, this->actor.id, this->ogParams, globalCtx->sceneNum);
EnItem00_CustomItemsParticles(&this->actor, globalCtx, randoGetItemEntry);
GetItem_Draw(globalCtx, randoGetItemEntry.gid);
} else {
s32 texIndex = this->actor.params - 3;
@ -1384,12 +1416,10 @@ void EnItem00_DrawHeartPiece(EnItem00* this, GlobalContext* globalCtx) {
if (gSaveContext.n64ddFlag) {
f32 mtxScale = 16.0f;
Matrix_Scale(mtxScale, mtxScale, mtxScale, MTXMODE_APPLY);
s32 randoGetItemId = Randomizer_GetRandomizedItemId(GI_HEART_PIECE, this->actor.id, this->ogParams, globalCtx->sceneNum);
if ((randoGetItemId >= GI_MINUET_OF_FOREST && randoGetItemId <= GI_DOUBLE_DEFENSE) ||
(randoGetItemId >= GI_STICK_UPGRADE_20 && randoGetItemId <= GI_NUT_UPGRADE_40)) {
EnItem00_CustomItemsParticles(&this->actor, globalCtx, randoGetItemId);
}
GetItem_Draw(globalCtx, Randomizer_GetItemModelFromId(randoGetItemId));
GetItemEntry randoGetItemEntry =
Randomizer_GetRandomizedItem(GI_HEART_PIECE, this->actor.id, this->ogParams, globalCtx->sceneNum);
EnItem00_CustomItemsParticles(&this->actor, globalCtx, randoGetItemEntry);
GetItem_Draw(globalCtx, randoGetItemEntry.gid);
} else {
s32 pad;

View file

@ -1590,70 +1590,6 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) {
osSyncPrintf("item_get_setting=%d pt=%d z=%x\n", item, slot, gSaveContext.inventory.items[slot]);
osSyncPrintf(VT_RST);
if (item == ITEM_SINGLE_MAGIC) {
gSaveContext.magicAcquired = true;
gSaveContext.unk_13F6 = 0x30;
Magic_Fill(globalCtx);
return ITEM_NONE;
} else if (item == ITEM_DOUBLE_MAGIC) {
if (!gSaveContext.magicAcquired) {
gSaveContext.magicAcquired = true;
}
gSaveContext.doubleMagic = true;
gSaveContext.unk_13F6 = 0x60;
gSaveContext.magicLevel = 0;
Magic_Fill(globalCtx);
return ITEM_NONE;
}
if (item == ITEM_DOUBLE_DEFENSE) {
gSaveContext.doubleDefense = true;
gSaveContext.inventory.defenseHearts = 20;
gSaveContext.healthAccumulator = 0x140;
return ITEM_NONE;
}
if (item >= ITEM_BOTTLE_WITH_RED_POTION &&
item <= ITEM_BOTTLE_WITH_BIG_POE) {
temp = SLOT(ITEM_BOTTLE);
for (i = 0; i < 4; i++) {
if (gSaveContext.inventory.items[temp + i] == ITEM_NONE) {
switch (item) {
case ITEM_BOTTLE_WITH_RED_POTION:
item = ITEM_POTION_RED;
break;
case ITEM_BOTTLE_WITH_GREEN_POTION:
item = ITEM_POTION_GREEN;
break;
case ITEM_BOTTLE_WITH_BLUE_POTION:
item = ITEM_POTION_BLUE;
break;
case ITEM_BOTTLE_WITH_FAIRY:
item = ITEM_FAIRY;
break;
case ITEM_BOTTLE_WITH_FISH:
item = ITEM_FISH;
break;
case ITEM_BOTTLE_WITH_BLUE_FIRE:
item = ITEM_BLUE_FIRE;
break;
case ITEM_BOTTLE_WITH_BUGS:
item = ITEM_BUG;
break;
case ITEM_BOTTLE_WITH_POE:
item = ITEM_POE;
break;
case ITEM_BOTTLE_WITH_BIG_POE:
item = ITEM_BIG_POE;
break;
}
gSaveContext.inventory.items[temp + i] = item;
return ITEM_NONE;
}
}
}
if ((item >= ITEM_MEDALLION_FOREST) && (item <= ITEM_MEDALLION_LIGHT)) {
gSaveContext.inventory.questItems |= gBitFlags[item - ITEM_MEDALLION_FOREST + QUEST_MEDALLION_FOREST];
@ -2237,6 +2173,84 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) {
return temp;
}
u16 Randomizer_Item_Give(GlobalContext* globalCtx, GetItemEntry giEntry) {
uint16_t item = giEntry.itemId;
uint16_t temp;
uint16_t i;
uint16_t slot;
slot = SLOT(item);
if (item == RG_MAGIC_SINGLE) {
gSaveContext.magicAcquired = true;
gSaveContext.unk_13F6 = 0x30;
Magic_Fill(globalCtx);
return RG_NONE;
} else if (item == RG_MAGIC_DOUBLE) {
if (!gSaveContext.magicAcquired) {
gSaveContext.magicAcquired = true;
}
gSaveContext.doubleMagic = true;
gSaveContext.unk_13F6 = 0x60;
gSaveContext.magicLevel = 0;
Magic_Fill(globalCtx);
return RG_NONE;
}
if (item == RG_DOUBLE_DEFENSE) {
gSaveContext.doubleDefense = true;
gSaveContext.inventory.defenseHearts = 20;
gSaveContext.healthAccumulator = 0x140;
return RG_NONE;
}
if (item >= RG_BOTTLE_WITH_RED_POTION && item <= RG_BOTTLE_WITH_BIG_POE) {
temp = SLOT(ITEM_BOTTLE);
for (i = 0; i < 4; i++) {
if (gSaveContext.inventory.items[temp + i] == ITEM_NONE) {
switch (item) {
case RG_BOTTLE_WITH_RED_POTION:
item = ITEM_POTION_RED;
break;
case RG_BOTTLE_WITH_GREEN_POTION:
item = ITEM_POTION_GREEN;
break;
case RG_BOTTLE_WITH_BLUE_POTION:
item = ITEM_POTION_BLUE;
break;
case RG_BOTTLE_WITH_FAIRY:
item = ITEM_FAIRY;
break;
case RG_BOTTLE_WITH_FISH:
item = ITEM_FISH;
break;
case RG_BOTTLE_WITH_BLUE_FIRE:
item = ITEM_BLUE_FIRE;
break;
case RG_BOTTLE_WITH_BUGS:
item = ITEM_BUG;
break;
case RG_BOTTLE_WITH_POE:
item = ITEM_POE;
break;
case RG_BOTTLE_WITH_BIG_POE:
item = ITEM_BIG_POE;
break;
}
gSaveContext.inventory.items[temp + i] = item;
return ITEM_NONE;
}
}
}
temp = gSaveContext.inventory.items[slot];
osSyncPrintf("Item_Register(%d)=%d %d\n", slot, item, temp);
INV_CONTENT(item) = item;
return temp;
}
u8 Item_CheckObtainability(u8 item) {
s16 i;
s16 slot = SLOT(item);

View file

@ -201,8 +201,8 @@ void GivePlayerRandoRewardSongOfTime(GlobalContext* globalCtx, RandomizerCheck c
if (gSaveContext.entranceIndex == 0x050F && player != NULL && !Player_InBlockingCsMode(globalCtx, player) &&
!Flags_GetTreasure(globalCtx, 0x1F) && gSaveContext.nextTransition == 0xFF) {
GetItemID getItemId = Randomizer_GetItemIdFromKnownCheck(check, GI_SONG_OF_TIME);
GiveItemWithoutActor(globalCtx, getItemId);
GetItemEntry getItemEntry = Randomizer_GetItemFromKnownCheck(check, RG_SONG_OF_TIME);
GiveItemEntryWithoutActor(globalCtx, getItemEntry);
player->pendingFlag.flagID = 0x1F;
player->pendingFlag.flagType = FLAG_SCENE_TREASURE;
}
@ -216,8 +216,8 @@ void GivePlayerRandoRewardNocturne(GlobalContext* globalCtx, RandomizerCheck che
gSaveContext.entranceIndex == 0x0195) && LINK_IS_ADULT && CHECK_QUEST_ITEM(QUEST_MEDALLION_FOREST) &&
CHECK_QUEST_ITEM(QUEST_MEDALLION_FIRE) && CHECK_QUEST_ITEM(QUEST_MEDALLION_WATER) && player != NULL &&
!Player_InBlockingCsMode(globalCtx, player) && !Flags_GetEventChkInf(0xAA)) {
GetItemID getItemId = Randomizer_GetItemIdFromKnownCheck(check, GI_NOCTURNE_OF_SHADOW);
GiveItemWithoutActor(globalCtx, getItemId);
GetItemEntry getItemEntry = Randomizer_GetItemFromKnownCheck(check, RG_NOCTURNE_OF_SHADOW);
GiveItemEntryWithoutActor(globalCtx, getItemEntry);
Flags_SetEventChkInf(0xAA);
}
}
@ -228,8 +228,8 @@ void GivePlayerRandoRewardRequiem(GlobalContext* globalCtx, RandomizerCheck chec
if ((gSaveContext.gameMode == 0) && (gSaveContext.respawnFlag <= 0) && (gSaveContext.cutsceneIndex < 0xFFF0)) {
if ((gSaveContext.entranceIndex == 0x01E1) && !Flags_GetEventChkInf(0xAC) && player != NULL &&
!Player_InBlockingCsMode(globalCtx, player)) {
GetItemID getItemId = Randomizer_GetItemIdFromKnownCheck(check, GI_SONG_OF_TIME);
GiveItemWithoutActor(globalCtx, getItemId);
GetItemEntry getItemEntry = Randomizer_GetItemFromKnownCheck(check, RG_SONG_OF_TIME);
GiveItemEntryWithoutActor(globalCtx, getItemEntry);
Flags_SetEventChkInf(0xAC);
}
}
@ -242,21 +242,22 @@ void GivePlayerRandoRewardZeldaLightArrowsGift(GlobalContext* globalCtx, Randomi
(gEntranceTable[((void)0, gSaveContext.entranceIndex)].scene == SCENE_TOKINOMA) &&
!Flags_GetTreasure(globalCtx, 0x1E) && player != NULL && !Player_InBlockingCsMode(globalCtx, player) &&
globalCtx->sceneLoadFlag == 0) {
GetItemID getItemId = Randomizer_GetItemIdFromKnownCheck(check, GI_ARROW_LIGHT);
GiveItemWithoutActor(globalCtx, getItemId);
player->pendingFlag.flagID = 0x1E;
player->pendingFlag.flagType = FLAG_SCENE_TREASURE;
GetItemEntry getItem = Randomizer_GetItemFromKnownCheck(check, GI_ARROW_LIGHT);
if (player->pendingFlag.flagType == FLAG_NONE && GiveItemEntryWithoutActor(globalCtx, getItem)) {
player->pendingFlag.flagID = 0x1E;
player->pendingFlag.flagType = FLAG_SCENE_TREASURE;
}
}
}
void GivePlayerRandoRewardSariaGift(GlobalContext* globalCtx, RandomizerCheck check) {
Player* player = GET_PLAYER(globalCtx);
if (gSaveContext.entranceIndex == 0x05E0) {
GetItemID getItemId = Randomizer_GetItemIdFromKnownCheck(check, GI_ZELDAS_LULLABY);
GetItemEntry getItemEntry = Randomizer_GetItemFromKnownCheck(check, RG_ZELDAS_LULLABY);
if ((!Flags_GetEventChkInf(0xC1) || (player->getItemId == getItemId && getItemId != GI_ICE_TRAP)) &&
if ((!Flags_GetEventChkInf(0xC1) || (player->getItemId == getItemEntry.getItemId && getItemEntry.getItemId != GI_ICE_TRAP)) &&
player != NULL && !Player_InBlockingCsMode(globalCtx, player)) {
GiveItemWithoutActor(globalCtx, getItemId);
GiveItemEntryWithoutActor(globalCtx, getItemEntry);
Flags_SetEventChkInf(0xC1);
}
}

View file

@ -2,6 +2,7 @@
#include "vt.h"
#include <string.h>
#include <soh/Enhancements/randomizer/randomizerTypes.h>
#define NUM_DUNGEONS 8
#define NUM_TRIALS 6
@ -306,11 +307,11 @@ void GiveLinkDekuNutUpgrade(GetItemID giid) {
}
void GiveLinkMagic(GetItemID giid) {
if (giid == GI_SINGLE_MAGIC) {
if (giid == RG_MAGIC_SINGLE) {
gSaveContext.magicLevel = 1;
gSaveContext.magicAcquired = true;
gSaveContext.doubleMagic = false;
} else if (giid == GI_DOUBLE_MAGIC) {
} else if (giid == RG_MAGIC_DOUBLE) {
gSaveContext.magicLevel = 2;
gSaveContext.magicAcquired = true;
gSaveContext.doubleMagic = true;
@ -326,40 +327,40 @@ void GiveLinkSong(GetItemID getItemId) {
uint32_t bitMask;
switch (getItemId) {
case GI_ZELDAS_LULLABY:
case RG_ZELDAS_LULLABY:
bitMask = 1 << QUEST_SONG_LULLABY;
break;
case GI_SUNS_SONG:
case RG_SUNS_SONG:
bitMask = 1 << QUEST_SONG_SUN;
break;
case GI_EPONAS_SONG:
case RG_EPONAS_SONG:
bitMask = 1 << QUEST_SONG_EPONA;
break;
case GI_SONG_OF_STORMS:
case RG_SONG_OF_STORMS:
bitMask = 1 << QUEST_SONG_STORMS;
break;
case GI_SONG_OF_TIME:
case RG_SONG_OF_TIME:
bitMask = 1 << QUEST_SONG_TIME;
break;
case GI_SARIAS_SONG:
case RG_SARIAS_SONG:
bitMask = 1 << QUEST_SONG_SARIA;
break;
case GI_MINUET_OF_FOREST:
case RG_MINUET_OF_FOREST:
bitMask = 1 << QUEST_SONG_MINUET;
break;
case GI_BOLERO_OF_FIRE:
case RG_BOLERO_OF_FIRE:
bitMask = 1 << QUEST_SONG_BOLERO;
break;
case GI_SERENADE_OF_WATER:
case RG_SERENADE_OF_WATER:
bitMask = 1 << QUEST_SONG_SERENADE;
break;
case GI_NOCTURNE_OF_SHADOW:
case RG_NOCTURNE_OF_SHADOW:
bitMask = 1 << QUEST_SONG_NOCTURNE;
break;
case GI_REQUIEM_OF_SPIRIT:
case RG_REQUIEM_OF_SPIRIT:
bitMask = 1 << QUEST_SONG_REQUIEM;
break;
case GI_PRELUDE_OF_LIGHT:
case RG_PRELUDE_OF_LIGHT:
bitMask = 1 << QUEST_SONG_PRELUDE;
break;
}
@ -367,43 +368,43 @@ void GiveLinkSong(GetItemID getItemId) {
gSaveContext.inventory.questItems |= bitMask;
}
void GiveLinkDungeonReward(GetItemID getItemId) {
void GiveLinkDungeonReward(uint16_t getItemId) {
s16 item;
u8 medallion = 0;
switch (getItemId) {
case GI_MEDALLION_FOREST:
case RG_FOREST_MEDALLION:
item = ITEM_MEDALLION_FOREST;
medallion = 1;
break;
case GI_MEDALLION_FIRE:
case RG_FIRE_MEDALLION:
item = ITEM_MEDALLION_FIRE;
medallion = 1;
break;
case GI_MEDALLION_WATER:
case RG_WATER_MEDALLION:
item = ITEM_MEDALLION_WATER;
medallion = 1;
break;
case GI_MEDALLION_SHADOW:
case RG_SHADOW_MEDALLION:
item = ITEM_MEDALLION_SHADOW;
medallion = 1;
break;
case GI_MEDALLION_SPIRIT:
case RG_SPIRIT_MEDALLION:
item = ITEM_MEDALLION_SPIRIT;
medallion = 1;
break;
case GI_MEDALLION_LIGHT:
case RG_LIGHT_MEDALLION:
item = ITEM_MEDALLION_LIGHT;
medallion = 1;
break;
case GI_STONE_KOKIRI:
case RG_KOKIRI_EMERALD:
item = ITEM_KOKIRI_EMERALD;
break;
case GI_STONE_GORON:
case RG_GORON_RUBY:
item = ITEM_GORON_RUBY;
break;
case GI_STONE_ZORA:
case RG_ZORA_SAPPHIRE:
item = ITEM_ZORA_SAPPHIRE;
break;
}
@ -416,9 +417,9 @@ void GiveLinkDungeonReward(GetItemID getItemId) {
}
void GiveLinksPocketMedallion() {
GetItemID getItemId = Randomizer_GetItemIdFromKnownCheck(RC_LINKS_POCKET, RG_NONE);
GetItemEntry getItemEntry = Randomizer_GetItemFromKnownCheck(RC_LINKS_POCKET, RG_NONE);
GiveLinkDungeonReward(getItemId);
GiveLinkDungeonReward(getItemEntry.getItemId);
}
/**
@ -696,95 +697,71 @@ void Sram_InitSave(FileChooseContext* fileChooseCtx) {
}
if(Randomizer_GetSettingValue(RSK_SKIP_CHILD_ZELDA)) {
s32 giid = Randomizer_GetItemIdFromKnownCheck(RC_SONG_FROM_IMPA, GI_ZELDAS_LULLABY);
if(giid >= GI_ZELDAS_LULLABY && giid <= GI_PRELUDE_OF_LIGHT) {
GiveLinkSong(giid);
} else if (giid == GI_RUPEE_GREEN ||
giid == GI_RUPEE_BLUE ||
giid == GI_RUPEE_RED ||
giid == GI_RUPEE_PURPLE ||
giid == GI_RUPEE_GOLD) {
GiveLinkRupeesByGetItemId(giid);
} else if (giid == GI_BOMBCHUS_10 ||
giid == GI_BOMBCHUS_5 ||
giid == GI_BOMBCHUS_20) {
GiveLinkBombchus(giid);
} else if (giid == GI_STICKS_1 ||
giid == GI_STICKS_5 ||
giid == GI_STICKS_10) {
GiveLinkDekuSticksByGetItemId(giid);
} else if (giid == GI_NUTS_5 ||
giid == GI_NUTS_10) {
GiveLinkDekuNutsByGetItemId(giid);
} else if (giid == GI_BEAN) {
GiveLinkBeans();
} else if (giid >= GI_MEDALLION_LIGHT && giid <= GI_STONE_ZORA) {
GiveLinkDungeonReward(giid);
} else if (giid == GI_SWORD_KOKIRI) {
GiveLinkKokiriSword();
} else if (giid == GI_SWORD_BGS) {
GiveLinkBiggoronSword();
} else if (giid == GI_SWORD_KNIFE) {
GiveLinkGiantsKnife();
} else if (giid == GI_SHIELD_DEKU) {
GiveLinkDekuShield();
} else if (giid == GI_SHIELD_HYLIAN) {
GiveLinkHylianShield();
} else if (giid == GI_SHIELD_MIRROR) {
GiveLinkMirrorShield();
} else if (giid == GI_TUNIC_GORON) {
GiveLinkGoronTunic();
} else if (giid == GI_TUNIC_ZORA) {
GiveLinkZoraTunic();
} else if (giid == GI_BOOTS_IRON) {
GiveLinkIronBoots();
} else if (giid == GI_BOOTS_HOVER) {
GiveLinkHoverBoots();
} else if (giid == GI_SLINGSHOT ||
giid == GI_BULLET_BAG_40 ||
giid == GI_BULLET_BAG_50) {
GiveLinkBulletBagUpgrade(giid);
} else if (giid == GI_BOW ||
giid == GI_QUIVER_40 ||
giid == GI_QUIVER_50) {
GiveLinkQuiverUpgrade(giid);
} else if (giid == GI_BOMB_BAG_20 ||
giid == GI_BOMB_BAG_30 ||
giid == GI_BOMB_BAG_40) {
GiveLinkBombBagUpgrade(giid);
} else if (giid == GI_BRACELET ||
giid == GI_GAUNTLETS_SILVER ||
giid == GI_GAUNTLETS_GOLD) {
GiveLinkStrengthUpgrade(giid);
} else if (giid == GI_SCALE_SILVER ||
giid == GI_SCALE_GOLD) {
GiveLinkScaleUpgrade(giid);
} else if (giid == GI_WALLET_ADULT ||
giid == GI_WALLET_GIANT) {
GiveLinkWalletUpgrade(giid);
} else if (giid == GI_STONE_OF_AGONY) {
GiveLinkStoneOfAgony();
} else if (giid == GI_GERUDO_CARD) {
GiveLinkGerudoCard();
} else if (giid == GI_HEART_PIECE) {
GiveLinkPieceOfHeart();
} else if (giid == GI_HEART_CONTAINER) {
GiveLinkHeartContainer();
} else if (giid == GI_STICK_UPGRADE_20 ||
giid == GI_STICK_UPGRADE_30) {
GiveLinkDekuStickUpgrade(giid);
} else if (giid == GI_NUT_UPGRADE_30 ||
giid == GI_NUT_UPGRADE_40) {
GiveLinkDekuNutUpgrade(giid);
} else if (giid == GI_SINGLE_MAGIC ||
giid == GI_DOUBLE_MAGIC) {
GiveLinkMagic(giid);
} else if (giid == GI_DOUBLE_DEFENSE) {
GiveLinkDoubleDefense();
} else {
s32 iid = Randomizer_GetItemIDFromGetItemID(giid);
if (iid != -1) INV_CONTENT(iid) = iid;
GetItemEntry getItem = Randomizer_GetItemFromKnownCheck(RC_SONG_FROM_IMPA, RG_ZELDAS_LULLABY);
s32 giid = getItem.getItemId;
if (getItem.modIndex == MOD_NONE) {
if (giid == GI_RUPEE_GREEN || giid == GI_RUPEE_BLUE || giid == GI_RUPEE_RED ||
giid == GI_RUPEE_PURPLE || giid == GI_RUPEE_GOLD) {
GiveLinkRupeesByGetItemId(giid);
} else if (giid == GI_BOMBCHUS_10 || giid == GI_BOMBCHUS_5 || giid == GI_BOMBCHUS_20) {
GiveLinkBombchus(giid);
} else if (giid == GI_STICKS_1 || giid == GI_STICKS_5 || giid == GI_STICKS_10) {
GiveLinkDekuSticksByGetItemId(giid);
} else if (giid == GI_NUTS_5 || giid == GI_NUTS_10) {
GiveLinkDekuNutsByGetItemId(giid);
} else if (giid == GI_BEAN) {
GiveLinkBeans();
} else if (giid == GI_SWORD_KOKIRI) {
GiveLinkKokiriSword();
} else if (giid == GI_SWORD_BGS) {
GiveLinkBiggoronSword();
} else if (giid == GI_SWORD_KNIFE) {
GiveLinkGiantsKnife();
} else if (giid == GI_SHIELD_DEKU) {
GiveLinkDekuShield();
} else if (giid == GI_SHIELD_HYLIAN) {
GiveLinkHylianShield();
} else if (giid == GI_SHIELD_MIRROR) {
GiveLinkMirrorShield();
} else if (giid == GI_TUNIC_GORON) {
GiveLinkGoronTunic();
} else if (giid == GI_TUNIC_ZORA) {
GiveLinkZoraTunic();
} else if (giid == GI_BOOTS_IRON) {
GiveLinkIronBoots();
} else if (giid == GI_BOOTS_HOVER) {
GiveLinkHoverBoots();
} else if (giid == GI_SLINGSHOT || giid == GI_BULLET_BAG_40 || giid == GI_BULLET_BAG_50) {
GiveLinkBulletBagUpgrade(giid);
} else if (giid == GI_BOW || giid == GI_QUIVER_40 || giid == GI_QUIVER_50) {
GiveLinkQuiverUpgrade(giid);
} else if (giid == GI_BOMB_BAG_20 || giid == GI_BOMB_BAG_30 || giid == GI_BOMB_BAG_40) {
GiveLinkBombBagUpgrade(giid);
} else if (giid == GI_BRACELET || giid == GI_GAUNTLETS_SILVER || giid == GI_GAUNTLETS_GOLD) {
GiveLinkStrengthUpgrade(giid);
} else if (giid == GI_SCALE_SILVER || giid == GI_SCALE_GOLD) {
GiveLinkScaleUpgrade(giid);
} else if (giid == GI_WALLET_ADULT || giid == GI_WALLET_GIANT) {
GiveLinkWalletUpgrade(giid);
} else if (giid == GI_STONE_OF_AGONY) {
GiveLinkStoneOfAgony();
} else if (giid == GI_GERUDO_CARD) {
GiveLinkGerudoCard();
} else if (giid == GI_HEART_PIECE) {
GiveLinkPieceOfHeart();
} else if (giid == GI_HEART_CONTAINER) {
GiveLinkHeartContainer();
} else if (giid == GI_STICK_UPGRADE_20 || giid == GI_STICK_UPGRADE_30) {
GiveLinkDekuStickUpgrade(giid);
} else if (giid == GI_NUT_UPGRADE_30 || giid == GI_NUT_UPGRADE_40) {
GiveLinkDekuNutUpgrade(giid);
} else {
s32 iid = getItem.itemId;
if (iid != -1) INV_CONTENT(iid) = iid;
}
} else if (getItem.modIndex == MOD_RANDOMIZER) {
Randomizer_Item_Give(NULL, getItem);
}
// malon/talon back at ranch