1#include "KartObject.hh"
3#include "game/kart/KartParam.hh"
4#include "game/kart/KartSub.hh"
5#include "game/kart/KartSuspension.hh"
6#include "game/kart/KartTire.hh"
8#include "game/field/ObjectCollisionKart.hh"
10#include "game/render/KartModel.hh"
12#include "game/system/RaceConfig.hh"
13#include "game/system/RaceManager.hh"
19 m_pointers.param = param;
23KartObject::~KartObject() {
24 EGG::egg_delete(m_pointers.param);
25 EGG::egg_delete(m_pointers.body);
26 EGG::egg_delete(m_pointers.sub);
27 EGG::egg_delete(m_pointers.model);
28 EGG::egg_delete(m_pointers.objectCollisionKart);
30 for (
auto *susp : m_pointers.suspensions) {
31 EGG::egg_delete(susp);
34 for (
auto *tire : m_pointers.tires) {
35 EGG::egg_delete(tire);
40void KartObject::createTires() {
41 constexpr u16 BSP_WHEEL_INDICES[8] = {0, 0, 1, 1, 2, 2, 3, 3};
43 KartSuspensionPhysics::TireType::Kart,
44 KartSuspensionPhysics::TireType::KartReflected,
45 KartSuspensionPhysics::TireType::Kart,
46 KartSuspensionPhysics::TireType::KartReflected,
47 KartSuspensionPhysics::TireType::Kart,
48 KartSuspensionPhysics::TireType::KartReflected,
49 KartSuspensionPhysics::TireType::Kart,
50 KartSuspensionPhysics::TireType::KartReflected,
53 auto bodyType = m_pointers.param->stats().body;
54 u32 tireCount = m_pointers.param->tireCount();
60 for (u16 wheelIdx = 0, i = 0; i < tireCount; ++i) {
65 u16 bspWheelIdx = BSP_WHEEL_INDICES[i];
68 KartSuspension *sus = EGG::egg_new<KartSuspension>();
69 KartTire *tire = (bspWheelIdx == 0) ? EGG::egg_new<KartTireFront>(tireType, bspWheelIdx) :
70 EGG::egg_new<KartTire>(tireType, bspWheelIdx);
72 m_pointers.suspensions.push_back(sus);
73 m_pointers.tires.push_back(tire);
75 sus->init(wheelIdx++, tireType, bspWheelIdx);
81 return EGG::egg_new<KartBodyKart>(physics);
85void KartObject::init() {
86 prepareTiresAndSuspensions();
88 auto *physics = KartPhysics::Create(*m_pointers.param);
89 auto *body = createBody(physics);
90 m_pointers.body = body;
92 for (u16 tireIdx = 0; tireIdx < m_pointers.param->tireCount(); ++tireIdx) {
93 m_pointers.tires[tireIdx]->init(tireIdx);
95 m_pointers.objectCollisionKart = EGG::egg_new<Field::ObjectCollisionKart>();
99void KartObject::initImpl() {
100 sub()->initAABB(m_pointers,
this);
102 objectCollisionKart()->init(param()->playerIdx());
110 System::RaceManager::Instance()->findKartStartPoint(position, euler_angles_deg);
111 move()->setInitialPhysicsValues(position, euler_angles_deg);
115void KartObject::prepareTiresAndSuspensions() {
116 constexpr u16 LOCAL_20[4] = {2, 1, 1, 1};
117 constexpr u16 LOCAL_28[4] = {2, 1, 1, 2};
119 const BSP &rBsp = m_pointers.param->bsp();
123 if (rBsp.wheels[0].enable != 0) {
124 wheelCount += LOCAL_20[
static_cast<u16
>(bodyWheels)];
126 if (rBsp.wheels[1].enable != 0) {
127 wheelCount += LOCAL_28[
static_cast<u16
>(bodyWheels)];
129 if (rBsp.wheels[2].enable != 0) {
130 wheelCount += LOCAL_20[
static_cast<u16
>(bodyWheels)];
132 if (rBsp.wheels[3].enable != 0) {
133 wheelCount += LOCAL_28[
static_cast<u16
>(bodyWheels)];
136 m_pointers.param->setTireCount(wheelCount);
137 m_pointers.param->setSuspCount(wheelCount);
141void KartObject::createSub() {
142 m_pointers.sub = EGG::egg_new<KartSub>();
143 m_pointers.sub->createSubsystems(m_pointers.param->isBike(), m_pointers.param->stats());
147void KartObject::createModel() {
151 m_pointers.model = EGG::egg_new<Render::KartModelBike>();
153 m_pointers.model = EGG::egg_new<Render::KartModelKart>();
158 m_pointers.model->init();
162void KartObject::calcSub() {
167void KartObject::calc() {
177KartObject *KartObject::Create(Character character, Vehicle vehicle, u8 playerIdx) {
180 KartParam *param = EGG::egg_new<KartParam>(character, vehicle, playerIdx);
182 KartObject *
object =
nullptr;
183 if (vehicle < Vehicle::Standard_Bike_S) {
184 object = EGG::egg_new<KartObject>(param);
186 object = EGG::egg_new<KartObjectBike>(param);
190 object->m_pointers.sub->copyPointers(object->m_pointers);
195 for (u16 i = 0; i <
object->suspCount(); ++i) {
196 object->suspension(i)->initPhysics();
199 for (u16 i = 0; i <
object->tireCount(); ++i) {
200 object->tire(i)->initBsp();
210KartObjectBike::~KartObjectBike() =
default;
214 if (m_pointers.param->isVehicleRelativeBike()) {
215 return EGG::egg_new<KartBodyQuacker>(physics);
217 return EGG::egg_new<KartBodyBike>(physics);
222void KartObjectBike::createTires() {
223 for (u16 wheelIdx = 0; wheelIdx < m_pointers.param->suspCount(); ++wheelIdx) {
224 KartSuspension *sus =
nullptr;
225 KartTire *tire =
nullptr;
227 if (wheelIdx == 0 || wheelIdx == 2) {
228 sus = EGG::egg_new<KartSuspensionFrontBike>();
229 tire = EGG::egg_new<KartTireFrontBike>(KartSuspensionPhysics::TireType::Bike, 0);
231 sus = EGG::egg_new<KartSuspensionRearBike>();
232 tire = EGG::egg_new<KartTireRearBike>(KartSuspensionPhysics::TireType::Bike, 1);
235 m_pointers.suspensions.push_back(sus);
236 m_pointers.tires.push_back(tire);
238 sus->init(wheelIdx, KartSuspensionPhysics::TireType::Bike, wheelIdx);
static std::list< KartObjectProxy *, EGG::Allocator< KartObjectProxy * > > s_proxyList
List of all KartObjectProxy children.
static void ApplyAll(const KartAccessor *pointers)
For all proxies in the static list, synchronizes all pointers to the KartAccessor.
The highest level abstraction for a kart.
void prepare()
Sets the initial position and rotation of the kart based off the current track.
Houses stats regarding a given character/vehicle combo.
Manages the lifecycle of KartDynamics, handles moving floors and trick rotation.
TireType
Every other kart tire is a mirror of the first. Bikes do not leverage this.
Pertains to kart-related functionality.
Shared between classes who inherit KartObjectProxy so they can access one another.
Body
The body style of the vehicle. Basically the number of wheels.
@ Three_Wheel_Kart
Used by Blue Falcon.