A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
KartMove.cc
1#include "KartMove.hh"
2
3#include "game/kart/KartCollide.hh"
4#include "game/kart/KartDynamics.hh"
5#include "game/kart/KartJump.hh"
6#include "game/kart/KartParam.hh"
7#include "game/kart/KartPhysics.hh"
8#include "game/kart/KartScale.hh"
9#include "game/kart/KartSub.hh"
10#include "game/kart/KartSuspension.hh"
11
12#include "game/field/CollisionDirector.hh"
14#include "game/field/ObjectDirector.hh"
15
16#include "game/item/ItemDirector.hh"
17#include "game/item/KartItem.hh"
18
19#include "game/system/CourseMap.hh"
20#include "game/system/RaceManager.hh"
21#include "game/system/map/MapdataCannonPoint.hh"
22#include "game/system/map/MapdataJugemPoint.hh"
23
24#include <egg/math/Math.hh>
25#include <egg/math/Quat.hh>
26
27namespace Kart {
28
30 f32 speed;
31 f32 height;
32 f32 decelFactor;
33 f32 endDecel;
34};
35
36static constexpr std::array<CannonParameter, 3> CANNON_PARAMETERS = {{
37 {500.0f, 0.0f, 6000.0f, -1.0f},
38 {500.0f, 5000.0f, 6000.0f, -1.0f},
39 {120.0f, 2000.0f, 1000.0f, 45.0f},
40}};
41
43KartMove::KartMove() : m_smoothedUp(EGG::Vector3f::ey), m_scale(1.0f, 1.0f, 1.0f) {
44 m_totalScale = 1.0f;
45 m_hitboxScale = 1.0f;
46 m_shockSpeedMultiplier = 1.0f;
47 m_invScale = 1.0f;
48 m_padType.makeAllZero();
49 m_flags.makeAllZero();
50 m_jump = nullptr;
51}
52
54KartMove::~KartMove() {
55 delete m_jump;
56 delete m_halfPipe;
57 delete m_kartScale;
58}
59
61void KartMove::createSubsystems(const KartParam::Stats &stats) {
62 m_jump = new KartJump(this);
63 m_halfPipe = new KartHalfPipe;
64 m_kartScale = new KartScale(stats);
65}
66
71 m_realTurn = 0.0f;
72 m_rawTurn = 0.0f;
73
74 auto &status = KartObjectProxy::status();
75
76 if (status.onBit(eStatus::InAction, eStatus::CannonStart, eStatus::InCannon,
78 return;
79 }
80
81 if (status.onBit(eStatus::BeforeRespawn)) {
82 return;
83 }
84
85 if (status.offBit(eStatus::Hop) || m_hopStickX == 0) {
86 m_rawTurn = -state()->stickX();
87 if (status.onBit(eStatus::JumpPadMushroomCollision)) {
88 m_rawTurn *= 0.35f;
89 } else if (status.onBit(eStatus::AirtimeOver20)) {
90 m_rawTurn *= 0.01f;
91 }
92 } else {
93 m_rawTurn = static_cast<f32>(m_hopStickX);
94 }
95
96 f32 reactivity;
97 if (state()->isDrifting()) {
98 reactivity = param()->stats().driftReactivity;
99 } else {
100 reactivity = param()->stats().handlingReactivity;
101 }
102
103 m_weightedTurn = m_rawTurn * reactivity + m_weightedTurn * (1.0f - reactivity);
104 m_weightedTurn = std::max(-1.0f, std::min(1.0f, m_weightedTurn));
105
107
108 if (!state()->isDrifting()) {
109 return;
110 }
111
112 m_realTurn = (m_weightedTurn + static_cast<f32>(m_hopStickX)) * 0.5f;
113 m_realTurn = m_realTurn * 0.8f + 0.2f * static_cast<f32>(m_hopStickX);
114 m_realTurn = std::max(-1.0f, std::min(1.0f, m_realTurn));
115}
116
118void KartMove::setTurnParams() {
119 static constexpr std::array<DriftingParameters, 3> DRIFTING_PARAMS_ARRAY = {{
120 {10.0f, 0.5f, 0.5f, 1.0f},
121 {10.0f, 0.5f, 0.5f, 0.2f},
122 {10.0f, 0.22f, 0.5f, 0.2f},
123 }};
124
125 init(false, false);
126 m_dir = bodyFront();
127 m_lastDir = m_dir;
128 m_vel1Dir = m_dir;
129 m_landingDir = m_dir;
130 m_outsideDriftLastDir = m_dir;
131 m_driftingParams = &DRIFTING_PARAMS_ARRAY[static_cast<u32>(param()->stats().driftType)];
132 m_kartScale->reset();
133}
134
136void KartMove::init(bool b1, bool b2) {
137 m_lastSpeed = 0.0f;
138 m_baseSpeed = param()->stats().speed;
139 m_jumpPadSoftSpeedLimit = m_softSpeedLimit = param()->stats().speed;
140 m_speed = 0.0f;
141 setKartSpeedLimit();
142 m_acceleration = 0.0f;
144 m_up = EGG::Vector3f::ey;
145 m_smoothedUp = EGG::Vector3f::ey;
146 m_vel1Dir = EGG::Vector3f::ez;
147 m_lastDir = EGG::Vector3f::ez;
148 m_dir = EGG::Vector3f::ez;
149 m_landingDir = EGG::Vector3f::ez;
150 m_dirDiff = EGG::Vector3f::zero;
151 m_hasLandingDir = false;
152 m_outsideDriftAngle = 0.0f;
153 m_landingAngle = 0.0f;
154 m_outsideDriftLastDir = EGG::Vector3f::ez;
155 m_speedRatio = 0.0f;
156 m_speedRatioCapped = 0.0f;
157 m_kclSpeedFactor = 1.0f;
158 m_kclRotFactor = 1.0f;
160 m_kclWheelRotFactor = 1.0f;
161
162 if (!b2) {
164 }
165
166 m_hopStickX = 0;
167 m_hopFrame = 0;
168 m_hopUp = EGG::Vector3f::ey;
169 m_hopDir = EGG::Vector3f::ez;
170 m_divingRot = 0.0f;
171 m_standStillBoostRot = 0.0f;
172 m_driftState = DriftState::NotDrifting;
173 m_smtCharge = 0;
174 m_mtCharge = 0;
175 m_outsideDriftBonus = 0.0f;
176 m_boost.reset();
177 m_zipperBoostTimer = 0;
178 m_zipperBoostMax = 0;
179 m_reject.reset();
181 m_ssmtCharge = 0;
184 m_nonZipperAirtime = 0;
185 m_realTurn = 0.0f;
186 m_weightedTurn = 0.0f;
187
188 if (!b1) {
189 m_scale.set(1.0f);
190 m_totalScale = 1.0f;
191 m_hitboxScale = 1.0f;
192 m_shockSpeedMultiplier = 1.0f;
193 m_invScale = 1.0f;
195 m_shockTimer = 0;
196 m_crushTimer = 0;
197 }
198
199 m_jumpPadMinSpeed = 0.0f;
200 m_jumpPadMaxSpeed = 0.0f;
201 m_jumpPadBoostMultiplier = 0.0f;
202 m_jumpPadProperties = nullptr;
203 m_rampBoost = 0;
204 m_autoDriftAngle = 0.0f;
205 m_autoDriftStartFrameCounter = 0;
206
207 m_cannonEntryOfsLength = 0.0f;
208 m_cannonEntryPos.setZero();
209 m_cannonEntryOfs.setZero();
210 m_cannonOrthog.setZero();
211 m_cannonProgress.setZero();
212
213 m_hopVelY = 0.0f;
214 m_hopPosY = 0.0f;
215 m_hopGravity = 0.0f;
216 m_timeInRespawn = 0;
219 m_respawnTimer = 0;
220 m_bumpTimer = 0;
221 m_drivingDirection = DrivingDirection::Forwards;
222 m_padType.makeAllZero();
223 m_flags.makeAllZero();
224 m_jump->reset();
225 m_halfPipe->reset();
226 m_rawTurn = 0.0f;
227}
228
230void KartMove::clear() {
231 auto &status = KartObjectProxy::status();
232
233 if (status.onBit(eStatus::OverZipper)) {
235 }
236
237 clearBoost();
238 clearJumpPad();
239 clearRampBoost();
240 clearZipperBoost();
241 clearSsmt();
242 clearOffroadInvincibility();
243 m_halfPipe->end(false);
244 m_jump->end();
245 clearRejectRoad();
246}
247
251 EGG::Quatf quaternion = EGG::Quatf::FromRPY(angles * DEG2RAD);
252 EGG::Vector3f newPos = position;
254 Field::KCLTypeMask kcl_flags = KCL_NONE;
255
256 bool bColliding = Field::CollisionDirector::Instance()->checkSphereFullPush(100.0f, newPos,
257 EGG::Vector3f::inf, KCL_ANY, &info, &kcl_flags, 0);
258
259 if (bColliding && (kcl_flags & KCL_TYPE_FLOOR)) {
260 newPos = newPos + info.tangentOff + (info.floorNrm * -100.0f);
261 newPos += info.floorNrm * bsp().initialYPos;
262 }
263
264 setPos(newPos);
265 setRot(quaternion);
266
267 sub()->initPhysicsValues();
268
269 physics()->setPos(pos());
270 physics()->setVelocity(dynamics()->velocity());
271
272 m_landingDir = bodyFront();
273 m_dir = bodyFront();
274 m_up = bodyUp();
275 dynamics()->setTop(m_up);
276
277 for (u16 tireIdx = 0; tireIdx < suspCount(); ++tireIdx) {
278 suspension(tireIdx)->setInitialState();
279 }
280}
281
288 auto &status = KartObjectProxy::status();
289
290 if (status.onBit(eStatus::InRespawn)) {
291 calcInRespawn();
292 return;
293 }
294
295 dynamics()->resetInternalVelocity();
296 m_burnout.calc();
298 m_halfPipe->calc();
299 calcTop();
300 tryEndJumpPad();
301 calcRespawnBoost();
303 m_jump->calc();
304
305 m_bumpTimer = std::max(m_bumpTimer - 1, 0);
306
308 calcDirs();
309 calcStickyRoad();
310 calcOffroad();
311 calcTurn();
312
313 if (status.offBit(eStatus::AutoDrift)) {
315 }
316
317 calcWheelie();
318 calcSsmt();
319 calcBoost();
321 calcZipperBoost();
322 calcShock();
323 calcCrushed();
324 calcScale();
325
326 if (status.onBit(eStatus::InCannon)) {
327 calcCannon();
328 }
329
333 calcRotation();
334}
335
337void KartMove::calcRespawnStart() {
338 constexpr float RESPAWN_HEIGHT = 700.0f;
339
340 const auto *jugemPoint = System::RaceManager::Instance()->jugemPoint();
341 const EGG::Vector3f &jugemPos = jugemPoint->pos();
342 const EGG::Vector3f &jugemRot = jugemPoint->rot();
343
344 EGG::Vector3f respawnPos = jugemPos;
345 respawnPos.y += RESPAWN_HEIGHT;
346 EGG::Vector3f respawnRot = EGG::Vector3f(0.0f, jugemRot.y, 0.0f);
347
348 setInitialPhysicsValues(respawnPos, respawnRot);
349
350 Item::ItemDirector::Instance()->kartItem(0).clear();
351
352 status().resetBit(eStatus::TriggerRespawn).setBit(eStatus::InRespawn);
353}
354
356void KartMove::calcInRespawn() {
357 constexpr f32 LAKITU_VELOCITY = 1.5f;
358 constexpr u16 RESPAWN_DURATION = 110;
359
360 auto &status = KartObjectProxy::status();
361
362 if (status.offBit(eStatus::InRespawn)) {
363 return;
364 }
365
366 EGG::Vector3f newPos = pos();
367 newPos.y -= LAKITU_VELOCITY;
368 dynamics()->setPos(newPos);
369 dynamics()->setNoGravity(true);
370
371 if (++m_timeInRespawn > RESPAWN_DURATION) {
372 status.resetBit(eStatus::InRespawn).setBit(eStatus::AfterRespawn, eStatus::RespawnKillY);
373 m_timeInRespawn = 0;
374 m_flags.setBit(eFlags::Respawned);
375 dynamics()->setNoGravity(false);
376 }
377}
378
380void KartMove::calcRespawnBoost() {
381 constexpr s16 RESPAWN_BOOST_DURATION = 30;
382 constexpr s16 RESPAWN_BOOST_INPUT_LENIENCY = 4;
383
384 auto &status = KartObjectProxy::status();
385
386 if (status.onBit(eStatus::AfterRespawn)) {
387 if (status.onBit(eStatus::TouchingGround)) {
388 if (m_respawnPreLandTimer > 0) {
389 if (status.offBit(eStatus::BeforeRespawn, eStatus::InAction)) {
390 activateBoost(KartBoost::Type::AllMt, RESPAWN_BOOST_DURATION);
391 m_respawnTimer = RESPAWN_BOOST_DURATION;
392 }
393 } else {
394 m_respawnPostLandTimer = RESPAWN_BOOST_INPUT_LENIENCY;
395 }
396
397 status.resetBit(eStatus::AfterRespawn);
399 }
400
402
403 if (m_flags.onBit(eFlags::Respawned) && status.onBit(eStatus::AccelerateStart)) {
404 m_respawnPreLandTimer = RESPAWN_BOOST_INPUT_LENIENCY;
406 }
407 } else {
408 if (m_respawnPostLandTimer > 0) {
409 if (status.onBit(eStatus::AccelerateStart)) {
410 if (status.offBit(eStatus::BeforeRespawn, eStatus::InAction)) {
411 activateBoost(KartBoost::Type::AllMt, RESPAWN_BOOST_DURATION);
412 m_respawnTimer = RESPAWN_BOOST_DURATION;
413 }
414
416 }
417
419 } else {
421 }
422 }
423
424 m_respawnTimer = std::max(0, m_respawnTimer - 1);
425}
426
428void KartMove::calcTop() {
429 f32 stabilizationFactor = 0.1f;
430 m_hasLandingDir = false;
431 EGG::Vector3f inputTop = state()->top();
432 auto &status = KartObjectProxy::status();
433
434 if (status.onBit(eStatus::GroundStart) && m_nonZipperAirtime >= 3) {
435 m_smoothedUp = inputTop;
436 m_up = inputTop;
437 m_landingDir = m_dir.perpInPlane(m_smoothedUp, true);
438 m_dirDiff = m_landingDir.proj(m_landingDir);
439 m_hasLandingDir = true;
440 } else {
441 if (status.onBit(eStatus::Hop) && m_hopPosY > 0.0f) {
442 stabilizationFactor = m_driftingParams->stabilizationFactor;
443 } else if (status.onBit(eStatus::TouchingGround)) {
444 if ((m_flags.onBit(eFlags::TrickableSurface) || state()->trickableTimer() > 0) &&
445 inputTop.dot(m_dir) > 0.0f && m_speed > 50.0f &&
446 collide()->surfaceFlags().onBit(KartCollide::eSurfaceFlags::NotTrickable)) {
447 inputTop = m_up;
448 } else {
449 m_up = inputTop;
450 }
451
452 f32 scalar = 0.8f;
453
454 if (status.onBit(eStatus::HalfPipeRamp) ||
455 (status.offBit(eStatus::Boost, eStatus::RampBoost, eStatus::Wheelie,
457 (status.offBit(eStatus::ZipperBoost) || m_zipperBoostTimer > 15))) {
458 f32 topDotZ = 0.8f - 6.0f * (EGG::Mathf::abs(inputTop.dot(componentZAxis())));
459 scalar = std::min(0.8f, std::max(0.3f, topDotZ));
460 }
461
462 m_smoothedUp += (inputTop - m_smoothedUp) * scalar;
464
465 f32 bodyDotFront = bodyFront().dot(m_smoothedUp);
466
467 if (bodyDotFront < -0.1f) {
468 stabilizationFactor += std::min(0.2f, EGG::Mathf::abs(bodyDotFront) * 0.5f);
469 }
470
471 if (collide()->surfaceFlags().onBit(KartCollide::eSurfaceFlags::BoostRamp)) {
472 stabilizationFactor = 0.4f;
473 }
474 } else {
476 }
477 }
478
479 dynamics()->setStabilizationFactor(stabilizationFactor);
480
481 m_nonZipperAirtime = status.onBit(eStatus::OverZipper) ? 0 : state()->airtime();
482 m_flags.changeBit(collide()->surfaceFlags().onBit(KartCollide::eSurfaceFlags::Trickable),
484}
485
489 auto &status = KartObjectProxy::status();
490
492 return;
493 }
494
495 if (m_smoothedUp.y <= 0.99f) {
496 m_smoothedUp += (EGG::Vector3f::ey - m_smoothedUp) * 0.03f;
498 } else {
499 m_smoothedUp = EGG::Vector3f::ey;
500 }
501
502 if (m_up.y <= 0.99f) {
503 m_up += (EGG::Vector3f::ey - m_up) * 0.03f;
504 m_up.normalise();
505 } else {
506 m_up = EGG::Vector3f::ey;
507 }
508}
509
514 const auto *raceMgr = System::RaceManager::Instance();
515 if (!raceMgr->isStageReached(System::RaceManager::Stage::Race)) {
516 return;
517 }
518
519 if (m_padType.onBit(ePadType::BoostPanel)) {
520 tryStartBoostPanel();
521 }
522
523 if (m_padType.onBit(ePadType::BoostRamp)) {
525 }
526
527 if (m_padType.onBit(ePadType::JumpPad)) {
529 }
530
531 m_padType.makeAllZero();
532}
533
535void KartMove::calcDirs() {
536 EGG::Vector3f right = dynamics()->mainRot().rotateVector(EGG::Vector3f::ex);
537 EGG::Vector3f local_88 = right.cross(m_smoothedUp);
538 local_88.normalise();
539 m_flags.setBit(eFlags::LaunchBoost);
540 auto &status = KartObjectProxy::status();
541
542 if (status.offBit(eStatus::InATrick, eStatus::OverZipper) &&
543 (((status.onBit(eStatus::TouchingGround) || status.offBit(eStatus::RampBoost) ||
544 !m_jump->isBoostRampEnabled()) &&
545 status.offBit(eStatus::JumpPad) && state()->airtime() <= 5) ||
546 status.onBit(eStatus::JumpPadMushroomCollision,
547 eStatus::NoSparkInvisibleWall))) {
548 if (status.onBit(eStatus::Hop)) {
549 local_88 = m_hopDir;
550 }
551
552 EGG::Matrix34f mat;
553 mat.setAxisRotation(DEG2RAD * (m_autoDriftAngle + m_outsideDriftAngle + m_landingAngle),
555 EGG::Vector3f local_b8 = mat.multVector(local_88);
556 local_b8 = local_b8.perpInPlane(m_smoothedUp, true);
557
558 EGG::Vector3f dirDiff = local_b8 - m_dir;
559
560 if (dirDiff.squaredLength() <= std::numeric_limits<f32>::epsilon()) {
561 m_dir = local_b8;
562 m_dirDiff.setZero();
563 } else {
564 EGG::Vector3f origDirCross = m_dir.cross(local_b8);
565 m_dirDiff += m_kclRotFactor * dirDiff;
566 m_dir += m_dirDiff;
567 m_dir.normalise();
568 m_dirDiff *= 0.1f;
569 EGG::Vector3f newDirCross = m_dir.cross(local_b8);
570
571 if (origDirCross.dot(newDirCross) < 0.0f) {
572 m_dir = local_b8;
573 m_dirDiff.setZero();
574 }
575 }
576
577 m_vel1Dir = m_dir.perpInPlane(m_smoothedUp, true);
578 m_flags.resetBit(eFlags::LaunchBoost);
579 } else {
580 m_vel1Dir = m_dir;
581 }
582
583 if (status.offBit(eStatus::OverZipper)) {
584 m_jump->tryStart(m_smoothedUp.cross(m_dir));
585 }
586
587 if (m_hasLandingDir) {
588 f32 dot = m_dir.dot(m_landingDir);
589 EGG::Vector3f cross = m_dir.cross(m_landingDir);
590 f32 crossDot = cross.length();
591 f32 angle = EGG::Mathf::atan2(crossDot, dot);
592 angle = EGG::Mathf::abs(angle);
593
594 f32 fVar4 = 1.0f;
595 if (cross.dot(m_smoothedUp) < 0.0f) {
596 fVar4 = -1.0f;
597 }
598
599 m_landingAngle += (angle * RAD2DEG) * fVar4;
600 }
601
602 if (m_landingAngle <= 0.0f) {
603 if (m_landingAngle < 0.0f) {
604 m_landingAngle = std::min(0.0f, m_landingAngle + 2.0f);
605 }
606 } else {
607 m_landingAngle = std::max(0.0f, m_landingAngle - 2.0f);
608 }
609}
610
612void KartMove::calcStickyRoad() {
613 constexpr f32 STICKY_RADIUS = 200.0f;
614 constexpr Field::KCLTypeMask STICKY_MASK =
616
617 auto &status = KartObjectProxy::status();
618
619 if (status.onBit(eStatus::OverZipper)) {
621 return;
622 }
623
624 if ((status.offBit(eStatus::StickyRoad) &&
625 collide()->surfaceFlags().offBit(KartCollide::eSurfaceFlags::Trickable)) ||
626 EGG::Mathf::abs(m_speed) <= 20.0f) {
627 return;
628 }
629
630 EGG::Vector3f pos = dynamics()->pos();
631 EGG::Vector3f vel = dynamics()->movingObjVel() + m_speed * m_vel1Dir;
632 Field::CollisionInfo colInfo;
633 colInfo.bbox.setZero();
634 Field::KCLTypeMask kcl_flags = KCL_NONE;
635 bool stickyRoad = false;
636
637 for (size_t i = 0; i < 3; ++i) {
638 EGG::Vector3f newPos = pos + vel;
639 if (Field::CollisionDirector::Instance()->checkSphereFull(STICKY_RADIUS, newPos,
640 EGG::Vector3f::inf, STICKY_MASK, &colInfo, &kcl_flags, 0)) {
641 m_vel1Dir = m_vel1Dir.perpInPlane(colInfo.floorNrm, true);
642 dynamics()->setMovingObjVel(dynamics()->movingObjVel().rej(colInfo.floorNrm));
643 dynamics()->setMovingRoadVel(dynamics()->movingRoadVel().rej(colInfo.floorNrm));
644
645 if (status.onBit(eStatus::MovingWaterStickyRoad)) {
646 m_up = colInfo.floorNrm;
647 m_smoothedUp = colInfo.floorNrm;
648 }
649
650 stickyRoad = true;
651
652 break;
653 }
654 vel *= 0.5f;
655 pos += -STICKY_RADIUS * componentYAxis();
656 }
657
658 if (!stickyRoad) {
660 }
661}
662
667 auto &status = KartObjectProxy::status();
668
670 m_kclSpeedFactor = 1.0f;
671 m_kclRotFactor = param()->stats().kclRot[0];
672 } else {
673 bool anyWheel = status.onBit(eStatus::AnyWheelCollision);
674 if (anyWheel) {
678 }
679
681 const CollisionData &colData = collisionData();
682 if (anyWheel) {
683 if (colData.speedFactor < m_kclWheelSpeedFactor) {
684 m_kclSpeedFactor = colData.speedFactor;
685 }
686 m_kclRotFactor = (m_kclWheelRotFactor + colData.rotFactor) /
687 static_cast<f32>(m_floorCollisionCount + 1);
688 } else {
689 m_kclSpeedFactor = colData.speedFactor;
690 m_kclRotFactor = colData.rotFactor;
691 }
692 }
693 }
694
695 calcRisingWater();
696}
697
699void KartMove::calcRisingWater() {
700 auto *objDir = Field::ObjectDirector::Instance();
701 auto *psea = objDir->psea();
702 if (!psea) {
703 return;
704 }
705
706 f32 pos = wheelPos(0).y;
707 u16 count = tireCount();
708 for (u16 wheelIdx = 0; wheelIdx < count; ++wheelIdx) {
709 f32 tmp = wheelEdgePos(wheelIdx).y;
710 if (wheelIdx == 0 || tmp < pos) {
711 pos = tmp;
712 }
713 }
714
715 if (objDir->risingWaterKillPlaneHeight() > pos) {
716 collide()->activateOob(true, nullptr, false, false);
717 }
718
719 f32 dist = -objDir->distAboveRisingWater(pos);
720 if (dist > 0.0f && status().offBit(Kart::eStatus::BoostOffroadInvincibility)) {
721 f32 speedScale = std::min(1.0f, dist / 100.0f);
722 m_kclSpeedFactor = 1.0f - (1.0f - param()->stats().kclSpeed[3]) * speedScale;
723 }
724}
725
727void KartMove::calcBoost() {
728 auto &status = KartObjectProxy::status();
729
730 if (m_boost.calc()) {
732 } else {
733 status.resetBit(eStatus::Boost);
734 }
735
736 calcRampBoost();
737}
738
740void KartMove::calcRampBoost() {
741 auto &status = KartObjectProxy::status();
742
743 if (status.offBit(eStatus::RampBoost)) {
744 return;
745 }
746
748 if (--m_rampBoost < 1) {
749 m_rampBoost = 0;
750 status.resetBit(eStatus::RampBoost);
751 }
752}
753
758 auto &status = KartObjectProxy::status();
759
761 return;
762 }
763
764 if (--m_ssmtDisableAccelTimer < 0 ||
765 (m_flags.offBit(eFlags::SsmtLeeway) && status.offBit(eStatus::Brake))) {
768 }
769}
770
775 constexpr s16 MAX_SSMT_CHARGE = 75;
776 constexpr s16 SSMT_BOOST_FRAMES = 30;
777 constexpr s16 LEEWAY_FRAMES = 1;
778 constexpr s16 DISABLE_ACCEL_FRAMES = 20;
779
781
782 auto &status = KartObjectProxy::status();
783
784 if (status.onBit(eStatus::ChargingSSMT)) {
785 if (++m_ssmtCharge > MAX_SSMT_CHARGE) {
786 m_ssmtCharge = MAX_SSMT_CHARGE;
789 }
790
791 return;
792 }
793
794 m_ssmtCharge = 0;
795
796 if (m_flags.offBit(eFlags::SsmtCharged)) {
797 return;
798 }
799
800 if (m_flags.onBit(eFlags::SsmtLeeway)) {
801 if (--m_ssmtLeewayTimer < 0) {
804 m_ssmtDisableAccelTimer = DISABLE_ACCEL_FRAMES;
806 } else {
808 activateBoost(KartBoost::Type::AllMt, SSMT_BOOST_FRAMES);
811 }
812 }
813 } else {
814 if (status.onBit(eStatus::Accelerate) && status.offBit(eStatus::Brake)) {
815 activateBoost(KartBoost::Type::AllMt, SSMT_BOOST_FRAMES);
818 } else {
819 m_ssmtLeewayTimer = LEEWAY_FRAMES;
820 m_flags.setBit(eFlags::SsmtLeeway);
822 m_ssmtDisableAccelTimer = LEEWAY_FRAMES;
823 }
824 }
825}
826
832 auto &status = KartObjectProxy::status();
833
836 if (status.offBit(eStatus::DriftInput)) {
838 } else if (status.offBit(eStatus::SlipdriftCharge)) {
839 if (m_hopStickX == 0) {
840 if (status.onBit(eStatus::StickRight)) {
841 m_hopStickX = -1;
842 } else if (status.onBit(eStatus::StickLeft)) {
843 m_hopStickX = 1;
844 }
846 onHop();
847 }
848 }
849 }
850 }
851
852 if (status.onBit(eStatus::Hop)) {
853 if (m_hopStickX == 0) {
854 if (status.onBit(eStatus::StickRight)) {
855 m_hopStickX = -1;
856 } else if (status.onBit(eStatus::StickLeft)) {
857 m_hopStickX = 1;
858 }
859 }
860 if (m_hopFrame < 3) {
861 ++m_hopFrame;
862 }
863 } else if (status.onBit(eStatus::SlipdriftCharge)) {
864 m_hopFrame = 0;
865 }
866
868}
869
874 m_hopStickX = 0;
875 m_hopFrame = 0;
877 m_driftState = DriftState::NotDrifting;
878 m_smtCharge = 0;
879 m_mtCharge = 0;
880}
881
886 m_outsideDriftAngle = 0.0f;
887 m_hopStickX = 0;
888 m_hopFrame = 0;
889 m_driftState = DriftState::NotDrifting;
890 m_smtCharge = 0;
891 m_mtCharge = 0;
892 m_outsideDriftBonus = 0.0f;
894 eStatus::DriftAuto);
895 m_autoDriftAngle = 0.0f;
896 m_hopStickX = 0;
897 m_autoDriftStartFrameCounter = 0;
898}
899
901void KartMove::clearJumpPad() {
902 m_jumpPadMinSpeed = 0.0f;
903 status().resetBit(eStatus::JumpPad);
904}
905
907void KartMove::clearRampBoost() {
908 m_rampBoost = 0;
909 status().resetBit(eStatus::RampBoost);
910}
911
913void KartMove::clearZipperBoost() {
914 m_zipperBoostTimer = 0;
916}
917
919void KartMove::clearBoost() {
920 m_boost.resetActive();
921 status().resetBit(eStatus::Boost);
922}
923
925void KartMove::clearSsmt() {
926 m_ssmtCharge = 0;
930}
931
933void KartMove::clearOffroadInvincibility() {
936}
937
938void KartMove::clearRejectRoad() {
939 status().resetBit(eStatus::RejectRoadTrigger, eStatus::NoSparkInvisibleWall);
940}
941
946 constexpr s16 AUTO_DRIFT_START_DELAY = 12;
947
948 auto &status = KartObjectProxy::status();
949
950 if (status.offBit(eStatus::AutoDrift)) {
951 return;
952 }
953
954 if (canStartDrift() &&
956 EGG::Mathf::abs(state()->stickX()) > 0.85f) {
957 m_autoDriftStartFrameCounter =
958 std::min<s16>(AUTO_DRIFT_START_DELAY, m_autoDriftStartFrameCounter + 1);
959 } else {
960 m_autoDriftStartFrameCounter = 0;
961 }
962
963 if (m_autoDriftStartFrameCounter >= AUTO_DRIFT_START_DELAY) {
964 status.setBit(eStatus::DriftAuto);
965
966 if (status.onBit(eStatus::TouchingGround)) {
967 if (state()->stickX() < 0.0f) {
968 m_hopStickX = 1;
969 m_autoDriftAngle -= 30.0f * param()->stats().driftAutomaticTightness;
970
971 } else {
972 m_hopStickX = -1;
973 m_autoDriftAngle += 30.0f * param()->stats().driftAutomaticTightness;
974 }
975 }
976
977 f32 halfTarget = 0.5f * param()->stats().driftOutsideTargetAngle;
978 m_autoDriftAngle = std::min(halfTarget, std::max(-halfTarget, m_autoDriftAngle));
979 } else {
980 status.resetBit(eStatus::DriftAuto);
981 m_hopStickX = 0;
982
983 if (m_autoDriftAngle > 0.0f) {
984 m_autoDriftAngle =
985 std::max(0.0f, m_autoDriftAngle - param()->stats().driftOutsideDecrement);
986 } else {
987 m_autoDriftAngle =
988 std::min(0.0f, m_autoDriftAngle + param()->stats().driftOutsideDecrement);
989 }
990 }
991
992 EGG::Quatf angleAxis;
993 angleAxis.setAxisRotation(-m_autoDriftAngle * DEG2RAD, m_up);
994 physics()->composeExtraRot(angleAxis);
995}
996
1001 bool isHopping = calcPreDrift();
1002 auto &status = KartObjectProxy::status();
1003
1004 if (status.offBit(eStatus::OverZipper)) {
1005 const EGG::Vector3f rotZ = dynamics()->mainRot().rotateVector(EGG::Vector3f::ez);
1006
1007 if (status.offBit(eStatus::TouchingGround) &&
1008 param()->stats().driftType != KartParam::Stats::DriftType::Inside_Drift_Bike &&
1009 status.offBit(eStatus::JumpPadMushroomCollision) &&
1011 m_flags.onBit(eFlags::LaunchBoost)) {
1012 const EGG::Vector3f up = dynamics()->mainRot().rotateVector(EGG::Vector3f::ey);
1014
1015 if (driftRej.normalise() != 0.0f) {
1016 f32 rejCrossDirMag = driftRej.cross(rotZ).length();
1017 f32 angle = EGG::Mathf::atan2(rejCrossDirMag, driftRej.dot(rotZ));
1018 f32 sign = 1.0f;
1019 if ((rotZ.z * (rotZ.x - driftRej.x)) - (rotZ.x * (rotZ.z - driftRej.z)) > 0.0f) {
1020 sign = -1.0f;
1021 }
1022
1023 m_outsideDriftAngle += angle * RAD2DEG * sign;
1024 }
1025 }
1026
1027 m_outsideDriftLastDir = rotZ;
1028 }
1029
1030 // TODO: Is this backwards/inverted?
1031 if (((status.offBit(eStatus::Hop) || m_hopFrame < 3) &&
1033 (status.onBit(eStatus::InAction) || status.offBit(eStatus::TouchingGround))) {
1034 if (canHop()) {
1035 hop();
1036 isHopping = true;
1037 }
1038 } else {
1040 isHopping = false;
1041 }
1042
1044
1045 if (status.offBit(eStatus::DriftManual)) {
1046 if (!isHopping && status.onBit(eStatus::TouchingGround)) {
1048
1049 if (action()->flags().offBit(KartAction::eFlags::Rotating) || m_speed <= 20.0f) {
1050 f32 driftAngleDecr = param()->stats().driftOutsideDecrement;
1051 if (m_outsideDriftAngle > 0.0f) {
1052 m_outsideDriftAngle = std::max(0.0f, m_outsideDriftAngle - driftAngleDecr);
1053 } else if (m_outsideDriftAngle < 0.0f) {
1054 m_outsideDriftAngle = std::min(0.0f, m_outsideDriftAngle + driftAngleDecr);
1055 }
1056 }
1057 }
1058 } else {
1059 // This is a different comparison than @ref KartMove::canStartDrift().
1060 bool canStartDrift = m_speed > MINIMUM_DRIFT_THRESOLD * m_baseSpeed;
1061
1062 if (status.offBit(eStatus::OverZipper) &&
1064 status.onBit(eStatus::InAction, eStatus::RejectRoadTrigger,
1066 !canStartDrift)) {
1067 if (canStartDrift) {
1068 releaseMt();
1069 }
1070
1072 m_flags.setBit(eFlags::DriftReset);
1073 } else {
1075 }
1076 }
1077}
1078
1083 constexpr f32 OUTSIDE_DRIFT_BONUS = 0.5f;
1084
1085 const auto &stats = param()->stats();
1086 auto &status = KartObjectProxy::status();
1087
1088 if (stats.driftType != KartParam::Stats::DriftType::Inside_Drift_Bike) {
1089 f32 driftAngle = 0.0f;
1090
1091 if (status.onBit(eStatus::Hop)) {
1092 const EGG::Vector3f rotZ = dynamics()->mainRot().rotateVector(EGG::Vector3f::ez);
1093 EGG::Vector3f rotRej = rotZ.rej(m_hopUp);
1094
1095 if (rotRej.normalise() != 0.0f) {
1096 const EGG::Vector3f hopCrossRot = m_hopDir.cross(rotRej);
1097 driftAngle =
1098 EGG::Mathf::atan2(hopCrossRot.length(), m_hopDir.dot(rotRej)) * RAD2DEG;
1099 }
1100 }
1101
1102 m_outsideDriftAngle += driftAngle * static_cast<f32>(-m_hopStickX);
1103 m_outsideDriftAngle = std::max(-60.0f, std::min(60.0f, m_outsideDriftAngle));
1104 }
1105
1107
1108 if (status.offBit(eStatus::DriftInput)) {
1109 return;
1110 }
1111
1112 if (getAppliedHopStickX() == 0) {
1113 return;
1114 }
1115
1116 status.setBit(eStatus::DriftManual).resetBit(eStatus::Hop);
1117 m_driftState = DriftState::ChargingMt;
1118 m_outsideDriftBonus = OUTSIDE_DRIFT_BONUS * (m_speedRatioCapped * stats.driftManualTightness);
1119}
1120
1125 constexpr f32 SMT_LENGTH_FACTOR = 3.0f;
1126
1127 auto &status = KartObjectProxy::status();
1128
1129 if (m_driftState < DriftState::ChargedMt || status.onBit(eStatus::Brake)) {
1130 m_driftState = DriftState::NotDrifting;
1131 return;
1132 }
1133
1134 u16 mtLength = param()->stats().miniTurbo;
1135
1136 if (m_driftState == DriftState::ChargedSmt) {
1137 mtLength *= SMT_LENGTH_FACTOR;
1138 }
1139
1140 if (status.offBit(eStatus::BeforeRespawn, eStatus::InAction)) {
1141 activateBoost(KartBoost::Type::AllMt, mtLength);
1142 }
1143
1144 m_driftState = DriftState::NotDrifting;
1145}
1146
1151 if (state()->airtime() > 5) {
1152 return;
1153 }
1154
1155 if (param()->stats().driftType != KartParam::Stats::DriftType::Inside_Drift_Bike) {
1156 if (m_hopStickX == -1) {
1157 f32 angle = m_outsideDriftAngle;
1158 f32 targetAngle = param()->stats().driftOutsideTargetAngle;
1159 if (angle > targetAngle) {
1160 m_outsideDriftAngle = std::max(m_outsideDriftAngle - 2.0f, targetAngle);
1161 } else if (angle < targetAngle) {
1162 m_outsideDriftAngle += 150.0f * param()->stats().driftManualTightness;
1163 m_outsideDriftAngle = std::min(m_outsideDriftAngle, targetAngle);
1164 }
1165 } else if (m_hopStickX == 1) {
1166 f32 angle = m_outsideDriftAngle;
1167 f32 targetAngle = -param()->stats().driftOutsideTargetAngle;
1168 if (targetAngle > angle) {
1169 m_outsideDriftAngle = std::min(m_outsideDriftAngle + 2.0f, targetAngle);
1170 } else if (targetAngle < angle) {
1171 m_outsideDriftAngle -= 150.0f * param()->stats().driftManualTightness;
1172 m_outsideDriftAngle = std::max(m_outsideDriftAngle, targetAngle);
1173 }
1174 }
1175 }
1176
1177 calcMtCharge();
1178}
1179
1184 f32 turn;
1185 auto &status = KartObjectProxy::status();
1186 bool drifting = state()->isDrifting() && status.offBit(eStatus::JumpPadMushroomCollision);
1187 bool autoDrift = status.onBit(eStatus::AutoDrift);
1188 const auto &stats = param()->stats();
1189
1190 if (drifting) {
1191 turn = autoDrift ? stats.driftAutomaticTightness : stats.driftManualTightness;
1192 } else {
1193 turn = autoDrift ? stats.handlingAutomaticTightness : stats.handlingManualTightness;
1194 }
1195
1196 if (drifting && stats.driftType != KartParam::Stats::DriftType::Inside_Drift_Bike) {
1197 m_outsideDriftBonus *= 0.99f;
1198 turn += m_outsideDriftBonus;
1199 }
1200
1201 bool forwards = true;
1202 if (status.onBit(eStatus::Brake) && m_speed <= 0.0f) {
1203 forwards = false;
1204 }
1205
1206 turn *= m_realTurn;
1207 if (status.onBit(eStatus::ChargingSSMT)) {
1208 turn = m_realTurn * 0.04f;
1209 } else {
1210 if (status.onBit(eStatus::Hop) && m_hopPosY > 0.0f) {
1211 turn *= 1.4f;
1212 }
1213
1214 if (!drifting) {
1215 bool noTurn = false;
1217 EGG::Mathf::abs(m_speed) < 1.0f) {
1218 if (!(status.onBit(eStatus::Hop) && m_hopPosY > 0.0f)) {
1219 turn = 0.0f;
1220 noTurn = true;
1221 }
1222 }
1223 if (forwards && !noTurn) {
1224 if (m_speed >= 20.0f) {
1225 turn *= 0.5f;
1226 if (m_speed < 70.0f) {
1227 turn += (1.0f - (m_speed - 20.0f) / 50.0f) * turn;
1228 }
1229 } else {
1230 turn = (turn * 0.4f) + (m_speed / 20.0f) * (turn * 0.6f);
1231 }
1232 }
1233 }
1234
1235 if (!forwards) {
1236 turn = -turn;
1237 }
1238
1239 if (status.onBit(eStatus::ZipperBoost) && status.offBit(eStatus::DriftManual)) {
1240 turn *= 2.0f;
1241 }
1242
1243 f32 stickX = EGG::Mathf::abs(state()->stickX());
1244 if (autoDrift && stickX > 0.3f) {
1245 f32 stickScalar = (stickX - 0.3f) / 0.7f;
1246 stickX = drifting ? 0.2f : 0.5f;
1247 turn += stickScalar * (turn * stickX * m_speedRatioCapped);
1248 }
1249 }
1250
1251 if (status.offBit(eStatus::InAction, eStatus::ZipperTrick)) {
1252 if (status.offBit(eStatus::TouchingGround)) {
1253 if (status.onBit(eStatus::RampBoost) && m_jump->isBoostRampEnabled()) {
1254 turn = 0.0f;
1255 } else if (status.offBit(eStatus::JumpPadMushroomCollision)) {
1256 u32 airtime = state()->airtime();
1257 if (airtime >= 70) {
1258 turn = 0.0f;
1259 } else if (airtime >= 30) {
1260 turn = std::max(0.0f, turn * (1.0f - (airtime - 30) * 0.025f));
1261 }
1262 }
1263 }
1264
1265 const EGG::Vector3f forward = dynamics()->mainRot().rotateVector(EGG::Vector3f::ez);
1266 f32 angle = EGG::Mathf::atan2(forward.cross(m_dir).length(), forward.dot(m_dir));
1267 angle = EGG::Mathf::abs(angle) * RAD2DEG;
1268
1269 if (angle > 60.0f) {
1270 turn *= std::max(0.0f, 1.0f - (angle - 60.0f) / 40.0f);
1271 }
1272 }
1273
1274 calcVehicleRotation(turn);
1275}
1276
1281 const auto *raceMgr = System::RaceManager::Instance();
1282 auto &status = KartObjectProxy::status();
1283
1284 if (raceMgr->isStageReached(System::RaceManager::Stage::Race)) {
1285 f32 speedFix = dynamics()->speedFix();
1286 if (status.onBit(eStatus::InAction) ||
1287 ((status.onBit(eStatus::WallCollisionStart) || state()->wallBonkTimer() == 0 ||
1288 EGG::Mathf::abs(speedFix) >= 3.0f) &&
1289 status.offBit(eStatus::DriftManual))) {
1290 m_speed += speedFix;
1291 }
1292 }
1293
1294 if (m_speed < -20.0f) {
1295 m_speed += 0.5f;
1296 }
1297
1298 bool water = false;
1299
1300 if (status.onBit(eStatus::MovingWaterVertical) ||
1301 (status.onBit(eStatus::MovingWaterDecaySpeed) &&
1302 status.offBit(eStatus::MushroomBoost) && EGG::Mathf::abs(m_speed) > 5.0f)) {
1303 water = true;
1304 m_speed *= collide()->pullPath().roadSpeedDecay();
1305 }
1306
1307 m_acceleration = 0.0f;
1308 m_speedDragMultiplier = 1.0f;
1309
1310 if (status.onBit(eStatus::InAction)) {
1311 action()->calcVehicleSpeed();
1312 return;
1313 }
1314
1315 if ((status.onAllBit(eStatus::SomethingWallCollision, eStatus::TouchingGround) &&
1318 status.onBit(eStatus::DisableAcceleration, eStatus::ChargingSSMT)) {
1319 if (status.onBit(eStatus::RampBoost) && state()->airtime() < 4) {
1320 m_acceleration = 7.0f;
1321 } else {
1322 if (status.onBit(eStatus::JumpPad) && status.offBit(eStatus::Accelerate)) {
1323 m_speedDragMultiplier = 0.99f;
1324 } else {
1325 if (status.onBit(eStatus::OverZipper)) {
1326 m_speedDragMultiplier = 0.999f;
1327 } else {
1328 if (state()->airtime() > 5) {
1329 m_speedDragMultiplier = 0.999f;
1330 }
1331 }
1332 }
1334 }
1335 } else if (status.offBit(eStatus::Boost)) {
1336 if (status.offBit(eStatus::JumpPad, eStatus::RampBoost)) {
1337 if (status.onBit(eStatus::Accelerate)) {
1340 } else {
1341 if (status.offBit(eStatus::Brake) ||
1343 eStatus::SomethingWallCollision)) {
1344 m_speed *= m_speed > 0.0f ? 0.98f : 0.95f;
1345 } else if (m_drivingDirection == DrivingDirection::Braking) {
1346 m_acceleration = -1.5f;
1348 if (++m_backwardsAllowCounter > 15) {
1349 m_drivingDirection = DrivingDirection::Backwards;
1350 }
1351 } else if (m_drivingDirection == DrivingDirection::Backwards) {
1352 m_acceleration = -2.0f;
1353 }
1354 }
1355
1357 const auto &stats = param()->stats();
1358
1359 f32 x = 1.0f - EGG::Mathf::abs(m_weightedTurn) * m_speedRatioCapped;
1360 m_speed *= stats.turningSpeed + (1.0f - stats.turningSpeed) * x;
1361 }
1362 } else {
1363 m_acceleration = water ? calcVehicleAcceleration() : 7.0f;
1364 }
1365 } else {
1366 m_acceleration = water ? calcVehicleAcceleration() : m_boost.acceleration();
1367 }
1368}
1369
1373 f32 vel = 0.0f;
1374 f32 initialVel = 1.0f - m_smoothedUp.y;
1375 if (EGG::Mathf::abs(m_speed) < 30.0f && m_smoothedUp.y > 0.0f && initialVel > 0.0f) {
1376 initialVel = std::min(initialVel * 2.0f, 2.0f);
1377 vel += initialVel;
1378 vel *= std::min(0.5f, std::max(-0.5f, -bodyFront().y));
1379 }
1380 m_speed += vel;
1381}
1382
1387 f32 ratio = m_speed / m_softSpeedLimit;
1388 if (ratio < 0.0f) {
1389 return 1.0f;
1390 }
1391
1392 std::span<const f32> as;
1393 std::span<const f32> ts;
1394 if (state()->isDrifting()) {
1395 as = param()->stats().accelerationDriftA;
1396 ts = param()->stats().accelerationDriftT;
1397 } else {
1398 as = param()->stats().accelerationStandardA;
1399 ts = param()->stats().accelerationStandardT;
1400 }
1401
1402 size_t i = 0;
1403 f32 acceleration = 0.0f;
1404 f32 t_curr = 0.0f;
1405 for (; i < ts.size(); ++i) {
1406 if (ratio < ts[i]) {
1407 acceleration = as[i] + ((as[i + 1] - as[i]) / (ts[i] - t_curr)) * (ratio - t_curr);
1408 break;
1409 }
1410
1411 t_curr = ts[i];
1412 }
1413
1414 return i < ts.size() ? acceleration : as.back();
1415}
1416
1421 constexpr f32 ROTATION_SCALAR_NORMAL = 0.5f;
1422 constexpr f32 ROTATION_SCALAR_MIDAIR = 0.2f;
1423 constexpr f32 ROTATION_SCALAR_BOOST_RAMP = 4.0f;
1424 constexpr f32 OOB_SLOWDOWN_RATE = 0.95f;
1425 constexpr f32 TERMINAL_VELOCITY = 90.0f;
1426
1428 auto &status = KartObjectProxy::status();
1429
1430 if (status.offBit(eStatus::InAction)) {
1431 dynamics()->setKillExtVelY(status.onBit(eStatus::RespawnKillY));
1432 }
1433
1434 if (status.onBit(eStatus::Burnout)) {
1435 m_speed = 0.0f;
1436 } else {
1437 if (m_acceleration < 0.0f) {
1438 if (m_speed < -20.0f) {
1439 m_acceleration = 0.0f;
1440 } else {
1441 if (m_speed + m_acceleration <= -20.0f) {
1442 m_acceleration = -20.0f - m_speed;
1443 }
1444 }
1445 }
1446
1448 }
1449
1450 if (status.onBit(eStatus::BeforeRespawn)) {
1451 m_speed *= OOB_SLOWDOWN_RATE;
1452 } else {
1453 if (status.onBit(eStatus::ChargingSSMT)) {
1454 m_speed *= 0.8f;
1455 } else {
1456 if (m_drivingDirection == DrivingDirection::Braking && m_speed < 0.0f) {
1457 m_speed = 0.0f;
1460 }
1461 }
1462 }
1463
1464 f32 speedLimit = status.onBit(eStatus::JumpPad) ? m_jumpPadMaxSpeed : m_baseSpeed;
1465 const f32 boostMultiplier = m_boost.multiplier();
1466 const f32 boostSpdLimit = m_boost.speedLimit();
1467 m_jumpPadBoostMultiplier = boostMultiplier;
1468
1469 f32 scaleMultiplier = m_shockSpeedMultiplier;
1470 if (status.onBit(eStatus::Crushed)) {
1471 scaleMultiplier *= 0.7f;
1472 }
1473
1474 f32 wheelieBonus = boostMultiplier + getWheelieSoftSpeedLimitBonus();
1475 speedLimit *= status.onBit(eStatus::JumpPadFixedSpeed) ?
1476 1.0f :
1477 scaleMultiplier * (wheelieBonus * m_kclSpeedFactor);
1478
1479 bool ignoreScale = status.onBit(eStatus::RampBoost, eStatus::ZipperInvisibleWall,
1481 f32 boostSpeed = ignoreScale ? 1.0f : scaleMultiplier;
1482 boostSpeed *= boostSpdLimit * m_kclSpeedFactor;
1483
1484 if (status.offBit(eStatus::JumpPad) && boostSpeed > 0.0f && boostSpeed > speedLimit) {
1485 speedLimit = boostSpeed;
1486 }
1487
1488 m_jumpPadSoftSpeedLimit = boostSpdLimit * m_kclSpeedFactor;
1489
1490 if (status.onBit(eStatus::RampBoost)) {
1491 speedLimit = std::max(speedLimit, 100.0f);
1492 }
1493
1494 m_lastDir = (m_speed > 0.0f) ? 1.0f * m_dir : -1.0f * m_dir;
1495
1496 f32 local_c8 = 1.0f;
1497 speedLimit *= calcWallCollisionSpeedFactor(local_c8);
1498
1499 if (m_softSpeedLimit <= speedLimit) {
1500 m_softSpeedLimit = speedLimit;
1502 m_softSpeedLimit = std::max(m_softSpeedLimit - 3.0f, speedLimit);
1503 } else {
1504 m_softSpeedLimit = speedLimit;
1505 }
1506
1508
1509 m_speed = std::min(m_softSpeedLimit, std::max(-m_softSpeedLimit, m_speed));
1510
1511 if (status.onBit(eStatus::JumpPad)) {
1512 m_speed = std::max(m_speed, m_jumpPadMinSpeed);
1513 }
1514
1515 calcWallCollisionStart(local_c8);
1516
1517 m_speedRatio = EGG::Mathf::abs(m_speed / m_baseSpeed);
1518 m_speedRatioCapped = std::min(1.0f, m_speedRatio);
1519
1520 EGG::Vector3f crossVec = m_smoothedUp.cross(m_dir);
1521 if (m_speed < 0.0f) {
1522 crossVec = -crossVec;
1523 }
1524
1525 f32 rotationScalar = ROTATION_SCALAR_NORMAL;
1526 if (collide()->surfaceFlags().onBit(KartCollide::eSurfaceFlags::BoostRamp)) {
1527 rotationScalar = ROTATION_SCALAR_BOOST_RAMP;
1528 } else if (status.offBit(eStatus::TouchingGround)) {
1529 rotationScalar = ROTATION_SCALAR_MIDAIR;
1530 }
1531
1532 EGG::Matrix34f local_90;
1533 local_90.setAxisRotation(DEG2RAD * rotationScalar, crossVec);
1534 m_vel1Dir = local_90.multVector33(m_vel1Dir);
1535
1536 const auto *raceMgr = System::RaceManager::Instance();
1537 if (status.offBit(eStatus::InAction, eStatus::DisableBackwardsAccel, eStatus::Accelerate) &&
1539 raceMgr->isStageReached(System::RaceManager::Stage::Race)) {
1541 }
1542
1544 EGG::Vector3f nextSpeed = m_speed * m_vel1Dir;
1545
1546 f32 maxSpeedY = status.onBit(eStatus::OverZipper) ? KartHalfPipe::TerminalVelocity() :
1547 TERMINAL_VELOCITY;
1548 nextSpeed.y = std::min(nextSpeed.y, maxSpeedY);
1549
1550 dynamics()->setIntVel(dynamics()->intVel() + nextSpeed);
1551
1552 if (status.onBit(eStatus::TouchingGround) &&
1554 if (status.onBit(eStatus::Brake)) {
1555 if (m_drivingDirection == DrivingDirection::Forwards) {
1556 m_drivingDirection = m_processedSpeed > 5.0f ? DrivingDirection::Braking :
1557 DrivingDirection::Backwards;
1558 }
1559 } else {
1560 if (m_processedSpeed >= 0.0f) {
1561 m_drivingDirection = DrivingDirection::Forwards;
1562 }
1563 }
1564 } else {
1565 m_drivingDirection = DrivingDirection::Forwards;
1566 }
1567}
1568
1573 auto &status = KartObjectProxy::status();
1574
1576 return 1.0f;
1577 }
1578
1579 onWallCollision();
1580
1582 return 1.0f;
1583 }
1584
1585 EGG::Vector3f wallNrm = collisionData().wallNrm;
1586 if (wallNrm.y > 0.0f) {
1587 wallNrm.y = 0.0f;
1588 wallNrm.normalise();
1589 }
1590
1591 f32 dot = m_lastDir.dot(wallNrm);
1592
1593 if (dot < 0.0f) {
1594 f1 = std::max(0.0f, dot + 1.0f);
1595
1596 return std::min(1.0f, f1 * (status.onBit(eStatus::WallCollision) ? 0.4f : 0.7f));
1597 }
1598
1599 return 1.0f;
1600}
1601
1607
1608 auto &status = KartObjectProxy::status();
1609
1610 if (status.offBit(eStatus::WallCollisionStart)) {
1611 return;
1612 }
1613
1614 m_outsideDriftAngle = 0.0f;
1615 if (status.offBit(eStatus::InAction)) {
1616 m_dir = bodyFront();
1617 m_vel1Dir = m_dir;
1618 m_landingDir = m_dir;
1619 }
1620
1621 if (status.offBit(eStatus::ZipperInvisibleWall, eStatus::OverZipper) && param_2 < 0.9f) {
1622 f32 speedDiff = m_lastSpeed - m_speed;
1623 const CollisionData &colData = collisionData();
1624
1625 if (speedDiff > 30.0f) {
1626 m_flags.setBit(eFlags::WallBounce);
1627 EGG::Vector3f newPos = colData.relPos + pos();
1628 f32 dot = -bodyUp().dot(colData.relPos) * 0.5f;
1629 EGG::Vector3f scaledUp = dot * bodyUp();
1630 newPos -= scaledUp;
1631
1632 speedDiff = std::min(60.0f, speedDiff);
1633 EGG::Vector3f scaledWallNrm = speedDiff * colData.wallNrm;
1634
1635 auto [proj, rej] = scaledWallNrm.projAndRej(m_vel1Dir);
1636 proj *= 0.3f;
1637 rej *= 0.9f;
1638
1639 if (status.onBit(eStatus::Boost)) {
1640 proj = EGG::Vector3f::zero;
1641 rej = EGG::Vector3f::zero;
1642 }
1643
1644 if (bodyFront().dot(colData.wallNrm) > 0.0f) {
1645 proj = EGG::Vector3f::zero;
1646 }
1647 rej *= 0.9f;
1648
1649 EGG::Vector3f projRejSum = proj + rej;
1650 f32 bumpDeviation = 0.0f;
1651 if (m_flags.offBit(eFlags::DriftReset) && status.onBit(eStatus::TouchingGround)) {
1652 bumpDeviation = param()->stats().bumpDeviationLevel;
1653 }
1654
1655 dynamics()->applyWrenchScaled(newPos, projRejSum, bumpDeviation);
1656 } else if (wallKclType() == COL_TYPE_SPECIAL_WALL && wallKclVariant() == 2) {
1657 dynamics()->addForce(colData.wallNrm * 15.0f);
1658 collide()->startFloorMomentRate();
1659 }
1660
1661 if (wallKclType() == COL_TYPE_SPECIAL_WALL && wallKclVariant() == 0) {
1662 dynamics()->addForce(colData.wallNrm * 15.0f);
1663 collide()->startFloorMomentRate();
1664 }
1665 }
1666}
1667
1672 f32 next = 0.0f;
1673 f32 scalar = 1.0f;
1674
1675 auto &status = KartObjectProxy::status();
1676
1677 if (status.onBit(eStatus::TouchingGround)) {
1678 if (System::RaceManager::Instance()->stage() == System::RaceManager::Stage::Countdown) {
1679 next = 0.015f * -state()->startBoostCharge();
1680 } else if (status.offBit(eStatus::ChargingSSMT)) {
1681 if (status.offBit(eStatus::JumpPad, eStatus::RampBoost, eStatus::SoftWallDrift)) {
1682 f32 speedDiff = m_lastSpeed - m_speed;
1683 scalar = std::min(3.0f, std::max(speedDiff, -3.0f));
1684
1685 if (status.onBit(eStatus::MushroomBoost)) {
1686 next = (scalar * 0.15f) * 0.25f;
1687 if (status.onBit(eStatus::Wheelie)) {
1688 next *= 0.5f;
1689 }
1690 } else {
1691 next = (scalar * 0.15f) * 0.08f;
1692 }
1693 scalar = m_driftingParams->boostRotFactor;
1694 }
1695 } else {
1696 constexpr s16 MAX_SSMT_CHARGE = 75;
1697 next = 0.015f * (-static_cast<f32>(m_ssmtCharge) / static_cast<f32>(MAX_SSMT_CHARGE));
1698 }
1699 }
1700
1701 if (m_flags.onBit(eFlags::WallBounce)) {
1702 m_standStillBoostRot = isBike() ? next * 3.0f : next * 10.0f;
1703 } else {
1704 m_standStillBoostRot += scalar * (next * m_invScale - m_standStillBoostRot);
1705 }
1706}
1707
1712 constexpr f32 DIVE_LIMIT = 0.8f;
1713
1714 m_divingRot *= 0.96f;
1715
1716 auto &status = KartObjectProxy::status();
1717
1718 if (status.onBit(eStatus::TouchingGround, eStatus::CannonStart, eStatus::InCannon,
1719 eStatus::InAction, eStatus::OverZipper)) {
1720 return;
1721 }
1722
1723 f32 stickY = state()->stickY();
1724
1725 if (status.onBit(eStatus::InATrick) && m_jump->type() == TrickType::BikeSideStuntTrick) {
1726 stickY = std::min(1.0f, stickY + 0.4f);
1727 }
1728
1729 u32 airtime = state()->airtime();
1730
1731 if (airtime > 50) {
1732 if (EGG::Mathf::abs(stickY) < 0.1f) {
1733 m_divingRot += 0.05f * (-0.025f - m_divingRot);
1734 }
1735 } else {
1736 stickY *= (airtime / 50.0f);
1737 }
1738
1739 m_divingRot = std::max(-DIVE_LIMIT, std::min(DIVE_LIMIT, m_divingRot + stickY * 0.005f));
1740
1741 EGG::Vector3f angVel2 = dynamics()->angVel2();
1742 angVel2.x += m_divingRot;
1743 dynamics()->setAngVel2(angVel2);
1744
1745 if (state()->airtime() < 50) {
1746 return;
1747 }
1748
1749 EGG::Vector3f topRotated = dynamics()->mainRot().rotateVector(EGG::Vector3f::ey);
1750 EGG::Vector3f forwardRotated = dynamics()->mainRot().rotateVector(EGG::Vector3f::ez);
1751 f32 upDotTop = m_up.dot(topRotated);
1752 EGG::Vector3f upCrossTop = m_up.cross(topRotated);
1753 f32 crossNorm = upCrossTop.length();
1754 f32 angle = EGG::Mathf::abs(EGG::Mathf::atan2(crossNorm, upDotTop));
1755
1756 f32 fVar1 = angle * RAD2DEG - 20.0f;
1757 if (fVar1 <= 0.0f) {
1758 return;
1759 }
1760
1761 f32 mult = std::min(1.0f, fVar1 / 20.0f);
1762 if (forwardRotated.y > 0.0f) {
1763 dynamics()->setGravity((1.0f - 0.2f * mult) * dynamics()->gravity());
1764 } else {
1765 dynamics()->setGravity((0.2f * mult + 1.0f) * dynamics()->gravity());
1766 }
1767}
1768
1773 auto &status = KartObjectProxy::status();
1774
1775 if (EGG::Mathf::abs(m_speed) >= 10.0f || status.onBit(eStatus::Boost, eStatus::RampBoost) ||
1778 return;
1779 }
1780
1782}
1783
1785void KartMove::calcHopPhysics() {
1786 m_hopVelY = m_hopVelY * 0.998f + m_hopGravity;
1788
1789 if (m_hopPosY < 0.0f) {
1790 m_hopPosY = 0.0f;
1791 m_hopVelY = 0.0f;
1792 }
1793}
1794
1796void KartMove::calcRejectRoad() {
1797 m_reject.calcRejectRoad();
1798}
1799
1801bool KartMove::calcZipperCollision(f32 radius, f32 scale, EGG::Vector3f &pos,
1802 EGG::Vector3f &upLocal, const EGG::Vector3f &prevPos, Field::CollisionInfo *colInfo,
1803 Field::KCLTypeMask *maskOut, Field::KCLTypeMask flags) const {
1804 upLocal = mainRot().rotateVector(EGG::Vector3f::ey);
1805 pos = dynamics()->pos() + (-scale * m_scale.y) * upLocal;
1806
1807 auto *colDir = Field::CollisionDirector::Instance();
1808 return colDir->checkSphereFullPush(radius, pos, prevPos, flags, colInfo, maskOut, 0);
1809}
1810
1812f32 KartMove::calcSlerpRate(f32 scale, const EGG::Quatf &from, const EGG::Quatf &to) const {
1813 f32 dotNorm = std::max(-1.0f, std::min(1.0f, from.dot(to)));
1814 f32 acos = EGG::Mathf::acos(dotNorm);
1815 return acos > 0.0f ? std::min(0.1f, scale / acos) : 0.1f;
1816}
1817
1819void KartMove::applyForce(f32 force, const EGG::Vector3f &hitDir, bool stop) {
1820 constexpr s16 BUMP_COOLDOWN = 5;
1821
1822 if (m_bumpTimer >= 1) {
1823 return;
1824 }
1825
1826 dynamics()->addForce(force * hitDir.perpInPlane(m_up, true));
1827 collide()->startFloorMomentRate();
1828
1829 m_bumpTimer = BUMP_COOLDOWN;
1830
1831 if (stop) {
1832 m_speed = 0.0f;
1833 }
1834}
1835
1839 f32 tiltMagnitude = 0.0f;
1840 auto &status = KartObjectProxy::status();
1841
1842 if (status.offBit(eStatus::InAction, eStatus::SoftWallDrift) &&
1844 EGG::Vector3f front = componentZAxis();
1845 front = front.perpInPlane(m_up, true);
1846 EGG::Vector3f frontSpeed = velocity().rej(front).perpInPlane(m_up, false);
1847 f32 magnitude = tiltMagnitude;
1848
1849 if (frontSpeed.squaredLength() > std::numeric_limits<f32>::epsilon()) {
1850 magnitude = frontSpeed.length();
1851
1852 if (front.z * frontSpeed.x - front.x * frontSpeed.z > 0.0f) {
1853 magnitude = -magnitude;
1854 }
1855
1856 tiltMagnitude = -1.0f;
1857 if (-1.0f <= magnitude) {
1858 tiltMagnitude = std::min(1.0f, magnitude);
1859 }
1860 }
1861 } else if (status.offBit(eStatus::Hop) || m_hopPosY <= 0.0f) {
1862 EGG::Vector3f angVel0 = dynamics()->angVel0();
1863 angVel0.z *= 0.98f;
1864 dynamics()->setAngVel0(angVel0);
1865 }
1866
1867 f32 lean =
1868 m_invScale * (tiltMagnitude * param()->stats().tilt * EGG::Mathf::abs(m_weightedTurn));
1869
1871
1872 EGG::Vector3f angVel0 = dynamics()->angVel0();
1873 angVel0.x += m_standStillBoostRot;
1874 angVel0.z += lean;
1875 dynamics()->setAngVel0(angVel0);
1876
1877 EGG::Vector3f angVel2 = dynamics()->angVel2();
1878 angVel2.y += turn;
1879 dynamics()->setAngVel2(angVel2);
1880
1881 calcDive();
1882}
1883
1888 // TODO: Some of these are shared between the base and derived class implementations.
1889 constexpr u16 MAX_MT_CHARGE = 270;
1890 constexpr u16 MAX_SMT_CHARGE = 300;
1891 constexpr u16 BASE_MT_CHARGE = 2;
1892 constexpr u16 BASE_SMT_CHARGE = 2;
1893 constexpr f32 BONUS_CHARGE_STICK_THRESHOLD = 0.4f;
1894 constexpr u16 EXTRA_MT_CHARGE = 3;
1895
1896 if (m_driftState == DriftState::ChargedSmt) {
1897 return;
1898 }
1899
1900 f32 stickX = state()->stickX();
1901
1902 if (m_driftState == DriftState::ChargingMt) {
1903 m_mtCharge += BASE_MT_CHARGE;
1904
1905 if (-BONUS_CHARGE_STICK_THRESHOLD <= stickX) {
1906 if (BONUS_CHARGE_STICK_THRESHOLD < stickX && m_hopStickX == -1) {
1907 m_mtCharge += EXTRA_MT_CHARGE;
1908 }
1909 } else if (m_hopStickX != -1) {
1910 m_mtCharge += EXTRA_MT_CHARGE;
1911 }
1912
1913 if (m_mtCharge > MAX_MT_CHARGE) {
1914 m_mtCharge = MAX_MT_CHARGE;
1915 m_driftState = DriftState::ChargingSmt;
1916 }
1917 }
1918
1919 if (m_driftState != DriftState::ChargingSmt) {
1920 return;
1921 }
1922
1923 m_smtCharge += BASE_SMT_CHARGE;
1924
1925 if (-BONUS_CHARGE_STICK_THRESHOLD <= stickX) {
1926 if (BONUS_CHARGE_STICK_THRESHOLD < stickX && m_hopStickX == -1) {
1927 m_smtCharge += EXTRA_MT_CHARGE;
1928 }
1929 } else if (m_hopStickX != -1) {
1930 m_smtCharge += EXTRA_MT_CHARGE;
1931 }
1932
1933 if (m_smtCharge > MAX_SMT_CHARGE) {
1934 m_smtCharge = MAX_SMT_CHARGE;
1935 m_driftState = DriftState::ChargedSmt;
1936 }
1937}
1938
1940void KartMove::initOob() {
1941 clearBoost();
1942 clearJumpPad();
1943 clearRampBoost();
1944 clearZipperBoost();
1945 clearSsmt();
1946 clearOffroadInvincibility();
1947}
1948
1953 status().setBit(eStatus::Hop).resetBit(eStatus::DriftManual);
1954 onHop();
1955
1956 m_hopUp = dynamics()->mainRot().rotateVector(EGG::Vector3f::ey);
1957 m_hopDir = dynamics()->mainRot().rotateVector(EGG::Vector3f::ez);
1958 m_driftState = DriftState::NotDrifting;
1959 m_smtCharge = 0;
1960 m_mtCharge = 0;
1961 m_hopStickX = 0;
1962 m_hopFrame = 0;
1963 m_hopPosY = 0.0f;
1964 m_hopGravity = dynamics()->gravity();
1965 m_hopVelY = m_driftingParams->hopVelY;
1966 m_outsideDriftBonus = 0.0f;
1967
1968 EGG::Vector3f extVel = dynamics()->extVel();
1969 extVel.y = 0.0f + m_hopVelY;
1970 dynamics()->setExtVel(extVel);
1971
1972 EGG::Vector3f totalForce = dynamics()->totalForce();
1973 totalForce.y = 0.0f;
1974 dynamics()->setTotalForce(totalForce);
1975}
1976
1978void KartMove::tryStartBoostPanel() {
1979 constexpr s16 BOOST_PANEL_DURATION = 60;
1980
1981 if (status().onBit(eStatus::BeforeRespawn, eStatus::InAction)) {
1982 return;
1983 }
1984
1985 activateBoost(KartBoost::Type::MushroomAndBoostPanel, BOOST_PANEL_DURATION);
1986 setOffroadInvincibility(BOOST_PANEL_DURATION);
1987}
1988
1993 constexpr s16 BOOST_RAMP_DURATION = 60;
1994
1995 auto &status = KartObjectProxy::status();
1996
1997 if (status.onBit(eStatus::BeforeRespawn, eStatus::InAction)) {
1998 return;
1999 }
2000
2001 status.setBit(eStatus::RampBoost);
2002 m_rampBoost = BOOST_RAMP_DURATION;
2003 setOffroadInvincibility(BOOST_RAMP_DURATION);
2004}
2005
2011 static constexpr std::array<JumpPadProperties, 8> JUMP_PAD_PROPERTIES = {{
2012 {50.0f, 50.0f, 35.0f},
2013 {50.0f, 50.0f, 47.0f},
2014 {59.0f, 59.0f, 30.0f},
2015 {73.0f, 73.0f, 45.0f},
2016 {73.0f, 73.0f, 53.0f},
2017 {56.0f, 56.0f, 50.0f},
2018 {55.0f, 55.0f, 35.0f},
2019 {56.0f, 56.0f, 50.0f},
2020 }};
2021
2022 auto &status = KartObjectProxy::status();
2023
2024 if (status.onBit(eStatus::BeforeRespawn, eStatus::InAction, eStatus::HalfPipeRamp)) {
2025 return;
2026 }
2027
2028 status.setBit(eStatus::JumpPad);
2029 s32 jumpPadVariant = state()->jumpPadVariant();
2030 m_jumpPadProperties = &JUMP_PAD_PROPERTIES[jumpPadVariant];
2031
2032 if (jumpPadVariant == 3 || jumpPadVariant == 4) {
2033 if (m_jumpPadBoostMultiplier > 1.3f || m_jumpPadSoftSpeedLimit > 110.0f) {
2034 // Set speed to 100 if the player has boost from a boost panel or mushroom(item) before
2035 // hitting the jump pad
2036 static constexpr std::array<JumpPadProperties, 2> JUMP_PAD_PROPERTIES_SHROOM_BOOST = {{
2037 {100.0f, 100.0f, 70.0f},
2038 {100.0f, 100.0f, 65.0f},
2039 }};
2040 m_jumpPadProperties = &JUMP_PAD_PROPERTIES_SHROOM_BOOST[jumpPadVariant != 3];
2041 }
2042
2043 status.setBit(eStatus::JumpPadFixedSpeed);
2044 }
2045
2046 if (jumpPadVariant == 4) {
2047 status.setBit(eStatus::JumpPadMushroomTrigger, eStatus::JumpPadMushroomVelYInc,
2048 eStatus::JumpPadMushroomCollision);
2049 } else {
2050 EGG::Vector3f extVel = dynamics()->extVel();
2051 EGG::Vector3f totalForce = dynamics()->totalForce();
2052
2053 extVel.y = m_jumpPadProperties->velY;
2054 totalForce.y = 0.0f;
2055
2056 dynamics()->setExtVel(extVel);
2057 dynamics()->setTotalForce(totalForce);
2058
2059 if (jumpPadVariant != 3) {
2060 EGG::Vector3f dir = m_dir;
2061 dir.y = 0.0f;
2062 dir.normalise();
2063 m_speed *= m_dir.dot(dir);
2064 m_dir = dir;
2065 m_vel1Dir = dir;
2066 status.setBit(eStatus::JumpPadDisableYsusForce);
2067 }
2068 }
2069
2070 m_jumpPadMinSpeed = m_jumpPadProperties->minSpeed;
2071 m_jumpPadMaxSpeed = m_jumpPadProperties->maxSpeed;
2072 m_speed = std::max(m_speed, m_jumpPadMinSpeed);
2073}
2074
2076void KartMove::tryEndJumpPad() {
2077 auto &status = KartObjectProxy::status();
2078 if (status.onBit(eStatus::JumpPadMushroomTrigger)) {
2079 if (status.onBit(eStatus::GroundStart)) {
2080 status.resetBit(eStatus::JumpPadMushroomTrigger, eStatus::JumpPadFixedSpeed,
2081 eStatus::JumpPadMushroomVelYInc);
2082 }
2083
2084 if (status.onBit(eStatus::JumpPadMushroomVelYInc)) {
2085 EGG::Vector3f newExtVel = dynamics()->extVel();
2086 newExtVel.y += 20.0f;
2087 if (m_jumpPadProperties->velY < newExtVel.y) {
2088 newExtVel.y = m_jumpPadProperties->velY;
2089 status.resetBit(eStatus::JumpPadMushroomVelYInc);
2090 }
2091 dynamics()->setExtVel(newExtVel);
2092 }
2093 }
2094
2095 if (status.onBit(eStatus::GroundStart) && status.offBit(eStatus::JumpPadMushroomTrigger)) {
2096 cancelJumpPad();
2097 }
2098}
2099
2101void KartMove::cancelJumpPad() {
2102 m_jumpPadMinSpeed = 0.0f;
2103 status().resetBit(eStatus::JumpPad);
2104}
2105
2107void KartMove::activateBoost(KartBoost::Type type, s16 frames) {
2108 if (m_boost.activate(type, frames)) {
2109 status().setBit(eStatus::Boost);
2110 }
2111}
2112
2114void KartMove::applyStartBoost(s16 frames) {
2115 activateBoost(KartBoost::Type::AllMt, frames);
2116}
2117
2119void KartMove::activateMushroom() {
2120 constexpr s16 MUSHROOM_DURATION = 90;
2121
2122 auto &status = KartObjectProxy::status();
2123
2124 if (status.onBit(eStatus::BeforeRespawn, eStatus::InAction)) {
2125 return;
2126 }
2127
2128 activateBoost(KartBoost::Type::MushroomAndBoostPanel, MUSHROOM_DURATION);
2129
2130 m_mushroomBoostTimer = MUSHROOM_DURATION;
2132 setOffroadInvincibility(MUSHROOM_DURATION);
2133}
2134
2136void KartMove::activateZipperBoost() {
2137 constexpr s16 BASE_DURATION = 50;
2138 constexpr s16 TRICK_DURATION = 100;
2139
2140 auto &status = KartObjectProxy::status();
2141
2142 if (status.onBit(eStatus::BeforeRespawn, eStatus::InAction)) {
2143 return;
2144 }
2145
2146 s16 boostDuration = status.onBit(eStatus::ZipperTrick) ? TRICK_DURATION : BASE_DURATION;
2147 activateBoost(KartBoost::Type::TrickAndZipper, boostDuration);
2148
2149 setOffroadInvincibility(boostDuration);
2150 m_zipperBoostTimer = 0;
2151 m_zipperBoostMax = boostDuration;
2153}
2154
2160 if (timer > m_offroadInvincibility) {
2161 m_offroadInvincibility = timer;
2162 }
2163
2165}
2166
2171 auto &status = KartObjectProxy::status();
2172
2174 return;
2175 }
2176
2177 if (--m_offroadInvincibility > 0) {
2178 return;
2179 }
2180
2182}
2183
2187 auto &status = KartObjectProxy::status();
2188
2189 if (status.offBit(eStatus::MushroomBoost)) {
2190 return;
2191 }
2192
2193 if (--m_mushroomBoostTimer > 0) {
2194 return;
2195 }
2196
2198}
2199
2201void KartMove::calcZipperBoost() {
2202 auto &status = KartObjectProxy::status();
2203
2204 if (status.offBit(eStatus::ZipperBoost)) {
2205 return;
2206 }
2207
2209
2210 if (status.offBit(eStatus::OverZipper) && ++m_zipperBoostTimer >= m_zipperBoostMax) {
2211 m_zipperBoostTimer = 0;
2213 }
2214
2215 if (m_zipperBoostTimer < 10) {
2216 EGG::Vector3f angVel = dynamics()->angVel0();
2217 angVel.y = 0.0f;
2218 dynamics()->setAngVel0(angVel);
2219 }
2220}
2221
2223void KartMove::landTrick() {
2224 static constexpr std::array<s16, 3> KART_TRICK_BOOST_DURATION = {{
2225 40,
2226 70,
2227 85,
2228 }};
2229 static constexpr std::array<s16, 3> BIKE_TRICK_BOOST_DURATION = {{
2230 45,
2231 80,
2232 95,
2233 }};
2234
2235 if (status().onBit(eStatus::BeforeRespawn, eStatus::InAction)) {
2236 return;
2237 }
2238
2239 s16 duration;
2240 if (isBike()) {
2241 duration = BIKE_TRICK_BOOST_DURATION[static_cast<u32>(m_jump->variant())];
2242 } else {
2243 duration = KART_TRICK_BOOST_DURATION[static_cast<u32>(m_jump->variant())];
2244 }
2245
2246 activateBoost(KartBoost::Type::TrickAndZipper, duration);
2247}
2248
2250void KartMove::activateCrush(u16 timer) {
2251 status().setBit(eStatus::Crushed);
2252 m_crushTimer = timer;
2253 m_kartScale->startCrush();
2254}
2255
2257void KartMove::calcCrushed() {
2258 if (status().offBit(eStatus::Crushed)) {
2259 return;
2260 }
2261
2262 if (--m_crushTimer == 0) {
2263 status().resetBit(eStatus::Crushed);
2264 m_kartScale->endCrush();
2265 }
2266}
2267
2269void KartMove::calcScale() {
2270 m_kartScale->calc();
2271
2272 const EGG::Vector3f sizeScale = m_kartScale->sizeScale();
2273 setScale(m_kartScale->pressScale() * sizeScale);
2274 m_totalScale = m_shockSpeedMultiplier;
2275 m_hitboxScale = std::max(sizeScale.z, m_totalScale);
2276
2277 if (sizeScale.z != 1.0f) {
2278 setInertiaScale(m_scale);
2279 }
2280
2281 m_invScale = m_scale.z > 1.0f ? 1.0f / m_scale.z : 1.0f;
2282}
2283
2285void KartMove::applyShrink(u16 timer) {
2286 auto &status = state()->status();
2287
2288 if (status.onBit(eStatus::InRespawn, eStatus::AfterRespawn, eStatus::CannonStart)) {
2289 return;
2290 }
2291
2292 action()->start(Action::UNK_15);
2293 Item::ItemDirector::Instance()->kartItem(0).clear();
2294 status.setBit(eStatus::Shocked);
2295
2296 if (timer > m_shockTimer) {
2297 m_shockTimer = timer;
2298 m_kartScale->startShrink(0);
2299 }
2300}
2301
2303void KartMove::calcShock() {
2304 auto &status = state()->status();
2305
2306 if (status.onBit(eStatus::Shocked)) {
2307 if (--m_shockTimer == 0) {
2308 deactivateShock(false);
2309 }
2310
2311 m_shockSpeedMultiplier = std::max(0.7f, m_shockSpeedMultiplier - 0.03f);
2312 } else {
2313 m_shockSpeedMultiplier = std::min(1.0f, m_shockSpeedMultiplier + 0.05f);
2314 }
2315}
2316
2318void KartMove::deactivateShock(bool resetSpeed) {
2319 status().resetBit(eStatus::Shocked);
2320 m_shockTimer = 0;
2321 m_kartScale->endShrink(0);
2322
2323 if (resetSpeed) {
2324 m_shockSpeedMultiplier = 1.0f;
2325 }
2326}
2327
2329void KartMove::enterCannon() {
2330 init(true, true);
2331 physics()->clearDecayingRot();
2332 m_boost.resetActive();
2333
2334 auto &status = KartObjectProxy::status();
2335
2336 status.resetBit(eStatus::Boost);
2337
2338 cancelJumpPad();
2339 clearRampBoost();
2340 clearZipperBoost();
2341 clearSsmt();
2342 clearOffroadInvincibility();
2343
2344 dynamics()->reset();
2345
2346 clearDrift();
2347
2348 status.resetBit(eStatus::Hop, eStatus::CannonStart)
2349 .setBit(eStatus::InCannon, eStatus::SkipWheelCalc);
2350
2351 const auto [cannonPos, cannonDir] = getCannonPosRot();
2352 m_cannonEntryPos = pos();
2353 m_cannonEntryOfs = cannonPos - pos();
2354 m_cannonEntryOfsLength = m_cannonEntryOfs.normalise();
2355 m_cannonEntryOfs.normalise();
2356 m_dir = m_cannonEntryOfs;
2357 m_vel1Dir = m_cannonEntryOfs;
2358 m_cannonOrthog = EGG::Vector3f::ey.perpInPlane(m_cannonEntryOfs, true);
2359 m_cannonProgress.setZero();
2360}
2361
2363void KartMove::calcCannon() {
2364 auto [cannonPos, cannonDir] = getCannonPosRot();
2365 EGG::Vector3f forwardXZ = cannonPos - m_cannonEntryPos - m_cannonProgress;
2366 EGG::Vector3f forward = forwardXZ;
2367 f32 forwardLength = forward.normalise();
2368 forwardXZ.y = 0;
2369 forwardXZ.normalise();
2370 EGG::Vector3f local94 = m_cannonEntryOfs;
2371 local94.y = 0;
2372 local94.normalise();
2373 m_speedRatioCapped = 1.0f;
2374 m_speedRatio = 1.5f;
2375 EGG::Matrix34f cannonOrientation;
2376 cannonOrientation.makeOrthonormalBasis(forward, EGG::Vector3f::ey);
2377 EGG::Vector3f up = cannonOrientation.multVector33(EGG::Vector3f::ey);
2378 m_smoothedUp = up;
2379 m_up = up;
2380
2381 if (forwardLength < 30.0f || local94.dot(forwardXZ) <= 0.0f) {
2382 exitCannon();
2383 return;
2384 }
2386 const auto *cannonPoint =
2387 System::CourseMap::Instance()->getCannonPoint(state()->cannonPointId());
2388 size_t cannonParameterIdx = std::max<s16>(0, cannonPoint->parameterIdx());
2389 ASSERT(cannonParameterIdx < CANNON_PARAMETERS.size());
2390 const auto &cannonParams = CANNON_PARAMETERS[cannonParameterIdx];
2391 f32 newSpeed = cannonParams.speed;
2392 if (forwardLength < cannonParams.decelFactor) {
2393 f32 factor = std::max(0.0f, forwardLength / cannonParams.decelFactor);
2394
2395 newSpeed = cannonParams.endDecel;
2396 if (newSpeed <= 0.0f) {
2397 newSpeed = m_baseSpeed;
2398 }
2399
2400 newSpeed += factor * (cannonParams.speed - newSpeed);
2401 if (cannonParams.endDecel > 0.0f) {
2402 m_speed = std::min(newSpeed, m_speed);
2403 }
2404 }
2405
2406 m_cannonProgress += m_cannonEntryOfs * newSpeed;
2407
2408 EGG::Vector3f newPos = EGG::Vector3f::zero;
2409 if (cannonParams.height > 0.0f) {
2410 f32 fVar9 = EGG::Mathf::SinFIdx(
2411 (1.0f - (forwardLength / m_cannonEntryOfsLength)) * 180.0f * DEG2FIDX);
2412 newPos = fVar9 * cannonParams.height * m_cannonOrthog;
2413 }
2414
2415 dynamics()->setPos(m_cannonEntryPos + m_cannonProgress + newPos);
2416 m_dir = m_cannonEntryOfs;
2417 m_vel1Dir = m_cannonEntryOfs;
2418
2419 calcRotCannon(forward);
2420
2421 dynamics()->setExtVel(EGG::Vector3f::zero);
2422}
2423
2425void KartMove::calcRotCannon(const EGG::Vector3f &forward) {
2426 EGG::Vector3f local48 = forward;
2427 local48.normalise();
2428 EGG::Vector3f local54 = bodyFront();
2429 EGG::Vector3f local60 = local54 + ((local48 - local54) * 0.3f);
2430 local54.normalise();
2431 local60.normalise();
2432 // also local70, localA8
2433 EGG::Quatf local80;
2434 local80.makeVectorRotation(local54, local60);
2435 local80 *= dynamics()->fullRot();
2436 local80.normalise();
2437 EGG::Quatf localB8;
2438 localB8.makeVectorRotation(local80.rotateVector(EGG::Vector3f::ey), smoothedUp());
2439 EGG::Quatf newRot = local80.slerpTo(localB8.multSwap(local80), 0.3f);
2440 dynamics()->setFullRot(newRot);
2441 dynamics()->setMainRot(newRot);
2442}
2443
2445void KartMove::exitCannon() {
2446 auto &status = KartObjectProxy::status();
2447
2448 if (status.offBit(eStatus::InCannon)) {
2449 return;
2450 }
2451
2452 status.resetBit(eStatus::InCannon, eStatus::SkipWheelCalc).setBit(eStatus::AfterCannon);
2453 dynamics()->setIntVel(m_cannonEntryOfs * m_speed);
2454}
2455
2457void KartMove::triggerRespawn() {
2458 m_timeInRespawn = 0;
2459 status().setBit(eStatus::TriggerRespawn);
2460}
2461
2463KartMoveBike::KartMoveBike() : m_leanRot(0.0f) {}
2464
2466KartMoveBike::~KartMoveBike() = default;
2467
2471 constexpr f32 MAX_WHEELIE_ROTATION = 0.07f;
2472 constexpr u16 WHEELIE_COOLDOWN = 20;
2473
2474 status().setBit(eStatus::Wheelie);
2475 m_wheelieFrames = 0;
2476 m_maxWheelieRot = MAX_WHEELIE_ROTATION;
2477 m_wheelieCooldown = WHEELIE_COOLDOWN;
2478 m_wheelieRotDec = 0.0f;
2479 m_autoHardStickXFrames = 0;
2480}
2481
2486 status().resetBit(eStatus::Wheelie);
2487 m_wheelieRotDec = 0.0f;
2488 m_autoHardStickXFrames = 0;
2489}
2490
2492void KartMoveBike::createSubsystems(const KartParam::Stats &stats) {
2493 m_jump = new KartJumpBike(this);
2495 m_kartScale = new KartScale(stats);
2496}
2497
2502 f32 leanRotInc = m_turningParams->leanRotIncRace;
2503 f32 leanRotCap = m_turningParams->leanRotCapRace;
2504 const auto *raceManager = System::RaceManager::Instance();
2505
2506 auto &status = KartObjectProxy::status();
2507
2508 if (status.offBit(eStatus::ChargingSSMT)) {
2509 if (!raceManager->isStageReached(System::RaceManager::Stage::Race) ||
2510 EGG::Mathf::abs(m_speed) < 5.0f) {
2511 leanRotInc = m_turningParams->leanRotIncCountdown;
2512 leanRotCap = m_turningParams->leanRotCapCountdown;
2513 }
2514 } else {
2515 leanRotInc = m_turningParams->leanRotIncSSMT;
2516 leanRotCap = m_turningParams->leanRotCapSSMT;
2517 }
2518
2519 m_leanRotCap += 0.3f * (leanRotCap - m_leanRotCap);
2520 m_leanRotInc += 0.3f * (leanRotInc - m_leanRotInc);
2521
2522 f32 stickX = state()->stickX();
2523 f32 extVelXFactor = 0.0f;
2524 f32 leanRotMin = -m_leanRotCap;
2525 f32 leanRotMax = m_leanRotCap;
2526
2527 if (status.onBit(eStatus::BeforeRespawn, eStatus::InAction, eStatus::Wheelie,
2529 eStatus::SoftWallDrift, eStatus::SomethingWallCollision, eStatus::HWG,
2530 eStatus::CannonStart, eStatus::InCannon)) {
2531 m_leanRot *= m_turningParams->leanRotDecayFactor;
2532 } else if (!state()->isDrifting()) {
2533 if (stickX <= 0.2f) {
2534 if (stickX >= -0.2f) {
2535 m_leanRot *= m_turningParams->leanRotDecayFactor;
2536 } else {
2538 extVelXFactor = m_turningParams->leanRotShallowFactor;
2539 }
2540 } else {
2542 extVelXFactor = -m_turningParams->leanRotShallowFactor;
2543 }
2544 } else {
2545 leanRotMax = m_turningParams->leanRotMaxDrift;
2546 leanRotMin = m_turningParams->leanRotMinDrift;
2547
2548 if (m_hopStickX == 1) {
2549 leanRotMin = -leanRotMax;
2550 leanRotMax = -m_turningParams->leanRotMinDrift;
2551 }
2552 if (m_hopStickX == -1) {
2553 if (stickX == 0.0f) {
2554 m_leanRot += (0.5f - m_leanRot) * 0.05f;
2555 } else {
2556 m_leanRot += m_turningParams->driftStickXFactor * stickX;
2557 extVelXFactor = -m_turningParams->leanRotShallowFactor * stickX;
2558 }
2559 } else if (stickX == 0.0f) {
2560 m_leanRot += (-0.5f - m_leanRot) * 0.05f;
2561 } else {
2562 m_leanRot += m_turningParams->driftStickXFactor * stickX;
2563 extVelXFactor = -m_turningParams->leanRotShallowFactor * stickX;
2564 }
2565 }
2566
2567 bool capped = false;
2568 if (leanRotMin <= m_leanRot) {
2569 if (leanRotMax < m_leanRot) {
2570 m_leanRot = leanRotMax;
2571 capped = true;
2572 }
2573 } else {
2574 m_leanRot = leanRotMin;
2575 capped = true;
2576 }
2577
2578 if (!capped) {
2579 dynamics()->setExtVel(dynamics()->extVel() + componentXAxis() * extVelXFactor);
2580 }
2581
2582 f32 leanRotScalar = state()->isDrifting() ? 0.065f : 0.05f;
2583
2585
2586 dynamics()->setAngVel2(dynamics()->angVel2() +
2587 EGG::Vector3f(m_standStillBoostRot, turn * wheelieRotFactor(),
2588 m_leanRot * leanRotScalar));
2589
2590 calcDive();
2591
2592 EGG::Vector3f top = m_up;
2593
2595 f32 scalar = (m_speed >= 0.0f) ? m_speedRatioCapped * 2.0f : 0.0f;
2596 scalar = std::min(1.0f, scalar);
2597 top = scalar * m_up + (1.0f - scalar) * EGG::Vector3f::ey;
2598
2599 if (std::numeric_limits<f32>::epsilon() < top.squaredLength()) {
2600 top.normalise();
2601 }
2602 }
2603
2604 dynamics()->setTop_(top);
2605}
2606
2612 static constexpr std::array<TurningParameters, 2> TURNING_PARAMS_ARRAY = {{
2613 {0.8f, 0.08f, 1.0f, 0.1f, 1.2f, 0.8f, 0.08f, 0.6f, 0.15f, 1.6f, 0.9f, 180},
2614 {1.0f, 0.1f, 1.0f, 0.05f, 1.5f, 0.7f, 0.08f, 0.6f, 0.15f, 1.3f, 0.9f, 180},
2615 }};
2616
2617 KartMove::setTurnParams();
2618
2619 if (param()->stats().driftType == KartParam::Stats::DriftType::Outside_Drift_Bike) {
2620 m_turningParams = &TURNING_PARAMS_ARRAY[0];
2621 } else if (param()->stats().driftType == KartParam::Stats::DriftType::Inside_Drift_Bike) {
2622 m_turningParams = &TURNING_PARAMS_ARRAY[1];
2623 }
2624
2625 if (System::RaceManager::Instance()->isStageReached(System::RaceManager::Stage::Race)) {
2626 m_leanRotInc = m_turningParams->leanRotIncRace;
2627 m_leanRotCap = m_turningParams->leanRotCapRace;
2628 } else {
2629 m_leanRotInc = m_turningParams->leanRotIncCountdown;
2630 m_leanRotCap = m_turningParams->leanRotCapCountdown;
2631 }
2632}
2633
2635void KartMoveBike::init(bool b1, bool b2) {
2636 KartMove::init(b1, b2);
2637
2638 m_leanRot = 0.0f;
2639 m_leanRotCap = 0.0f;
2640 m_leanRotInc = 0.0f;
2641 m_wheelieRot = 0.0f;
2642 m_maxWheelieRot = 0.0f;
2643 m_wheelieFrames = 0;
2645 m_autoHardStickXFrames = 0;
2646}
2647
2649void KartMoveBike::clear() {
2650 KartMove::clear();
2651 cancelWheelie();
2652}
2653
2657 constexpr u32 FAILED_WHEELIE_FRAMES = 15;
2658 constexpr f32 AUTO_WHEELIE_CANCEL_STICK_THRESHOLD = 0.85f;
2659
2661 m_wheelieCooldown = std::max(0, m_wheelieCooldown - 1);
2662
2663 auto &status = KartObjectProxy::status();
2664
2665 if (status.onBit(eStatus::Wheelie)) {
2666 bool cancelAutoWheelie = false;
2667
2668 if (status.offBit(eStatus::AutoDrift) ||
2669 EGG::Mathf::abs(state()->stickX()) <= AUTO_WHEELIE_CANCEL_STICK_THRESHOLD) {
2670 m_autoHardStickXFrames = 0;
2671 } else {
2672 if (++m_autoHardStickXFrames > 15) {
2673 cancelAutoWheelie = true;
2674 }
2675 }
2676
2678 if (m_turningParams->maxWheelieFrames < m_wheelieFrames || cancelAutoWheelie ||
2679 (!canWheelie() && FAILED_WHEELIE_FRAMES <= m_wheelieFrames)) {
2680 cancelWheelie();
2681 } else {
2682 m_wheelieRot += 0.01f;
2683 EGG::Vector3f angVel0 = dynamics()->angVel0();
2684 angVel0.x *= 0.9f;
2685 dynamics()->setAngVel0(angVel0);
2686 }
2687 } else if (0.0f < m_wheelieRot) {
2688 m_wheelieRotDec -= 0.001f;
2689 m_wheelieRotDec = std::max(-0.03f, m_wheelieRotDec);
2691 }
2692
2693 m_wheelieRot = std::max(0.0f, std::min(m_wheelieRot, m_maxWheelieRot));
2694
2695 f32 vel1DirUp = m_vel1Dir.dot(EGG::Vector3f::ey);
2696
2697 if (m_wheelieRot > 0.0f) {
2698 if (vel1DirUp <= 0.5f || m_wheelieFrames < FAILED_WHEELIE_FRAMES) {
2699 EGG::Vector3f angVel2 = dynamics()->angVel2();
2700 angVel2.x -= m_wheelieRot * (1.0f - EGG::Mathf::abs(vel1DirUp));
2701 dynamics()->setAngVel2(angVel2);
2702 } else {
2703 cancelWheelie();
2704 }
2705
2706 status.setBit(eStatus::WheelieRot);
2707 } else {
2708 status.resetBit(eStatus::WheelieRot);
2709 }
2710}
2711
2718 if (status().onBit(eStatus::AutoDrift)) {
2719 return;
2720 }
2721
2722 cancelWheelie();
2723}
2724
2730
2735 constexpr u16 MAX_MT_CHARGE = 270;
2736 constexpr u16 BASE_MT_CHARGE = 2;
2737 constexpr f32 BONUS_CHARGE_STICK_THRESHOLD = 0.4f;
2738 constexpr u16 EXTRA_MT_CHARGE = 3;
2739
2740 if (m_driftState != DriftState::ChargingMt) {
2741 return;
2742 }
2743
2744 m_mtCharge += BASE_MT_CHARGE;
2745
2746 f32 stickX = state()->stickX();
2747 if (-BONUS_CHARGE_STICK_THRESHOLD <= stickX) {
2748 if (BONUS_CHARGE_STICK_THRESHOLD < stickX && m_hopStickX == -1) {
2749 m_mtCharge += EXTRA_MT_CHARGE;
2750 }
2751 } else if (m_hopStickX != -1) {
2752 m_mtCharge += EXTRA_MT_CHARGE;
2753 }
2754
2755 if (m_mtCharge > MAX_MT_CHARGE) {
2756 m_mtCharge = MAX_MT_CHARGE;
2757 m_driftState = DriftState::ChargedMt;
2758 }
2759}
2760
2762void KartMoveBike::initOob() {
2763 KartMove::initOob();
2764 cancelWheelie();
2765}
2766
2770 constexpr s16 COOLDOWN_FRAMES = 20;
2771 bool dpadUp = inputs()->currentState().trickUp();
2772 auto &status = KartObjectProxy::status();
2773
2774 if (status.offBit(eStatus::Wheelie)) {
2775 if (dpadUp && status.onBit(eStatus::TouchingGround)) {
2777 eStatus::Hop, eStatus::DriftAuto, eStatus::InAction)) {
2778 return;
2779 }
2780
2781 if (m_wheelieCooldown > 0) {
2782 return;
2783 }
2784
2785 startWheelie();
2786 }
2787 } else if (inputs()->currentState().trickDown() && m_wheelieCooldown <= 0) {
2788 cancelWheelie();
2789 m_wheelieCooldown = COOLDOWN_FRAMES;
2790 }
2791}
2792
2793} // namespace Kart
@ COL_TYPE_MOVING_WATER
Koopa Cape and DS Yoshi Falls.
@ COL_TYPE_STICKY_ROAD
Player sticks if within 200 units (rBC stairs).
@ COL_TYPE_SPECIAL_WALL
Various other wall types, determined by variant.
#define KCL_TYPE_BIT(x)
#define KCL_TYPE_FLOOR
0x20E80FFF - Any KCL that the player or items can drive/land on.
A 3 x 4 matrix.
Definition Matrix.hh:8
void makeOrthonormalBasis(const Vector3f &v0, const Vector3f &v1)
Sets a 3x3 orthonormal basis for a local coordinate system.
Definition Matrix.cc:154
void setAxisRotation(f32 angle, const Vector3f &axis)
Rotates the matrix about an axis.
Definition Matrix.cc:180
Vector3f multVector33(const Vector3f &vec) const
Multiplies a 3x3 matrix by a vector.
Definition Matrix.cc:249
Vector3f multVector(const Vector3f &vec) const
Multiplies a vector by a matrix.
Definition Matrix.cc:225
constexpr bool offBit(Es... es) const
Checks if all of the corresponding bits for the provided enum values are off.
Definition BitFlag.hh:412
constexpr bool onBit(Es... es) const
Checks if any of the corresponding bits for the provided enum values are on.
Definition BitFlag.hh:379
constexpr TBitFlagExt< N, E > & resetBit(Es... es)
Resets the corresponding bits for the provided enum values.
Definition BitFlag.hh:355
constexpr bool onAllBit(Es... es) const
Checks if all of the corresponding bits for the provided enum values are on.
Definition BitFlag.hh:401
constexpr bool offAnyBit(Es... es) const
Checks if any of the corresponding bits for the provided enum values are off.
Definition BitFlag.hh:434
constexpr TBitFlagExt< N, E > & setBit(Es... es)
Sets the corresponding bits for the provided enum values.
Definition BitFlag.hh:344
bool start(Action action)
Starts an action.
Definition KartAction.cc:49
bool activate(Type type, s16 frames)
Starts/restarts a boost of the given type.
Definition KartBoost.cc:21
bool calc()
Computes the current frame's boost multiplier, acceleration, and speed limit.
Definition KartBoost.cc:38
void applyWrenchScaled(const EGG::Vector3f &p, const EGG::Vector3f &f, f32 scale)
Applies a force linearly and rotationally to the kart.
Handles the physics and boosts associated with zippers.
f32 m_leanRot
Z-axis rotation of the bike from leaning.
Definition KartMove.hh:545
f32 m_leanRotCap
The maximum leaning rotation.
Definition KartMove.hh:546
void calcWheelie() override
STAGE 1+ - Every frame, checks player input for wheelies and computes wheelie rotation.
Definition KartMove.cc:2656
void calcMtCharge() override
Every frame during a drift, calculates MT charge based on player input.
Definition KartMove.cc:2734
virtual void startWheelie()
STAGE 1+ - Sets the wheelie bit flag and some wheelie-related variables.
Definition KartMove.cc:2470
f32 m_wheelieRotDec
The wheelie rotation decrementor, used after a wheelie has ended.
Definition KartMove.hh:552
u32 m_wheelieFrames
Tracks wheelie duration and cancels the wheelie after 180 frames.
Definition KartMove.hh:550
f32 m_wheelieRot
X-axis rotation from wheeling.
Definition KartMove.hh:548
const TurningParameters * m_turningParams
Inside/outside drifting bike turn info.
Definition KartMove.hh:554
void setTurnParams() override
On init, sets the bike's lean rotation cap and increment.In addition to setting the lean rotation cap...
Definition KartMove.cc:2611
f32 m_maxWheelieRot
The maximum wheelie rotation.
Definition KartMove.hh:549
void tryStartWheelie()
STAGE 1+ - Every frame, checks player input to see if we should start or stop a wheelie.
Definition KartMove.cc:2769
void onWallCollision() override
Called when you collide with a wall. All it does for bikes is cancel wheelies.
Definition KartMove.cc:2727
void onHop() override
Virtual function that just cancels wheelies when you hop.
Definition KartMove.cc:2717
bool canWheelie() const override
Checks if the kart is going fast enough to wheelie.
Definition KartMove.hh:536
void calcVehicleRotation(f32) override
Every frame, calculates rotation, EV, and angular velocity for the bike.
Definition KartMove.cc:2501
s16 m_wheelieCooldown
The number of frames before another wheelie can start.
Definition KartMove.hh:551
f32 m_leanRotInc
The incrementor for leaning rotation.
Definition KartMove.hh:547
virtual void cancelWheelie()
Clears the wheelie bit flag and resets the rotation decrement.
Definition KartMove.cc:2485
f32 m_baseSpeed
The speed associated with the current character/vehicle stats.
Definition KartMove.hh:382
void calcRotation()
Every frame, calculates kart rotation based on player input.
Definition KartMove.cc:1183
s16 m_ssmtLeewayTimer
Frames to forgive letting go of A before clearing SSMT charge.
Definition KartMove.hh:424
s32 m_hopFrame
A timer that can prevent subsequent hops until reset.
Definition KartMove.hh:409
void calcDisableBackwardsAccel()
Computes the current cooldown duration between braking and reversing.
Definition KartMove.cc:757
EGG::Vector3f m_hopUp
The up vector when hopping.
Definition KartMove.hh:410
u16 m_mushroomBoostTimer
Number of frames until the mushroom boost runs out.
Definition KartMove.hh:432
void calcSpecialFloor()
Every frame, calculates any boost resulting from a boost panel.
Definition KartMove.cc:513
void calcWallCollisionStart(f32 param_2)
If we started to collide with a wall this frame, applies rotation.
Definition KartMove.cc:1605
KartHalfPipe * m_halfPipe
Pertains to zipper physics.
Definition KartMove.hh:463
f32 m_kclRotFactor
Float between 0-1 that scales the player's turning radius on offroad.
Definition KartMove.hh:404
f32 m_outsideDriftBonus
Added to angular velocity when outside drifting.
Definition KartMove.hh:417
void tryStartBoostRamp()
Sets offroad invincibility and enables the ramp boost bitfield flag.
Definition KartMove.cc:1992
void calcDeceleration()
Definition KartMove.cc:1372
u16 m_smtCharge
A value between 0 and 300 representing current SMT charge.
Definition KartMove.hh:416
f32 m_speedRatio
The ratio between current speed and the player's base speed stat.
Definition KartMove.hh:402
@ DriftReset
Set when a wall bonk should cancel your drift.
@ SsmtCharged
Set after holding a stand-still mini-turbo for 75 frames.
@ TrickableSurface
Set when driving on a trickable surface.
@ SsmtLeeway
If set, activates SSMT when not pressing A or B.
@ WallBounce
Set when our speed loss from wall collision is > 30.0f.
@ Respawned
Set when Lakitu lets go of the player, cleared when landing.
void tryStartJumpPad()
Applies calculations to start interacting with a jump pad.
Definition KartMove.cc:2010
f32 m_jumpPadMinSpeed
Snaps the player to a minimum speed when first touching a jump pad.
Definition KartMove.hh:437
f32 m_hopPosY
Relative position as the result of a hop. Starts at 0.
Definition KartMove.hh:451
DrivingDirection m_drivingDirection
Current state of driver's direction.
Definition KartMove.hh:458
u16 m_crushTimer
Number of frames until player will be uncrushed.
Definition KartMove.hh:435
bool calcPreDrift()
Each frame, checks for hop or slipdrift. Computes drift direction based on player input.
Definition KartMove.cc:831
f32 m_speed
Current speed, restricted to the soft speed limit.
Definition KartMove.hh:384
s16 m_offroadInvincibility
How many frames until the player is affected by offroad.
Definition KartMove.hh:422
void calcAirtimeTop()
Calculates rotation of the bike due to excessive airtime.
Definition KartMove.cc:488
void startManualDrift()
Called when the player lands from a drift hop, or to start a slipdrift.
Definition KartMove.cc:1082
void controlOutsideDriftAngle()
Every frame, handles mini-turbo charging and outside drifting bike rotation.
Definition KartMove.cc:1150
f32 m_softSpeedLimit
Base speed + boosts + wheelies, restricted to the hard speed limit.
Definition KartMove.hh:383
virtual void hop()
Initializes hop information, resets upwards EV and clears upwards force.
Definition KartMove.cc:1952
void calcStandstillBoostRot()
STAGE Computes the x-component of angular velocity based on the kart's speed.
Definition KartMove.cc:1671
EGG::Vector3f m_outsideDriftLastDir
Used to compute the next m_outsideDriftAngle.
Definition KartMove.hh:400
void calcManualDrift()
Each frame, handles hopping, drifting, and mini-turbos.
Definition KartMove.cc:1000
virtual void calcMtCharge()
Every frame during a drift, calculates MT/SMT charge based on player input.
Definition KartMove.cc:1887
void calcSsmt()
Calculates standstill mini-turbo components, if applicable.
Definition KartMove.cc:774
void calcAcceleration()
Every frame, applies acceleration to the kart's internal velocity.
Definition KartMove.cc:1420
f32 m_processedSpeed
Offset 0x28. It's only ever just a copy of m_speed.
Definition KartMove.hh:386
void releaseMt()
Stops charging a mini-turbo, and applies boost if charged.
Definition KartMove.cc:1124
f32 m_kclSpeedFactor
Float between 0-1 that scales the player's speed on offroad.
Definition KartMove.hh:403
f32 m_weightedTurn
Magnitude+direction of stick input, factoring in the kart's stats.
Definition KartMove.hh:427
void calcVehicleSpeed()
Every frame, computes speed based on acceleration and any active boosts.
Definition KartMove.cc:1280
f32 m_lastSpeed
Last frame's speed, cached to calculate angular velocity.
Definition KartMove.hh:385
s16 m_ssmtDisableAccelTimer
Counter that tracks delay before starting to reverse.
Definition KartMove.hh:425
void calcOffroadInvincibility()
Checks a timer to see if we are still ignoring offroad slowdown.
Definition KartMove.cc:2170
KartBurnout m_burnout
Manages the state of start boost burnout.
Definition KartMove.hh:465
f32 calcVehicleAcceleration() const
Every frame, computes acceleration based off the character/vehicle stats.
Definition KartMove.cc:1386
void calcAutoDrift()
Each frame, handles automatic transmission drifting.
Definition KartMove.cc:945
f32 m_realTurn
The "true" turn magnitude. Equal to m_weightedTurn unless drifting.
Definition KartMove.hh:426
const DriftingParameters * m_driftingParams
Drift-type-specific parameters.
Definition KartMove.hh:466
void clearDrift()
Definition KartMove.cc:884
void calc()
Each frame, calculates the kart's movement.
Definition KartMove.cc:287
EGG::Vector3f m_up
Vector perpendicular to the floor, pointing upwards.
Definition KartMove.hh:391
s16 m_ssmtCharge
Increments every frame up to 75 when charging stand-still MT.
Definition KartMove.hh:423
f32 m_speedDragMultiplier
After 5 frames of airtime, this causes speed to slowly decay.
Definition KartMove.hh:389
u16 m_mtCharge
A value between 0 and 270 representing current MT charge.
Definition KartMove.hh:415
void calcSsmtStart()
Calculates whether we are starting a standstill mini-turbo.
Definition KartMove.cc:1772
s16 m_respawnPostLandTimer
Counts up to 4 if not accelerating after respawn landing.
Definition KartMove.hh:455
virtual f32 getWheelieSoftSpeedLimitBonus() const
Returns the % speed boost from wheelies. For karts, this is always 0.
Definition KartMove.hh:111
f32 m_kclWheelRotFactor
The slowest rotation multiplier of each wheel's floor collision.
Definition KartMove.hh:406
void resetDriftManual()
Clears drift state. Called when touching ground and drift is canceled.
Definition KartMove.cc:873
f32 m_totalScale
[Unused] Always 1.0f
Definition KartMove.hh:429
f32 m_acceleration
Captures the acceleration from player input and boosts.
Definition KartMove.hh:388
virtual void calcVehicleRotation(f32 turn)
Every frame, calculates rotation, EV, and angular velocity for the kart.
Definition KartMove.cc:1838
s16 m_respawnPreLandTimer
Counts down from 4 when pressing A before landing from respawn.
Definition KartMove.hh:454
virtual void calcTurn()
Each frame, looks at player input and kart stats. Saves turn-related info.
Definition KartMove.cc:70
f32 m_divingRot
Induces x-axis angular velocity based on up/down stick input.
Definition KartMove.hh:412
f32 m_outsideDriftAngle
The facing angle of an outward-drifting vehicle.
Definition KartMove.hh:398
EGG::Vector3f m_lastDir
m_speed from the previous frame but with signed magnitude.
Definition KartMove.hh:394
EGG::Vector3f m_smoothedUp
A smoothed up vector, mostly used after significant airtime.
Definition KartMove.hh:390
bool canStartDrift() const
Definition KartMove.hh:139
s32 getAppliedHopStickX() const
Factors in vehicle speed to retrieve our hop direction and magnitude.
Definition KartMove.hh:247
u16 m_floorCollisionCount
The number of tires colliding with the floor.
Definition KartMove.hh:407
void calcDive()
Responds to player input to handle up/down kart tilt mid-air.
Definition KartMove.cc:1711
void calcOffroad()
Each frame, computes rotation and speed scalars from the floor KCL.
Definition KartMove.cc:666
s16 m_bumpTimer
Set when a Reaction::SmallBump collision occurs.
Definition KartMove.hh:457
KartScale * m_kartScale
Manages scaling due to TF stompers and MH cars.
Definition KartMove.hh:464
@ WaitingForBackwards
Holding reverse but waiting on a 15 frame delay.
s16 m_timeInRespawn
The number of frames elapsed after position snap from respawn.
Definition KartMove.hh:453
s32 m_hopStickX
A ternary for the direction of our hop, 0 if still neutral hopping.
Definition KartMove.hh:408
s16 m_backwardsAllowCounter
Tracks the 15f delay before reversing.
Definition KartMove.hh:459
f32 calcWallCollisionSpeedFactor(f32 &f1)
Every frame, computes a speed scalar if we are colliding with a wall.
Definition KartMove.cc:1572
void calcMushroomBoost()
Checks a timer to see if we are still boosting from a mushroom.
Definition KartMove.cc:2186
f32 m_hopGravity
Always main gravity (-1.3f).
Definition KartMove.hh:452
f32 m_hopVelY
Relative velocity due to a hop. Starts at 10 and decreases with gravity.
Definition KartMove.hh:450
f32 m_hardSpeedLimit
Absolute speed cap. It's 120, unless you're in a bullet (140).
Definition KartMove.hh:387
void setInitialPhysicsValues(const EGG::Vector3f &position, const EGG::Vector3f &angles)
Initializes the kart's position and rotation. Calls tire suspension initializers.
Definition KartMove.cc:250
f32 m_rawTurn
Float in range [-1, 1]. Represents stick magnitude + direction.
Definition KartMove.hh:467
void setOffroadInvincibility(s16 timer)
Ignores offroad KCL collision for a set amount of time.
Definition KartMove.cc:2159
f32 m_speedRatioCapped
m_speedRatio but capped at 1.0f.
Definition KartMove.hh:401
EGG::Vector3f m_scale
Normally the unit vector, but may vary due to crush animations.
Definition KartMove.hh:428
f32 m_kclWheelSpeedFactor
The slowest speed multiplier of each wheel's floor collision.
Definition KartMove.hh:405
EGG::Vector3f m_hopDir
Used for outward drift. Tracks the forward vector of our rotation.
Definition KartMove.hh:411
EGG::Vector3f bodyUp() const
Returns the second column of the rotation matrix, which is the "up" direction.
EGG::Vector3f bodyFront() const
Returns the third column of the rotation matrix, which is the facing vector.
Mainly responsible for calculating scaling for the squish/unsquish animation.
Definition KartScale.hh:9
EGG core library.
Definition Archive.cc:6
Pertains to kart-related functionality.
@ BikeSideStuntTrick
A side StuntTrick with a bike.
@ Wheelie
Set while we are in a wheelie (even during the countdown).
@ HopStart
Set if m_bDriftInput was toggled on this frame.
@ RejectRoad
Collision which causes a change in the player's pos and rot.
@ DisableBackwardsAccel
Enforces a 20f delay when reversing after charging SSMT.
@ HalfPipeRamp
Set while colliding with zipper KCL.
@ Boost
Set while in a boost.
@ BoostOffroadInvincibility
Set if we should ignore offroad slowdown this frame.
@ HWG
Set when "Horizontal Wall Glitch" is active.
@ ZipperTrick
Set while tricking mid-air from a zipper.
@ SlipdriftCharge
Currently in a drift w/ automatic.
@ Hop
Set while we are in a drift hop. Clears when we land.
@ MushroomBoost
Set while we are in a mushroom boost.
@ StickyRoad
Like the rBC stairs.
@ StickLeft
Set on left stick input. Mutually exclusive to m_bStickRight.
@ RespawnKillY
Set while respawning to cap external velocity at 0.
@ VehicleBodyFloorCollision
Set if the vehicle body is colliding with the floor.
@ RejectRoadTrigger
e.g. DK Summit ending, and Maple Treeway side walls.
@ GroundStart
Set first frame landing from airtime.
@ Accelerate
Accel button is pressed.
@ StickRight
Set on right stick input. Mutually exclusive to m_bStickLeft.
@ ActionMidZipper
Set when we enter an action while mid-air from a zipper.
@ DriftInput
A "fake" button, normally set if you meet the speed requirement to hop.
@ AirtimeOver20
Set after 20 frames of airtime, resets on landing.
@ ZipperBoost
Set when boosting after landing from a zipper.
@ DriftManual
Currently in a drift w/ manual.
@ OverZipper
Set while mid-air from a zipper.
@ ChargingSSMT
Tracks whether we are charging a stand-still mini-turbo.
@ AccelerateStart
Set if m_bAccelerate was toggled on this frame.
@ Burnout
Set during a burnout on race start.
@ WallCollisionStart
Set if we have just started colliding with a wall.
@ AnyWheelCollision
Set when any wheel is touching floor collision.
@ AutoDrift
True if auto transmission, false if manual.
@ Wall3Collision
Set when colliding with wall KCL COL_TYPE_WALL_2.
@ TouchingGround
Set when any part of the vehicle is colliding with floor KCL.
@ ZipperInvisibleWall
Set when colliding with invisible wall above a zipper.
@ BeforeRespawn
Set on respawn collision, cleared on position snap.
@ WallCollision
Set if we are colliding with a wall.
A quaternion, used to represent 3D rotation.
Definition Quat.hh:12
void normalise()
Scales the quaternion to a unit length.
Definition Quat.cc:28
Vector3f rotateVector(const Vector3f &vec) const
Rotates a vector based on the quat.
Definition Quat.cc:55
Quatf slerpTo(const Quatf &q2, f32 t) const
Performs spherical linear interpolation.
Definition Quat.cc:84
void setAxisRotation(f32 angle, const Vector3f &axis)
Set the quat given angle and axis.
Definition Quat.cc:111
f32 dot(const Quatf &q) const
Computes .
Definition Quat.hh:107
void makeVectorRotation(const Vector3f &from, const Vector3f &to)
Captures rotation between two vectors.
Definition Quat.cc:40
constexpr TBitFlag< T, E > & resetBit(Es... es)
Resets the corresponding bits for the provided enum values.
Definition BitFlag.hh:73
constexpr bool onBit(Es... es) const
Checks if any of the corresponding bits for the provided enum values are on.
Definition BitFlag.hh:108
constexpr TBitFlag< T, E > & changeBit(bool on, Es... es)
Changes the state of the corresponding bits for the provided enum values.
Definition BitFlag.hh:85
constexpr bool offBit(Es... es) const
Checks if all of the corresponding bits for the provided enum values are off.
Definition BitFlag.hh:141
constexpr void makeAllZero()
Resets all the bits to zero.
Definition BitFlag.hh:234
constexpr TBitFlag< T, E > & setBit(Es... es)
Sets the corresponding bits for the provided enum values.
Definition BitFlag.hh:62
A 3D float vector.
Definition Vector.hh:88
f32 normalise()
Normalizes the vector and returns the original length.
Definition Vector.cc:52
f32 dot(const Vector3f &rhs) const
The dot product between two vectors.
Definition Vector.hh:187
f32 length() const
The square root of the vector's dot product.
Definition Vector.hh:192
f32 squaredLength() const
The dot product between the vector and itself.
Definition Vector.hh:182
Vector3f proj(const Vector3f &rhs) const
The projection of this vector onto rhs.
Definition Vector.hh:204
Vector3f perpInPlane(const EGG::Vector3f &rhs, bool normalise) const
Calculates the orthogonal vector, based on the plane defined by this vector and rhs.
Definition Vector.cc:114
Vector3f rej(const Vector3f &rhs) const
The rejection of this vector onto rhs.
Definition Vector.hh:210
Information about the current collision and its properties.
Various character/vehicle-related handling and speed stats.
Definition KartParam.hh:67
f32 driftManualTightness
Affects turn radius when manual drifting.
Definition KartParam.hh:106
std::array< f32, 32 > kclRot
Rotation scalars, indexed using KCL attributes.
Definition KartParam.hh:113
f32 driftAutomaticTightness
Affects turn radius when automatic drifting.
Definition KartParam.hh:107
std::array< f32, 32 > kclSpeed
Speed multipliers, indexed using KCL attributes.
Definition KartParam.hh:112
f32 driftReactivity
A weight applied to turn radius when drifting.
Definition KartParam.hh:108
f32 speed
Base full speed of the character/vehicle combo.
Definition KartParam.hh:96
f32 handlingReactivity
A weight applied to turn radius when not drifting.
Definition KartParam.hh:105
u32 miniTurbo
The framecount duration of a charged mini-turbo.
Definition KartParam.hh:111