SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
WaterPressureBullet.cpp
1#include "Game/MapObj/WaterPressureBullet.hpp"
2#include "Game/LiveActor/ActorCameraInfo.hpp"
3#include "JSystem/JMath/JMath.hpp"
4
5WaterPressureBullet::WaterPressureBullet(const char *pName) : LiveActor(pName) {
6 _8C.x = 0.0f;
7 _8C.y = 0.0f;
8 _8C.z = 0.0f;
9 _98.x = 0.0f;
10 _98.y = 0.0f;
11 _98.z = 0.0f;
12 _A4 = 0;
13 _A8 = 0.0f;
14 mHostActor = nullptr;
15 _B0 = false;
16 _B1 = false;
17 _B2 = false;
18 mCameraInfo = nullptr;
19}
20
22 initModelManagerWithAnm("WaterBullet", nullptr, false);
23 MR::connectToSceneMapObjStrongLight(this);
24 initHitSensor(2);
25 MR::addHitSensor(this, "body", 24, 4, 100.0f, TVec3f(0.0f, 0.0f, 0.0f));
26 MR::addHitSensor(this, "binder", 106, 4, 100.0f, TVec3f(0.0f, 0.0f, 0.0f));
27 initBinder(100.0f, 0.0f, 0);
28 initEffectKeeper(0, nullptr, false);
29 initSound(6, false);
30 TVec3f offs;
31 offs.x = 0.0f;
32 offs.y = 0.0f;
33 offs.z = 0.0f;
34 MR::initStarPointerTarget(this, 100.0f, offs);
35 MR::initShadowVolumeSphere(this, 75.0f);
36 MR::setShadowDropLength(this, nullptr, 1500.0f);
37 MR::registerDemoSimpleCastAll(this);
38 initNerve(&NrvWaterPressureBullet::WaterPressureBulletNrvFly::sInstance);
39 makeActorDead();
40}
41
42void WaterPressureBullet::kill() {
43 if (MR::isPlayerInRush() && mHostActor) {
44 MR::startBckPlayer("GCaptureBreak", (const char*)nullptr);
45 MR::endBindAndPlayerJumpWithRollLanding(this, mVelocity, 0);
46 mHostActor = nullptr;
47 endHostCamera();
48 }
49
50 MR::emitEffect(this, "Break");
51 MR::startSound(this, "SE_OJ_W_PRESS_BUBBLE_BREAK", -1, -1);
52 LiveActor::kill();
53}
54
55#ifdef NON_MATCHING
56void WaterPressureBullet::control() {
57 bool v1 = true;
58 bool v2 = false;
59
60 if (_B2 && mHostActor == nullptr) {
61 v2 = true;
62 }
63
64 if (!v2 && _B2) {
65 v1 = false;
66 }
67
68 if (v1 && MR::isStarPointerPointing2POnTriggerButton(this, "弱", true, false)) {
69 kill();
70 }
71 else {
72 TVec3f stack_8;
73 if (MR::isNearZero(mVelocity, 0.001)) {
74 stack_8.set(mGravity);
75 }
76 else {
77 stack_8.set(mVelocity);
78 }
79
80 f32 val = (45.511112f * MR::negFloat(2.5f));
81 MR::turnVecToVecCosOnPlane(&_8C, stack_8, _98, JMASCos(val));
82 }
83}
84#endif
85
87 TPos3f pos;
88 MR::makeMtxFrontSidePos(&pos, _8C, _98, mPosition);
89 MR::setBaseTRMtx(this, pos);
90}
91
92void WaterPressureBullet::shotWaterBullet(LiveActor *pActor, const TPos3f &rPos, f32 a3, bool a4, bool a5, bool a6, ActorCameraInfo **pInfo) {
93 f32 z = rPos.mMtx[2][2];
94 f32 y = rPos.mMtx[1][2];
95 f32 x = rPos.mMtx[0][2];
96 _A8 = a3;
97 _A4 = pActor;
98 _B0 = a4;
99 _B1 = a5;
100 _B2 = a6;
101 mCameraInfo = pInfo;
102 _8C.set<f32>(x, y, z);
103 mVelocity.scale(_A8, _8C);
104 z = rPos.mMtx[2][3];
105 y = rPos.mMtx[1][3];
106 x = rPos.mMtx[0][3];
107 mPosition.set<f32>(x, y, z);
108 z = rPos.mMtx[2][0];
109 y = rPos.mMtx[1][0];
110 x = rPos.mMtx[0][0];
111 _98.set<f32>(x, y, z);
112 mRotation.zero();
113 makeActorAppeared();
114 MR::validateHitSensors(this);
115 MR::invalidateClipping(this);
116 MR::setShadowDropLength(this, nullptr, 1500.0f);
117
118 if (!_B0) {
119 MR::onCalcGravity(this);
120 }
121
122 setNerve(&NrvWaterPressureBullet::WaterPressureBulletNrvFly::sInstance);
123}
124
125void WaterPressureBullet::exeFly() {
126 if (MR::isFirstStep(this)) {
127 MR::startBck(this, "Shot", nullptr);
128 }
129
130 if (MR::isBckOneTimeAndStopped(this)) {
131 MR::startBck(this, "Move", nullptr);
132 }
133
134 if (mHostActor != nullptr && MR::isBckOneTimeAndStopped(mHostActor)) {
135 MR::startBckPlayer("WaterBulletWait", (const char*)nullptr);
136 }
137
138 if (mHostActor != nullptr) {
139 MR::startLevelSound(this, "SE_OJ_LV_W_PRESS_BUBBLE_SUS", -1, -1, -1);
140 }
141
142 if (!_B0) {
143 JMAVECScaleAdd(mGravity.toCVec(), mVelocity.toCVec(), mVelocity.toVec(), 0.40000001f);
144 }
145
146 if (MR::isPadSwing(0) && mHostActor != nullptr && !_B2) {
147 MR::startSound(mHostActor, "SE_PV_TWIST_START", -1, -1);
148 MR::startSound(mHostActor, "SE_PM_SPIN_ATTACK", -1, -1);
149 MR::tryRumblePadMiddle(this, 0);
150 setNerve(&NrvWaterPressureBullet::WaterPressureBulletNrvSpinKill::sInstance);
151 return;
152 }
153
154 bool v2 = false;
155
156 if (MR::isBinded(this) || MR::isInWater(this, TVec3f(0.0f, 0.0f, 0.0f))) {
157 v2 = true;
158 }
159
160 if (v2) {
161 if (!_B1 || mHostActor == nullptr || MR::isBindedGroundSand(this)) {
162 kill();
163 return;
164 }
165
166 TVec3f* vel = &mVelocity;
167 TVec3f* grav = &mGravity;
168 f32 dot = grav->dot(mVelocity);
169 JMAVECScaleAdd(grav->toCVec(), vel->toCVec(), vel->toVec(), -dot);
170 }
171
172 if (!_B2 && MR::isGreaterEqualStep(this, 180) || _B2 && MR::isGreaterEqualStep(this, 300)) {
173 kill();
174 }
175}
176
177void WaterPressureBullet::exeSpinKill() {
178 if (MR::isFirstStep(this)) {
179 MR::startBckPlayer("Spin2nd", (const char*)nullptr);
180 mVelocity.zero();
181 MR::invalidateHitSensors(this);
182
183 if (MR::isPlayerInRush()) {
184 if (mHostActor != nullptr) {
185 MR::endBindAndPlayerJump(this, mVelocity, 0);
186 mHostActor = nullptr;
187 endHostCamera();
188 }
189 }
190 }
191
192 kill();
193}
194
195void WaterPressureBullet::attackSensor(HitSensor *a1, HitSensor *a2) {
196 if (MR::isSensorMapObj(a2)) {
197 kill();
198 }
199}
200
201bool WaterPressureBullet::receiveMsgPlayerAttack(u32 msg, HitSensor *, HitSensor *) {
202 if (MR::isMsgFireBallAttack(msg)) {
203 kill();
204 return true;
205 }
206
207 return false;
208}
209
210bool WaterPressureBullet::receiveOtherMsg(u32 msg, HitSensor *a2, HitSensor *a3) {
211 if (MR::isDead(this)) {
212 return false;
213 }
214
215 if (MR::isMsgAutoRushBegin(msg) && MR::isSensorPlayer(a2) && mHostActor == nullptr) {
216 if (MR::isDemoActive()) {
217 kill();
218 return false;
219 }
220
221 if (!inviteMario(a2)) {
222 return false;
223 }
224 else {
225 MR::startSound(this, "SE_OJ_W_PRESS_BUBBLE_IN", -1, -1);
226 MR::startSound(mHostActor, "SE_PV_CATCH", -1, -1);
227 return true;
228 }
229 }
230 else if (msg == 152) {
231 return true;
232 }
233 else if (msg == 147) {
234 kill();
235 return true;
236 }
237 else if (msg == 161 && mHostActor != nullptr) {
238 updateSuffererMtx();
239 return true;
240 }
241
242 return false;
243}
244
245bool WaterPressureBullet::startHostCamera() const {
246 if (_A4 != nullptr && mCameraInfo != nullptr) {
247 MR::startActorCameraNoTarget(_A4, *mCameraInfo, -1);
248 return true;
249 }
250
251 return false;
252}
253
254bool WaterPressureBullet::endHostCamera() const {
255 if (_A4 != nullptr && mCameraInfo != nullptr) {
256 MR::endActorCamera(_A4, *mCameraInfo, true, -1);
257 return true;
258 }
259
260 return false;
261}
262
263bool WaterPressureBullet::inviteMario(HitSensor *pSensor) {
264 MR::tryRumblePadMiddle(this, 0);
265
266 if (MR::isOnGroundPlayer() && MR::isNearAngleDegree(mVelocity, mGravity, 60.0f)) {
267 if (_B1) {
268 TVec3f* vel = &mVelocity;
269 TVec3f* grav = &mGravity;
270 f32 dot = grav->dot(mVelocity);
271 JMAVECScaleAdd(grav->toCVec(), vel->toCVec(), vel->toVec(), -dot);
272 }
273 else {
274 kill();
275 MR::sendArbitraryMsg(76, pSensor, getSensor("body"));
276 return false;
277 }
278 }
279
280 mHostActor = pSensor->mActor;
281 MR::startBckWithInterpole(this, "Touch", 0);
282 MR::startBckPlayer("WaterBulletStart", 2);
283 startHostCamera();
284 MR::setShadowDropLength(this, nullptr, 2000.0f);
285 return true;
286}
287
288void WaterPressureBullet::updateSuffererMtx() {
289 TPos3f pos;
290 pos.identity();
291
292 if (isNerve(&NrvWaterPressureBullet::WaterPressureBulletNrvSpinKill::sInstance)) {
293 TVec3f front;
294 MR::calcFrontVec(&front, mHostActor);
295 MR::calcMtxFromGravityAndZAxis(&pos, mHostActor, mGravity, front);
296 }
297 else {
298 MtxPtr mtx = getBaseMtx();
299 pos.setInline(mtx);
300 }
301
302 MR::setBaseTRMtx(this, pos);
303}
304
305WaterPressureBullet::~WaterPressureBullet() {
306
307}
308
309namespace NrvWaterPressureBullet {
310 INIT_NERVE(WaterPressureBulletNrvFly);
311 INIT_NERVE(WaterPressureBulletNrvSpinKill);
312
313 void WaterPressureBulletNrvSpinKill::execute(Spine *pSpine) const {
314 WaterPressureBullet* bullet = reinterpret_cast<WaterPressureBullet*>(pSpine->mExecutor);
315 bullet->exeSpinKill();
316 }
317
318 void WaterPressureBulletNrvFly::execute(Spine *pSpine) const {
319 WaterPressureBullet* bullet = reinterpret_cast<WaterPressureBullet*>(pSpine->mExecutor);
320 bullet->exeFly();
321 }
322};
The basis of a drawable actor that can contain states (see: Nerve)
Definition LiveActor.hpp:24
TVec3f mRotation
3D vector of the actor's rotation.
Definition LiveActor.hpp:96
TVec3f mPosition
3D vector of the actor's position.
Definition LiveActor.hpp:95
TVec3f mVelocity
3D vector of the actor's velocity.
Definition LiveActor.hpp:98
TVec3f mGravity
3D vector of the actor's gravity.
Definition LiveActor.hpp:99
virtual MtxPtr getBaseMtx() const
Gets the base matrix of the model used for the actor.
HitSensor * getSensor(const char *pSensorName) const
Gets a sensor.
Definition Spine.hpp:9
virtual void init(const JMapInfoIter &)
Intializes the NameObj and can set various settings and construct necessary classes.
virtual void calcAndSetBaseMtx()
Calculates and sets the base matrix of the actor.