Files
st/src/000_Second/Item/ItemManager.cpp
T
Yanis 530fcd8c07 Decompile overlay 24 (Part 2) (#66)
* remove scratch links

* UnkAdventureModeSystem1 OK

* UnkStruct_ov024_020d8694_024 OK

* UnkTitleCardSystem1_024 99%

* UnkTitleCardSystem1_024 OK

* fix regressions

* title card vfunc_08 oddity

* tools: make build.ninja deterministic and delink when objdiff rebuild-on-change

* clean up link node mess

* UnkStruct_020d8698_024 24%

* UnkStruct_020d8698_024 49%

* UnkStruct_020d8698_024 65%

* fix build issues

* UnkStruct_020d8698_024 92%

* UnkStruct_020d8698_024 OK

* delink data_ov024_020d8694 symbol

* tools: revert previous objdiff change and reduce ds-rom logs on objdiff
2026-05-24 17:20:48 +02:00

266 lines
6.4 KiB
C++

#include "Item/ItemManager.hpp"
#include "Unknown/UnkStruct_020d8698.hpp"
#include "global.h"
const u8 gQuiverCapacities[UpgradeCapacity_Max] = {
CAPACITY_QUIVER_TIER_1,
CAPACITY_QUIVER_TIER_2,
CAPACITY_QUIVER_TIER_3,
};
const u8 gBombBagCapacities[UpgradeCapacity_Max] = {
CAPACITY_BOMB_BAG_TIER_1,
CAPACITY_BOMB_BAG_TIER_2,
CAPACITY_BOMB_BAG_TIER_3,
};
ARM void ItemManager::SetFlag(ItemFlag itemFlag) {
SET_FLAG(this->mFlags, itemFlag);
}
ARM void ItemManager::ClearFlag(ItemFlag itemFlag) {
UNSET_FLAG(this->mFlags, itemFlag);
}
ARM bool ItemManager::HasRecruitUniform() {
return GET_FLAG(this->mFlags, ItemFlag_RecruitUniform) && (this->mUnk_12 & 1);
}
ARM unk32 ItemManager::func_ov000_020a86a4() {
if (GET_FLAG(this->mFlags, ItemFlag_AncientShield) && (this->mUnk_12 & 2)) {
return 1;
}
if (GET_FLAG(this->mFlags, ItemFlag_Shield)) {
return 0;
}
return -1;
}
ARM u32 ItemManager::GetItemAmount(ItemFlag itemFlag) {
bool canUse = GET_FLAG(this->mFlags, itemFlag);
switch (itemFlag) {
case ItemFlag_Bow:
return canUse ? this->mArrowAmount : 0;
case ItemFlag_Bombs:
return canUse ? this->mBombAmount : 0;
default:
break;
}
return canUse;
}
ARM u8 ItemManager::GetQuiverCapacity() {
if (GET_FLAG(this->mFlags, ItemFlag_Bow) == 0) {
return 0;
}
return gQuiverCapacities[this->mQuiverCapacity];
}
ARM u8 ItemManager::GetBombBagCapacity() {
if (GET_FLAG(this->mFlags, ItemFlag_Bombs) == 0) {
return 0;
}
return gBombBagCapacities[this->mBombBagCapacity];
}
ARM void ItemManager::GiveRupees(s32 amount, bool param2, bool param3) {
u16 prevNumRupees = this->mNumRupees;
s32 newAmount = this->mNumRupees + amount;
if (newAmount > 9999) {
newAmount = 9999;
} else if (newAmount < 0) {
newAmount = 0;
}
this->mNumRupees = newAmount;
if (param3) {
data_ov024_020d8698->func_ov024_020cd368(param2 && prevNumRupees != this->mNumRupees, true);
}
}
ARM void ItemManager::GiveSmallKeys(s32 amount) {
s32 newAmount = this->mKeyAmount + amount;
if (newAmount > MAX_KEYS) {
newAmount = MAX_KEYS;
} else if (newAmount < 0) {
newAmount = 0;
}
this->mKeyAmount = newAmount;
}
ARM void ItemManager::GiveArrows(s32 amount) {
s32 maxArrows = this->GetQuiverCapacity();
s32 newAmount = this->mArrowAmount + amount;
if (newAmount > maxArrows) {
newAmount = maxArrows;
} else if (newAmount < 0) {
newAmount = 0;
}
this->mArrowAmount = newAmount;
}
ARM void ItemManager::GiveBombs(s32 amount) {
s32 maxBombs = this->GetBombBagCapacity();
s32 newAmount = this->mBombAmount + amount;
if (newAmount > maxBombs) {
newAmount = maxBombs;
} else if (newAmount < 0) {
newAmount = 0;
}
this->mBombAmount = newAmount;
}
ARM bool ItemManager::TryEquipForcedItem() {
if (this->mForcedItem != ItemFlag_None) {
this->mEquippedItem = this->mForcedItem;
this->mForcedItem = ItemFlag_None;
data_ov024_020d8698->func_ov024_020cd458(this->mEquippedItem, false);
return true;
}
return false;
}
ARM void ItemManager::GivePotion(PotionType type) {
switch (type) {
case PotionType_Red:
case PotionType_Purple:
case PotionType_Yellow:
for (u32 i = 0; i < ARRAY_LEN(this->mPotions); i++) {
if (this->mPotions[i] == PotionType_None) {
this->mPotions[i] = type;
break;
}
}
break;
default:
break;
}
}
ARM bool ItemManager::HasPotion() {
for (u32 i = 0; i < ARRAY_LEN(this->mPotions); i++) {
if (this->mPotions[i] != PotionType_None) {
return true;
}
}
return false;
}
ARM bool ItemManager::HasPurplePotion() {
for (u32 i = 0; i < ARRAY_LEN(this->mPotions); i++) {
if (this->mPotions[i] == PotionType_Purple) {
return true;
}
}
return false;
}
ARM void ItemManager::RemovePurplePotion() {
for (s32 i = ARRAY_LEN(this->mPotions) - 1; i >= 0; i--) {
if (this->mPotions[i] == PotionType_Purple) {
this->mPotions[i] = PotionType_None;
return;
}
}
}
ARM bool ItemManager::PotionSlotsFull() {
for (u32 i = 0; i < ARRAY_LEN(this->mPotions); i++) {
if (this->mPotions[i] == PotionType_None) {
return false;
}
}
return true;
}
ARM UnkStruct_ov000_020afc48 *ItemManager::func_ov000_020a8974(ItemFlag itemFlag) {
return &data_ov000_020afc48[itemFlag];
}
ARM ItemFlag ItemManager::GetEquippedItemFlag(ItemId itemId) {
ItemFlag itemFlag;
for (itemFlag = 0; itemFlag < ItemFlag_EQUIP_COUNT; itemFlag++) {
UnkStruct_ov000_020afc48 *pEquipItem = ItemManager::func_ov000_020a8974(itemFlag);
if (itemId == pEquipItem->mItemId) {
return itemFlag;
}
}
return ItemFlag_None;
}
THUMB void ItemManager::func_ov000_020a89bc() {
if (this->mUnk_20->mUnk_14.func_ov053_0213caf0() != 0) {
this->mUnk_24 = 0;
}
}
ARM bool ItemManager::func_ov000_020a89d4() {
if (this->mUnk_20 != NULL) {
return (this->mUnk_20->mUnk_14.mUnk_08 & 0xFFFF) != 0xFFFF;
}
return false;
}
ARM bool ItemManager::func_ov000_020a8a0c() {
if (this->mUnk_20 == NULL || this->mEquippedItem == ItemFlag_None ||
IS_ITEM_RESTRICTED(this->mItemRestrictions, this->mEquippedItem) || this->GetItemAmount(this->mEquippedItem) == 0) {
return false;
}
return this->mUnk_20->func_ov031_020db874(this->mEquippedItem);
}
ARM void ItemManager::func_ov000_020a8a5c() {
if (this->mUnk_20 == NULL) {
return;
}
this->mUnk_20->func_ov031_020db8cc();
}
ARM bool ItemManager::func_ov000_020a8a74() {
if (this->mUnk_20 == NULL) {
return false;
}
return this->mUnk_20->func_ov031_020db8f8();
}
ARM unk32 ItemManager::func_ov000_020a8a90() {
return this->mUnk_20 != NULL ? this->mUnk_20->mUnk_00 : 0;
}
ARM unk32 ItemManager::func_ov000_020a8aa4() {
return this->mUnk_20 != NULL ? this->mUnk_20->mUnk_04 : 0;
}
ARM unk32 ItemManager::func_ov000_020a8ab8() {
return this->mUnk_20 != NULL ? this->mUnk_20->mUnk_0C : 0;
}
ARM unk32 ItemManager::func_ov000_020a8acc() {
return this->mUnk_20 != NULL ? this->mUnk_20->mUnk_10 : 0;
}