A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
KartState.hh
1#pragma once
2
3#include "game/kart/KartObjectProxy.hh"
4
5namespace Kart {
6
13public:
14 KartState();
15
16 void init();
17 void reset();
18
19 void calcInput();
20 void calc();
21 void resetFlags();
22 void calcCollisions();
23 void calcStartBoost();
25 void handleStartBoost(size_t idx);
26 void resetEjection();
27
29 void clearBitfield0();
30 void clearBitfield1();
31 void clearBitfield2();
32 void clearBitfield3();
33
34 void setAccelerate(bool isSet) {
35 m_bAccelerate = isSet;
36 }
37
38 void setDriftInput(bool isSet) {
39 m_bDriftInput = isSet;
40 }
41
42 void setDriftManual(bool isSet) {
43 m_bDriftManual = isSet;
44 }
45
46 void setBeforeRespawn(bool isSet) {
47 m_bBeforeRespawn = isSet;
48 }
49
50 void setWallCollision(bool isSet) {
51 m_bWallCollision = isSet;
52 }
53
54 void setHopStart(bool isSet) {
55 m_bHopStart = isSet;
56 }
57
58 void setVehicleBodyFloorCollision(bool isSet) {
60 }
61
62 void setAnyWheelCollision(bool isSet) {
64 }
65
66 void setWallCollisionStart(bool isSet) {
68 }
69
70 void setStickyRoad(bool isSet) {
71 m_bStickyRoad = isSet;
72 }
73
74 void setAllWheelsCollision(bool isSet) {
76 }
77
78 void setTouchingGround(bool isSet) {
79 m_bTouchingGround = isSet;
80 }
81
82 void setHop(bool isSet) {
83 m_bHop = isSet;
84 }
85
86 void setBoost(bool isSet) {
87 m_bBoost = isSet;
88 }
89
90 void setMushroomBoost(bool isSet) {
91 m_bMushroomBoost = isSet;
92 }
93
94 void setSlipdriftCharge(bool isSet) {
95 m_bSlipdriftCharge = isSet;
96 }
97
98 void setDriftAuto(bool isSet) {
99 m_bDriftAuto = isSet;
100 }
101
102 void setWheelie(bool isSet) {
103 m_bWheelie = isSet;
104 }
105
106 void setJumpPad(bool isSet) {
107 m_bJumpPad = isSet;
108 }
109
110 void setRampBoost(bool isSet) {
111 m_bRampBoost = isSet;
112 }
113
114 void setInAction(bool isSet) {
115 m_bInAction = isSet;
116 }
117
118 void setTriggerRespawn(bool isSet) {
119 m_bTriggerRespawn = isSet;
120 }
121
122 void setCannonStart(bool isSet) {
123 m_bCannonStart = isSet;
124 }
125
126 void setInCannon(bool isSet) {
127 m_bInCannon = isSet;
128 }
129
130 void setTrickStart(bool isSet) {
131 m_bTrickStart = isSet;
132 }
133
134 void setInATrick(bool isSet) {
135 m_bInATrick = isSet;
136 }
137
138 void setBoostOffroadInvincibility(bool isSet) {
140 }
141
142 void setHalfPipeRamp(bool isSet) {
143 m_bHalfPipeRamp = isSet;
144 }
145
146 void setOverZipper(bool isSet) {
147 m_bOverZipper = isSet;
148 }
149
150 void setJumpPadMushroomCollision(bool isSet) {
151 m_bJumpPadMushroomCollision = isSet;
152 }
153
154 void setZipperInvisibleWall(bool isSet) {
156 }
157
158 void setZipperBoost(bool isSet) {
159 m_bZipperBoost = isSet;
160 }
161
162 void setZipperStick(bool isSet) {
163 m_bZipperStick = isSet;
164 }
165
166 void setZipperTrick(bool isSet) {
167 m_bZipperTrick = isSet;
168 }
169
170 void setDisableBackwardsAccel(bool isSet) {
172 }
173
174 void setRespawnKillY(bool isSet) {
175 m_bRespawnKillY = isSet;
176 }
177
178 void setBurnout(bool isSet) {
179 m_bBurnout = isSet;
180 }
181
182 void setTrickRot(bool isSet) {
183 m_bTrickRot = isSet;
184 }
185
186 void setJumpPadMushroomVelYInc(bool isSet) {
187 m_bJumpPadMushroomVelYInc = isSet;
188 }
189
190 void setChargingSsmt(bool isSet) {
191 m_bChargingSsmt = isSet;
192 }
193
194 void setRejectRoad(bool isSet) {
195 m_bRejectRoad = isSet;
196 }
197
198 void setRejectRoadTrigger(bool isSet) {
199 m_bRejectRoadTrigger = isSet;
200 }
201
202 void setTrickable(bool isSet) {
203 m_bTrickable = isSet;
204 }
205
206 void setWheelieRot(bool isSet) {
207 m_bWheelieRot = isSet;
208 }
209
210 void setSkipWheelCalc(bool isSet) {
211 m_bSkipWheelCalc = isSet;
212 }
213
214 void setJumpPadMushroomTrigger(bool isSet) {
215 m_bJumpPadMushroomTrigger = isSet;
216 }
217
218 void setNoSparkInvisibleWall(bool isSet) {
219 m_bNoSparkInvisibleWall = isSet;
220 }
221
222 void setInRespawn(bool isSet) {
223 m_bInRespawn = isSet;
224 }
225
226 void setAfterRespawn(bool isSet) {
227 m_bAfterRespawn = isSet;
228 }
229
230 void setJumpPadFixedSpeed(bool isSet) {
231 m_bJumpPadFixedSpeed = isSet;
232 }
233
234 void setJumpPadDisableYsusForce(bool isSet) {
235 m_bJumpPadDisableYsusForce = isSet;
236 }
237
238 void setSomethingWallCollision(bool isSet) {
239 m_bSomethingWallCollision = isSet;
240 }
241
242 void setSoftWallDrift(bool isSet) {
243 m_bSoftWallDrift = isSet;
244 }
245
246 void setHWG(bool isSet) {
247 m_bHWG = isSet;
248 }
249
250 void setAfterCannon(bool isSet) {
251 m_bAfterCannon = isSet;
252 }
253
254 void setActionMidZipper(bool isSet) {
255 m_bActionMidZipper = isSet;
256 }
257
258 void setEndHalfPipe(bool isSet) {
259 m_bEndHalfPipe = isSet;
260 }
261
262 void setCannonPointId(u16 val) {
263 m_cannonPointId = val;
264 }
265
266 void setBoostRampType(s32 val) {
267 m_boostRampType = val;
268 }
269
270 void setJumpPadVariant(s32 val) {
271 m_jumpPadVariant = val;
272 }
273
274 void setHalfPipeInvisibilityTimer(s16 val) {
275 m_halfPipeInvisibilityTimer = val;
276 }
277
278 void setTrickableTimer(s16 val) {
279 m_trickableTimer = val;
280 }
282
284 [[nodiscard]] bool isDrifting() const {
286 }
287
288 [[nodiscard]] bool isAccelerate() const {
289 return m_bAccelerate;
290 }
291
292 [[nodiscard]] bool isBrake() const {
293 return m_bBrake;
294 }
295
296 [[nodiscard]] bool isDriftInput() const {
297 return m_bDriftInput;
298 }
299
300 [[nodiscard]] bool isDriftManual() const {
301 return m_bDriftManual;
302 }
303
304 [[nodiscard]] bool isBeforeRespawn() const {
305 return m_bBeforeRespawn;
306 }
307
308 [[nodiscard]] bool isWall3Collision() const {
309 return m_bWall3Collision;
310 }
311
312 [[nodiscard]] bool isWallCollision() const {
313 return m_bWallCollision;
314 }
315
316 [[nodiscard]] bool isHopStart() const {
317 return m_bHopStart;
318 }
319
320 [[nodiscard]] bool isAccelerateStart() const {
321 return m_bAccelerateStart;
322 }
323
324 [[nodiscard]] bool isGroundStart() const {
325 return m_bGroundStart;
326 }
327
328 [[nodiscard]] bool isVehicleBodyFloorCollision() const {
330 }
331
332 [[nodiscard]] bool isAnyWheelCollision() const {
334 }
335
336 [[nodiscard]] bool isAllWheelsCollision() const {
338 }
339
340 [[nodiscard]] bool isStickLeft() const {
341 return m_bStickLeft;
342 }
343
344 [[nodiscard]] bool isWallCollisionStart() const {
346 }
347
348 [[nodiscard]] bool isAirtimeOver20() const {
349 return m_bAirtimeOver20;
350 }
351
352 [[nodiscard]] bool isStickyRoad() const {
353 return m_bStickyRoad;
354 }
355
356 [[nodiscard]] bool isTouchingGround() const {
357 return m_bTouchingGround;
358 }
359
360 [[nodiscard]] bool isHop() const {
361 return m_bHop;
362 }
363
364 [[nodiscard]] bool isSoftWallDrift() const {
365 return m_bSoftWallDrift;
366 }
367
368 [[nodiscard]] bool isHWG() const {
369 return m_bHWG;
370 }
371
372 [[nodiscard]] bool isAfterCannon() const {
373 return m_bAfterCannon;
374 }
375
376 [[nodiscard]] bool isActionMidZipper() const {
377 return m_bActionMidZipper;
378 }
379
380 [[nodiscard]] bool isChargeStartBoost() const {
381 return m_bChargeStartBoost;
382 }
383
384 [[nodiscard]] bool isBoost() const {
385 return m_bBoost;
386 }
387
388 [[nodiscard]] bool isAirStart() const {
389 return m_bAirStart;
390 }
391
392 [[nodiscard]] bool isStickRight() const {
393 return m_bStickRight;
394 }
395
396 [[nodiscard]] bool isMushroomBoost() const {
397 return m_bMushroomBoost;
398 }
399
400 [[nodiscard]] bool isDriftAuto() const {
401 return m_bDriftAuto;
402 }
403
404 [[nodiscard]] bool isSlipdriftCharge() const {
405 return m_bSlipdriftCharge;
406 }
407
408 [[nodiscard]] bool isWheelie() const {
409 return m_bWheelie;
410 }
411
412 [[nodiscard]] bool isJumpPad() const {
413 return m_bJumpPad;
414 }
415
416 [[nodiscard]] bool isRampBoost() const {
417 return m_bRampBoost;
418 }
419
420 [[nodiscard]] bool isInAction() const {
421 return m_bInAction;
422 }
423
424 [[nodiscard]] bool isTriggerRespawn() const {
425 return m_bTriggerRespawn;
426 }
427
428 [[nodiscard]] bool isCannonStart() const {
429 return m_bCannonStart;
430 }
431
432 [[nodiscard]] bool isInCannon() const {
433 return m_bInCannon;
434 }
435
436 [[nodiscard]] bool isTrickStart() const {
437 return m_bTrickStart;
438 }
439
440 [[nodiscard]] bool isInATrick() const {
441 return m_bInATrick;
442 }
443
444 [[nodiscard]] bool isBoostOffroadInvincibility() const {
446 }
447
448 [[nodiscard]] bool isHalfPipeRamp() const {
449 return m_bHalfPipeRamp;
450 }
451
452 [[nodiscard]] bool isOverZipper() const {
453 return m_bOverZipper;
454 }
455
456 [[nodiscard]] bool isJumpPadMushroomCollision() const {
457 return m_bJumpPadMushroomCollision;
458 }
459
460 [[nodiscard]] bool isZipperInvisibleWall() const {
462 }
463
464 [[nodiscard]] bool isZipperBoost() const {
465 return m_bZipperBoost;
466 }
467
468 [[nodiscard]] bool isZipperTrick() const {
469 return m_bZipperTrick;
470 }
471
472 [[nodiscard]] bool isDisableBackwardsAccel() const {
474 }
475
476 [[nodiscard]] bool isRespawnKillY() const {
477 return m_bRespawnKillY;
478 }
479
480 [[nodiscard]] bool isBurnout() const {
481 return m_bBurnout;
482 }
483
484 [[nodiscard]] bool isZipperStick() const {
485 return m_bZipperStick;
486 }
487
488 [[nodiscard]] bool isTrickRot() const {
489 return m_bTrickRot;
490 }
491
492 [[nodiscard]] bool isJumpPadMushroomVelYInc() const {
493 return m_bJumpPadMushroomVelYInc;
494 }
495
496 [[nodiscard]] bool isChargingSsmt() const {
497 return m_bChargingSsmt;
498 }
499
500 [[nodiscard]] bool isRejectRoad() const {
501 return m_bRejectRoad;
502 }
503
504 [[nodiscard]] bool isRejectRoadTrigger() const {
506 }
507
508 [[nodiscard]] bool isTrickable() const {
509 return m_bTrickable;
510 }
511
512 [[nodiscard]] bool isWheelieRot() const {
513 return m_bWheelieRot;
514 }
515
516 [[nodiscard]] bool isJumpPadDisableYsusForce() const {
517 return m_bJumpPadDisableYsusForce;
518 }
519
520 [[nodiscard]] bool isSkipWheelCalc() const {
521 return m_bSkipWheelCalc;
522 }
523
524 [[nodiscard]] bool isJumpPadMushroomTrigger() const {
525 return m_bJumpPadMushroomTrigger;
526 }
527
528 [[nodiscard]] bool isNoSparkInvisibleWall() const {
529 return m_bNoSparkInvisibleWall;
530 }
531
532 [[nodiscard]] bool isInRespawn() const {
533 return m_bInRespawn;
534 }
535
536 [[nodiscard]] bool isAfterRespawn() const {
537 return m_bAfterRespawn;
538 }
539
540 [[nodiscard]] bool isJumpPadFixedSpeed() const {
541 return m_bJumpPadFixedSpeed;
542 }
543
544 [[nodiscard]] bool isUNK2() const {
545 return m_bUNK2;
546 }
547
548 [[nodiscard]] bool isSomethingWallCollision() const {
549 return m_bSomethingWallCollision;
550 }
551
552 [[nodiscard]] bool isEndHalfPipe() const {
553 return m_bEndHalfPipe;
554 }
555
556 [[nodiscard]] bool isAutoDrift() const {
557 return m_bAutoDrift;
558 }
559
560 [[nodiscard]] u16 cannonPointId() const {
561 return m_cannonPointId;
562 }
563
564 [[nodiscard]] s32 boostRampType() const {
565 return m_boostRampType;
566 }
567
568 [[nodiscard]] s32 jumpPadVariant() const {
569 return m_jumpPadVariant;
570 }
571
572 [[nodiscard]] f32 stickX() const {
573 return m_stickX;
574 }
575
576 [[nodiscard]] f32 stickY() const {
577 return m_stickY;
578 }
579
580 [[nodiscard]] u32 airtime() const {
581 return m_airtime;
582 }
583
584 [[nodiscard]] const EGG::Vector3f &top() const {
585 return m_top;
586 }
587
588 [[nodiscard]] const EGG::Vector3f &softWallSpeed() const {
589 return m_softWallSpeed;
590 }
591
592 [[nodiscard]] f32 startBoostCharge() const {
593 return m_startBoostCharge;
594 }
595
596 [[nodiscard]] s16 wallBonkTimer() const {
597 return m_wallBonkTimer;
598 }
599
600 [[nodiscard]] s16 trickableTimer() const {
601 return m_trickableTimer;
602 }
604
605private:
606 // Bits from the base game's bitfields are marked with prefix 'b'
607
612 bool m_bBrake;
633 bool m_bHop;
634 bool m_bBoost;
635 bool m_bAirStart;
639 bool m_bSlipdriftCharge;
641 bool m_bJumpPad;
642 bool m_bRampBoost;
644
648 bool m_bInAction;
649 bool m_bTriggerRespawn;
650 bool m_bCannonStart;
651 bool m_bInCannon;
652 bool m_bTrickStart;
653 bool m_bInATrick;
657 bool m_bJumpPadMushroomCollision;
665 bool m_bTrickRot;
666 bool m_bJumpPadMushroomVelYInc;
670 bool m_bTrickable;
672
676 bool m_bWheelieRot;
677 bool m_bSkipWheelCalc;
678 bool m_bJumpPadMushroomTrigger;
679 bool m_bNoSparkInvisibleWall;
680 bool m_bInRespawn;
681 bool m_bAfterRespawn;
682 bool m_bJumpPadFixedSpeed;
683 bool m_bJumpPadDisableYsusForce;
685
689 bool m_bUNK2;
690 bool m_bSomethingWallCollision;
691 bool m_bSoftWallDrift;
692 bool m_bHWG;
693 bool m_bAfterCannon;
694 bool m_bActionMidZipper;
696 bool m_bEndHalfPipe;
698
704
705 u32 m_airtime;
706 EGG::Vector3f m_top;
707 EGG::Vector3f m_softWallSpeed;
708 s32 m_hwgTimer;
709 u16 m_cannonPointId;
710 s32 m_boostRampType;
711 s32 m_jumpPadVariant;
712 s16 m_halfPipeInvisibilityTimer;
718 s16 m_trickableTimer;
719};
720
721} // namespace Kart
Base class for most kart-related objects.
Houses various flags and other variables to preserve the kart's state.
Definition KartState.hh:12
bool m_bZipperBoost
Set when boosting after landing from a zipper.
Definition KartState.hh:659
bool m_bRespawnKillY
Set while respawning to cap external velocity at 0.
Definition KartState.hh:663
bool m_bBoost
Set while in a boost.
Definition KartState.hh:634
bool m_bChargeStartBoost
Like m_bAccelerate but during countdown.
Definition KartState.hh:695
bool m_bHop
Set while we are in a drift hop. Clears when we land.
Definition KartState.hh:633
bool m_bBeforeRespawn
Set on respawn collision, cleared on position snap.
Definition KartState.hh:619
void clearBitfield1()
Helper function to clear all bit flags at 0x8-0xB in KartState.
Definition KartState.cc:458
size_t m_startBoostIdx
Used to map m_startBoostCharge to a start boost duration.
Definition KartState.hh:716
void clearBitfield0()
Helper function to clear all bit flags at 0x4-0x7 in KartState.
Definition KartState.cc:426
bool m_bHopStart
Set if m_bDriftInput was toggled on this frame.
Definition KartState.hh:622
bool m_bHWG
Set when "Horizontal Wall Glitch" is active.
Definition KartState.hh:692
bool m_bBurnout
Set during a burnout on race start.
Definition KartState.hh:664
bool m_bDriftAuto
Currently in a drift w/ automatic.
Definition KartState.hh:638
bool m_bStickRight
Set on right stick input. Mutually exclusive to m_bStickLeft.
Definition KartState.hh:636
void clearBitfield2()
Helper function to clear all bit flags at 0xC-0xF in KartState.
Definition KartState.cc:485
void calcStartBoost()
STAGE 1 - Each frame, calculates the start boost charge.
Definition KartState.cc:361
bool m_bRejectRoad
Collision which causes a change in the player's pos and rot.
Definition KartState.hh:668
bool m_bWallCollision
Set if we are colliding with a wall.
Definition KartState.hh:621
bool m_bZipperTrick
Set while tricking mid-air from a zipper.
Definition KartState.hh:661
s16 m_wallBonkTimer
2f counter that stunts your speed after hitting a wall.
Definition KartState.hh:717
void calcCollisions()
Each frame, checks for collision and saves relevant bit flags.
Definition KartState.cc:154
bool m_bAllWheelsCollision
Set when all wheels are touching floor collision.
Definition KartState.hh:627
bool m_bDriftInput
A "fake" button, normally set if you meet the speed requirement to hop.
Definition KartState.hh:617
void clearBitfield3()
Helper function to clear all bit flags at 0x10-0x13 in KartState.
Definition KartState.cc:497
void calcHandleStartBoost()
On countdown end, calculates and applies our start boost charge.
Definition KartState.cc:379
f32 m_stickY
One of 15 discrete stick values from [-1.0, 1.0].
Definition KartState.hh:714
bool m_bChargingSsmt
Tracks whether we are charging a stand-still mini-turbo.
Definition KartState.hh:667
bool m_bAccelerateStart
Set if m_bAccelerate was toggled on this frame.
Definition KartState.hh:623
bool m_bDriftManual
Currently in a drift w/ manual.
Definition KartState.hh:618
bool m_bAutoDrift
True if auto transmission, false if manual.
Definition KartState.hh:702
void handleStartBoost(size_t idx)
Applies the relevant start boost duration.
Definition KartState.cc:410
void calc()
Every frame, resets the input state and saves collision-related bit flags.
Definition KartState.cc:117
bool m_bZipperStick
Set while mid-air and still influenced by the zipper.
Definition KartState.hh:660
bool m_bMushroomBoost
Set while we are in a mushroom boost.
Definition KartState.hh:637
bool m_bDisableBackwardsAccel
Enforces a 20f delay when reversing after charging SSMT.
Definition KartState.hh:662
bool m_bHalfPipeRamp
Set while colliding with zipper KCL.
Definition KartState.hh:655
f32 m_stickX
One of 15 discrete stick values from [-1.0, 1.0].
Definition KartState.hh:713
bool m_bVehicleBodyFloorCollision
Set if the vehicle body is colliding with the floor.
Definition KartState.hh:625
bool m_bBoostOffroadInvincibility
Set if we should ignore offroad slowdown this frame.
Definition KartState.hh:654
bool m_bAnyWheelCollision
Set when any wheel is touching floor collision.
Definition KartState.hh:626
bool m_bStickyRoad
Like the rBC stairs.
Definition KartState.hh:631
bool m_bWall3Collision
Set when colliding with wall KCL COL_TYPE_WALL_2.
Definition KartState.hh:620
f32 m_startBoostCharge
0-1 representation of start boost charge. Burnout if >0.95f.
Definition KartState.hh:715
bool m_bWheelie
Set while we are in a wheelie (even during the countdown).
Definition KartState.hh:640
bool m_bZipperInvisibleWall
Set when colliding with invisible wall above a zipper.
Definition KartState.hh:658
bool m_bTouchingGround
Set when any part of the vehicle is colliding with floor KCL.
Definition KartState.hh:632
bool m_bRejectRoadTrigger
e.g. DK Summit ending, and Maple Treeway side walls.
Definition KartState.hh:669
bool m_bStickLeft
Set on left stick input. Mutually exclusive to m_bStickRight.
Definition KartState.hh:628
void calcInput()
Each frame, read input and save related bit flags. Also handles start boosts.
Definition KartState.cc:70
bool m_bWallCollisionStart
Set if we have just started colliding with a wall.
Definition KartState.hh:629
bool m_bOverZipper
Set while mid-air from a zipper.
Definition KartState.hh:656
bool m_bAccelerate
Accel button is pressed.
Definition KartState.hh:611
void resetEjection()
Resets certain bitfields pertaining to ejections (reject road, half pipe zippers, etc....
Definition KartState.cc:420
bool m_bGroundStart
Set first frame landing from airtime.
Definition KartState.hh:624
bool m_bAirtimeOver20
Set after 20 frames of airtime, resets on landing.
Definition KartState.hh:630
Pertains to kart-related functionality.
A 3D float vector.
Definition Vector.hh:83