diff --git a/config/RMCP01/module/symbols.txt b/config/RMCP01/module/symbols.txt index 246b810f..086f57c9 100644 --- a/config/RMCP01/module/symbols.txt +++ b/config/RMCP01/module/symbols.txt @@ -13887,7 +13887,7 @@ ItemSlotData_checkSpawnTimer = .text:0x807BB380; // type:function size:0xAC scop ItemSlotData_decideItem = .text:0x807BB42C; // type:function size:0x4A4 scope:global align:4 fn_1_2AB51C = .text:0x807BB8D0; // type:function size:0xEC ItemSlotData_resetLightningTimer = .text:0x807BB9BC; // type:function size:0xC scope:global align:4 -fn_1_2AB614 = .text:0x807BB9C8; // type:function size:0xC +ItemSlotData_resetBlueShellTimer = .text:0x807BB9C8; // type:function size:0xC scope:global align:4 ItemSlotData_resetBlooperTimer = .text:0x807BB9D4; // type:function size:0xC scope:global align:4 ItemSlotData_resetPowTimer = .text:0x807BB9E0; // type:function size:0xC scope:global align:4 ItemSlotData_updateTimers = .text:0x807BB9EC; // type:function size:0xA8 scope:global align:4 diff --git a/src/item/ItemSlotTable.cpp b/src/item/ItemSlotTable.cpp new file mode 100644 index 00000000..fabe43a9 --- /dev/null +++ b/src/item/ItemSlotTable.cpp @@ -0,0 +1,85 @@ +#include +#include + +extern "C" u32 RaceInfo_getCountdown(void *); + +namespace Item { + +ItemSlotTable *ItemSlotTable::sInstance = nullptr; + +void ItemSlotTable::resetLightningTimer() { + mLightningTimer = 1800; +} + +void ItemSlotTable::resetBlueShellTimer() { + mBlueShellTimer = 1800; +} + +void ItemSlotTable::resetBlooperTimer() { + mBlooperTimer = 900; +} + +void ItemSlotTable::resetPowTimer() { + mPowTimer = 1200; +} + +bool ItemSlotTable::checkSpawnTimer(int itemObjId, int param_3) { + s32 threshold = (param_3 != 0) ? 300 : 0; + switch (itemObjId) { + case 6: + return mLightningTimer > threshold; + case 5: + return mBlueShellTimer > threshold; + case 10: + return mBlooperTimer > threshold; + case 11: + return mPowTimer > threshold; + default: + return false; + } +} + +extern const u16 sPlayerCountPositionRemap[12][12]; + +void ItemSlotTable::scaleTable(ItemSlotTableHolder *holder) { + ItemSlotChanceRow *data = holder->data; + ItemSlotChanceRow *dest = data; + for (s32 pos = 0; pos < (s32)mPlayerCount; pos++) { + u16 remappedPos = sPlayerCountPositionRemap[mPlayerCount - 1][pos]; + ItemSlotChanceRow *src = &data[(u16)(remappedPos - 1)]; + for (int i = 0; i < 19; i++) { + dest->itemChances[i] = src->itemChances[i]; + } + dest++; + } + for (s32 pos = mPlayerCount; pos < 12; pos++) { + for (int i = 0; i < 19; i++) { + dest->itemChances[i] = 0; + } + dest++; + } +} + +void ItemSlotTable::updateTimers() { + if (RaceInfo_getCountdown(System::RaceManager::spInstance) == 0) { + mLightningTimer = 1800; + mBlueShellTimer = 1800; + mBlooperTimer = 900; + mPowTimer = 1200; + } + + if (mLightningTimer > 0) { + mLightningTimer--; + } + if (mBlueShellTimer > 0) { + mBlueShellTimer--; + } + if (mBlooperTimer > 0) { + mBlooperTimer--; + } + if (mPowTimer > 0) { + mPowTimer--; + } +} + +} // namespace Item diff --git a/src/item/ItemSlotTable.hpp b/src/item/ItemSlotTable.hpp new file mode 100644 index 00000000..5e8322b9 --- /dev/null +++ b/src/item/ItemSlotTable.hpp @@ -0,0 +1,48 @@ +#pragma once + +#include +#include + +namespace Item { + +struct ItemSlotChanceRow { + u16 itemChances[19]; +}; + +struct ItemSlotTableHolder { + u32 count; // 0x0 + ItemSlotChanceRow *data; // 0x4 +}; + +class ItemSlotTable : public EGG::Disposer { +public: + ItemSlotTable(); + virtual ~ItemSlotTable(); + + static ItemSlotTable *createInstance(); + static void destroyInstance(); + + void resetLightningTimer(); + void resetBlueShellTimer(); + void resetBlooperTimer(); + void resetPowTimer(); + void updateTimers(); + bool checkSpawnTimer(int itemObjId, int param_3); + void scaleTable(ItemSlotTableHolder *holder); + + static ItemSlotTable *sInstance; + + ItemSlotTableHolder mPlayerChances; // 0x10 + ItemSlotTableHolder mCpuChances; // 0x18 + ItemSlotTableHolder mSpecialChances; // 0x20 + int *mItemsInWheel; // 0x28 + int *mSpecialBoxItemsInWheel; // 0x2C + void *mSomethingSpecialChances; // 0x30 + s32 mLightningTimer; // 0x34 + s32 mBlueShellTimer; // 0x38 + s32 mBlooperTimer; // 0x3C + s32 mPowTimer; // 0x40 + u32 mPlayerCount; // 0x44 +}; + +} // namespace Item