SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
RailMoveObj.cpp
1#include "Game/MapObj/RailMoveObj.hpp"
2#include "Game/MapObj/MapPartsRailMover.hpp"
3#include "Game/MapObj/MapPartsRailRotator.hpp"
4#include "Game/MapObj/StageEffectDataTable.hpp"
5
6RailMoveObj::RailMoveObj(const char *pName) : MapObjActor(pName) {
7 _C4.setZero();
8 _D0 = 0;
9}
10
11void RailMoveObj::init(const JMapInfoIter &rIter) {
12 MapObjActor::init(rIter);
14 info.setupHioNode("地形オブジェ");
15 info.setupDefaultPos();
16 info.setupConnectToScene();
17 info.setupEffect(0);
18 info.setupSound(0x6);
19 info.setupSoundPos(getSoundCalcPos());
20 info.setupGroupClipping(0x20);
21 info.setupSeAppear();
22 info.setupRailMover();
23 info.setupRailPosture();
24 info.setupShadow(0);
25 info.setupBaseMtxFollowTarget();
26 info.setupNerve(&NrvRailMoveObj::HostTypeMove::sInstance);
27 MapObjActorUtil::setupInitInfoTypical(&info, mObjectName);
28 setupInitInfo(rIter, &info);
29 initialize(rIter, info);
30
31 if (MR::isConnectedWithRail(rIter)) {
32 f32 radius = 0.0f;
33 MR::calcModelBoundingRadius(&radius, this);
34 MR::initAndSetRailClipping(&_C4, this, 100.0f, radius);
35 }
36 else {
37 setNerve(&NrvRailMoveObj::HostTypeDone::sInstance);
38 }
39
40 s32 condition_type = 0;
41 MR::getMapPartsArgMoveConditionType(&condition_type, rIter);
42
43 if (!MR::isMoveStartUnconditional(condition_type)) {
44 setNerve(&NrvRailMoveObj::HostTypeWaitForPlayerOn::sInstance);
45 }
46
47 if (MR::isDemoCast(this, 0) && MR::tryRegisterDemoActionNerve(this, &NrvRailMoveObj::HostTypeMove::sInstance, 0)) {
48 setNerve(&NrvRailMoveObj::HostTypeWait::sInstance);
49 }
50}
51
52TVec3f* RailMoveObj::getSoundCalcPos() {
53 return 0;
54}
55
56void RailMoveObj::startClipped() {
57 MapObjActor::startClipped();
58
59 if (mRailMover) {
60 if (MR::StageEffect::isExistStageEffectData(mObjectName)) {
61 MR::StageEffect::stopShakingCameraMoving(this, mObjectName);
62 }
63 }
64}
65
66void RailMoveObj::endClipped() {
67 MapObjActor::endClipped();
68
69 if (mRailMover) {
70 if (MapObjActorUtil::isRailMoverWorking(this)) {
71 if (!isNerve(&NrvRailMoveObj::HostTypeDone::sInstance)) {
72 if (MR::StageEffect::isExistStageEffectData(mObjectName)) {
73 MR::StageEffect::shakeCameraMoving(this, mObjectName);
74 }
75 }
76 }
77 }
78}
79
80void RailMoveObj::initCaseUseSwitchB(const MapObjActorInitInfo &rInitInfo) {
81 MapObjActor::initCaseUseSwitchB(rInitInfo);
82 setNerve(&NrvRailMoveObj::HostTypeWait::sInstance);
83}
84
85void RailMoveObj::initCaseNoUseSwitchB(const MapObjActorInitInfo &) {
86
87}
88
89void RailMoveObj::startMoveInner() {
90 MR::StageEffect::tryStageEffectStart(this, mObjectName);
91
92 if (MR::isExistBck(this, cMoveBckName)) {
93 MR::startBck(this, cMoveBckName, 0);
94 }
95
96 if (MR::StageEffect::isExistStageEffectData(mObjectName)) {
97 MR::StageEffect::shakeCameraMoving(this, mObjectName);
98 }
99}
100
101void RailMoveObj::move() {
102 if (MapObjActorUtil::isRailMoverWorking(this)) {
103 MR::StageEffect::tryStageEffectMoving(this, mObjectName);
104 }
105}
106
107void RailMoveObj::doAtEndPoint() {
108 MR::StageEffect::tryStageEffectStop(this, mObjectName);
109
110 if (MR::isExistBck(this, cMoveBckName) && MR::isBckPlaying(this, cMoveBckName)) {
111 MR::stopBck(this);
112 }
113
114 if (MR::StageEffect::isExistStageEffectData(mObjectName)) {
115 MR::StageEffect::stopShakingCameraMoving(this, mObjectName);
116 }
117}
118
119bool RailMoveObj::endMove() {
120 doAtEndPoint();
121 return true;
122}
123
124bool RailMoveObj::isMoving() const {
125 return MapObjActorUtil::isRailMoverWorking(this);
126}
127
128bool RailMoveObj::receiveOtherMsg(u32 msg, HitSensor *, HitSensor *) {
129 if (msg == 0xCF && isNerve(&NrvRailMoveObj::HostTypeMove::sInstance)) {
130 kill();
131 return true;
132 }
133
134 return false;
135}
136
137void RailMoveObj::exeWait() {
138 if (!isNerve(&NrvRailMoveObj::HostTypeDone::sInstance) && (!MR::isDemoCast(this, 0) || !MR::isRegisteredDemoActionNerve(this)) && (!MR::isValidSwitchB(this) || MR::isOnSwitchB(this)) && (!isNerve(&NrvRailMoveObj::HostTypeWaitForPlayerOn::sInstance) || MR::isOnPlayer(this))) {
139 tryStartMove();
140 }
141}
142
143bool RailMoveObj::tryStartMove() {
144 setNerve(&NrvRailMoveObj::HostTypeMove::sInstance);
145 return true;
146}
147
148void RailMoveObj::exeMove() {
149 if (MR::isFirstStep(this)) {
150 startMapPartsFunctions();
151 }
152
153 if (!_D0 && MapObjActorUtil::isRailMoverWorking(this)) {
154 startMoveInner();
155 }
156
157 _D0 = MapObjActorUtil::isRailMoverWorking(this);
158 move();
159
160 if (mRailMover->isReachedEnd()) {
161 if (mRailMover->isDone() && endMove()) {
162 setNerve(&NrvRailMoveObj::HostTypeDone::sInstance);
163 }
164 else {
165 doAtEndPoint();
166 }
167 }
168}
169
170RailMoveObjPress::RailMoveObjPress(const char *pName) : RailMoveObj(pName) {
171
172}
173
175 RailMoveObj::init(rIter);
176 MR::setBodySensorType(this, 0x76);
177}
178
179RailMoveObjBreakAtEnd::RailMoveObjBreakAtEnd(const char *pName) : RailMoveObj(pName) {
180
181}
182
183void RailMoveObjBreakAtEnd::doAtEndPoint() {
184 RailMoveObj::doAtEndPoint();
185
186 if (MR::isRegisteredEffect(this, "Break")) {
187 MR::emitEffect(this, "Break");
188 }
189
190 kill();
191}
192
193void RailMoveIndirectObj::connectToScene(const MapObjActorInitInfo &rInfo) {
194 MR::connectToSceneIndirectMapObj(this);
195}
196
198 RailMoveObj::init(rIter);
199 MR::invalidateShadow(this, 0);
200}
201
202void RailMoveObjSwitchShadow::initCaseUseSwitchA(const MapObjActorInitInfo &rInfo) {
203 void (RailMoveObjSwitchShadow::*startFunc)(void) = &RailMoveObjSwitchShadow::startOnShadow;
204 MR::listenStageSwitchOnA(this, MR::Functor(this, startFunc));
205}
206
207void RailMoveObjSwitchShadow::startOnShadow() {
208 MR::validateShadow(this, 0);
209}
210
211RailDemoMoveObj::RailDemoMoveObj(const char *pName) : RailMoveObj(pName) {
212 mDemoControl = 0;
213}
214
216 RailMoveObj::init(rIter);
217 mDemoControl = new DemoCtrlBase(this, mObjectName);
218 mDemoControl->init(rIter);
219 makeActorAppeared();
220}
221
222bool RailDemoMoveObj::tryStartMove() {
223 if (!mDemoControl->tryStart()) {
224 return false;
225 }
226
227 setNerve(&NrvRailMoveObj::HostTypeMove::sInstance);
228 return true;
229}
230
231void RailDemoMoveObj::startMoveInner() {
232 const char* start_sound = MR::StageEffect::getStartSe(mObjectName);
233
234 if (start_sound) {
235 MR::startSound(this, start_sound, -1, -1);
236 }
237}
238
239void RailDemoMoveObj::move() {
240 mDemoControl->update();
241
242 if (MapObjActorUtil::isRailMoverWorking(this)) {
243 const char* moving_sound = MR::StageEffect::getMovingSe(mObjectName);
244
245 if (moving_sound) {
246 MR::startLevelSound(this, moving_sound, -1, -1, -1);
247 }
248 }
249}
250
251bool RailDemoMoveObj::endMove() {
252 MR::validateClipping(this);
253
254 if (!mDemoControl->isExistEndFrame()) {
255 mDemoControl->end();
256 }
257
258 const char* stop_sound = MR::StageEffect::getStopSe(mObjectName);
259 if (stop_sound) {
260 MR::startSound(this, stop_sound, -1, -1);
261 }
262
263 return mDemoControl->isDone();
264}
265
266RailRotateMoveObj::RailRotateMoveObj(const char *pName) : RailMoveObj(pName) {
267
268}
269
270void RailRotateMoveObj::setupInitInfo(const JMapInfoIter &rIter, MapObjActorInitInfo *pInfo) {
271 pInfo->setupRailRotator();
272}
273
274bool RailRotateMoveObj::receiveOtherMsg(u32 msg, HitSensor *a2, HitSensor *a3) {
275 if (msg == 0xCB) {
276 return tryStartRotateAtPoint();
277 }
278
279 if (msg == 0xCC) {
280 mRailMover->endRotateAtPoint();
281 return true;
282 }
283
284 if (msg == 0xCD) {
285 return tryStartRotateBetweenPoints();
286 }
287
288 return RailMoveObj::receiveOtherMsg(msg, a2, a3);
289}
290
291void RailRotateMoveObj::initCaseUseSwitchB(const MapObjActorInitInfo &rInfo) {
292 setNerve(&NrvRailMoveObj::HostTypeWait::sInstance);
293 void (RailRotateMoveObj::*pauseFunc)(void) = &MapObjActor::pauseMapPartsFunctions;
294 MR::listenStageSwitchOffB(this, MR::Functor(this, pauseFunc));
295}
296
297bool RailRotateMoveObj::tryStartRotateAtPoint() {
298 s32 cur_point = MR::getCurrentRailPointNo(this);
299 if (!mRailRotator->hasRotation(cur_point)) {
300 return false;
301 }
302
303 if (mRailRotator->hasRotationBetweenPoints(cur_point)) {
304 return false;
305 }
306
307 mRailRotator->rotateAtPoint(cur_point);
308 return true;
309}
310
311bool RailRotateMoveObj::tryStartRotateBetweenPoints() {
312 MapPartsRailRotator* rail_rotator = mRailRotator;
313 s32 cur_point = MR::getCurrentRailPointNo(this);
314
315 if (!rail_rotator->hasRotationBetweenPoints(cur_point)) {
316 return false;
317 }
318
319 f32 next_time = 0.0f;
320 mRailMover->calcTimeToNextRailPoint(&next_time);
321 MapPartsRailRotator* uhm = mRailRotator;
322 s32 new_point = MR::getCurrentRailPointNo(this);
323 uhm->rotateBetweenPoints(new_point, next_time);
324 return true;
325}
326
327namespace NrvRailMoveObj {
328 INIT_NERVE(HostTypeWait);
329 INIT_NERVE(HostTypeWaitForPlayerOn);
330 INIT_NERVE(HostTypeMove);
331 INIT_NERVE(HostTypeDone);
332
333 void HostTypeDone::execute(Spine *pSpine) const {
334 RailMoveObj* obj = reinterpret_cast<RailMoveObj*>(pSpine->mExecutor);
335 obj->exeWait();
336 }
337
338 void HostTypeMove::execute(Spine *pSpine) const {
339 RailMoveObj* obj = reinterpret_cast<RailMoveObj*>(pSpine->mExecutor);
340 obj->exeMove();
341 }
342
343 void HostTypeWaitForPlayerOn::execute(Spine *pSpine) const {
344 RailMoveObj* obj = reinterpret_cast<RailMoveObj*>(pSpine->mExecutor);
345 obj->exeWait();
346 }
347
348 void HostTypeWait::execute(Spine *pSpine) const {
349 RailMoveObj* obj = reinterpret_cast<RailMoveObj*>(pSpine->mExecutor);
350 obj->exeWait();
351 }
352};
353
354RailMoveObjPress::~RailMoveObjPress() {
355
356}
357
358RailMoveObjBreakAtEnd::~RailMoveObjBreakAtEnd() {
359
360}
361
362RailMoveIndirectObj::~RailMoveIndirectObj() {
363
364}
365
366RailMoveObjSwitchShadow::~RailMoveObjSwitchShadow() {
367
368}
369
370RailDemoMoveObj::~RailDemoMoveObj() {
371
372}
373
374RailRotateMoveObj::~RailRotateMoveObj() {
375
376}
virtual void init(const JMapInfoIter &)
Intializes the NameObj and can set various settings and construct necessary classes.
virtual void init(const JMapInfoIter &)
Intializes the NameObj and can set various settings and construct necessary classes.
virtual void init(const JMapInfoIter &)
Intializes the NameObj and can set various settings and construct necessary classes.
virtual void init(const JMapInfoIter &)
Intializes the NameObj and can set various settings and construct necessary classes.
virtual void init(const JMapInfoIter &)
Intializes the NameObj and can set various settings and construct necessary classes.
Definition Spine.hpp:9