Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/RMCP01/module/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
85 changes: 85 additions & 0 deletions src/item/ItemSlotTable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include <item/ItemSlotTable.hpp>
#include <system/RaceManager.hpp>

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
48 changes: 48 additions & 0 deletions src/item/ItemSlotTable.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#pragma once

#include <rk_types.h>
#include <egg/core/eggDisposer.hpp>

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
Loading