A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
KartParam.cc
1#include "KartParam.hh"
2
3#include "game/kart/KartParamFileManager.hh"
4
5namespace Kart {
6
7KartParam::KartParam(Character character, Vehicle vehicle, u8 playerIdx) {
8 initStats(character, vehicle);
9 initHitboxes(vehicle);
10 m_playerIdx = playerIdx;
11 m_isBike = vehicle >= Vehicle::Standard_Bike_S;
12 if (m_isBike) {
13 initBikeDispParams(vehicle);
14 }
15}
16
17KartParam::~KartParam() = default;
18
20void KartParam::initStats(Character character, Vehicle vehicle) {
21 auto *fileManager = KartParamFileManager::Instance();
22
23 auto vehicleStream = fileManager->getVehicleStream(vehicle);
24 auto driverStream = fileManager->getDriverStream(character);
25
26 m_stats = Stats(vehicleStream);
27 m_stats.applyCharacterBonus(driverStream);
28}
29
30void KartParam::initBikeDispParams(Vehicle vehicle) {
31 auto *fileManager = KartParamFileManager::Instance();
32
33 auto dispParamsStream = fileManager->getBikeDispParamsStream(vehicle);
34 m_bikeDisp = BikeDisp(dispParamsStream);
35}
36
37void KartParam::initHitboxes(Vehicle vehicle) {
38 auto *fileManager = KartParamFileManager::Instance();
39
40 auto hitboxStream = fileManager->getHitboxStream(vehicle);
41 m_bsp = BSP(hitboxStream);
42}
43
44KartParam::BikeDisp::BikeDisp() = default;
45
46KartParam::BikeDisp::BikeDisp(EGG::RamStream &stream) {
47 read(stream);
48}
49
50void KartParam::BikeDisp::read(EGG::RamStream &stream) {
51 stream.skip(0xc);
52 m_handlePos.read(stream);
53 m_handleRot.read(stream);
54}
55
56KartParam::Stats::Stats() = default;
57
58KartParam::Stats::Stats(EGG::RamStream &stream) {
59 read(stream);
60}
61
65 body = static_cast<Body>(stream.read_s32());
66 driftType = static_cast<DriftType>(stream.read_s32());
67 weightClass = static_cast<WeightClass>(stream.read_s32());
68 _00c = stream.read_f32();
69 weight = stream.read_f32();
70 bumpDeviationLevel = stream.read_f32();
71 speed = stream.read_f32();
72 turningSpeed = stream.read_f32();
73 tilt = stream.read_f32();
74 accelerationStandardA[0] = stream.read_f32();
75 accelerationStandardA[1] = stream.read_f32();
76 accelerationStandardA[2] = stream.read_f32();
77 accelerationStandardA[3] = stream.read_f32();
78 accelerationStandardT[0] = stream.read_f32();
79 accelerationStandardT[1] = stream.read_f32();
80 accelerationStandardT[2] = stream.read_f32();
81 accelerationDriftA[0] = stream.read_f32();
82 accelerationDriftA[1] = stream.read_f32();
83 accelerationDriftT[0] = stream.read_f32();
84 handlingManualTightness = stream.read_f32();
85 handlingAutomaticTightness = stream.read_f32();
86 handlingReactivity = stream.read_f32();
87 driftManualTightness = stream.read_f32();
88 driftAutomaticTightness = stream.read_f32();
89 driftReactivity = stream.read_f32();
90 driftOutsideTargetAngle = stream.read_f32();
91 driftOutsideDecrement = stream.read_f32();
92 miniTurbo = stream.read_u32();
93
94 for (size_t i = 0; i < kclSpeed.size(); ++i) {
95 kclSpeed[i] = stream.read_f32();
96 }
97 for (size_t i = 0; i < kclRot.size(); ++i) {
98 kclRot[i] = stream.read_f32();
99 }
100
101 itemUnk170 = stream.read_f32();
102 itemUnk174 = stream.read_f32();
103 itemUnk178 = stream.read_f32();
104 itemUnk17c = stream.read_f32();
105 maxNormalAcceleration = stream.read_f32();
106 megaScale = stream.read_f32();
107 wheelDistance = stream.read_f32();
108}
109
113 stream.skip(0x10);
114 weight += stream.read_f32();
115
116 stream.skip(0x4);
117 speed += stream.read_f32();
118 turningSpeed += stream.read_f32();
119
120 stream.skip(0x4);
121 accelerationStandardA[0] += stream.read_f32();
122 accelerationStandardA[1] += stream.read_f32();
123 accelerationStandardA[2] += stream.read_f32();
124 accelerationStandardA[3] += stream.read_f32();
125 accelerationStandardA[0] += stream.read_f32();
126 accelerationStandardA[1] += stream.read_f32();
127 accelerationStandardA[2] += stream.read_f32();
128 accelerationDriftA[0] += stream.read_f32();
129 accelerationDriftA[1] += stream.read_f32();
130 accelerationDriftT[0] += stream.read_f32();
131 handlingManualTightness += stream.read_f32();
132 handlingAutomaticTightness += stream.read_f32();
133 handlingReactivity += stream.read_f32();
134 driftManualTightness += stream.read_f32();
135 driftAutomaticTightness += stream.read_f32();
136 driftReactivity += stream.read_f32();
137 driftOutsideTargetAngle += stream.read_f32();
138 driftOutsideDecrement += stream.read_f32();
139 miniTurbo += stream.read_u32();
140
141 for (size_t i = 0; i < kclSpeed.size(); ++i) {
142 kclSpeed[i] += stream.read_f32();
143 }
144
145 for (size_t i = 0; i < kclRot.size(); ++i) {
146 kclRot[i] += stream.read_f32();
147 }
148}
149
150BSP::BSP() = default;
151
152BSP::BSP(EGG::RamStream &stream) {
153 read(stream);
154}
155
156void BSP::read(EGG::RamStream &stream) {
157 initialYPos = stream.read_f32();
158
159 for (auto &hitbox : hitboxes) {
160 hitbox.enable = stream.read_u16();
161 stream.skip(2);
162 hitbox.position.read(stream);
163 hitbox.radius = stream.read_f32();
164 hitbox.wallsOnly = stream.read_u16();
165 hitbox.tireCollisionIdx = stream.read_u16();
166 }
167
168 cuboids[0].read(stream);
169 cuboids[1].read(stream);
170 angVel0Factor = stream.read_f32();
171 _1a0 = stream.read_f32();
172
173 for (auto &wheel : wheels) {
174 wheel.enable = stream.read_u16();
175 stream.skip(2);
176 wheel.springStiffness = stream.read_f32();
177 wheel.dampingFactor = stream.read_f32();
178 wheel.maxTravel = stream.read_f32();
179 wheel.relPosition.read(stream);
180 wheel.xRot = stream.read_f32();
181 wheel.wheelRadius = stream.read_f32();
182 wheel.sphereRadius = stream.read_f32();
183 wheel._28 = stream.read_u32();
184 }
185
186 rumbleHeight = stream.read_f32();
187 rumbleSpeed = stream.read_f32();
188}
189
190} // namespace Kart
A stream of data stored in memory.
Definition Stream.hh:64
Pertains to kart-related functionality.
void applyCharacterBonus(EGG::RamStream &stream)
Applies character stats on top of the kart stats.
Definition KartParam.cc:112
DriftType
The type of drift (inside/outside).
Definition KartParam.hh:77
void read(EGG::RamStream &stream)
Parses out the stats for a given KartParam.bin stream.
Definition KartParam.cc:64
Body
The body style of the vehicle. Basically the number of wheels.
Definition KartParam.hh:69