SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
ChooChooTrain.cpp
1#include "Game/MapObj/ChooChooTrain.hpp"
2#include "Game/Util.hpp"
3#include "Game/Util/Array.hpp"
4
5ChooChooTrain::ChooChooTrain(const char *pName) : LiveActor(pName), mModelArray() {
6 _98.x = 0.0f;
7 _98.y = 0.0f;
8 _98.z = 0.0f;
9 mRailCoord = 5.0f;
10 mWhistleTimer = 0;
11}
12
13void ChooChooTrain::startClipped() {
14 LiveActor::startClipped();
15
16 for (s32 i = 0; i < mModelArray.mCount; i++) {
17 mModelArray.mArray.mArr[i]->startClipped();
18 }
19}
20
21void ChooChooTrain::endClipped() {
22 LiveActor::endClipped();
23
24 for (s32 i = 0; i < mModelArray.mCount; i++) {
25 mModelArray.mArray.mArr[i]->endClipped();
26 }
27}
28
30 if (MR::isValidInfo(rIter)) {
31 MR::isConnectedWithRail(rIter);
32 }
33
34 MR::initDefaultPos(this, rIter);
35 initRailRider(rIter);
36 initModelManagerWithAnm("ChooChooTrain", 0, false);
37 MR::connectToSceneCollisionMapObj(this);
38 initEffectKeeper(0, 0, false);
39 initSound(4, false);
40 mWhistleTimer = MR::getRandom((s32)0xB4, (s32)0x258);
41 MR::onCalcGravity(this);
42 MR::initShadowVolumeSphere(this, 80.0f * mScale.y);
43 initHitSensor(1);
44 MR::addMessageSensorMapObjMoveCollision(this, "body");
45 MR::initCollisionParts(this, "ChooChooTrain", getSensor("body"), 0);
46 MR::onCalcGravity(this);
47 s32 temp_var = -1;
48 s32 defTrainParts = 3;
49 MR::getJMapInfoArg0NoInit(rIter, &temp_var);
50
51 if (temp_var > 0) {
52 defTrainParts = temp_var;
53 }
54
55 temp_var = -1;
56 MR::getJMapInfoArg1NoInit(rIter, &temp_var);
57
58 if (temp_var > 0) {
59 mRailCoord = temp_var;
60 }
61
62 mModelArray.mArray.mArr = new ModelObj*[defTrainParts];
63 mModelArray.mArray.mMaxSize = defTrainParts;
64
65 s32 curIdx = 0;
66 while (curIdx < defTrainParts) {
67 ModelObj* obj = new ModelObj("汽車ポッポ客車", "ChooChooTrainBody", 0, -2, 0x1E, 2, false);
68 obj->initWithoutIter();
69 MR::initCollisionParts(obj, "ChooChooTrainBody", getSensor("body"), 0);
70 MR::invalidateClipping(obj);
71 s32 curCount = mModelArray.mCount;
72 mModelArray.mCount = curCount + 1;
73 mModelArray.mArray.mArr[curCount] = obj;
74 curIdx++;
75 }
76
77 makeActorAppeared();
78 MR::moveCoordToNearestPos(this, mPosition);
79 MR::moveTransToCurrentRailPos(this);
80 f32 railCoord = MR::getRailCoord(this);
81 MR::reverseRailDirection(this);
82
83 curIdx = 0;
84 while (curIdx < defTrainParts) {
85 MR::moveCoord(this, 1080.0f * mScale.y);
86 MR::moveTransToOtherActorRailPos(mModelArray.mArray.mArr[curIdx], this);
87 MR::onCalcGravity(mModelArray.mArray.mArr[curIdx]);
88 mModelArray.mArray.mArr[curIdx]->makeActorAppeared();
89 MR::startBck(mModelArray.mArray.mArr[curIdx], "Run", 0);
90 curIdx++;
91 }
92
93 MR::reverseRailDirection(this);
94 MR::setRailCoord(this, railCoord);
95 MR::initAndSetRailClipping(&_98, this, 100.0f, 500.0f);
96 MR::startBck(this, "Run", 0);
97}
98
99void ChooChooTrain::control() {
100 MR::moveCoord(this, mRailCoord);
101 MR::moveTransToCurrentRailPos(this);
102 TVec3f stack_74(MR::getRailDirection(this));
103 MR::turnDirectionAndGravityH(this, stack_74, 0.5f, 1.0f);
104 f32 railCoord = MR::getRailCoord(this);
105 TVec3f stack_68;
106 MR::calcFrontVec(&stack_68, this);
107 TVec3f stack_5C;
108 stack_5C = mPosition - ((stack_68 * 532.0f) * mScale.y);
109 MR::reverseRailDirection(this);
110
111 TVec3f* vec;
112 s32 curIdx = 0;
113
114 while (curIdx < mModelArray.mCount) {
115 MR::moveCoord(this, 1080.0f * mScale.y);
116 MR::moveTransToOtherActorRailPos(mModelArray.mArray.mArr[curIdx], this);
117 stack_74 = (stack_5C - mModelArray.mArray.mArr[curIdx]->mPosition);
118 MR::turnDirectionAndGravityH(mModelArray.mArray.mArr[curIdx], stack_74, 0.5f, 1.0f);
119 MR::calcFrontVec(&stack_68, mModelArray.mArray.mArr[curIdx]);
120
121 vec = &mModelArray.mArray.mArr[curIdx]->mPosition;
122 stack_5C = (*vec - ((stack_68 * 532.0f) * mScale.y));
123 curIdx++;
124 }
125
126 MR::reverseRailDirection(this);
127 MR::setRailCoord(this, railCoord);
128 MR::startLevelSound(this, "SE_OJ_LV_TOY_SL_MOVE", -1, -1, -1);
129
130 if (mWhistleTimer < 0) {
131 MR::startSound(this, "SE_OJ_TOY_SL_WHISTLE", -1, -1);
132 mWhistleTimer = MR::getRandom((s32)0xB4, (s32)0x258);
133 }
134 else {
135 mWhistleTimer--;
136 }
137}
virtual void init(const JMapInfoIter &)
Intializes the NameObj and can set various settings and construct necessary classes.
The basis of a drawable actor that can contain states (see: Nerve)
Definition LiveActor.hpp:24
TVec3f mPosition
3D vector of the actor's position.
Definition LiveActor.hpp:95
TVec3f mScale
3D vector of the actor's scale.
Definition LiveActor.hpp:97
HitSensor * getSensor(const char *pSensorName) const
Gets a sensor.
void initWithoutIter()
Initializes a NameObj without a JMapInfoIter instance.
Definition NameObj.cpp:41