1#include "ObjectVolcanoBallLauncher.hh"
3#include "game/field/RailManager.hh"
4#include "game/field/obj/ObjectVolcanoBall.hh"
6#include "game/system/RaceManager.hh"
11ObjectVolcanoBallLauncher::ObjectVolcanoBallLauncher(
const System::MapdataGeoObj ¶ms)
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) {
27 EGG::Vector3f dir = points[1].pos - points[0].pos;
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 = owning_span<ObjectVolcanoBall *>(ballCount);
46 for (
auto *&ball : m_balls) {
47 ball =
new ObjectVolcanoBall(accel, finalVel, endPosY, params, vel);
55ObjectVolcanoBallLauncher::~ObjectVolcanoBallLauncher() =
default;
58void ObjectVolcanoBallLauncher::init() {
59 for (
auto *&ball : m_balls) {
61 ball->m_nextStateId = 0;
68void ObjectVolcanoBallLauncher::calc() {
69 u32 t = System::RaceManager::Instance()->timer();
72 t = (t -
static_cast<s32
>(m_initDelay)) %
static_cast<s32
>(m_cycleDuration);
74 if (
static_cast<f32
>(t) == m_cycleDuration - 1.0f) {
75 m_balls[m_currBallIdx++]->m_nextStateId = 1;
78 if (
static_cast<f32
>(t) == m_initDelay) {
79 m_balls[m_currBallIdx++]->m_nextStateId = 1;
84 if (m_currBallIdx == m_balls.size()) {