SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
ItemBlock.cpp
1#include "Game/MapObj/ItemBlock.hpp"
2#include "Game/Util.hpp"
3#include "JSystem/JGeometry/TVec.hpp"
4
5namespace NrvItemBlock {
6 INIT_NERVE(ItemBlockNrvStandby);
7 INIT_NERVE(ItemBlockNrvWait);
8 INIT_NERVE(ItemBlockNrvAppearItem);
9 INIT_NERVE(ItemBlockNrvAppearItemSplash);
10
11 void ItemBlockNrvAppearItemSplash::execute(Spine *pSpine) const {
12 ItemBlock *block = reinterpret_cast<ItemBlock *>(pSpine->mExecutor);
13 block->exeAppearItemSplash();
14 }
15
16 void ItemBlockNrvAppearItem::execute(Spine *pSpine) const {
17 ItemBlock *block = reinterpret_cast<ItemBlock *>(pSpine->mExecutor);
18 block->exeAppearItem();
19 }
20
21 void ItemBlockNrvWait::execute(Spine *pSpine) const {
22 ItemBlock *block = reinterpret_cast<ItemBlock *>(pSpine->mExecutor);
23 block->exeWait();
24 }
25
26 void ItemBlockNrvStandby::execute(Spine *pSpine) const {
27 ItemBlock *block = reinterpret_cast<ItemBlock *>(pSpine->mExecutor);
28 if (MR::isFirstStep(block)) {
29 MR::startBck(block, "Wait", nullptr);
30 }
31 }
32};
33
34namespace {
35 static Color8 hPointLight(0xFF, 0xE6, 0, 0xFF);
36};
37
38ItemBlock::ItemBlock(const char *pName) : LiveActor(pName) {
39 mKind = 0;
40 mTimer = 0;
41 mItemCount = 8;
42 _98 = 0;
43 mCalcShadowOneTime = false;
44}
45
46void ItemBlock::init(const JMapInfoIter &rIter) {
47 MR::initDefaultPos(this, rIter);
48 checkKind(rIter);
49 initBlock();
50 MR::connectToSceneMapObjStrongLight(this);
51 MR::useStageSwitchSleep(this, rIter);
52 initEffectKeeper(1, "CoinBlock", false);
53 initSound(4, false);
54 initNerve(&NrvItemBlock::ItemBlockNrvStandby::sInstance);
55 s32 arg = -1;
56 MR::getJMapInfoArg4NoInit(rIter, &arg);
57 MR::initShadowVolumeBox(this, TVec3f(150.0f, 150.0f, 150.0f));
58 MR::setShadowVolumeStartDropOffset(this, 0, 77.0f);
59
60 if (arg != -1) {
61 MR::setShadowDropLength(this, nullptr, arg);
62 }
63
64 MR::onShadowVolumeCutDropLength(this, nullptr);
65 MR::excludeCalcShadowToMyCollision(this, nullptr);
66
67 if (mCalcShadowOneTime) {
68 MR::onCalcShadowOneTime(this, nullptr);
69 } else {
70 MR::onCalcShadow(this, nullptr);
71 }
72
73 if (MR::isZeroGravity(this)) {
74 TVec3f upVec;
75 MR::calcUpVec(&upVec, this);
76 MR::setShadowDropDirection(this, 0, -upVec);
77 } else {
78 MR::calcGravity(this);
79 }
80
81 MR::offCalcGravity(this);
82 MR::setGroupClipping(this, rIter, 16);
83 MR::validateClipping(this);
84
85 appear();
86}
87
88void ItemBlock::startClipped() {
89 LiveActor::startClipped();
90 MR::forceDeleteEffect(this, "Glow");
91}
92
93void ItemBlock::endClipped() {
94 LiveActor::endClipped();
95 MR::emitEffect(this, "Glow");
96}
97
98void ItemBlock::checkKind(const JMapInfoIter &rIter) {
99 const char *name = nullptr;
100 MR::getObjectName(&name, rIter);
101
102 if (MR::isEqualString(name, "ItemBlockSwitch")) {
103 MR::needStageSwitchWriteDead(this, rIter);
104 mKind = 5;
105 } else if (MR::isEqualString(name, "TimerCoinBlock")) {
106 mKind = 1;
107 MR::declareCoin(this, 10);
108 } else if (MR::isEqualString(name, "SplashCoinBlock")) {
109 mKind = 2;
110 MR::declareCoin(this, mItemCount);
111 } else if (MR::isEqualString(name, "TimerPieceBlock")) {
112 mKind = 3;
113 MR::declareStarPiece(this, 20);
114 } else if (MR::isEqualString(name, "SplashPieceBlock")) {
115 mKind = 4;
116 MR::declareStarPiece(this, mItemCount);
117 }
118
119 s32 arg = -1;
120
121 if (mKind == 2 || mKind == 4) {
122 arg = -1;
123 MR::getJMapInfoArg0NoInit(rIter, &arg);
124
125 if (arg >= 0) {
126 mItemCount = arg;
127 } else {
128 mItemCount = 8;
129 }
130 }
131
132 if (mKind == 1 || mKind == 3) {
133 MR::getJMapInfoArg1NoInit(rIter, &arg);
134
135 if (arg == -1) {
136 mTimer = 240;
137 } else {
138 mTimer = arg;
139 }
140 }
141
142 arg = -1;
143 MR::getJMapInfoArg2NoInit(rIter, &arg);
144 mCalcShadowOneTime = !(arg - 1);
145}
146
147/*void ItemBlock::initBlock() {
148 initHitSensor(1);
149
150 if (mKind >= 6 || mKind < 1) {
151 return;
152 }
153
154 initModelManagerWithAnm("CoinBlock", nullptr, false);
155 TVec3f *mtx = new TVec3f(0.0f, 100.0f, 0.0f);
156 MR::addHitSensorMtxMapObj(this, "body", 8, 100.0f, MR::getJointMtx(this, "CoinBlock"), *mtx);
157 MR::initCollisionPartsAutoEqualScale(this, "CoinBlock", getSensor("body"), (MtxPtr)mtx);
158}*/
159
160void ItemBlock::appear() {
161 LiveActor::appear();
162 initNerve(&NrvItemBlock::ItemBlockNrvStandby::sInstance);
163
164 if (mKind > 6 || mKind < 1) {
165 return;
166 }
167
168 MR::startBrk(this, "CoinBlock");
169}
170
171void ItemBlock::kill() {
172 MR::startSound(this, "SE_EM_EXPLODE_S", -1, -1);
173 MR::emitEffect(this, "Break");
174 LiveActor::kill();
175}
176
177/*void ItemBlock::control() {
178 TVec3f upVec;
179 MR::calcUpVec(&upVec, this);
180 MR::requestPointLight(this, TVec3f(upVec * 100.0f), hPointLight, 0.998646f, -1);
181}*/
182
183bool ItemBlock::receiveMsgPlayerAttack(u32 msg, HitSensor *a1, HitSensor *a2) {
184 if (MR::isMsgPlayerUpperPunch(msg) && MR::isPlayerExistDown(this, 0.0f, 0.25f) && tryStartJumpPunch()) {
185 MR::sendArbitraryMsg(64, a1, a2);
186 return true;
187 }
188
189 return false;
190}
191
192bool ItemBlock::tryStartJumpPunch() {
193 if (isNerve(&NrvItemBlock::ItemBlockNrvStandby::sInstance)) {
194 if (mKind == 1 || mKind == 3) {
195 MR::startBck(this, "Appear", nullptr);
196 calcAnim();
197 mNoCalcAnim = true;
198 setNerve(&NrvItemBlock::ItemBlockNrvAppearItem::sInstance);
199 } else if (mKind == 2 || (u32)(mKind - 4) <= 1) {
200 setNerve(&NrvItemBlock::ItemBlockNrvAppearItemSplash::sInstance);
201 }
202
203 return true;
204 }
205
206 if (isNerve(&NrvItemBlock::ItemBlockNrvWait::sInstance)) {
207 if (mKind == 1 || mKind == 3) {
208 if (mKind == 1) {
209 if (MR::getDeclareRemnantCoinCount(this) == 1) {
210 mTimer = 0;
211 }
212 } else {
213 if (!(MR::getDeclareRemnantStarPieceCountNotExist(this) - 11)) {
214 mTimer = 0;
215 }
216 }
217
218 MR::startBck(this, "Appear", nullptr);
219 calcAnim();
220 mNoCalcAnim = true;
221 setNerve(&NrvItemBlock::ItemBlockNrvAppearItem::sInstance);
222
223 return true;
224 }
225 }
226
227 return false;
228}
229
230void ItemBlock::exeWait() {
231 if (MR::isFirstStep(this)) {
232 MR::startBck(this, "Wait", nullptr);
233 MR::invalidateClipping(this);
234 }
235
236 decTimer();
237}
238
239/*void ItemBlock::exeAppearItem() {
240 if (MR::isFirstStep(this)) {
241 if (!mTimer) {
242 MR::forceDeleteEffect(this, "Glow");
243 MR::startBck(this, "Bomb", nullptr);
244 }
245
246 MR::invalidateClipping(this);
247 }
248
249 if (MR::isStep(this, 1)) {
250 TVec3f gravVec;
251 TVec3f position(mPosition);
252 MR::calcGravityVector(this, &gravVec, nullptr, 0);
253
254 position.subInline(mPosition, gravVec * 100.0f);
255
256 if (mKind == 2) {
257 MR::startSystemSE("SE_SY_ITEM_APPEAR", -1, -1);
258 }
259
260 if (mKind >= 1) {
261 MR::hopCoin(this, position, -gravVec);
262 }
263
264 if (mKind >= 4) {
265 } else {
266 if (mTimer || MR::getDeclareRemnantStarPieceCountNotExist(this) != 11) {
267 MR::appearStarPieceToDirection(this, position, -gravVec, 11, 10.0f, 40.0f, false);
268 } else {
269 MR::hopStarPiece(this, position, -gravVec);
270 }
271
272 MR::startSound(this, "SE_OJ_STAR_PIECE_BURST", -1, -1);
273 }
274 }
275
276 decTimer();
277
278 if (!MR::isBckStopped(this)) {
279 return;
280 }
281
282 if (mTimer) {
283 setNerve(&NrvItemBlock::ItemBlockNrvWait::sInstance);
284 } else {
285 kill();
286 }
287}*/
288
289void ItemBlock::exeAppearItemSplash() {
290 if (MR::isFirstStep(this)) {
291 MR::forceDeleteEffect(this, "Glow");
292 MR::startBck(this, "Bomb", nullptr);
293 }
294
295 if (!MR::isBckStopped(this)) {
296 return;
297 }
298
299 if (mKind == 2) {
300 if (mItemCount == 1) {
301 MR::appearCoinPop(this, mPosition, 1);
302 } else {
303 MR::appearCoinCircle(this, mPosition, mItemCount);
304 }
305 } else if (mKind == 4) {
306 MR::appearStarPiece(this, mPosition, mItemCount, 10.0f, 40.0f, false);
307 MR::startSound(this, "SE_OJ_STAR_PIECE_BURST", -1, -1);
308 } else if (mKind == 5) {
309 MR::onSwitchDead(this);
310 }
311
312 mTimer = 0;
313 kill();
314}
315
316void ItemBlock::decTimer() {
317 --mTimer;
318 if (mTimer > 0) {
319 return;
320 }
321 mTimer = 0;
322}
323
324void ItemBlock::calcAnim() {
325 if (!mNoCalcAnim) {
326 LiveActor::calcAnim();
327 }
328 mNoCalcAnim = false;
329}
330
331ItemBlock::~ItemBlock() {
332
333}
virtual void init(const JMapInfoIter &)
Intializes the NameObj and can set various settings and construct necessary classes.
Definition ItemBlock.cpp:46
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
Definition Spine.hpp:9