1#include "ObjectChoropu.hh"
3#include "game/field/ObjectDirector.hh"
4#include "game/field/RailManager.hh"
6#include "game/system/RaceManager.hh"
11ObjectChoropu::ObjectChoropu(
const System::MapdataGeoObj ¶ms)
12 : ObjectCollidable(params), StateManager(this, STATE_ENTRIES) {
13 constexpr f32 MAX_SPEED = 20.0f;
15 m_startFrameOffset =
static_cast<s16
>(params.setting(1));
16 m_idleDuration = params.setting(0);
17 m_isStationary = strcmp(getName(),
"choropu") != 0;
19 s16 railIdx = params.pathId();
21 auto *rail = RailManager::Instance()->rail(railIdx);
22 rail->checkSphereFull();
26 if (!m_isStationary) {
27 const auto &flowTable = ObjectDirector::Instance()->flowTable();
28 const auto *collisionSet =
29 flowTable.set(flowTable.slot(flowTable.getIdFromName(
"choropu_ground")));
32 s16 height = parse<s16>(collisionSet->params.cylinder.height);
33 size_t groundCount =
static_cast<size_t>(MAX_GROUND_LEN / EGG::Mathf::abs(height * 2)) + 1;
34 m_groundObjs = owning_span<ObjectChoropuGround *>(groundCount);
36 for (
auto *&obj : m_groundObjs) {
37 obj =
new ObjectChoropuGround(m_pos, m_rot, m_scale);
39 obj->resize(RADIUS, MAX_SPEED);
42 m_groundHeight = m_groundObjs.front()->height();
45 m_objHoll =
new ObjectChoropuHoll(params);
50ObjectChoropu::~ObjectChoropu() =
default;
53void ObjectChoropu::init() {
58 m_objHoll->setScale(EGG::Vector3f(1.0f, m_objHoll->scale().y, 1.0f));
60 m_groundLength = 0.0f;
63 m_transMat = m_transform;
65 if (m_mapObj->pathId() == -1) {
69 m_railInterpolator->init(0.0f, 0);
70 m_railInterpolator->setPerPointVelocities(
true);
72 m_railMat = RailOrthonormalBasis(*m_railInterpolator);
73 m_pos = m_railMat.base(3);
74 m_flags.setBit(eFlags::Position);
77 m_objHoll->disableCollision();
84void ObjectChoropu::calc() {
85 constexpr u32 START_DELAY = 300;
88 u32 t = System::RaceManager::Instance()->timer();
89 if (t < m_startFrameOffset + START_DELAY) {
93 if (!m_isStationary) {
94 if (m_mapObj->pathId() == -1) {
98 m_railMat = RailOrthonormalBasis(*m_railInterpolator);
101 StateManager::calc();
103 m_objHoll->setScale(EGG::Vector3f(1.0f, m_objHoll->scale().y, 1.0f));
107Kart::Reaction ObjectChoropu::onCollision(Kart::KartObject * ,
108 Kart::Reaction reactionOnKart, Kart::Reaction ,
110 return m_currentStateId == 1 ? Kart::Reaction::SmallBump : reactionOnKart;
113void ObjectChoropu::enterStateStub() {}
116void ObjectChoropu::enterDigging() {
117 if (m_isStationary) {
120 for (
auto *&obj : m_groundObjs) {
121 obj->enableCollision();
125 m_objHoll->disableCollision();
126 m_groundLength = 0.0f;
131void ObjectChoropu::enterPeeking() {
132 if (m_isStationary) {
133 m_pos = m_transMat.base(3);
134 m_flags.setBit(eFlags::Position, eFlags::Rotation);
139 m_pos = m_railMat.base(3);
140 m_flags.setBit(eFlags::Position, eFlags::Rotation);
146 const auto &curTanDir = m_railInterpolator->curTangentDir();
147 s16 curPointIdx = m_railInterpolator->curPointIdx();
149 SetRotTangentHorizontal(mat, m_railInterpolator->floorNrm(curPointIdx), curTanDir);
150 mat.setBase(3, m_railInterpolator->curPos());
152 m_objHoll->setTransform(mat);
153 m_objHoll->setPos(mat.base(3));
154 m_objHoll->enableCollision();
159void ObjectChoropu::enterJumping() {
162 m_pos = m_isStationary ? m_transMat.base(3) : m_railMat.base(3);
163 m_flags.setBit(eFlags::Position, eFlags::Rotation);
167void ObjectChoropu::calcStateStub() {}
170void ObjectChoropu::calcDigging() {
171 if (m_isStationary) {
172 if (m_currentFrame > m_idleDuration) {
179 m_pos = m_railInterpolator->curPos();
180 m_flags.setBit(eFlags::Position);
182 if (m_railInterpolator->calc() == RailInterpolator::Status::SegmentEnd) {
183 if (m_railInterpolator->curPoint().setting[1] == 1) {
189 bool skipGroundCalc =
false;
191 if (m_railInterpolator->nextPoint().setting[1] == 1) {
192 f32 invT = 1.0f - m_railInterpolator->segmentT();
193 if (invT * m_railInterpolator->getCurrSegmentLength() < 250.0f) {
194 skipGroundCalc =
true;
198 if (!skipGroundCalc) {
205void ObjectChoropu::calcPeeking() {
206 constexpr s16 PEEK_DURATION = 40;
207 constexpr s16 STATE_DURATION = 100;
209 if (!m_isStationary) {
210 m_groundLength = std::max(0.0f, m_groundLength - m_railInterpolator->speed());
215 if (m_currentFrame > STATE_DURATION) {
219 if (m_currentFrame > PEEK_DURATION) {
225void ObjectChoropu::calcJumping() {
226 constexpr f32 JUMP_LINEAR_COEFFICIENT = 65.0f;
227 constexpr f32 JUMP_QUADRATIC_COEFFICIENT = 2.7f;
229 if (!m_isStationary) {
230 m_groundLength = std::max(0.0f, m_groundLength - m_railInterpolator->speed());
235 f32 pos = JUMP_LINEAR_COEFFICIENT *
static_cast<f32
>(m_currentFrame) -
236 static_cast<f32
>(m_currentFrame) * 0.5f * JUMP_QUADRATIC_COEFFICIENT *
237 static_cast<f32
>(m_currentFrame);
243 m_pos.y = pos + (m_isStationary ? m_transMat.base(3).y : m_railInterpolator->curPos().y);
244 m_flags.setBit(eFlags::Position);
248void ObjectChoropu::calcGround() {
249 m_groundLength += m_railInterpolator->getCurrVel();
250 if (m_groundLength > MAX_GROUND_LEN) {
251 m_groundLength = MAX_GROUND_LEN - 1.0f;
258void ObjectChoropu::calcGroundObjs() {
260 std::min(
static_cast<size_t>(m_groundLength / m_groundHeight) + 1, m_groundObjs.size());
262 for (
auto *&obj : m_groundObjs) {
263 obj->enableCollision();
266 for (
size_t i = idx; i < m_groundObjs.size(); ++i) {
267 m_groundObjs[i]->disableCollision();
270 if (m_groundLength > RADIUS) {
271 f32 height = std::min(m_groundHeight, m_groundLength) - RADIUS;
272 m_groundObjs[0]->calcPosAndMat(height, calcInterpolatedPose(RADIUS + 0.5f * height));
275 for (
size_t i = 1; i < idx - 1; ++i) {
276 f32 height = 0.5f * m_groundHeight + m_groundHeight *
static_cast<f32
>(i);
277 m_groundObjs[i]->calcPosAndMat(m_groundHeight, calcInterpolatedPose(height));
280 f32 height = m_groundLength - m_groundHeight *
static_cast<f32
>(idx - 1);
282 calcInterpolatedPose(0.5f * height + m_groundHeight *
static_cast<f32
>(idx - 1));
283 m_groundObjs[idx - 1]->calcPosAndMat(height, mat);
287EGG::Matrix34f ObjectChoropu::calcInterpolatedPose(f32 t)
const {
288 EGG::Vector3f curDir;
289 EGG::Vector3f curTanDir;
290 m_railInterpolator->evalCubicBezierOnPath(t, curDir, curTanDir);
291 EGG::Matrix34f mat = OrthonormalBasis(curTanDir);
292 mat.setBase(3, curDir);
297ObjectChoropuGround::ObjectChoropuGround(
const EGG::Vector3f &pos,
const EGG::Vector3f &rot,
298 const EGG::Vector3f &scale)
299 : ObjectCollidable(
"choropu_ground", pos, rot, scale) {
300 const auto &flowTable = ObjectDirector::Instance()->flowTable();
301 const auto *collisionSet =
302 flowTable.set(flowTable.slot(flowTable.getIdFromName(
"choropu_ground")));
303 ASSERT(collisionSet);
305 s16 height = parse<s16>(collisionSet->params.cylinder.height);
306 m_height = 2.0f * EGG::Mathf::abs(
static_cast<f32
>(height));
310ObjectChoropuGround::~ObjectChoropuGround() =
default;
313void ObjectChoropuGround::calcPosAndMat(f32 height,
const EGG::Matrix34f &mat) {
314 EGG::Matrix34f matTemp;
315 SetRotTangentHorizontal(matTemp, mat.base(2), EGG::Vector3f::ey);
316 matTemp.setBase(1, matTemp.base(1) * (height / m_height));
317 matTemp.setBase(3, mat.base(3));
318 m_flags.setBit(eFlags::Matrix);
319 m_transform = matTemp;
320 m_pos = matTemp.base(3);
324ObjectChoropuHoll::ObjectChoropuHoll(
const System::MapdataGeoObj ¶ms)
325 : ObjectCollidable(params) {}
328ObjectChoropuHoll::~ObjectChoropuHoll() =
default;