1#include "ObjectVolcanoBallLauncher.hh"
3#include "game/field/RailManager.hh"
4#include "game/field/obj/ObjectVolcanoBall.hh"
6#include "game/system/RaceManager.hh"
12 : ObjectCollidable(params), m_initDelay(static_cast<f32>(static_cast<s16>(params.setting(1)))),
13 m_cycleDuration(static_cast<f32>(static_cast<s16>(params.setting(2)))) {
14 const auto *rail = RailManager::Instance()->rail(params.pathId());
16 const auto &points = rail->points();
20 for (
auto &point : points) {
21 if (point.setting[0] == 1) {
29 EGG::Vector3f vel = dir *
static_cast<f32
>(
static_cast<s16
>(params.setting(0)));
30 f32 accel = vel.y * vel.y / (2.0f * (pos - points[0].pos.y));
32 f32 endPosY = points.back().pos.y;
37 EGG::Mathf::FindRootsQuadratic(0.5f * accel, -vel.y, endPosY - points[0].pos.y, t1, t2);
38 f32 fallTime = (t2 > 0.0f) ? t2 : (t1 > 0.0f) ? t1 : -1.0f;
40 f32 finalVel = 2.0f * accel * (pos - endPosY);
41 f32 burnDuration =
static_cast<f32
>(
static_cast<s16
>(params.setting(3)));
42 u32 ballCount =
static_cast<u32
>((fallTime + burnDuration) / m_cycleDuration) + 2;
44 m_balls = std::span<ObjectVolcanoBall *>(
new ObjectVolcanoBall *[ballCount], ballCount);
46 for (
auto *&ball : m_balls) {
47 ball =
new ObjectVolcanoBall(accel, finalVel, endPosY, params, vel);
55ObjectVolcanoBallLauncher::~ObjectVolcanoBallLauncher() {
56 delete[] m_balls.data();
60void ObjectVolcanoBallLauncher::init() {
61 for (
auto *&ball : m_balls) {
63 ball->m_nextStateId = 0;
70void ObjectVolcanoBallLauncher::calc() {
71 u32 t = System::RaceManager::Instance()->timer();
74 t = (t -
static_cast<s32
>(m_initDelay)) %
static_cast<s32
>(m_cycleDuration);
76 if (
static_cast<f32
>(t) == m_cycleDuration - 1.0f) {
77 m_balls[m_currBallIdx++]->m_nextStateId = 1;
80 if (
static_cast<f32
>(t) == m_initDelay) {
81 m_balls[m_currBallIdx++]->m_nextStateId = 1;
86 if (m_currBallIdx == m_balls.size()) {