SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
SwitchBox.cpp
1#include "Game/MapObj/SwitchBox.hpp"
2#include "Game/Util.hpp"
3#include "JSystem/JGeometry/TVec.hpp"
4
5SwitchBox::SwitchBox(const char *pName) : LiveActor(pName) {
6
7}
8
9void SwitchBox::init(const JMapInfoIter &rIter) {
10 MR::initDefaultPos(this, rIter);
11 initModelManagerWithAnm("SwitchBox", nullptr, false);
12 MR::connectToSceneMapObjNoCalcAnim(this);
13 initSound(2, false);
14 initNerve(&NrvSwitchBox::SwitchBoxNrvWait::sInstance);
15 initEffectKeeper(3, nullptr, false);
16 f32 newScale = mScale.x * 90.0f;
17 initHitSensor(2);
18 TVec3f sensorOffset;
19 sensorOffset.setInline(0.0f, newScale, 0.0f);
20 MR::addHitSensorMapObj(this, "body", 8, newScale, sensorOffset);
21
22 s32 local_38 = 1;
23
24 if (MR::checkJMapDataEntries(rIter)) {
25 MR::getJMapInfoArg1NoInit(rIter, &local_38);
26 }
27
28 setNerve(&NrvSwitchBox::SwitchBoxNrvWait::sInstance);
29 MR::initCollisionParts(this, "SwitchBox", getSensor("body"), nullptr);
30 MR::validateClipping(this);
31
32 _92 = 0;
33
34 if (local_38) {
35 _92 = 1;
36 }
37
38 if (_92) {
39 MR::initShadowVolumeBox(this, TVec3f(150.0f, 150.0f, 150.0f));
40 MR::setShadowVolumeStartDropOffset(this, nullptr, 77.0f);
41 MR::setShadowVolumeEndDropOffset(this, nullptr, 150.0f);
42 MR::excludeCalcShadowToMyCollision(this, nullptr);
43 MR::onShadowVolumeCutDropLength(this, nullptr);
44 MR::onCalcGravity(this);
45 MR::onCalcShadowOneTime(this, nullptr);
46 }
47
48 MR::addToAttributeGroupSearchTurtle(this);
49
50 if (MR::useStageSwitchReadAppear(this, rIter)) {
51 MR::syncStageSwitchAppear(this);
52 }
53
54 MR::needStageSwitchWriteDead(this, rIter);
55 appear();
56}
57
58void SwitchBox::initAfterPlacement() {
59
60}
61
62void SwitchBox::exeWait() {
63 if (_8c != 0) {
64 --_8c;
65 }
66
67 if (_8e != 0) {
68 --_8e;
69 if (_8e == 0) {
70 _90 = 1;
71 }
72 }
73
74 if (_90 == 0) {
75 setNerve(&NrvSwitchBox::SwitchBoxNrvHit::sInstance);
76 }
77}
78
79void SwitchBox::exeHit() {
80 if (getNerveStep() == 0) {
81 getSensor("body")->invalidate();
82 }
83
84 if (getNerveStep() == 5) {
85 MR::hideModel(this);
86 }
87
88 if (getNerveStep() == 15) {
89 kill();
90 }
91}
92
93void SwitchBox::appear() {
94 MR::offSwitchDead(this);
95
96 _90 = 1;
97 _8e = 0;
98 _8c = 0;
99
100 LiveActor::appear();
101 MR::showModel(this);
102 setNerve(&NrvSwitchBox::SwitchBoxNrvWait::sInstance);
103}
104
105void SwitchBox::kill() {
106 MR::onSwitchDead(this);
107 LiveActor::kill();
108}
109
110void SwitchBox::doHit(HitSensor *pSender, HitSensor *pReceiver) {
111 if (_90 != 0) {
112 --_90;
113 }
114
115 if (_90 == 0) {
116 MR::invalidateCollisionParts(this);
117 }
118
119 _8e = 30;
120
121 if (MR::isInWater(this, TVec3f(0.0f, 0.0f, 0.0f))) {
122 MR::startSound(this, "SE_OJ_S_BLOCK_BREAK_W", -1, -1);
123 MR::emitEffect(this, "BreakWater");
124 } else {
125 MR::startSound(this, "SE_OJ_S_BLOCK_BREAK", -1, -1);
126 MR::emitEffect(this, "Break");
127 }
128}
129
130bool SwitchBox::receiveMsgPlayerAttack(u32 msg, HitSensor *pSender, HitSensor *pReceiver) {
131 if (MR::isMsgPlayerUpperPunch(msg) && _90 != 0) {
132 doHit(pSender, pReceiver);
133 pSender->receiveMessage(0x40, pReceiver);
134 return true;
135 }
136
137 if (MR::isMsgPlayerHitAll(msg) && _90 != 0) {
138 doHit(pSender, pReceiver);
139 return true;
140 }
141
142 if (MR::isMsgPlayerHipDrop(msg) || MR::isMsgPlayerHipDropFloor(msg)) {
143 if (_8c != 0) {
144 doHit(pSender, pReceiver);
145 return true;
146 }
147
148 return true;
149 }
150
151 return false;
152}
153
154bool SwitchBox::receiveMsgEnemyAttack(u32 msg, HitSensor *pSender, HitSensor *pReceiver) {
155 if (_90 != 0) {
156 doHit(pSender, pReceiver);
157 return true;
158 }
159
160 return false;
161}
162
163bool SwitchBox::receiveOtherMsg(u32 msg, HitSensor *pSender, HitSensor *pReceiver) {
164 if (msg == 0x1b) {
165 return _90;
166 }
167
168 if (msg == 0x41) {
169 return !_90;
170 }
171
172 if (MR::isMsgFloorTouch(msg)) {
173 _8c = 2;
174 }
175
176 return false;
177}
178
179namespace NrvSwitchBox {
180 INIT_NERVE(SwitchBoxNrvWait);
181 INIT_NERVE(SwitchBoxNrvHit);
182
183 void SwitchBoxNrvHit::execute(Spine *pSpine) const {
184 SwitchBox *pActor = reinterpret_cast<SwitchBox *>(pSpine->mExecutor);
185 pActor->exeHit();
186 }
187
188 void SwitchBoxNrvWait::execute(Spine *pSpine) const {
189 SwitchBox *pActor = reinterpret_cast<SwitchBox *>(pSpine->mExecutor);
190 pActor->exeWait();
191 }
192};
The basis of a drawable actor that can contain states (see: Nerve)
Definition LiveActor.hpp:24
TVec3f mScale
3D vector of the actor's scale.
Definition LiveActor.hpp:97
HitSensor * getSensor(const char *pSensorName) const
Gets a sensor.
Definition Spine.hpp:9
virtual void init(const JMapInfoIter &rIter)
Intializes the NameObj and can set various settings and construct necessary classes.
Definition SwitchBox.cpp:9