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
12 changes: 6 additions & 6 deletions config/RMCP01/module/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3086,17 +3086,17 @@ __ct__Q24Kart9KartStateFPQ24Kart12KartSettings = .text:0x805943B4; // type:funct
init__Q24Kart9KartStateFv = .text:0x8059455C; // type:function size:0x38 scope:global align:4
reset__Q24Kart9KartStateFv = .text:0x80594594; // type:function size:0xA0 scope:global align:4
resetOob__Q24Kart9KartStateFv = .text:0x80594634; // type:function size:0x10 scope:global align:4
fn_1_84290 = .text:0x80594644; // type:function size:0xB0
PlayerSub1c_startOobWipe = .text:0x805946F4; // type:function size:0x10 scope:global align:4
fn_1_84350 = .text:0x80594704; // type:function size:0x48
updateWipe__Q24Kart9KartStateFv = .text:0x80594644; // type:function size:0xB0 scope:global align:4
startWipe__Q24Kart9KartStateFi = .text:0x805946F4; // type:function size:0x10 scope:global align:4
resetCollisionFlags__Q24Kart9KartStateFv = .text:0x80594704; // type:function size:0x48 scope:global align:4
PlayerSub1c_updateCollisionsAndMore = .text:0x8059474C; // type:function size:0x130 scope:global align:4
PlayerSub1c_updateFromInput = .text:0x8059487C; // type:function size:0x358 scope:global align:4
PlayerSub1c_updateCollisions = .text:0x80594BD4; // type:function size:0xD18 scope:global align:4
fn_1_85538 = .text:0x805958EC; // type:function size:0x4
fn_1_8553C = .text:0x805958F0; // type:function size:0x28
PlayerSub1c_updateStartBoostCharge = .text:0x80595918; // type:function size:0xBC scope:global align:4
PlayerSub1c_computeStartBoost = .text:0x805959D4; // type:function size:0x124 scope:global align:4
PlayerSub1c_applyStartBoost = .text:0x80595AF8; // type:function size:0x164 scope:global align:4
updateStartBoostCharge__Q24Kart9KartStateFv = .text:0x80595918; // type:function size:0xBC scope:global align:4
computeStartBoost__Q24Kart9KartStateFv = .text:0x805959D4; // type:function size:0x124 scope:global align:4
applyStartBoost__Q24Kart9KartStateFi = .text:0x80595AF8; // type:function size:0x164 scope:global align:4
fn_1_858A8 = .text:0x80595C5C; // type:function size:0x48
fn_1_858F0 = .text:0x80595CA4; // type:function size:0x10
fn_1_85900 = .text:0x80595CB4; // type:function size:0x10
Expand Down
10 changes: 8 additions & 2 deletions src/kart/KartMove.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class KartMove : public KartObjectProxy {
u16 flags() const { return mFlags; }
const KartJump* kartJump() { return mJump; }
const KartHalfPipe* kartHalfPipe() { return mHalfPipe; }
void* kartBurnout() { return mBurnout; }

void setStartBoostCharge(f32 charge) { mStartBoostCharge = charge; }

private:
u8 _00c[0x014 - 0x010];
Expand All @@ -90,7 +93,9 @@ class KartMove : public KartObjectProxy {
EGG::Vector3f mScale;
f32 mTotalScale;
f32 mHitboxScale;
u8 _170[0x238 - 0x178];
u8 _178[0x224 - 0x178];
f32 mStartBoostCharge;
u8 _228[0x238 - 0x228];
s16 _someTimer;
s16 mRespawnTimer;
u8 _23c[0x248 - 0x23c];
Expand All @@ -103,7 +108,8 @@ class KartMove : public KartObjectProxy {
u8 _256[0x258 - 0x256];
KartJump* mJump;
KartHalfPipe* mHalfPipe;
u8 _260[0x294 - 0x260];
u8 _260[0x264 - 0x260];
u8 mBurnout[0x294 - 0x264];
};
static_assert(sizeof(KartMove) == 0x294);

Expand Down
3 changes: 0 additions & 3 deletions src/kart/KartObjectProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ const EGG::Vector3f& KartObjectProxy::getWheelEdgePos(u32 wheelIdx) {
return kartWheel(wheelIdx)->getPhysics()->wheelEdgePos;
}

KartSettings* KartObjectProxy::kartSettings() { return mAccessor->kartSettings; }

const KartSettings* KartObjectProxy::kartSettings() const { return mAccessor->kartSettings; }
KartPhysics* KartObjectProxy::kartPhysics() { return mAccessor->mBody->getPhysics(); }

const KartPhysics* KartObjectProxy::kartPhysics() const { return mAccessor->mBody->getPhysics(); }
Expand Down
10 changes: 7 additions & 3 deletions src/kart/KartObjectProxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ class KartEnemy;
class KartAccessor_44;
class KartAccessor_48;
class KartNetReceiver;
class KartNetSender;
class KartNetSender {
public:
u8 _00[0x57];
u8 mStartBoostIdx;
};
class BoxColUnit;
class KartAccessor_50;
class KartAccessor_60;
Expand Down Expand Up @@ -84,8 +88,8 @@ class KartObjectProxy {
public:
KartObjectProxy();

KartSettings* kartSettings();
const KartSettings* kartSettings() const;
KartSettings* kartSettings() { return mAccessor->kartSettings; }
const KartSettings* kartSettings() const { return mAccessor->kartSettings; }
KartPhysics* kartPhysics();
const KartPhysics* kartPhysics() const;
KartDynamics* kartDynamics();
Expand Down
4 changes: 3 additions & 1 deletion src/kart/KartSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#include "KartDispParams.hpp"

namespace Kart {
class GpStats;
struct GpStats {
bool startBoostSuccessful;
};
class RaceStats;
class KartSettings {
public:
Expand Down
195 changes: 195 additions & 0 deletions src/kart/KartState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include <decomp.h>

#include "KartState.hpp"
#include "KartMove.hpp"
#include <system/Competition.hpp>
#include <system/RaceMode.hpp>

//https://decomp.me/scratch/7prZZ
namespace Kart {
Expand Down Expand Up @@ -56,4 +59,196 @@ KartState::KartState(KartSettings* settings) {
set(KART_FLAG_DEMO_LOSS);
}
}

void KartState::init() {
reset();
resetOob();
}

void KartState::reset() {
mFlags.field(3) = 0;
mFlags.field(2) = 0;
mFlags.field(1) = 0;
mFlags.field(0) = 0;
mAirtime = 0;
_24 = 0.0f;
mUp.setZero();
_40.setZero();
_58 = 0;
_5c = 0;
mHwgTimer = 0;
m_70 = 0;
mBoostRampType = -1;
mJumpPadType = -1;
_84 = 0;
mStartBoostCharge = 0.0f;
mStick.y = 0.0f;
mStick.x = 0.0f;
_a4 = 0;
_4c = m_a8 = EGG::Vector3f::zero;
_a6 = 0;
}

void KartState::resetOob() {
mWipeState = -1;
mWipeFrame = -1;
}

extern "C" s16 lbl_1_data_3958[];

void KartState::updateWipe() {
if (mWipeState == -1) {
return;
}

mWipeRatio = (f32)++mWipeFrame / (f32)lbl_1_data_3958[mWipeState];
if (1.0f < mWipeRatio) {
mWipeRatio = 1.0f;
}
if (mWipeFrame > lbl_1_data_3958[mWipeState]) {
mWipeState = -1;
}
}

void KartState::startWipe(int wipeState) {
mWipeState = wipeState;
mWipeFrame = 0;
}

void KartState::resetCollisionFlags() {
mFlags.field(0) &= ~(
KART_FLAG_MASK(KART_FLAG_ACCELERATE) |
KART_FLAG_MASK(KART_FLAG_BRAKE) |
KART_FLAG_MASK(KART_FLAG_DRIFT_INPUT) |
KART_FLAG_MASK(KART_FLAG_HOP_START) |
KART_FLAG_MASK(KART_FLAG_ACCELERATE_START) |
KART_FLAG_MASK(KART_FLAG_GROUND_START) |
KART_FLAG_MASK(KART_FLAG_STICK_LEFT) |
KART_FLAG_MASK(KART_FLAG_WALL_COLLISION_START) |
KART_FLAG_MASK(KART_FLAG_AIR_START) |
KART_FLAG_MASK(KART_FLAG_STICK_RIGHT));
mFlags.field(1) &= ~KART_FLAG_MASK(KART_FLAG_ZIPPER_INVISIBLE_WALL);
mFlags.field(2) &= ~(
KART_FLAG_MASK(KART_FLAG_STH_4C) |
KART_FLAG_MASK(KART_FLAG_DISABLE_Y_SUS_FORCE) |
KART_FLAG_MASK(KART_FLAG_STH_5E) |
KART_FLAG_MASK(KART_FLAG_STH_5F));
mStick.y = 0.0f;
mStick.x = 0.0f;
}

extern "C" f32 lbl_1_data_3918[];

void KartState::updateStartBoostCharge() {
const f32* data = lbl_1_data_3918;
if (on(KART_FLAG_CHARGE_START_BOOST)) {
f32 diff = data[0] - data[1];
mStartBoostCharge += data[0] - diff * mStartBoostCharge;
} else {
mStartBoostCharge *= data[2];
}

if (0.0f > mStartBoostCharge) {
mStartBoostCharge = 0.0f;
} else if (1.0f < mStartBoostCharge) {
mStartBoostCharge = 1.0f;
}

mProxy->kartMove()->setStartBoostCharge(10.0f * mStartBoostCharge);
}

struct StartBoostEntry {
f32 minCharge;
s16 frames;
s16 _pad;
};

extern "C" StartBoostEntry lbl_1_data_3928[];
extern "C" s32 RaceInfo_getCountdown(System::RaceManager*);
extern "C" void fn_1_78CFC(void*);
extern "C" void PlayerSub10_applyStartBoost(KartMove*, s16);
extern "C" void fn_1_2D780(System::RaceMode*, s32);
extern "C" void fn_1_8140C(KartObjectProxy*, s32);

void KartState::computeStartBoost() {
if (RaceInfo_getCountdown(System::RaceManager::spInstance) != 0) {
return;
}

if (!((const KartObjectProxy*)mProxy)->isCpu()) {
System::CourseId courseId =
System::RaceConfig::spInstance->mRaceScenario.mSettings.mCourseId;
if (courseId != System::CHAIN_CHOMP_ROULETTE &&
courseId != System::FUNKY_STADIUM) {
if (on(KART_FLAG_ACCELERATE)) {
if (mStartBoostCharge > lbl_1_data_3928[5].minCharge) {
mStartBoostIdx = -1;
} else if (mStartBoostCharge > lbl_1_data_3928[0].minCharge) {
const StartBoostEntry* entries = lbl_1_data_3928;
for (u8 idx = 1; idx <= 5; ++idx) {
const StartBoostEntry* entry = &entries[idx];
if (mStartBoostCharge > entry[-1].minCharge &&
mStartBoostCharge <= entry[0].minCharge) {
mStartBoostIdx = idx;
GpStats* gpStats = mProxy->kartSettings()->gpStats;
if (gpStats != nullptr) {
gpStats->startBoostSuccessful = true;
}
break;
}
}
}
}
}
}

applyStartBoost(mStartBoostIdx);
mFlags.field(3) &= ~KART_FLAG_MASK(KART_FLAG_CHARGE_START_BOOST);
}

static inline void checkTournamentObjective(
System::RaceConfig* config, System::RaceManager* manager) {
if (config->mRaceScenario.mSettings.mGameMode ==
System::RaceConfig::Settings::GAMEMODE_MISSION_TOURNAMENT &&
(int)config->mRaceScenario.mCompetitionSettings.objective == 10) {
static_cast<System::RaceModeCompetition*>(manager->raceMode)
->mObjectiveStatus = 2;
}
}

static inline void checkTournamentObjective(
System::RaceConfig* config, System::RaceManager* manager, int boost) {
if (config->mRaceScenario.mSettings.mGameMode ==
System::RaceConfig::Settings::GAMEMODE_MISSION_TOURNAMENT &&
(int)config->mRaceScenario.mCompetitionSettings.objective == 10) {
fn_1_2D780(manager->raceMode, boost);
}
}

void KartState::applyStartBoost(int startBoostIdx) {
if (startBoostIdx == -1) {
KartMove* move = mProxy->kartMove();
fn_1_78CFC(move->kartBurnout());
checkTournamentObjective(
System::RaceConfig::spInstance, System::RaceManager::spInstance);
if (mProxy->kartState()->on(KART_FLAG_ONLINE_LOCAL)) {
fn_1_8140C(mProxy, 0x1c);
}
} else if (startBoostIdx > 0) {
KartMove* move = mProxy->kartMove();
PlayerSub10_applyStartBoost(move, lbl_1_data_3928[startBoostIdx].frames);
checkTournamentObjective(
System::RaceConfig::spInstance, System::RaceManager::spInstance,
startBoostIdx);
if (mProxy->kartState()->on(KART_FLAG_ONLINE_LOCAL)) {
fn_1_8140C(mProxy, 0x1b);
KartNetSender* netSender = mProxy->kartNetSender();
netSender->mStartBoostIdx = startBoostIdx;
}
} else {
checkTournamentObjective(
System::RaceConfig::spInstance, System::RaceManager::spInstance);
}
}

} // namespace Kart
25 changes: 23 additions & 2 deletions src/kart/KartState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,29 @@
namespace Kart {

enum KartFlags {
KART_FLAG_ACCELERATE = 0,
KART_FLAG_BRAKE = 1,
KART_FLAG_DRIFT_INPUT = 2,
KART_FLAG_HOPPING = 3,
KART_FLAG_HOP_START = 7,
KART_FLAG_ACCELERATE_START = 8,
KART_FLAG_GROUND_START = 9,
KART_FLAG_STICK_LEFT = 13,
KART_FLAG_WALL_COLLISION_START = 14,
KART_FLAG_ALL_WHEELS_COLLISION = 15,
KART_FLAG_STICKY_ROAD = 16,
KART_FLAG_TOUCHING_GROUND = 18,
KART_FLAG_AUTO_DRIFT = 19,
KART_FLAG_AIR_START = 23,
KART_FLAG_STICK_RIGHT = 24,
KART_FLAG_LARGE_FLIP_HIT = 25,
KART_FLAG_IN_BULLET = 28,
KART_FLAG_JUMPPAD = 30,
KART_FLAG_HIT_ITEM_OR_OBJ = 32,
KART_FLAG_CANNON_START = 35,
KART_FLAG_IN_CANNON = 36,
KART_FLAG_HALFPIPE_RAMP = 41,
KART_FLAG_ZIPPER_INVISIBLE_WALL = 44,
KART_FLAG_AT_SUSP_LIMIT = 51,
/// Used for bouncy mushrooms
KART_FLAG_JUMPPAD_VELY_INCREASE = 55,
Expand All @@ -33,12 +43,16 @@ enum KartFlags {
KART_FLAG_HALFPIPE_RAMP_LOCAL = 0x43,
KART_FLAG_WHEELIE_ROT = 0x44,
KART_FLAG_SKIP_WHEEL_CALC = 0x45,
KART_FLAG_STH_4C = 0x4c,
KART_FLAG_DISABLE_Y_SUS_FORCE = 0x56,
KART_FLAG_HALFPIPE_MIDAIR = 0x57,
KART_FLAG_COL_INVISIBILITY = 0x59,
KART_FLAG_IN_A_BULLET = 0x5b,
KART_FLAG_STH_5E = 0x5e,
KART_FLAG_STH_5F = 0x5f,
KART_FLAG_STH_61 = 0x61,
KART_FLAG_STH_WALL_COL = 0x63,
KART_FLAG_CHARGE_START_BOOST = 0x68,
KART_FLAG_STH_KILLER = 0x6a,
KART_FLAG_CPU = 0x80,
KART_FLAG_LOCAL = 0x81,
Expand All @@ -51,15 +65,21 @@ enum KartFlags {
KART_FLAG_HAS_STOPPED = 0x8c
};

#define KART_FLAG_MASK(flag) (1 << ((flag) % 32))

class KartState {
public:
KartState(KartSettings* settings);
virtual ~KartState();
void init();
void reset();
void resetOob();
void updateWipe();
void startWipe(int wipeState);
void resetCollisionFlags();
void updateStartBoostCharge();
void computeStartBoost();
void applyStartBoost(int startBoostIdx);

bool on(size_t n) const {
return mFlags.on(n);
Expand Down Expand Up @@ -93,12 +113,13 @@ class KartState {
s32 mJumpPadType;
f32 _7c;
u32 mCannonPointId;
u8 _84[0x86 - 0x84];
u16 _84;
s16 mHalfpipeInvisibilityTimer;
EGG::Vector2f mStick;
int mWipeState;
s16 mWipeFrame;
u8 _96[0x9c - 0x96];
u8 _96[0x98 - 0x96];
f32 mWipeRatio;
f32 mStartBoostCharge;
s32 mStartBoostIdx;
u16 _a4;
Expand Down
Loading
Loading