SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
CoinGroup.cpp
1#include "Game/MapObj/CoinGroup.hpp"
2#include "Game/Util.hpp"
3
4CoinGroup::CoinGroup(const char *pName) : LiveActor(pName) {
5 mCoinArray = nullptr;
6 mCameraInfo = nullptr;
7 mCoinCount = 0;
8 mTimeLimit = -1;
9 mIsPurpleCoinGroup = false;
10}
11
12void CoinGroup::init(const JMapInfoIter &rIter) {
13 s32 count = 0;
14 MR::getJMapInfoArg0NoInit(rIter, &count);
15 mCoinCount = count;
16 mTimeLimit = -1;
17 MR::getJMapInfoArg1NoInit(rIter, &mTimeLimit);
18 mCoinArray = new Coin*[mCoinCount];
19
20 for (u32 i = 0; i < mCoinCount; i++) {
21 if (mIsPurpleCoinGroup) {
22 mCoinArray[i] = reinterpret_cast<Coin*>(MR::createPurpleCoin(this, getCoinName()));
23 }
24 else {
25 mCoinArray[i] = reinterpret_cast<Coin*>(MR::createCoin(this, getCoinName()));
26 }
27
28 mCoinArray[i]->setShadowAndPoseModeFromJMapIter(rIter);
29
30 if (mCoinArray[i]->_BA) {
31 MR::initDefaultPos(mCoinArray[i], rIter);
32 }
33
34 Coin* coin = mCoinArray[i];
35
36 coin->mScale.x = 1.0f;
37 coin->mScale.y = 1.0f;
38 coin->mScale.z = 1.0f;
39 mCoinArray[i]->initWithoutIter();
40 }
41
42 initCoinArray(rIter);
43 placementCoin();
44
45 if (MR::tryRegisterDemoCast(this, rIter)) {
46 MR::FunctorV0M<CoinGroup *, void (CoinGroup::*)()> demoFunc = MR::Functor<CoinGroup>(this, &CoinGroup::appearCoinAll);
47 MR::registerDemoActionFunctor(this, demoFunc, "コイン出現");
48 }
49 else if (MR::useStageSwitchReadAppear(this, rIter)) {
50 MR::connectToSceneMapObjMovement(this);
51 MR::syncStageSwitchAppear(this);
52 MR::initActorCamera(this, rIter, &mCameraInfo);
53
54 if (MR::isExistActorCamera(mCameraInfo)) {
55 initNerve(&NrvCoinGroup::CoinGroupNrvDemoAppear::sInstance);
56 }
57 else {
58 initNerve(&NrvCoinGroup::CoinGroupNrvAppear::sInstance);
59 }
60 }
61 else {
62 appearCoinFix();
63 }
64
65 if (MR::useStageSwitchReadB(this, rIter)) {
66 MR::FunctorV0M<CoinGroup *, void (CoinGroup::*)()> killFunc = MR::Functor<CoinGroup>(this, &CoinGroup::killCoinAll);
67 MR::listenStageSwitchOnB(this, killFunc);
68 }
69
70 MR::invalidateClipping(this);
71 makeActorDead();
72}
73
74void CoinGroup::killCoinAll() {
75 for (u32 i = 0; i < mCoinCount; i++) {
76 mCoinArray[i]->kill();
77 }
78}
79
80void CoinGroup::appearCoinAll() {
81 if (mTimeLimit >= 0) {
82 appearCoinAllTimer();
83 }
84 else {
85 appearCoinFix();
86 }
87}
88
89void CoinGroup::appearCoinFix() {
90 for (u32 i = 0; i < mCoinCount; i++) {
91 mCoinArray[i]->appear();
92 }
93}
94
95void CoinGroup::appearCoinAllTimer() {
96 for (u32 i = 0; i < mCoinCount; i++) {
97 mCoinArray[i]->appearFixTimer(mTimeLimit, -1);
98 }
99}
100
101void CoinGroup::setCoinTrans(s32 coinIndex, const TVec3f &rPos) {
102 Coin* coin = mCoinArray[coinIndex];
103 coin->mPosition.x = rPos.x;
104 coin->mPosition.y = rPos.y;
105 coin->mPosition.z = rPos.z;
106}
107
108void CoinGroup::appear() {
109 LiveActor::appear();
110
111 if (isNerve(&NrvCoinGroup::CoinGroupNrvDemoAppear::sInstance)) {
112 MR::requestStartDemo(this, "出現", &NrvCoinGroup::CoinGroupNrvDemoAppear::sInstance, &NrvCoinGroup::CoinGroupNrvTryStartDemo::sInstance);
113 }
114}
115
116void CoinGroup::exeAppear() {
117 if (MR::isStep(this, 3)) {
118 if (mIsPurpleCoinGroup) {
119 MR::startSystemSE("SE_SY_PURPLE_COIN_APPEAR", -1, -1);
120 }
121 else {
122 MR::startSystemSE("SE_SY_COIN_APPEAR", -1, -1);
123 }
124
125 appearCoinAll();
126 setNerve(&NrvCoinGroup::CoinGroupNrvKill::sInstance);
127 kill();
128 }
129}
130
131void CoinGroup::exeDemoAppear() {
132 if (MR::isFirstStep(this)) {
133 MR::startActorCameraTargetSelf(this, mCameraInfo, 30);
134 MR::startSystemSE("SE_SY_COIN_APPEAR", -1, -1);
135 appearCoinAll();
136 }
137
138 if (MR::isGreaterStep(this, 90)) {
139 MR::endDemo(this, "出現");
140 MR::endActorCamera(this, mCameraInfo, false, -1);
141 setNerve(&NrvCoinGroup::CoinGroupNrvKill::sInstance);
142 kill();
143 }
144}
145
146namespace NrvCoinGroup {
147 INIT_NERVE(CoinGroupNrvAppear);
148 INIT_NERVE(CoinGroupNrvTryStartDemo);
149 INIT_NERVE(CoinGroupNrvDemoAppear);
150 INIT_NERVE(CoinGroupNrvKill);
151
152 void CoinGroupNrvKill::execute(Spine *pSpine) const {
153 CoinGroup* coin = reinterpret_cast<CoinGroup*>(pSpine->mExecutor);
154 coin->kill();
155 }
156
157 void CoinGroupNrvDemoAppear::execute(Spine *pSpine) const {
158 CoinGroup* coin = reinterpret_cast<CoinGroup*>(pSpine->mExecutor);
159 coin->exeDemoAppear();
160 }
161
162 void CoinGroupNrvTryStartDemo::execute(Spine *pSpine) const {
163
164 }
165
166 void CoinGroupNrvAppear::execute(Spine *pSpine) const {
167 CoinGroup* coin = reinterpret_cast<CoinGroup*>(pSpine->mExecutor);
168 coin->exeAppear();
169 }
170};
171
172const char* CoinGroup::getCoinName() const {
173 return "コイン(グループ配置)";
174}
175
176void CoinGroup::placementCoin() {
177
178}
virtual void init(const JMapInfoIter &)
Intializes the NameObj and can set various settings and construct necessary classes.
Definition CoinGroup.cpp:12
Definition Coin.hpp:23
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
void initWithoutIter()
Initializes a NameObj without a JMapInfoIter instance.
Definition NameObj.cpp:41
Definition Spine.hpp:9