SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
ArrowSwitchMulti.cpp
1#include "Game/MapObj/ArrowSwitchMulti.hpp"
2#include "Game/MapObj/ArrowSwitchMultiHolder.hpp"
3#include "Game/Map/StageSwitch.hpp"
4
5ArrowSwitchTarget::ArrowSwitchTarget(const char *pName) : NameObj(pName) {
6 mJMapIDInfo = nullptr;
7 mStageSwitchCtrl = nullptr;
8 mTargetIdx = -1;
9 MR::createArrowSwitchMultiHolder();
10}
11
13 s32 arg;
14 MR::getJMapInfoArg0WithInit(rIter, &arg);
15 mJMapIDInfo = new JMapIdInfo(arg, rIter);
16 MR::getJMapInfoArg1WithInit(rIter, &mTargetIdx);
17 mStageSwitchCtrl = MR::createStageSwitchCtrl(this, rIter);
18}
19
20void ArrowSwitchTarget::initAfterPlacement() {
21 MR::registerArrowSwitchTarget(this);
22}
23
24void ArrowSwitchTarget::onTarget() {
25 if (mStageSwitchCtrl->isValidSwitchA()) {
26 mStageSwitchCtrl->onSwitchA();
27 }
28
29 if (mStageSwitchCtrl->isValidSwitchB()) {
30 mStageSwitchCtrl->offSwitchB();
31 }
32}
33
34void ArrowSwitchTarget::offTarget() {
35 if (mStageSwitchCtrl->isValidSwitchA()) {
36 mStageSwitchCtrl->offSwitchA();
37 }
38
39 if (mStageSwitchCtrl->isValidSwitchB()) {
40 mStageSwitchCtrl->onSwitchB();
41 }
42}
43
44
45ArrowSwitchMulti::ArrowSwitchMulti(const char *pName) : LiveActor(pName) {
46 mIDInfo = nullptr;
47 _A0 = 0.0f;
48 _A4 = 0.0f;
49 _A8 = 0;
50 _AC = 0;
51 _B0 = 1;
52 MR::createArrowSwitchMultiHolder();
53
54 for (u32 i = 0; i < 4; i++) {
55 mTargetArray[i] = nullptr;
56 }
57}
58
59void ArrowSwitchMulti::registerTarget(ArrowSwitchTarget *pTarget) {
60 mTargetArray[pTarget->mTargetIdx] = pTarget;
61}
62
64 MR::initDefaultPos(this, rIter);
65 initModelManagerWithAnm("ArrowSwitch", nullptr, false);
66 MR::connectToSceneNoSilhouettedMapObjStrongLight(this);
67 s32 arg;
68 MR::getJMapInfoArg0WithInit(rIter, &arg);
69 mIDInfo = new JMapIdInfo(arg, rIter);
70
71 if (MR::isInAreaObj("PlaneModeCube", mPosition)) {
72 initHitSensor(1);
73 MR::addHitSensorMapObj(this, "body", 8, 100.0f, TVec3f(0.0f, 50.0f, 250.0f));
74 }
75 else {
76 initHitSensor(2);
77 MR::addHitSensorMapObj(this, "body", 8, 100.0f, TVec3f(0.0f, 50.0f, 250.0f));
78 MR::addHitSensorMapObjMoveCollision(this, "collision", 8, 0.0f, TVec3f(0.0f, 0.0f, 0.0f));
79 MR::initCollisionParts(this, "ArrowSwitch", getSensor("collision"), nullptr);
80 }
81
82 initSound(4, false);
83 MR::registerArrowSwitchMulti(this);
84 initNerve(&NrvArrowSwitchMulti::ArrowSwitchMultiNrvWait::sInstance);
85 makeActorAppeared();
86}
87
88void ArrowSwitchMulti::control() {
89
90}
91
94 MtxPtr baseMtx = getBaseMtx();
95 TPos3f pos;
96 pos.setInline(baseMtx);
97 TMtx34f tr_mtx;
98 tr_mtx.identity();
99 f32 v11 = _A0;
100 v11 = v11 * PI_180;
101 f32 v12 = sin(v11);
102 f32 v13 = cos(v11);
103 tr_mtx.mMtx[0][2] = v12;
104 tr_mtx.mMtx[1][1] = 1.0f;
105 tr_mtx.mMtx[0][0] = v13;
106 tr_mtx.mMtx[2][0] = -v12;
107 tr_mtx.mMtx[2][2] = v13;
108 tr_mtx.mMtx[2][1] = 0.0f;
109 tr_mtx.mMtx[1][2] = 0.0f;
110 tr_mtx.mMtx[1][0] = 0.0f;
111 tr_mtx.mMtx[0][1] = 0.0f;
112 pos.concat(pos, tr_mtx);
113 MR::setBaseTRMtx(this, pos);
114}
115
116bool ArrowSwitchMulti::receiveMsgPlayerAttack(u32 msg, HitSensor *a2, HitSensor *a3) {
117 if (MR::isMsgPlayerHitAll(msg)) {
118 return requestPunch(a2, a3);
119 }
120
121 return false;
122}
123
124bool ArrowSwitchMulti::requestPunch(HitSensor *a1, HitSensor *a2) {
125 if (getSensor("body") != a2) {
126 return false;
127 }
128
129 if (!isNerve(&NrvArrowSwitchMulti::ArrowSwitchMultiNrvWait::sInstance)) {
130 return false;
131 }
132
133 if (_B0) {
134 _AC++;
135 _A4 = 6.0f;
136 }
137 else {
138 _AC--;
139 _A4 = -6.0f;
140 }
141
142 _AC = (_AC + 4) % 4;
143 MR::invalidateClipping(this);
144 setNerve(&NrvArrowSwitchMulti::ArrowSwitchMultiNrvRotate::sInstance);
145 return true;
146}
147
148void ArrowSwitchMulti::exeWait() {
149 if (MR::isFirstStep(this)) {
150 if (_AC % 2 == 1) {
151 MR::startBtk(this, "On");
152 }
153 else {
154 MR::startBtk(this, "Off");
155 }
156
157 MR::validateClipping(this);
158 }
159}
160
161// ArrowSwitchMulti::exeRotate
162
163ArrowSwitchMulti::~ArrowSwitchMulti() {
164
165}
166
167ArrowSwitchTarget::~ArrowSwitchTarget() {
168
169}
170
171namespace NrvArrowSwitchMulti {
172 INIT_NERVE(ArrowSwitchMultiNrvWait);
173 INIT_NERVE(ArrowSwitchMultiNrvRotate);
174
175 void ArrowSwitchMultiNrvRotate::execute(Spine *pSpine) const {
176 ArrowSwitchMulti* sw = reinterpret_cast<ArrowSwitchMulti*>(pSpine->mExecutor);
177 sw->exeRotate();
178 }
179
180 void ArrowSwitchMultiNrvWait::execute(Spine *pSpine) const {
181 ArrowSwitchMulti* sw = reinterpret_cast<ArrowSwitchMulti*>(pSpine->mExecutor);
182 sw->exeWait();
183 }
184};
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.
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 void calcAndSetBaseMtx()
Calculates and sets the base matrix of the actor.
virtual MtxPtr getBaseMtx() const
Gets the base matrix of the model used for the actor.
HitSensor * getSensor(const char *pSensorName) const
Gets a sensor.
The most basic form of an object.
Definition NameObj.hpp:11
Definition Spine.hpp:9