SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
AssemblyBlock.cpp
1#include "Game/MapObj/AssemblyBlock.hpp"
2#include "Game/LiveActor/PartsModel.hpp"
3#include "JSystem/JMath/JMath.hpp"
4
5namespace {
6 static const char* sReturnPosName = "合体ブロック故郷点";
7};
8
9AssemblyBlock::AssemblyBlock(const char *pName) : LiveActor(pName) {
10 _11C = -1;
11 mActivationRange = -1.0f;
12 _124.x = 0.0f;
13 _124.y = 0.0f;
14 _124.z = 0.0f;
15 _130 = 0.0f;
16 mActivationTime = 300;
17 mBloomModel = nullptr;
18 _13C = false;
19 _8C.identity();
20 _BC.identity();
21 _EC.identity();
22}
23
25 TVec3f stack_3C;
26 TVec3f stack_30;
27 TVec3f stack_24;
28 TVec3f stack_18;
29 char name[0x100];
30
31 MR::initDefaultPos(this, rIter);
32 MR::tryRegisterNamePosLinkObj(this, rIter);
33
34 if (!MR::tryFindLinkNamePos(this, sReturnPosName, _EC.toMtxPtr())) {
35 stack_18.x = 0.0f;
36 stack_18.y = 1000.0f;
37 stack_18.z = 1000.0f;
38 stack_3C.add(mPosition, stack_18);
39 _EC.setTrans(stack_3C);
40 }
41
42 MR::getMapPartsObjectNameIfExistShapeID(name, 0x100, rIter);
43 initModelManagerWithAnm(name, nullptr, false);
44
45 if (MR::isEqualString(name, "AssemblyBlockPartsTimerA")) {
46 _13C = true;
47 }
48 else {
49 _13C = false;
50 }
51
52 JMath::gekko_ps_copy12(&_BC, getBaseMtx());
53 JMath::gekko_ps_copy12(&_8C, &_EC);
54 MR::setBaseTRMtx(this, _8C);
55
56 if (MR::isEqualSubString(name, "PartsIce")) {
57 MR::connectToSceneIndirectMapObj(this);
58 }
59 else {
60 MR::connectToSceneMapObj(this);
61 }
62
63 initHitSensor(1);
64 MR::addBodyMessageSensorMapObj(this);
65 MR::initCollisionPartsAutoEqualScaleOne(this, name, getSensor(nullptr), nullptr);
66
67 _BC.getTrans(stack_30);
68 _EC.getTrans(stack_24);
69 _124.add(stack_30, stack_24);
70 _124.x *= 0.5f;
71 _124.y *= 0.5f;
72 _124.z *= 0.5f;
73 f32 boundRadius;
74 MR::calcModelBoundingRadius(&boundRadius, this);
75 f32 dist = PSVECDistance(_124.toCVec(), stack_24.toCVec());
76 MR::setClippingTypeSphere(this, (boundRadius + dist), &_124);
77 MR::getJMapInfoArg0NoInit(rIter, &mActivationRange);
78 if (mActivationRange <= 0.0f) {
79 mActivationRange = 2.0f * boundRadius;
80 }
81
82 MR::getJMapInfoArg1NoInit(rIter, &mActivationTime);
83 MR::getJMapInfoArg7NoInit(rIter, &_11C);
84 if (MR::getRandom((s32)0, (s32)2)) {
85 _130 = 0.0f;
86 }
87 else {
88 _130 = -0.1f;
89 }
90
91 if (_11C == -1) {
92 initEffectKeeper(0, "AssemblyBlock", false);
93 }
94 else {
95 initEffectKeeper(0, nullptr, false);
96 }
97
98 initSound(4, false);
99 TVec3f stack_C;
100 stack_C.x = 0.0f;
101 stack_C.y = 0.0f;
102 stack_C.z = 0.0f;
103 MR::initStarPointerTarget(this, 0.0f, stack_C);
104
105 if (MR::isEqualString(name, "AssemblyBlockPartsTimerA")) {
106 mBloomModel = MR::createBloomModel(this, getBaseMtx());
107 }
108
109 MR::tryStartAllAnim(this, "Wait");
110 initNerve(&NrvAssemblyBlock::AssemblyBlockNrvWait::sInstance);
111 makeActorAppeared();
112}
113
114// AssemblyBlock::exeWait
115
116void AssemblyBlock::exeAssemble() {
117 if (MR::isFirstStep(this)) {
118 MR::emitEffect(this, "Blur");
119
120 if (_13C) {
121 MR::startSound(this, "SE_OJ_ASSEMBLE_BLOCK_ST_F_", -1, -1);
122 }
123 else {
124 MR::startSound(this, "SE_OJ_ASSEMBLE_BLOCK_START", -1, -1);
125 }
126
127 MR::invalidateCollisionParts(this);
128 MR::invalidateHitSensors(this);
129 }
130
131 MR::blendMtx(_BC.toMtxPtr(), _EC.toMtxPtr(), MR::calcNerveRate(this, 10), _8C.toMtxPtr());
132
133 if (MR::isStep(this, 10)) {
134 if (_13C) {
135 MR::startSound(this, "SE_OJ_ASSEMBLE_BLOCK_ED_F", -1, -1);
136 }
137 else {
138 MR::startSound(this, "SE_OJ_ASSEMBLE_BLOCK_END", -1, -1);
139 }
140
141 setNerve(&NrvAssemblyBlock::AssemblyBlockNrvWait::sInstance);
142 }
143}
144
145void AssemblyBlock::exeAssembleWait() {
146 if (MR::isFirstStep(this)) {
147 if (MR::isEffectValid(this, "Blur")) {
148 MR::deleteEffect(this, "Blur");
149 }
150
151 MR::tryRumblePadWeak(this, 0);
152 MR::validateCollisionParts(this);
153 MR::validateHitSensors(this);
154 }
155
156 if (!_11C) {
157 setNerve(&NrvAssemblyBlock::AssemblyBlockNrvTimer::sInstance);
158 }
159 else {
160 tryStartReturn();
161 }
162}
163
164void AssemblyBlock::exeReturn() {
165 if (MR::isFirstStep(this)) {
166 MR::tryRumblePadWeak(this, 0);
167 MR::emitEffect(this, "Blur");
168
169 if (_13C) {
170 MR::startSound(this, "SE_OJ_ASSEMBLE_BLOCK_RET_F", -1, -1);
171 }
172 else {
173 MR::startSound(this, "SE_OJ_ASSEMBLE_BLOCK_RETURN", -1, -1);
174 }
175
176 MR::invalidateCollisionParts(this);
177 MR::invalidateHitSensors(this);
178 }
179
180 MR::blendMtx(_BC.toMtxPtr(), _EC.toMtxPtr(), MR::calcNerveRate(this, 10), _8C.toMtxPtr());
181
182 if (MR::isStep(this, 10)) {
183 setNerve(&NrvAssemblyBlock::AssemblyBlockNrvWait::sInstance);
184 }
185}
186
187void AssemblyBlock::exeTimer() {
188 if (MR::isStep(this, mActivationTime - 100)) {
189 MR::tryStartAllAnim(this, "Disappear");
190 }
191
192 if (MR::isStep(this, mActivationTime)) {
193 if (_13C) {
194 MR::startSound(this, "SE_OJ_ASSEMBLE_BLOCK_VAN_F", -1, -1);
195 }
196 else {
197 MR::startSound(this, "SE_OJ_ASSEMBLE_BLOCK_VANISH", -1, -1);
198 }
199
200 if (mBloomModel) {
201 mBloomModel->kill();
202 }
203
204 kill();
205 }
206}
207
209 MR::setBaseTRMtx(this, _8C);
210}
211
212bool AssemblyBlock::tryStartAssemble() {
213 bool isNotNear = !MR::isNearPlayerAnyTime(this, mActivationRange);
214
215 if (isNotNear) {
216 return false;
217 }
218
219 if (MR::isPlayerDead()) {
220 return false;
221 }
222
223 setNerve(&NrvAssemblyBlock::AssemblyBlockNrvAssemble::sInstance);
224 return true;
225}
226
227bool AssemblyBlock::tryStartReturn() {
228 if (MR::isStarPointerPointing2POnPressButton(this, "弱", true, false)) {
229 return false;
230 }
231
232 if (MR::isNearPlayerAnyTime(this, (mActivationRange + 50.0f))) {
233 return false;
234 }
235
236 if (MR::isPlayerDead()) {
237 return false;
238 }
239
240 setNerve(&NrvAssemblyBlock::AssemblyBlockNrvReturn::sInstance);
241 return true;
242}
243
244AssemblyBlock::~AssemblyBlock() {
245
246}
247
248namespace NrvAssemblyBlock {
249 INIT_NERVE(AssemblyBlockNrvWait);
250 INIT_NERVE(AssemblyBlockNrvAssemble);
251 INIT_NERVE(AssemblyBlockNrvAssembleWait);
252 INIT_NERVE(AssemblyBlockNrvReturn);
253 INIT_NERVE(AssemblyBlockNrvTimer);
254};
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.
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
virtual MtxPtr getBaseMtx() const
Gets the base matrix of the model used for the actor.
HitSensor * getSensor(const char *pSensorName) const
Gets a sensor.