SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
GeneralMapParts.cpp
1#include "Game/MapObj/GeneralMapParts.hpp"
2#include "Game/LiveActor/LiveActor.hpp"
3#include "Game/Util/BaseMatrixFollowTargetHolder.hpp"
4
5GeneralMapParts::GeneralMapParts(const char *pName) : MapParts(pName) {
6 mCameraInfo = nullptr;
7 mMoveConditionType = 0;
8 mSignMotionType = 0;
9 mShadowType = 0;
10 mFunctionArray.mCount = 0;
11 mAppearController = nullptr;
12 mRailRotator = nullptr;
13 mRailMover = nullptr;
14 mRotator = nullptr;
15 mGuideDrawer = nullptr;
16 mRailPosture = nullptr;
17 _E4 = 0;
18 _E5 = 0;
19}
20
22 MapParts::init(rIter);
23 MR::getMapPartsArgShadowType(&mShadowType, rIter);
24 MR::initMapPartsShadow(this, rIter);
25 MR::getMapPartsArgMoveConditionType(&mMoveConditionType, rIter);
26 MR::getMapPartsArgSignMotionType(&mSignMotionType, rIter);
27 initMapPartsFunction(rIter);
28 MR::initActorCamera(this, rIter, &mCameraInfo);
29 initNerve(&NrvGeneralMapParts::HostTypeWait::sInstance);
30 initSensorType(rIter);
31 initGravity(rIter);
32 MR::useStageSwitchWriteDead(this, rIter);
33
34 if (MR::useStageSwitchReadB(this, rIter)) {
35 void (GeneralMapParts::*switchOff)(void) = &GeneralMapParts::receiveMsgSwitchBOff;
36 void (GeneralMapParts::*switchOn)(void) = &GeneralMapParts::receiveMsgSwitchBOn;
37 MR::listenStageSwitchOnOffB(this, MR::Functor(this, switchOff), MR::Functor(this, switchOn));
38 }
39
40 if (MR::useStageSwitchReadAppear(this, rIter)) {
41 MR::syncStageSwitchAppear(this);
42 makeActorDead();
43 }
44 else {
45 appear();
46 }
47
48 MR::useStageSwitchSleep(this, rIter);
49}
50
51void GeneralMapParts::initAfterPlacement() {
52 if (isFixed()) {
53 if (!MR::isExistAnim(this, MR::getModelResName(this)) && !MR::isExistEffectTexMtx(this)) {
54 MR::offCalcAnim(this);
55 }
56
57 if (MR::hasMapPartsShadow(mShadowType)) {
58 MR::onCalcShadowOneTime(this, nullptr);
59 }
60 }
61}
62
63void GeneralMapParts::appear() {
64 MapParts::appear();
65
66 if (mGuideDrawer) {
67 mGuideDrawer->start();
68 }
69
70 if (MR::isValidSwitchB(this)) {
71 setNerve(&NrvGeneralMapParts::HostTypeWait::sInstance);
72 }
73 else if (!MR::isMoveStartTypeUnconditional(mMoveConditionType)) {
74 setNerve(&NrvGeneralMapParts::HostTypeWaitForPlayerOn::sInstance);
75 }
76 else {
77 startMove();
78 }
79}
80
81// GeneralMapParts::kill
82
83bool GeneralMapParts::receiveOtherMsg(u32 msg, HitSensor *a2, HitSensor *a3) {
84 if (mAppearController->receiveMsg(msg)) {
85 return true;
86 }
87
88 if (msg == 207) {
89 broadcastMsgToAllFunctions(207);
90 return true;
91 }
92
93 return MR::receiveMapPartsRotateMsg(this, msg, mRailMover, mRailRotator);
94}
95
96void GeneralMapParts::control() {
97 if (!_E5) {
98 if (mAppearController) {
99 mAppearController->movement();
100 }
101
102 if (mRailMover) {
103 mRailMover->movement();
104 if (MR::isValidSwitchDead(this) && mRailMover->isReachedEnd()) {
105 MR::onSwitchDead(this);
106 }
107 }
108
109 if (mRailPosture) {
110 mRailPosture->movement();
111 }
112
113 if (mRotator) {
114 mRotator->movement();
115 }
116
117 if (mRailRotator) {
118 mRailRotator->movement();
119 }
120
121 if (mGuideDrawer) {
122 mGuideDrawer->movement();
123 }
124
125 bool v9 = false;
126 if (mRailMover && mRailMover->isWorking()) {
127 v9 = true;
128 }
129
130 if (v9) {
131 mPosition.setInline(mRailMover->_28);
132 }
133 }
134}
135
137 bool v3 = false;
138 if (mRotator && mRotator->isWorking()) {
139 v3 = true;
140 }
141
142 bool v5 = false;
143 if (mRailRotator && mRailRotator->isWorking()) {
144 v5 = true;
145 }
146
147 bool v7 = false;
148 if (mRailPosture && mRailPosture->isWorking()) {
149 v7 = true;
150 }
151
152 if (!(v5 || v3 || v7)) {
154 }
155 else {
156 TPos3f mtx;
157 mtx.identity();
158
159 if (v7) {
160 mtx.concat(mRailPosture->_18);
161 }
162
163 if (v5) {
164 mtx.concat(mRailRotator->_5C);
165 }
166
167 if (v3) {
168 mtx.concat(mRotator->getRotateMtx());
169 }
170
171 mtx.mMtx[0][3] = mPosition.x;
172 mtx.mMtx[1][3] = mPosition.y;
173 mtx.mMtx[2][3] = mPosition.z;
174 MR::setBaseTRMtx(this, mtx);
175 }
176}
177
178void GeneralMapParts::initMapPartsFunction(const JMapInfoIter &rIter) {
179 mAppearController = new MapPartsAppearController(this);
180 mAppearController->init(rIter);
181 mFunctionArray.push_back(mAppearController);
182 f32 rotate_speed = 0.0f;
183 MR::getMapPartsArgRotateSpeed(&rotate_speed, rIter);
184 bool hasRotateSpeed = 0.0f != rotate_speed;
185
186 if (hasRotateSpeed) {
187 mRotator = new MapPartsRotator(this);
188 mRotator->init(rIter);
189 mFunctionArray.push_back(mRotator);
190 }
191
192 if (MR::isConnectedWithRail(rIter)) {
193 mRailMover = new MapPartsRailMover(this);
194 mRailMover->init(rIter);
195 mFunctionArray.push_back(mRailMover);
196 mRailRotator = new MapPartsRailRotator(this);
197 mRailRotator->init(rIter);
198 mFunctionArray.push_back(mRailRotator);
199 mGuideDrawer = MR::createMapPartsRailGuideDrawer(this, "RailPoint", rIter);
200 mFunctionArray.push_back(mGuideDrawer);
201 mRailPosture = new MapPartsRailPosture(this);
202 mRailPosture->init(rIter);
203 mFunctionArray.push_back(mRailPosture);
204 }
205}
206
207void GeneralMapParts::initSensorType(const JMapInfoIter &rIter) {
208 if (MR::isMapPartsPressOn(rIter)) {
209 MR::setBodySensorTypePress(this);
210 }
211 else if (!isFixed()) {
212 MR::setBodySensorTypeMoveCollision(this);
213 }
214 else {
215 MR::setBodySensorTypeMapObj(this);
216 }
217}
218
219void GeneralMapParts::initGravity(const JMapInfoIter &rIter) {
220 MR::addBaseMatrixFollowTarget(this, rIter, nullptr, nullptr);
221
222 if (!MR::isMapPartsShadowTypeNone(mShadowType)) {
223 if (isFixed()) {
224 MR::calcGravity(this);
225 }
226 else {
227 MR::onCalcGravity(this);
228 }
229 }
230}
231
232/*
233void GeneralMapParts::receiveMsgSwitchBOn() {
234 if (!MR::isValidSwitchB(this)) {
235 return;
236 }
237
238 if (!isNerve(&NrvGeneralMapParts::HostTypeWait::sInstance)) {
239 _E5 = 0;
240 }
241
242 if (MR::isExistActorCamera(mCameraInfo) && !_E4) {
243 MR::startActorCameraNoTarget(this, mCameraInfo, -1);
244 }
245
246 if (MR::getGroupFromArray(this)) {
247 MR::invalidateClipping(this);
248 bool flag = false;
249 if (isNerve(&NrvGeneralMapParts::HostTypeWait::sInstance) || isNerve(&NrvGeneralMapParts::HostTypeWaitForPlayerOn::sInstance)) {
250 flag = true;
251 }
252 }
253}
254*/
255
256void GeneralMapParts::receiveMsgSwitchBOff() {
257 if (MR::isValidSwitchB(this)) {
258 _E5 = 1;
259 }
260}
261
262// GeneralMapParts::broadcastMsgToAllFunctions
263
264bool GeneralMapParts::isFixed() const {
265 if (!mRailMover && !mRotator) {
266 return true;
267 }
268
269 return false;
270}
271
272void GeneralMapParts::startMove() {
273 if (!MR::hasMapPartsMoveStartSignMotion(mSignMotionType)) {
274 setNerve(&NrvGeneralMapParts::HostTypeMoveStart::sInstance);
275 }
276 else {
277 if (mRailPosture) {
278 mRailPosture->start();
279 }
280
281 if (mRotator) {
282 mRotator->start();
283 }
284
285 if (mRailMover) {
286 mRailMover->start();
287 }
288
289 if (mRailRotator) {
290 mRailRotator->start();
291 }
292
293 setNerve(&NrvGeneralMapParts::HostTypeMove::sInstance);
294 }
295}
296
297void GeneralMapParts::exeWait() {
298 if (isNerve(&NrvGeneralMapParts::HostTypeMove::sInstance) && MR::isExistActorCamera(mCameraInfo) && !_E4) {
299 if (MR::isStep(this, MR::getActorCameraFrames(this, mCameraInfo))) {
300 MR::endActorCamera(this, mCameraInfo, false, -1);
301 _E4 = 1;
302 }
303 }
304}
305
306void GeneralMapParts::exeMoveStart() {
307 if (MR::isFirstStep(this)) {
308 if (mRotator) {
309 mRotator->startWithSignalMotion();
310 }
311
312 if (mRailMover) {
313 mRailMover->startWithSignalMotion();
314 }
315 }
316
317 if (MR::isMapPartsSignMotionTypeMoveWait(mSignMotionType) && MR::isOnPlayer(MR::getBodySensor(this))) {
318 if (mRotator) {
319 mRotator->cancelSignalMotion();
320 }
321
322 if (mRailMover) {
323 mRailMover->cancelSignalMotion();
324 }
325
326 setNerve(&NrvGeneralMapParts::HostTypeWaitForPlayerOn::sInstance);
327 }
328 else {
329 if (MR::isStep(this, MapParts::getMoveStartSignalTime())) {
330 if (mRailMover) {
331 mRailMover->start();
332 }
333
334 if (mRailRotator) {
335 mRailRotator->start();
336 }
337
338 setNerve(&NrvGeneralMapParts::HostTypeMove::sInstance);
339 }
340 }
341}
342
343namespace NrvGeneralMapParts {
344 INIT_NERVE(HostTypeWait);
345 INIT_NERVE(HostTypeWaitForPlayerOn);
346 INIT_NERVE(HostTypeMoveStart);
347 INIT_NERVE(HostTypeMove);
348
349 void HostTypeMove::execute(Spine *pSpine) const {
350 GeneralMapParts* part = reinterpret_cast<GeneralMapParts*>(pSpine->mExecutor);
351 part->exeWait();
352 }
353
354 void HostTypeMoveStart::execute(Spine *pSpine) const {
355 GeneralMapParts* part = reinterpret_cast<GeneralMapParts*>(pSpine->mExecutor);
356 part->exeMoveStart();
357 }
358
359 void HostTypeWaitForPlayerOn::execute(Spine *pSpine) const {
360 GeneralMapParts* part = reinterpret_cast<GeneralMapParts*>(pSpine->mExecutor);
361 if (MR::isOnPlayer(MR::getBodySensor(part))) {
362 part->broadcastMsgToAllFunctions(0xCA);
363 part->startMove();
364 }
365 }
366
367 void HostTypeWait::execute(Spine *pSpine) const {
368 GeneralMapParts* part = reinterpret_cast<GeneralMapParts*>(pSpine->mExecutor);
369 part->exeWait();
370 }
371};
372
virtual void calcAndSetBaseMtx()
Calculates and sets the base matrix of the actor.
virtual void init(const JMapInfoIter &)
Intializes the NameObj and can set various settings and construct necessary classes.
TVec3f mPosition
3D vector of the actor's position.
Definition LiveActor.hpp:95
virtual void calcAndSetBaseMtx()
Calculates and sets the base matrix of the actor.
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 MapParts.cpp:13
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