SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
MapPartsFloatingForce.cpp
1#include "Game/MapObj/MapPartsFloatingForce.hpp"
2#include "Game/MapObj/FloaterFunction.hpp"
3#include "Game/LiveActor/LiveActor.hpp"
4#include "Game/Util.hpp"
5
6SpringStep::SpringStep(f32 cond, f32 speed, f32 angle) {
7 mSpringValue = 0;
8 mCondition = cond;
9 mSpeed = speed;
10 mAngle = angle;
11 mSpringValue = new SpringValue(cond, 0.0f, speed, angle, 0.0f);
12}
13
14void SpringStep::addSpringVelocity(f32 vel) {
15 mSpringValue->_10 += vel;
16}
17
18void SpringStep::setSpringBaseValue(f32 val) {
19 mCondition = val;
20 mSpringValue->setParam((f64)val, 0.0f, mSpeed, mAngle, 0.0f);
21}
22
23MapPartsFloatingForce::MapPartsFloatingForce(LiveActor *pActor) : MapPartsFunction(pActor, "浮力") {
24 mSpringStep = 0;
25 mObjectName = 0;
26 _20 = 0.0f;
27 mRotateAngle = 0.0f;
28 mRotateSpeed = 0.0f;
29 mRotateAccelType = 0;
30 _30.setZero();
31 _3C = 0.0f;
32 _40 = 1.0f;
33 _44 = 0.0f;
34 _48 = 0.0f;
35 _5C = 0.0f;
36}
37
39 initNerve(&NrvMapPartsFloatingForce::HostTypeWait::sInstance);
40 MR::getMapPartsArgRotateAccelType(&mRotateAccelType, rIter);
41
42 if (mRotateAccelType != 1) {
43 initForNormalMotion(rIter);
44 }
45 else {
46 initForSpringMotion(rIter);
47 }
48
49 MR::useStageSwitchReadA(mHost, rIter);
50}
51
52void MapPartsFloatingForce::setObjectName(const char *pName) {
53 mObjectName = pName;
54}
55
56void MapPartsFloatingForce::initForNormalMotion(const JMapInfoIter &rIter) {
57 s32 condition_type = 0;
58 MR::getMapPartsArgMoveConditionType(&condition_type, rIter);
59 _20 = condition_type;
60 MR::getMapPartsArgRotateSpeed(&mRotateSpeed, rIter);
61 MR::getMapPartsArgRotateAngle(&mRotateAngle, rIter);
62}
63
64void MapPartsFloatingForce::initForSpringMotion(const JMapInfoIter &rIter) {
65 s32 condition_type = 0;
66 MR::getMapPartsArgMoveConditionType(&condition_type, rIter);
67 _20 = condition_type;
68 f32 rotate_speed = 0.0f;
69 MR::getMapPartsArgRotateSpeed(&rotate_speed, rIter);
70 rotate_speed *= 0.001f;
71 f32 rotate_angle = 0.0f;
72 MR::getMapPartsArgRotateAngle(&rotate_angle, rIter);
73 rotate_angle *= 0.001f;
74 s32 rotate_axis = 0;
75 MR::getMapPartsArgRotateAxis(&rotate_axis, rIter);
76 _5C = 0.1f * rotate_axis;
77 mSpringStep = new SpringStep(-condition_type, rotate_speed, rotate_angle);
78}
79
80void MapPartsFloatingForce::updateVelocity() {
81 if (MR::isOnPlayer(MR::getBodySensor(mHost))) {
82 if (_20 <= _48) {
83 _4C = MR::converge<f32>(_4C, 0.0f, 0.050000001f);
84 }
85 else {
86 _4C = _4C + (0.000099999997f * mRotateSpeed);
87 }
88 }
89 else {
90 if (_48 <= 0.0f) {
91 _4C = MR::converge<f32>(_4C, 0.0f, 0.050000001f);
92 }
93 else {
94 _4C = _4C - (0.000099999997f * mRotateAngle);
95 }
96 }
97
98 _4C *= 0.98000002f;
99 _4C = MR::clamp(_4C, -50.0f, 50.0f);
100}
101
102// void MapPartsFloatingForce::updateVelocitySpring()
103
104bool MapPartsFloatingForce::tryOn() {
105 bool isSwitchOn = false;
106
107 if (MR::isValidSwitchA(mHost) && MR::isOnSwitchA(mHost)) {
108 isSwitchOn = true;
109 }
110
111 if (isSwitchOn) {
112 return false;
113 }
114
115 if (MR::isOnPlayer(MR::getBodySensor(mHost))) {
116 const char* ground_sound = FloaterFunction::getSeGroundOn(mObjectName);
117 if (ground_sound) {
118 MR::startSound(mHost, ground_sound, -1, -1);
119 }
120
121 setNerve(&NrvMapPartsFloatingForce::HostTypeMoveSpring::sInstance);
122 return true;
123 }
124
125 return false;
126}
127
128bool MapPartsFloatingForce::tryReturn() {
129 bool isSwitchOn = false;
130
131 if (MR::isValidSwitchA(mHost) && MR::isOnSwitchA(mHost)) {
132 isSwitchOn = true;
133 }
134
135 if (!isSwitchOn) {
136 if (MR::isOnPlayer(MR::getBodySensor(mHost))) {
137 return false;
138 }
139 }
140
141 setNerve(&NrvMapPartsFloatingForce::HostTypeMoveReturn::sInstance);
142 return true;
143}
144
145void MapPartsFloatingForce::exeWait() {
146 if (isFirstStep()) {
147 _48 = 0.0f;
148 }
149
150 if (mRotateAccelType == 1) {
151 tryOn();
152 }
153}
154
155// MapPartsFloatingForce::exeMove
156
157void MapPartsFloatingForce::exeMoveSpring() {
158 if (isFirstStep()) {
159 mSpringStep->setSpringBaseValue(-_20);
160 mSpringStep->addSpringVelocity(-_5C);
161 }
162
163 updateVelocitySpring();
164 mHost->mVelocity.set(_50);
165 tryReturn();
166}
167
168// MapPartsFloatingForce::exeMoveReturn
169
170MapPartsFloatingForce::~MapPartsFloatingForce() {
171
172}
173
174namespace NrvMapPartsFloatingForce {
175 INIT_NERVE(HostTypeWait);
176 INIT_NERVE(HostTypeMove);
177 INIT_NERVE(HostTypeMoveSpring);
178 INIT_NERVE(HostTypeMoveReturn);
179
180 void HostTypeMoveReturn::execute(Spine *pSpine) const {
181 MapPartsFloatingForce* force = reinterpret_cast<MapPartsFloatingForce*>(pSpine->mExecutor);
182 force->exeMoveReturn();
183 }
184
185 void HostTypeMoveSpring::execute(Spine *pSpine) const {
186 MapPartsFloatingForce* force = reinterpret_cast<MapPartsFloatingForce*>(pSpine->mExecutor);
187 force->exeMoveSpring();
188 }
189
190 void HostTypeMove::execute(Spine *pSpine) const {
191 MapPartsFloatingForce* force = reinterpret_cast<MapPartsFloatingForce*>(pSpine->mExecutor);
192 force->exeMove();
193 }
194
195 void HostTypeWait::execute(Spine *pSpine) const {
196 MapPartsFloatingForce* force = reinterpret_cast<MapPartsFloatingForce*>(pSpine->mExecutor);
197 force->exeWait();
198 }
199};
The basis of a drawable actor that can contain states (see: Nerve)
Definition LiveActor.hpp:24
TVec3f mVelocity
3D vector of the actor's velocity.
Definition LiveActor.hpp:98
virtual void init(const JMapInfoIter &)
Intializes the NameObj and can set various settings and construct necessary classes.
Definition Spine.hpp:9