SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
ChipBase.cpp
1#include "Game/MapObj/ChipBase.hpp"
2#include "Game/MapObj/ChipHolder.hpp"
3
4ChipBase::ChipBase(const char *pName, s32 chipType, const char *pChipName) : LiveActor(pName) {
5 mFlashingCtrl = 0;
6 mRailMover = 0;
7 mAirBubble = 0;
8 mChipName = pChipName;
9 mHost = 0;
10 mClippingRange.x = 0.0f;
11 mClippingRange.y = 0.0f;
12 mClippingRange.z = 0.0f;
13 mGroupID = -1;
14 mChipType = chipType;
15 _B5 = false;
16}
17
18void ChipBase::init(const JMapInfoIter &rIter) {
19 MR::createChipHolder(mChipType);
20 initJMapParam(rIter);
21 initModel(rIter);
22 initSensor();
23 initShadow(rIter);
24 initEffectKeeper(0, 0, false);
25 initSound(4, false);
26 initNerve(&NrvChipBase::ChipBaseNrvWait::sInstance);
27
28 if (MR::isValidInfo(rIter)) {
29 MR::setGroupClipping(this, rIter, 0x20);
30 }
31
32 mFlashingCtrl = new FlashingCtrl(this, true);
33 bool uses = MR::useStageSwitchReadAppear(this, rIter);
34 if (uses) {
35 MR::syncStageSwitchAppear(this);
36 makeActorDead();
37 }
38 else {
39 makeActorAppeared();
40 }
41}
42
43void ChipBase::initModel(const JMapInfoIter &rIter) {
44 mScale.scaleInline(1.0f);
45 initModelManagerWithAnm(mChipName, 0, false);
46 MR::connectToSceneNoSilhouettedMapObjStrongLight(this);
47
48 if (ChipBase::isNeedBubble(rIter)) {
49 mAirBubble = MR::createPartsModelNoSilhouettedMapObj(this, "アワ", "AirBubble", 0);
50 mAirBubble->initFixedPosition(TVec3f(0.0f, 0.0f, 0.0f), TVec3f(0.0f, 0.0f, 0.0f), 0);
51 MR::startBck(mAirBubble, "Move", 0);
52 }
53}
54
55void ChipBase::initSensor() {
56 f32 radius;
57 f32 scale_x = mScale.x;
58 initHitSensor(1);
59
60 if (mAirBubble) {
61 radius = 150.0f;
62 }
63 else {
64 radius = 80.0f;
65 }
66
67 TVec3f sensor(0.0f, 0.0f, 0.0f);
68 MR::addHitSensorEnemy(this, "body", 8, radius * scale_x, sensor);
69}
70
71#ifdef NON_MATCHING
72void ChipBase::initShadow(const JMapInfoIter &rIter) {
73 if (MR::isValidInfo(rIter)) {
74 MR::getJMapInfoArg2WithInit(rIter, &_B5);
75 }
76 else {
77 _B5 = false;
78 }
79
80 s32 shadowShape = -1;
81 if (MR::isValidInfo(rIter)) {
82 MR::getJMapInfoArg5NoInit(rIter, &shadowShape);
83 }
84
85 if (shadowShape == 0) {
86 MR::initShadowVolumeCylinder(this, 50.0f * mScale.x);
87 _B5 = false;
88 }
89 else {
90 MR::initShadowVolumeSphere(this, 50.0f * mScale.x);
91 }
92
93 f32 dropLength = 2000.0f;
94 if (MR::isValidInfo(rIter)) {
95 MR::getJMapInfoArg4NoInit(rIter, &dropLength);
96 }
97 MR::setShadowDropLength(this, 0, dropLength);
98
99 if (mRailMover || _B5) {
100 MR::onCalcShadowDropPrivateGravity(this, 0);
101 }
102 else {
103 MR::onCalcShadowOneTime(this, 0);
104 MR::onCalcShadowDropPrivateGravityOneTime(this, 0);
105 }
106}
107#endif
108
109void ChipBase::initJMapParam(const JMapInfoIter &rIter) {
110 if (MR::isValidInfo(rIter)) {
111 MR::initDefaultPos(this, rIter);
112 MR::getJMapInfoArg0NoInit(rIter, &mGroupID);
113
114 if (MR::isConnectedWithRail(rIter)) {
115 initRailRider(rIter);
116 mRailMover = new MapPartsRailMover(this);
117 mRailMover->init(rIter);
118 }
119 }
120}
121
122void ChipBase::initAfterPlacement() {
123 MR::registerChip(mChipType, this, mGroupID);
124 MR::setClippingRangeIncludeShadow(this, &mClippingRange, 100.0f);
125}
126
127void ChipBase::deactive() {
128 makeActorDead();
129 setNerve(&NrvChipBase::ChipBaseNrvDeactive::sInstance);
130}
131
132void ChipBase::setGroupID(s32 id) {
133 mGroupID = id;
134}
135
136void ChipBase::setHost(LiveActor *pActor) {
137 mHost = pActor;
138}
139
140void ChipBase::makeActorAppeared() {
141 if (!isNerve(&NrvChipBase::ChipBaseNrvDeactive::sInstance)) {
142 LiveActor::makeActorAppeared();
143 if (mRailMover) {
144 mRailMover->start();
145 }
146 }
147}
148
149void ChipBase::makeActorDead() {
150 if (mRailMover) {
151 mRailMover->end();
152 }
153
154 LiveActor::makeActorDead();
155}
156
157void ChipBase::control() {
158 if (mRailMover) {
159 mRailMover->movement();
160 mPosition.x = mRailMover->_28.x;
161 mPosition.y = mRailMover->_28.y;
162 mPosition.z = mRailMover->_28.z;
163 MR::setClippingRangeIncludeShadow(this, &mClippingRange, 100.0f);
164 }
165}
166
167void ChipBase::appearWait() {
168 if (!isNerve(&NrvChipBase::ChipBaseNrvDeactive::sInstance)) {
169 makeActorAppeared();
170 MR::validateClipping(this);
171 setNerve(&NrvChipBase::ChipBaseNrvWait::sInstance);
172 }
173}
174
175void ChipBase::appearFlashing(s32 a1) {
176 if (!isNerve(&NrvChipBase::ChipBaseNrvDeactive::sInstance)) {
177 appear();
178 MR::invalidateClipping(this);
179 mFlashingCtrl->start(a1);
180 setNerve(&NrvChipBase::ChipBaseNrvFlashing::sInstance);
181 }
182}
183
184bool ChipBase::requestGet(HitSensor *a1, HitSensor *a2) {
185 if (isGettable()) {
186 MR::noticeGetChip(mChipType, this, mGroupID);
187 setNerve(&NrvChipBase::ChipBaseNrvGot::sInstance);
188
189 if (mHost) {
190 mHost->receiveMessage(0x87, a1, a2);
191 }
192
193 return true;
194 }
195
196 return false;
197}
198
199bool ChipBase::requestShow() {
200 if (isNerve(&NrvChipBase::ChipBaseNrvHide::sInstance)) {
201 MR::startBck(this, "Wait", 0);
202 MR::showModel(this);
203 setNerve(&NrvChipBase::ChipBaseNrvWait::sInstance);
204 return true;
205 }
206
207 return false;
208}
209
210bool ChipBase::requestHide() {
211 if (isGettable()) {
212 MR::invalidateHitSensors(this);
213 MR::hideModel(this);
214 MR::stopBck(this);
215 MR::forceDeleteEffectAll(this);
216 setNerve(&NrvChipBase::ChipBaseNrvHide::sInstance);
217 return true;
218 }
219
220 return false;
221}
222
223bool ChipBase::requestStartControl() {
224 if (isNerve(&NrvChipBase::ChipBaseNrvWait::sInstance)) {
225 setNerve(&NrvChipBase::ChipBaseNrvControled::sInstance);
226 return true;
227 }
228
229 return false;
230}
231
232bool ChipBase::requestEndControl() {
233 if (isNerve(&NrvChipBase::ChipBaseNrvControled::sInstance)) {
234 setNerve(&NrvChipBase::ChipBaseNrvWait::sInstance);
235 return true;
236 }
237
238 return false;
239}
240
241void ChipBase::exeFlashing() {
242 if (MR::isFirstStep(this)) {
243 MR::startBck(this, "Wait", 0);
244 MR::validateHitSensors(this);
245 }
246
247 if (mFlashingCtrl->mIsEnded) {
248 kill();
249 }
250}
251
252#ifdef NON_MATCHING
253// mAirBubble load isn't loading twice
254void ChipBase::exeGot() {
255 if (MR::isFirstStep(this)) {
256 PartsModel* mdl = mAirBubble;
257 if (mdl != 0) {
258 MR::emitEffect(mdl, "RecoveryBubbleBreak");
259 MR::incPlayerOxygen(8);
260 mAirBubble->kill();
261 }
262
263 MR::emitEffect(this, "Get");
264 MR::tryRumblePadMiddle(this, 0);
265
266 if (!mChipType) {
267 MR::startSystemSE("SE_SY_BLUECHIP_GET", MR::getGotChipCount(mChipType, mGroupID), -1);
268 }
269 else {
270 if (mChipType == 1) {
271 MR::startSystemSE("SE_SY_YELLOWCHIP_GET", MR::getGotChipCount(mChipType, mGroupID), -1);
272 }
273 }
274 }
275
276 kill();
277}
278#endif
279
280bool ChipBase::isGettable() const {
281 if (MR::isDead(this)) {
282 return false;
283 }
284
285 bool ret;
286
287 if (MR::isLessStep(this, 0x28)) {
288 ret = false;
289 }
290 else {
291 ret = false;
292 if (isNerve(&NrvChipBase::ChipBaseNrvWait::sInstance) || isNerve(&NrvChipBase::ChipBaseNrvFlashing::sInstance)) {
293 ret = true;
294 }
295 }
296
297 return ret;
298}
299
300bool ChipBase::isNeedBubble(const JMapInfoIter &rIter) {
301 if (!MR::isValidInfo(rIter)) {
302 return false;
303 }
304
305 bool val = false;
306 MR::getJMapInfoArg3WithInit(rIter, &val);
307 return val;
308}
309
310void ChipBase::makeArchiveList(NameObjArchiveListCollector *pList, const JMapInfoIter &rIter) {
311 if (ChipBase::isNeedBubble(rIter)) {
312 pList->addArchive("AirBubble");
313 }
314}
315
316namespace NrvChipBase {
317 ChipBaseNrvDeactive ChipBaseNrvDeactive::sInstance;
318 ChipBaseNrvWait ChipBaseNrvWait::sInstance;
319 ChipBaseNrvControled ChipBaseNrvControled::sInstance;
320 ChipBaseNrvFlashing ChipBaseNrvFlashing::sInstance;
321 ChipBaseNrvHide ChipBaseNrvHide::sInstance;
322 ChipBaseNrvGot ChipBaseNrvGot::sInstance;
323
324 void ChipBaseNrvGot::execute(Spine *pSpine) const {
325 ChipBase* base = reinterpret_cast<ChipBase*>(pSpine->mExecutor);
326 base->exeGot();
327 }
328
329 void ChipBaseNrvHide::execute(Spine *pSpine) const {
330
331 }
332
333 void ChipBaseNrvFlashing::execute(Spine *pSpine) const {
334 ChipBase* base = reinterpret_cast<ChipBase*>(pSpine->mExecutor);
335 base->exeFlashing();
336 }
337
338 void ChipBaseNrvControled::execute(Spine *pSpine) const {
339 ChipBase* base = reinterpret_cast<ChipBase*>(pSpine->mExecutor);
340 MR::zeroVelocity(base);
341 }
342
343 void ChipBaseNrvWait::execute(Spine *pSpine) const {
344 ChipBase* base = reinterpret_cast<ChipBase*>(pSpine->mExecutor);
345
346 if (MR::isFirstStep(base)) {
347 MR::startBck(base, "Wait", 0);
348 MR::validateHitSensors(base);
349 }
350 }
351
352 void ChipBaseNrvDeactive::execute(Spine *pSpine) const {
353
354 }
355};
virtual void init(const JMapInfoIter &)
Intializes the NameObj and can set various settings and construct necessary classes.
Definition ChipBase.cpp:18
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
virtual void init(const JMapInfoIter &)
Intializes the NameObj and can set various settings and construct necessary classes.
Stores archive names of NameObjs.
Definition Spine.hpp:9