SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
BlackHole.cpp
1#include "Game/MapObj/BlackHole.hpp"
2#include "Game/LiveActor/ModelObj.hpp"
3#include "Game/Util.hpp"
4
5// BlackHole::BlackHole
6
7void BlackHole::init(const JMapInfoIter &rIter) {
8 initMapToolInfo(rIter);
9 initModel();
10 MR::connectToSceneMapObj(this);
11 initHitSensor(1);
12 MR::addHitSensorEye(this, "body", 0x10, _A0, TVec3f(0.0f, 0.0f, 0.0f));
13 initEffectKeeper(0, 0, false);
14 MR::setEffectHostMtx(this, "BlackHoleSuction", (MtxPtr)&_D8);
15 f32 radius = _A0;
16 f32 val = 500.0f * _9C;
17 if (radius >= val) {
18 radius = radius;
19 }
20 else {
21 radius = val;
22 }
23
24 f32 clippingRadius = 500.0f * radius;
25 MR::setClippingTypeSphere(this, clippingRadius);
26 MR::setClippingTypeSphere(mBlackHoleModel, clippingRadius);
27 MR::setClippingFarMax(this);
28 MR::setClippingFarMax(mBlackHoleModel);
29 initSound(4, false);
30
31 if (MR::tryRegisterDemoCast(this, rIter)) {
32 MR::registerDemoActionNerve(this, &NrvBlackHole::BlackHoleNrvDisappear::sInstance, 0);
33 }
34
35 bool isCreated = MR::createActorCameraInfoIfExist(rIter, &mCameraInfo);
36 if (isCreated) {
37 MR::initActorCamera(this, rIter, &mCameraInfo);
38 }
39
40 initNerve(&NrvBlackHole::BlackHoleNrvWait::sInstance);
41 bool uses = MR::useStageSwitchReadAppear(this, rIter);
42 if (uses) {
43 MR::syncStageSwitchAppear(this);
44 makeActorDead();
45 }
46 else {
47 makeActorAppeared();
48 }
49}
50
51void BlackHole::makeActorAppeared() {
52 bool isOnSwitch = false;
53 if (MR::isValidSwitchA(this) && MR::isOnSwitchA(this)) {
54 isOnSwitch = true;
55 }
56
57 if (isOnSwitch) {
58 LiveActor::makeActorAppeared();
59 mBlackHoleModel->makeActorAppeared();
60 }
61}
62
63void BlackHole::kill() {
64 LiveActor::kill();
65 mBlackHoleModel->kill();
66}
67
68bool BlackHole::tryStartDemoCamera() {
69 if (mCameraInfo) {
70 MR::startActorCameraTargetSelf(this, mCameraInfo, -1);
71 return true;
72 }
73
74 return false;
75}
76
77void BlackHole::attackSensor(HitSensor *a1, HitSensor *a2) {
78 if (isNerve(&NrvBlackHole::BlackHoleNrvWait::sInstance)) {
79 if (!_A4 || isInCubeBox(a2->mPosition)) {
80 if (MR::sendArbitraryMsg(0x73, a2, a1)) {
81 if (MR::isSensorPlayer(a2)) {
82 setNerve(&NrvBlackHole::BlackHoleNrvDemo::sInstance);
83 }
84 }
85 }
86 }
87}
88
89#ifdef NON_MATCHING
90// shrug
91void BlackHole::initMapToolInfo(const JMapInfoIter &rIter) {
92 MR::initDefaultPos(this, rIter);
93 MR::useStageSwitchReadA(this, rIter);
94 MR::useStageSwitchReadAppear(this, rIter);
95
96 if (MR::isEqualObjectName(rIter, "BlackHoleCube")) {
97 initCubeBox();
98 setName("ブラックホール[キューブ指定]");
99 }
100
101 if (_A4 == 0) {
102 _A0 = 500.0f * mScale.z;
103 }
104 else {
105 TVec3f stack_C;
106 stack_C.setInlineXYPS(mScale);
107 _A0 = PSVECMag(stack_C.toCVec());
108 }
109
110 f32 arg0;
111 bool ret = MR::getJMapInfoArg0NoInit(rIter, &arg0);
112
113 if (ret) {
114 _9C = arg0 / 1000.0f;
115 }
116 else if (_A4) {
117 _9C = 1.0f;
118 }
119 else {
120 _9C = mScale.x;
121 }
122}
123#endif
124
125void BlackHole::initModel() {
126 initModelManagerWithAnm("BlackHoleRange", 0, false);
127 mBlackHoleModel = MR::createModelObjMapObj("コアモデル", "BlackHole", getBaseMtx());
128 mBlackHoleModel->makeActorDead();
129 updateModelScale(_9C, _9C);
130}
131
132#ifdef NON_MATCHING
133void BlackHole::initCubeBox() {
134 MR::makeMtxRotate((MtxPtr)&_A8, mRotation.x, mRotation.y, mRotation.z);
135 _A8.mMtx[0][3] = mPosition.x;
136 _A8.mMtx[1][3] = mPosition.y;
137 _A8.mMtx[2][3] = mPosition.z;
138 _A4 = new TBox3f();
139 TVec3f stack_8(0.5f * (1000.0f * -mScale.x), 0.5f * (1000.0f * -mScale.y), 0.5f * (1000.0f * -mScale.z));
140 TVec3f stack_14(0.5f * (1000.0f * mScale.x), 0.5f * (1000.0f, mScale.z), 0.5f * (1000.0f * mScale.y));
141 _A4->mMin.set(stack_8);
142 _A4->mMax.set(stack_14);
143}
144#endif
145
146bool BlackHole::isInCubeBox(const TVec3f &rVec) const {
147 TVec3f stack_8;
148 _A8.multTranspose(rVec, stack_8);
149 bool ret = false;
150 TBox3f* box = _A4;
151 if (stack_8.x >= box->mMin.x && stack_8.y >= box->mMin.y && stack_8.z >= box->mMin.z && stack_8.x < box->mMax.x && stack_8.y < box->mMax.y && stack_8.z < box->mMax.z) {
152 ret = true;
153 }
154
155 return ret;
156}
157
158void BlackHole::updateModelScale(f32 a1, f32 a2) {
159 mScale.setAll<f32>(a1);
160 mBlackHoleModel->mScale.setAll<f32>(0.5f * a2);
161}
162
163void BlackHole::exeWait() {
164 if (MR::isFirstStep(this)) {
165 MR::startBck(this, "BlackHoleRange", 0);
166 MR::startBtk(this, "BlackHoleRange");
167 MR::startBtk(mBlackHoleModel, "BlackHole");
168 }
169
170 MR::startLevelSound(this, "SE_OJ_LV_BLACK_HOLE", -1, -1, -1);
171 bool isOnSwitch = false;
172 if (MR::isValidSwitchA(this) && MR::isOnSwitchA(this)) {
173 isOnSwitch = true;
174 }
175
176 if (isOnSwitch) {
177 kill();
178 }
179}
180
181void BlackHole::exeDisappear() {
182 if (MR::isFirstStep(this)) {
183 MR::startSound(this, "SE_OJ_BLACK_HOLE_DISAPPEAR", -1, -1);
184 }
185
186 f32 nerveEaseIn = MR::calcNerveEaseInValue(this, 0x5A, _9C, 0.0f);
187 f32 blackHoleEase = MR::calcNerveEaseInValue(this, 0x1E, 0x5A, _9C, 0.0f);
188 mScale.setAll<f32>(nerveEaseIn);
189 mBlackHoleModel->mScale.setAll<f32>(0.5f * blackHoleEase);
190
191 if (MR::isStep(this, 0x5A)) {
192 kill();
193 }
194}
195
196BlackHole::~BlackHole() {
197
198}
199
200namespace NrvBlackHole {
201 BlackHoleNrvWait BlackHoleNrvWait::sInstance;
202 BlackHoleNrvDemo BlackHoleNrvDemo::sInstance;
203 BlackHoleNrvDisappear BlackHoleNrvDisappear::sInstance;
204
205 void BlackHoleNrvDisappear::execute(Spine *pSpine) const {
206 BlackHole* blackHole = reinterpret_cast<BlackHole*>(pSpine->mExecutor);
207 blackHole->exeDisappear();
208 }
209
210 void BlackHoleNrvDemo::execute(Spine *pSpine) const {
211 BlackHole* blackHole = reinterpret_cast<BlackHole*>(pSpine->mExecutor);
212 MR::startLevelSound(blackHole, "SE_OJ_LV_BLACK_HOLE", -1, -1, -1);
213 }
214
215 void BlackHoleNrvWait::execute(Spine *pSpine) const {
216 BlackHole* blackHole = reinterpret_cast<BlackHole*>(pSpine->mExecutor);
217 blackHole->exeWait();
218 }
219
220};
virtual void init(const JMapInfoIter &)
Intializes the NameObj and can set various settings and construct necessary classes.
Definition BlackHole.cpp:7
TVec3f mRotation
3D vector of the actor's rotation.
Definition LiveActor.hpp:96
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 MtxPtr getBaseMtx() const
Gets the base matrix of the model used for the actor.
void setName(const char *pName)
Sets the NameObj's mName.
Definition NameObj.cpp:48
Definition Spine.hpp:9