Skip to content

Commit

Permalink
Merge 'Introduce a GetItemId enum' (#2119)
Browse files Browse the repository at this point in the history
# Conflicts:
#	ASM/c/item_table.c
  • Loading branch information
fenhl committed Sep 30, 2024
2 parents 0b80b50 + 253c738 commit 57be99e
Show file tree
Hide file tree
Showing 8 changed files with 1,273 additions and 603 deletions.
19 changes: 10 additions & 9 deletions ASM/c/get_items.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ void activate_override(override_t override) {
item_row_t* item_row = get_item_row(resolved_item_id);

active_override = override;
if (resolved_item_id == 0xCA) {
if (resolved_item_id == GI_TRIFORCE_PIECE) {
active_override_is_outgoing = 2; // Send to everyone
} else {
active_override_is_outgoing = override.value.base.player != PLAYER_ID;
Expand Down Expand Up @@ -353,7 +353,7 @@ void pop_ice_trap() {
override_t override = extended_savectx.incoming_queue[0];
override_key_t key = { .all = override.key.all };
override_value_base_t value = { .all = override.value.base.all };
if (value.item_id == 0x7C && value.player == PLAYER_ID) {
if (value.item_id == GI_ICE_TRAP && value.player == PLAYER_ID) {
push_pending_ice_trap();
pop_pending_item();
after_key_received(key);
Expand Down Expand Up @@ -406,9 +406,10 @@ void try_pending_item() {
if (override.key.all == 0) {
return;
}

uint16_t resolved_item_id = resolve_upgrades(override);
item_row_t* item_row = get_item_row(resolved_item_id);
if (override.value.base.item_id == 0xCA && override.value.base.player != PLAYER_ID) {
if (override.value.base.item_id == GI_TRIFORCE_PIECE && override.value.base.player != PLAYER_ID) {
call_effect_function(item_row);
pop_pending_item();
after_key_received(override.key);
Expand Down Expand Up @@ -502,10 +503,10 @@ void get_item(z64_actor_t* from_actor, z64_link_t* link, int8_t incoming_item_id

if (from_actor->actor_id == 0x0A) {
// Update chest contents
if (override.value.base.item_id == 0x7C && override.value.base.player == PLAYER_ID && (FAST_CHESTS || active_item_fast_chest) && z64_game.scene_index != 0x0010) {
if (override.value.base.item_id == GI_ICE_TRAP && override.value.base.player == PLAYER_ID && (FAST_CHESTS || active_item_fast_chest) && z64_game.scene_index != 0x0010) {
// Use ice trap base item ID to freeze Link as the chest opens rather than playing the full item get animation
//HACK: Not used in treasure box shop since it causes crashes that seem to be related to a timer being shared between ice traps and something in the minigame
base_item_id = 0x7C;
base_item_id = GI_ICE_TRAP;
}
from_actor->variable = (from_actor->variable & 0xF01F) | (base_item_id << 5);
}
Expand Down Expand Up @@ -885,7 +886,7 @@ int16_t get_override_drop_id(int16_t dropId) {

void dispatch_item(uint16_t resolved_item_id, uint8_t player, override_t* override, item_row_t* item_row) {
// Give the item to the right place
if (resolved_item_id == 0xCA) {
if (resolved_item_id == GI_TRIFORCE_PIECE) {
// Send triforce to everyone
push_outgoing_override(override);
call_effect_function(item_row);
Expand Down Expand Up @@ -991,7 +992,7 @@ void get_skulltula_token(z64_actor_t* token_actor) {
uint8_t player;
if (override.key.all == 0) {
// Give a skulltula token if there is no override
item_id = 0x5B;
item_id = GI_SKULL_TOKEN;
player = PLAYER_ID;
} else {
item_id = override.value.base.item_id;
Expand Down Expand Up @@ -1026,11 +1027,11 @@ void fairy_ocarina_getitem() {
override_t override = lookup_override_by_key(lw_gift_from_saria);
uint16_t resolved_item_id = resolve_upgrades(override);
switch (resolved_item_id) {
case 0x003B: { // Fairy Ocarina
case GI_OCARINA_FAIRY: { // Fairy Ocarina
z64_file.items[Z64_SLOT_OCARINA] = 0x07;
break;
}
case 0x000C: { // Ocarina of Time
case GI_OCARINA_OF_TIME: { // Ocarina of Time
z64_file.items[Z64_SLOT_OCARINA] = 0x08;
break;
}
Expand Down
626 changes: 316 additions & 310 deletions ASM/c/item_table.c

Large diffs are not rendered by default.

340 changes: 340 additions & 0 deletions ASM/c/item_table.h

Large diffs are not rendered by default.

101 changes: 51 additions & 50 deletions ASM/c/item_upgrades.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "item_upgrades.h"

#include "get_items.h"
#include "item_table.h"
#include "z64.h"

extern uint32_t FREE_BOMBCHU_DROPS;
Expand Down Expand Up @@ -36,128 +37,128 @@ uint16_t no_upgrade(z64_file_t* save, override_t override) {

uint16_t hookshot_upgrade(z64_file_t* save, override_t override) {
switch ((override.value.base.player == PLAYER_ID || !MW_PROGRESSIVE_ITEMS_ENABLE) ? save->items[Z64_SLOT_HOOKSHOT] : MW_PROGRESSIVE_ITEMS_STATE[override.value.base.player].hookshot) {
case ITEM_NONE: case 0: return 0x08; // Hookshot
default: return 0x09; // Longshot
case ITEM_NONE: case 0: return GI_HOOKSHOT; // Hookshot
default: return GI_LONGSHOT; // Longshot
}
}

uint16_t strength_upgrade(z64_file_t* save, override_t override) {
switch ((override.value.base.player == PLAYER_ID || !MW_PROGRESSIVE_ITEMS_ENABLE) ? save->strength_upgrade : MW_PROGRESSIVE_ITEMS_STATE[override.value.base.player].strength) {
case 0: return 0x54; // Goron Bracelet
case 1: return 0x35; // Silver Gauntlets
default: return 0x36; // Gold Gauntlets
case 0: return GI_GORONS_BRACELET; // Goron Bracelet
case 1: return GI_SILVER_GAUNTLETS; // Silver Gauntlets
default: return GI_GOLD_GAUNTLETS; // Gold Gauntlets
}
}

uint16_t bomb_bag_upgrade(z64_file_t* save, override_t override) {
switch ((override.value.base.player == PLAYER_ID || !MW_PROGRESSIVE_ITEMS_ENABLE) ? save->bomb_bag : MW_PROGRESSIVE_ITEMS_STATE[override.value.base.player].bomb_bag) {
case 0: return 0x32; // Bomb Bag
case 1: return 0x33; // Bigger Bomb Bag
default: return 0x34; // Biggest Bomb Bag
case 0: return GI_BOMB_BAG_20; // Bomb Bag
case 1: return GI_BOMB_BAG_30; // Bigger Bomb Bag
default: return GI_BOMB_BAG_40; // Biggest Bomb Bag
}
}

uint16_t bow_upgrade(z64_file_t* save, override_t override) {
switch ((override.value.base.player == PLAYER_ID || !MW_PROGRESSIVE_ITEMS_ENABLE) ? save->quiver : MW_PROGRESSIVE_ITEMS_STATE[override.value.base.player].bow) {
case 0: return 0x04; // Bow
case 1: return 0x30; // Big Quiver
default: return 0x31; // Biggest Quiver
case 0: return GI_BOW; // Bow
case 1: return GI_QUIVER_40; // Big Quiver
default: return GI_QUIVER_50; // Biggest Quiver
}
}

uint16_t slingshot_upgrade(z64_file_t* save, override_t override) {
switch ((override.value.base.player == PLAYER_ID || !MW_PROGRESSIVE_ITEMS_ENABLE) ? save->bullet_bag : MW_PROGRESSIVE_ITEMS_STATE[override.value.base.player].slingshot) {
case 0: return 0x05; // Slingshot
case 1: return 0x60; // Bullet Bag (40)
default: return 0x7B; // Bullet Bag (50)
case 0: return GI_SLINGSHOT; // Slingshot
case 1: return GI_BULLET_BAG_40; // Bullet Bag (40)
default: return GI_BULLET_BAG_50; // Bullet Bag (50)
}
}

uint16_t wallet_upgrade(z64_file_t* save, override_t override) {
switch ((override.value.base.player == PLAYER_ID || !MW_PROGRESSIVE_ITEMS_ENABLE) ? save->wallet : MW_PROGRESSIVE_ITEMS_STATE[override.value.base.player].wallet) {
case 0: return 0x45; // Adult's Wallet
case 1: return 0x46; // Giant's Wallet
default: return 0xC7; // Tycoon's Wallet
case 0: return GI_WALLET_ADULT; // Adult's Wallet
case 1: return GI_WALLET_GIANT; // Giant's Wallet
default: return GI_TYCOONS_WALLET; // Tycoon's Wallet
}
}

uint16_t scale_upgrade(z64_file_t* save, override_t override) {
switch ((override.value.base.player == PLAYER_ID || !MW_PROGRESSIVE_ITEMS_ENABLE) ? save->diving_upgrade : MW_PROGRESSIVE_ITEMS_STATE[override.value.base.player].scale) {
case 0: return 0x37; // Silver Scale
default: return 0x38; // Gold Scale
case 0: return GI_SCALE_SILVER; // Silver Scale
default: return GI_SCALE_GOLDEN; // Gold Scale
}
}

uint16_t nut_upgrade(z64_file_t* save, override_t override) {
switch ((override.value.base.player == PLAYER_ID || !MW_PROGRESSIVE_ITEMS_ENABLE) ? save->nut_upgrade : MW_PROGRESSIVE_ITEMS_STATE[override.value.base.player].nuts) {
case 0: return 0x79; // 30 Nuts. 0 and 1 are both starting capacity
case 1: return 0x79; // 30 Nuts
default: return 0x7A; // 40 Nuts
case 0: return GI_DEKU_NUT_UPGRADE_30; // 30 Nuts. 0 and 1 are both starting capacity
case 1: return GI_DEKU_NUT_UPGRADE_30; // 30 Nuts
default: return GI_DEKU_NUT_UPGRADE_40; // 40 Nuts
}
}

uint16_t stick_upgrade(z64_file_t* save, override_t override) {
switch ((override.value.base.player == PLAYER_ID || !MW_PROGRESSIVE_ITEMS_ENABLE) ? save->stick_upgrade : MW_PROGRESSIVE_ITEMS_STATE[override.value.base.player].sticks) {
case 0: return 0x77; // 20 Sticks. 0 and 1 are both starting capacity
case 1: return 0x77; // 20 Sticks
default: return 0x78; // 30 Sticks
case 0: return GI_DEKU_STICK_UPGRADE_20; // 20 Sticks. 0 and 1 are both starting capacity
case 1: return GI_DEKU_STICK_UPGRADE_20; // 20 Sticks
default: return GI_DEKU_STICK_UPGRADE_30; // 30 Sticks
}
}

uint16_t magic_upgrade(z64_file_t* save, override_t override) {
switch ((override.value.base.player == PLAYER_ID || !MW_PROGRESSIVE_ITEMS_ENABLE) ? save->magic_acquired : MW_PROGRESSIVE_ITEMS_STATE[override.value.base.player].magic) {
case 0: return 0xB9; // Single Magic
default: return 0xBA; // Double Magic
case 0: return GI_MAGIC_METER; // Single Magic
default: return GI_DOUBLE_MAGIC; // Double Magic
}
}

uint16_t bombchu_upgrade(z64_file_t* save, override_t override) {
if (save->items[Z64_SLOT_BOMBCHU] == ITEM_NONE) {
return 0x6B; // Bombchu 20 pack
return GI_BOMBCHUS_20; // Bombchu 20 pack
}
if (save->ammo[8] <= 5) {
return 0x03; // Bombchu 10 pack
return GI_BOMBCHUS_10; // Bombchu 10 pack
}
return 0x6A; // Bombchu 5 pack
return GI_BOMBCHUS_5; // Bombchu 5 pack
}

uint16_t ocarina_upgrade(z64_file_t* save, override_t override) {
switch ((override.value.base.player == PLAYER_ID || !MW_PROGRESSIVE_ITEMS_ENABLE) ? save->items[Z64_SLOT_OCARINA] : MW_PROGRESSIVE_ITEMS_STATE[override.value.base.player].ocarina) {
case ITEM_NONE: case 0: return 0x3B; // Fairy Ocarina
default: return 0x0C; // Ocarina of Time
case ITEM_NONE: case 0: return GI_OCARINA_FAIRY; // Fairy Ocarina
default: return GI_OCARINA_OF_TIME; // Ocarina of Time
}
}

uint16_t arrows_to_rupee(z64_file_t* save, override_t override) {
return ((override.value.base.player == PLAYER_ID || !MW_PROGRESSIVE_ITEMS_ENABLE) ? save->quiver : MW_PROGRESSIVE_ITEMS_STATE[override.value.base.player].bow) ? override.value.base.item_id : 0x4D; // Blue Rupee
return ((override.value.base.player == PLAYER_ID || !MW_PROGRESSIVE_ITEMS_ENABLE) ? save->quiver : MW_PROGRESSIVE_ITEMS_STATE[override.value.base.player].bow) ? override.value.base.item_id : GI_RUPEE_BLUE; // Blue Rupee
}

uint16_t bombs_to_rupee(z64_file_t* save, override_t override) {
return ((override.value.base.player == PLAYER_ID || !MW_PROGRESSIVE_ITEMS_ENABLE) ? save->bomb_bag : MW_PROGRESSIVE_ITEMS_STATE[override.value.base.player].bomb_bag) ? override.value.base.item_id : 0x4D; // Blue Rupee
return ((override.value.base.player == PLAYER_ID || !MW_PROGRESSIVE_ITEMS_ENABLE) ? save->bomb_bag : MW_PROGRESSIVE_ITEMS_STATE[override.value.base.player].bomb_bag) ? override.value.base.item_id : GI_RUPEE_BLUE; // Blue Rupee
}

uint16_t seeds_to_rupee(z64_file_t* save, override_t override) {
return ((override.value.base.player == PLAYER_ID || !MW_PROGRESSIVE_ITEMS_ENABLE) ? save->bullet_bag : MW_PROGRESSIVE_ITEMS_STATE[override.value.base.player].slingshot) ? override.value.base.item_id : 0x4D; // Blue Rupee
return ((override.value.base.player == PLAYER_ID || !MW_PROGRESSIVE_ITEMS_ENABLE) ? save->bullet_bag : MW_PROGRESSIVE_ITEMS_STATE[override.value.base.player].slingshot) ? override.value.base.item_id : GI_RUPEE_BLUE; // Blue Rupee
}

uint16_t letter_to_bottle(z64_file_t* save, override_t override) {
if (save->event_chk_inf[3] & 0x0008) // "King Zora Moved Aside"
return 0xC8; // Redundant Letter Bottle
return GI_REDUNDANT_LETTER_BOTTLE; // Redundant Letter Bottle
if (save->items[Z64_SLOT_BOTTLE_1] == 0x1B || save->items[Z64_SLOT_BOTTLE_2] == 0x1B
|| save->items[Z64_SLOT_BOTTLE_3] == 0x1B || save->items[Z64_SLOT_BOTTLE_4] == 0x1B)
return 0xC8; // Redundant Letter Bottle
return GI_REDUNDANT_LETTER_BOTTLE; // Redundant Letter Bottle
return override.value.base.item_id;
}

uint16_t health_upgrade_cap(z64_file_t* save, override_t override) {
if (save->energy_capacity >= 20 * 0x10) { // Already at capped health.
if (override.value.base.item_id == 0x76) { // Piece of Heart (Chest Game)
return 0x7F;
if (override.value.base.item_id == GI_HEART_PIECE_WIN) { // Piece of Heart (Chest Game)
return GI_CAPPED_PIECE_OF_HEART_CHESTGAME;
}
if (override.value.base.item_id == 0x3D) { // Heart Container
return 0x7E;
if (override.value.base.item_id == GI_HEART_CONTAINER) { // Heart Container
return GI_CAPPED_HEART_CONTAINER;
}
return 0x7D; // Piece of Heart / Fallthrough
return GI_CAPPED_PIECE_OF_HEART; // Piece of Heart / Fallthrough
}
return override.value.base.item_id;
}
Expand All @@ -168,9 +169,9 @@ uint16_t bombchus_to_bag(z64_file_t* save, override_t override) {
// tell player about chu drops. Different bags
// to preserve original chu refill count.
switch (override.value.base.item_id) {
case 0x03: return 0xD5; // 10 pack
case 0x6A: return 0xD6; // 5 pack
case 0x6B: return 0xD4; // 20 pack
case GI_BOMBCHUS_10: return GI_BOMBCHU_BAG_10; // 10 pack
case GI_BOMBCHUS_5: return GI_BOMBCHU_BAG_5; // 5 pack
case GI_BOMBCHUS_20: return GI_BOMBCHU_BAG_20; // 20 pack
}
} else {
// Subsequent chu packs stay as chu packs
Expand All @@ -181,15 +182,15 @@ uint16_t bombchus_to_bag(z64_file_t* save, override_t override) {
uint16_t upgrade_key_model(z64_file_t* save, override_t override) {
uint16_t item_id = override.value.base.item_id;
if (CUSTOM_KEY_MODELS) {
if (item_id == 0x0071) {
if (item_id == GI_DOOR_KEY) {
// Treasure Chest Game Key
return 0x0118;
} else if (item_id < 0x00AF) {
return GI_SMALL_KEY_MODEL_CHEST_GAME;
} else if (item_id < GI_SMALL_KEY_MIN) {
// Boss Keys
return item_id + 0x74;
return item_id + GI_BOSS_KEY_MODEL_MIN - GI_BOSS_KEY_TEMPLE;
} else {
// Small Keys
return item_id + 0x60;
return item_id + GI_SMALL_KEY_MODEL_MIN - GI_SMALL_KEY_MIN;
}
} else {
return item_id;
Expand Down
5 changes: 3 additions & 2 deletions ASM/c/objects.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "objects.h"
#include "z64.h"
#include "get_items.h"
#include "item_table.h"

extern uint8_t FIX_BROKEN_DROPS;

Expand All @@ -27,10 +28,10 @@ void enitem00_set_link_incoming_item_id(z64_actor_t* actor, z64_game_t* game, in
// Run z64_ActorOfferGetItem regardless of FIX_BROKEN_DROPS
if (!z64_ActorOfferGetItem(&this->actor, game, incoming_item_id, 50.0f, 10.0f) && FIX_BROKEN_DROPS) {
switch (incoming_item_id) {
case 0x43: // GI_MAGIC_SMALL
case GI_MAGIC_JAR_SMALL: // GI_MAGIC_SMALL
z64_GiveItem(game, Z64_ITEM_MAGIC_SMALL);
break;
case 0x44: // GI_MAGIC_LARGE
case GI_MAGIC_JAR_LARGE: // GI_MAGIC_LARGE
z64_GiveItem(game, Z64_ITEM_MAGIC_LARGE);
break;
}
Expand Down
Loading

0 comments on commit 57be99e

Please sign in to comment.