Skip to content

Commit

Permalink
Include bottle modifiers.
Browse files Browse the repository at this point in the history
Users can now select bottles and the contents of said bottles, giving full inventory control!
  • Loading branch information
PhlexPlexico committed Jul 4, 2021
1 parent 391d73e commit 229f079
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 49 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"mprealsupport": "cpp",
"matrixfunctions": "cpp",
"vips8": "cpp",
"*.inc": "c"
"*.inc": "c",
"filesystem": "cpp"
}
}
9 changes: 5 additions & 4 deletions source/game/common_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ struct EquipmentData {
struct InventoryData {
std::array<ItemId, 24> items;
std::array<ItemId, 24> masks;
std::array<u8, 24> item_counts;
std::array<ItemId, 7> bottles;
std::array<u8, 17> item_counts;
u8 field_48[24];
u8 field_60[24];
union InventoryCountRegister {
Expand Down Expand Up @@ -191,7 +192,7 @@ struct SaveData {
/// 0x0000 is midnight, 0x4000 is 6am, 0x8000 is noon, 0xc000 is 6pm.
u16 time;
u16 anonymous_3;
u16 anonymous_4;
u16 rupee_accumulator;
act::Player::Form player_form;
char anonymous_5;
char field_20;
Expand Down Expand Up @@ -235,7 +236,7 @@ struct SaveData {
int anonymous_58;
u8 gap11EC[36];
union SkulltulaRegister {
int raw;
u32 raw;

BitField<0, 16, int> swamp_count;
BitField<16, 16, int> ocean_count;
Expand Down Expand Up @@ -567,7 +568,7 @@ struct RespawnData {
u8 btn_i_can_use_item;
//u32 stored_mask_id_maybe;
u32 temp_collect_flags_maybe;
};
};
static_assert(sizeof(RespawnData) == 0x20);

enum class UsableButton : u8 {
Expand Down
30 changes: 30 additions & 0 deletions source/game/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,36 @@ bool HasOcarina() {
return items[0] == ItemId::Ocarina;
}

bool HasBottle(ItemId bottle_contents) {
const auto& bottles = GetCommonData().save.inventory.bottles;
return std::any_of(bottles.begin(), bottles.end(), [&](ItemId id) { return bottle_contents == id && bottle_contents != game::ItemId::None; });
}

void RemoveBottle(u32 bottle_index) {
auto& bottles = GetCommonData().save.inventory.bottles;
bottles[bottle_index] = ItemId::None;
}

void GiveBottle(u32 bottle_index, ItemId item_id) {
auto& bottles = GetCommonData().save.inventory.bottles;
game::EquipmentData& mappedEquips = GetCommonData().save.equipment;
if (mappedEquips.data[0].item_btn_y == bottles[bottle_index]) {
mappedEquips.data[0].item_btn_y = item_id;
} else if (mappedEquips.data[0].item_btn_x == bottles[bottle_index]) {
mappedEquips.data[0].item_btn_x = item_id;
} else if (mappedEquips.data[0].item_btn_i == bottles[bottle_index]) {
mappedEquips.data[0].item_btn_i = item_id;
} else if (mappedEquips.data[0].item_btn_ii == bottles[bottle_index]) {
mappedEquips.data[0].item_btn_ii = item_id;
}
bottles[bottle_index] = item_id;
// This pointer fills the next empty bottle.
// rst::util::GetPointer<int(game::GlobalContext*, game::ItemId)>(0x233BEC)(
// gctx, item_id);

}


bool HasItem(ItemId item_id) {
const auto& items = GetCommonData().save.inventory.items;
return std::any_of(items.begin(), items.end(), [&](ItemId id) { return item_id == id; });
Expand Down
3 changes: 3 additions & 0 deletions source/game/items.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ enum class MaskId : u8 {
};

bool HasOcarina();
bool HasBottle(ItemId bottle_contents);
void RemoveBottle(u32 bottle_index);
void GiveBottle(u32 bottle_index, ItemId item_id);
bool HasItem(ItemId item_id);
void GiveItem(ItemId item_id);
void RemoveItem(ItemId item_id);
Expand Down
70 changes: 26 additions & 44 deletions source/msys/inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


static game::ItemId SelectedBottle;
static u32 SelectedBottleIndex;
static u32 SelectedBottleItemIndex;
static u32 BottleNumber;

void RemoveItemFromButtons(game::ItemId item_id) {
Expand All @@ -28,7 +28,7 @@ static void DisableMenuToggles(ToggleMenu* menu) {
}

static void Inventory_ItemsMenuInit(void) {
//game::InventoryData& inventory = game::GetCommonData().save.inventory;
game::InventoryData& inventory = game::GetCommonData().save.inventory;
InventoryItemsMenu.items[(u32)game::ItemId::Ocarina].on = game::HasOcarina();
InventoryItemsMenu.items[(u32)game::ItemId::Arrow].on = game::HasItem(game::ItemId::Arrow);
InventoryItemsMenu.items[(u32)game::ItemId::FireArrow].on =
Expand Down Expand Up @@ -60,11 +60,9 @@ static void Inventory_ItemsMenuInit(void) {
InventoryItemsMenu.items[(u32)game::ItemId::GreatFairySword - 2].on =
game::HasItem(game::ItemId::GreatFairySword);
// Loop through bottles and check which ones we have.
// u32 numBottles =
// std::count_if(inventory.items.begin(), inventory.items.end(), game::ItemIsBottled);
// for (u32 i = 0; i < numBottles; i++) {
// InventoryItemsMenu.items[(u32)game::ItemId::Bottle + i - 3].on = true;
// }
for (u32 i = 15; i < 22; i++) {
InventoryItemsMenu.items[i].on = game::HasBottle(inventory.bottles[i-15]);
}
}

static void Inventory_SongsMenuInit(void) {
Expand Down Expand Up @@ -335,55 +333,38 @@ void Inventory_ItemsToggle(s32 selected) {
}

static void Inventory_BottlesMenuInit(void) {
//game::CommonData& cdata = game::GetCommonData();
for (u32 i = (u32)game::ItemId::RedPotion; i < (u32)game::ItemId::MoonTear; ++i) {
if (game::HasItem(SelectedBottle)) {
InventoryBottlesMenu.items[i].on = game::HasItem((game::ItemId)i);
// Can only have one thing in a selected bottle, no need to continue.
// break;
u32 curIndex = 0;
for (u32 i = (u32)game::ItemId::Bottle; i < (u32)game::ItemId::MoonTear; ++i) {
if (i == (u32)SelectedBottle) {
InventoryBottlesMenu.items[curIndex].on = 1;
} else {
InventoryBottlesMenu.items[curIndex].on = 0;
}
++curIndex;
}
InventoryBottlesMenu.items[BottleContents::None].on = !game::HasItem(SelectedBottle);
}

void Inventory_BottlesMenuFunc(s32 selected) {
game::CommonData& cdata = game::GetCommonData();
// Get the selected bottle.
u32 bottle_number = selected - 14;
u32 current_bottle = 0;
// Loop through to the specific selected bottle.
for (u32 i = cdata.save.inventory.items.size(); i < cdata.save.inventory.items.size(); i++) {
if (game::ItemIsBottled(cdata.save.inventory.items[i])) {
if (current_bottle != bottle_number) {
current_bottle++;
} else if (current_bottle == bottle_number) {
SelectedBottle = cdata.save.inventory.items[i];
SelectedBottleIndex = i;
BottleNumber = current_bottle;
break;
} else {
SelectedBottleIndex = 255;
SelectedBottle = game::ItemId::None;
}
}

}
BottleNumber = selected - 15;
SelectedBottle = cdata.save.inventory.bottles[BottleNumber];
SelectedBottleItemIndex = selected;
Inventory_BottlesMenuInit();
ToggleMenuShow(&InventoryBottlesMenu);
}

void Inventory_BottleSelect(s32 selected) {
game::CommonData& cdata = game::GetCommonData();
if (selected != BottleContents::None) { // selected a bottled content
cdata.save.inventory.items[SelectedBottleIndex] =
game::ItemId((u32)game::ItemId::Bottle + (u32)selected);
u32 newItem = (u32)game::ItemId::Bottle + (u32)selected;
DisableMenuToggles(&InventoryBottlesMenu);
if (selected != 22) { // selected a bottled content
game::GiveBottle(BottleNumber, (game::ItemId)newItem);
InventoryBottlesMenu.items[selected].on = 1;
InventoryItemsMenu.items[14 + BottleNumber].on = 1;
InventoryItemsMenu.items[SelectedBottleItemIndex].on = 1;
} else { // erase the bottle
cdata.save.inventory.items[SelectedBottleIndex] = game::ItemId::None;
DisableMenuToggles(&InventoryBottlesMenu);
InventoryBottlesMenu.items[InventoryBottlesMenu.nbItems - 1].on = 1;
InventoryItemsMenu.items[14 + BottleNumber].on = 0;
game::RemoveBottle(BottleNumber);
InventoryBottlesMenu.items[selected].on = 1;
InventoryItemsMenu.items[SelectedBottleItemIndex].on = 0;
}
}

Expand Down Expand Up @@ -569,7 +550,7 @@ Menu InventoryMenu = {

ToggleMenu InventoryItemsMenu = {
.title="Items",
.nbItems=15,
.nbItems=22,
.items= {
{.on=0, .title="Ocarina", .method = Inventory_ItemsToggle},
{.on=0, .title="Hero's Bow", .method = Inventory_ItemsToggle},
Expand All @@ -592,6 +573,7 @@ ToggleMenu InventoryItemsMenu = {
{.on=0, .title="Bottle #4", .method = Inventory_BottlesMenuFunc},
{.on=0, .title="Bottle #5", .method = Inventory_BottlesMenuFunc},
{.on=0, .title="Bottle #6", .method = Inventory_BottlesMenuFunc},
{.on=0, .title="Bottle #7", .method = Inventory_BottlesMenuFunc},
}
};

Expand Down Expand Up @@ -681,7 +663,7 @@ ToggleMenu InventoryShieldsMenu = {

ToggleMenu InventoryBottlesMenu = {
.title="Choose Bottle Contents",
.nbItems = 14,
.nbItems = 23,
.items={
{.on=0, .title="Empty Bottle", .method = Inventory_BottleSelect},
{.on=0, .title="Red Potion", .method = Inventory_BottleSelect},
Expand Down

0 comments on commit 229f079

Please sign in to comment.