1#include "KartAction.hh"
3#include "game/kart/KartMove.hh"
4#include "game/kart/KartPhysics.hh"
5#include "game/kart/KartState.hh"
7#include <egg/math/Math.hh>
12KartAction::KartAction()
13 : m_currentAction(Action::None), m_hitDepth(
EGG::Vector3f::zero), m_onStart(nullptr),
14 m_onCalc(nullptr), m_onEnd(nullptr), m_actionParams(nullptr), m_rotationParams(nullptr),
18KartAction::~KartAction() =
default;
21void KartAction::init() {
22 m_currentAction = Action::None;
23 m_flags.makeAllZero();
27void KartAction::calc() {
28 if (m_currentAction == Action::None || !m_onCalc) {
32 if (calcCurrentAction()) {
38void KartAction::calcVehicleSpeed() {
39 move()->setSpeed(m_actionParams->calcSpeedMult * move()->speed());
46bool KartAction::start(Action action) {
47 ASSERT(action != Action::None);
49 if (state()->isInRespawn() || state()->isAfterRespawn() || state()->isBeforeRespawn() ||
50 state()->isInCannon()) {
54 size_t actionIdx =
static_cast<size_t>(action);
55 if (m_currentAction != Action::None && s_actionParams[actionIdx].priority <= m_priority) {
60 m_currentAction = action;
61 m_actionParams = &s_actionParams[actionIdx];
62 m_priority = m_actionParams->priority;
63 m_onStart = s_onStart[actionIdx];
64 m_onCalc = s_onCalc[actionIdx];
65 m_onEnd = s_onEnd[actionIdx];
66 state()->setInAction(
true);
68 m_flags.makeAllZero();
82void KartAction::startRotation(
size_t idx) {
83 m_rotation = EGG::Quatf::ident;
90 m_rotationDirection = dir.cross(bodyFront()).
dot(bodyUp()) > 0.0f ? 1.0f : -1.0f;
92 m_flags.setBit(eFlags::Rotating);
96 m_hitDepth = hitDepth;
99const KartAction::Flags &KartAction::flags()
const {
104void KartAction::end() {
105 state()->setInAction(
false);
106 dynamics()->setForceUpright(
true);
108 m_currentAction = Action::None;
110 m_flags.makeAllZero();
116bool KartAction::calcCurrentAction() {
118 return (this->*m_onCalc)();
122void KartAction::calcEndAction(
bool endArg) {
123 if (m_currentAction == Action::None) {
128 (this->*m_onEnd)(endArg);
134bool KartAction::calcRotation() {
135 if (!m_rotationParams) {
140 if (m_currentAngle > m_finalAngle * m_rotationParams->slowdownThreshold) {
141 m_angleIncrement *= m_multiplier;
142 if (m_rotationParams->minAngleIncrement > m_angleIncrement) {
143 m_angleIncrement = m_rotationParams->minAngleIncrement;
146 m_multiplier -= m_multiplierDecrement;
147 if (m_rotationParams->minMultiplier > m_multiplier) {
148 m_multiplier = m_rotationParams->minMultiplier;
152 m_currentAngle += m_angleIncrement;
153 if (m_finalAngle < m_currentAngle) {
154 m_currentAngle = m_finalAngle;
162void KartAction::calcUp() {
163 m_up += (move()->up() - m_up) * 0.3f;
168void KartAction::applyStartSpeed() {
169 move()->setSpeed(m_actionParams->startSpeedMult * move()->speed());
170 if (m_actionParams->startSpeedMult == 0.0f) {
171 move()->clearDrift();
176void KartAction::setRotation(
size_t idx) {
177 ASSERT(idx - 1 < s_rotationParams.size());
178 m_rotationParams = &s_rotationParams[--idx];
180 m_finalAngle = m_rotationParams->finalAngle;
181 m_angleIncrement = m_rotationParams->initialAngleIncrement;
182 m_multiplierDecrement = m_rotationParams->initialMultiplierDecrement;
183 m_currentAngle = 0.0f;
191void KartAction::startStub() {}
194void KartAction::startAction1() {
202bool KartAction::calcStub() {
207bool KartAction::calcAction1() {
209 bool finished = calcRotation();
211 m_rotation.setAxisRotation(DEG2RAD * (m_currentAngle * m_rotationDirection), m_up);
212 physics()->composeExtraRot(m_rotation);
220void KartAction::endStub(
bool ) {}
223void KartAction::endAction1(
bool arg) {
225 physics()->composeDecayingExtraRot(m_rotation);
233const std::array<KartAction::ActionParams, KartAction::MAX_ACTION> KartAction::s_actionParams = {{
254const std::array<KartAction::RotationParams, 5> KartAction::s_rotationParams = {{
255 {10.0f, 1.5f, 0.9f, 0.005f, 0.6f, 360.0f},
256 {11.0f, 1.5f, 0.9f, 0.0028f, 0.7f, 720.0f},
257 {11.0f, 1.5f, 0.9f, 0.0028f, 0.8f, 1080.0f},
258 {7.0f, 1.5f, 0.9f, 0.005f, 0.6f, 450.0f},
259 {9.0f, 1.5f, 0.9f, 0.0028f, 0.7f, 810.0f},
262const std::array<KartAction::StartActionFunc, KartAction::MAX_ACTION> KartAction::s_onStart = {{
263 &KartAction::startStub,
264 &KartAction::startAction1,
265 &KartAction::startStub,
266 &KartAction::startStub,
267 &KartAction::startStub,
268 &KartAction::startStub,
269 &KartAction::startStub,
270 &KartAction::startStub,
271 &KartAction::startStub,
272 &KartAction::startStub,
273 &KartAction::startStub,
274 &KartAction::startStub,
275 &KartAction::startStub,
276 &KartAction::startStub,
277 &KartAction::startStub,
278 &KartAction::startStub,
279 &KartAction::startStub,
280 &KartAction::startStub,
283const std::array<KartAction::CalcActionFunc, KartAction::MAX_ACTION> KartAction::s_onCalc = {{
284 &KartAction::calcStub,
285 &KartAction::calcAction1,
286 &KartAction::calcStub,
287 &KartAction::calcStub,
288 &KartAction::calcStub,
289 &KartAction::calcStub,
290 &KartAction::calcStub,
291 &KartAction::calcStub,
292 &KartAction::calcStub,
293 &KartAction::calcStub,
294 &KartAction::calcStub,
295 &KartAction::calcStub,
296 &KartAction::calcStub,
297 &KartAction::calcStub,
298 &KartAction::calcStub,
299 &KartAction::calcStub,
300 &KartAction::calcStub,
301 &KartAction::calcStub,
304const std::array<KartAction::EndActionFunc, KartAction::MAX_ACTION> KartAction::s_onEnd = {{
305 &KartAction::endStub,
306 &KartAction::endAction1,
307 &KartAction::endStub,
308 &KartAction::endStub,
309 &KartAction::endStub,
310 &KartAction::endStub,
311 &KartAction::endStub,
312 &KartAction::endStub,
313 &KartAction::endStub,
314 &KartAction::endStub,
315 &KartAction::endStub,
316 &KartAction::endStub,
317 &KartAction::endStub,
318 &KartAction::endStub,
319 &KartAction::endStub,
320 &KartAction::endStub,
321 &KartAction::endStub,
322 &KartAction::endStub,
Pertains to kart-related functionality.
f32 normalise()
Normalizes the vector and returns the original length.
f32 dot(const Vector3f &rhs) const
The dot product between two vectors.