SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
CrystalSwitch.cpp
1#include "Game/MapObj/CrystalSwitch.hpp"
2
3/* Note -- this file was compiled super early on in the game's life, so it was compiled under -O2 where the release build is -O4,p. Keep this in mind! */
4
5CrystalSwitch::CrystalSwitch(const char *pName) : LiveActor(pName) {
6 _8C = 0;
7 _90 = 300;
8 mRotateSpeed = 0.0f;
9 _98 = 0;
10}
11
13 MR::initDefaultPos(this, rIter);
14 initModelManagerWithAnm("CrystalSwitch", nullptr, false);
15 MR::connectToSceneMapObj(this);
16 initHitSensor(1);
17 TVec3f sensor_offs;
18 sensor_offs.x = 0.0f;
19 sensor_offs.y = 100.0f;
20 sensor_offs.z = 0.0f;
21 MR::addHitSensorMapObj(this, "body", 16, 100.0f, sensor_offs);
22 initSound(4, false);
23 MR::needStageSwitchWriteA(this, rIter);
24 MR::getJMapInfoArg0NoInit(rIter, &_90);
25 initNerve(&NrvCrystalSwitch::CrystalSwitchNrvOff::sInstance);
26 initEffectKeeper(0, nullptr, false);
27 MR::startBck(this, "Wait", nullptr);
28 MR::startBpk(this, "Off");
29 appear();
30}
31
32void CrystalSwitch::control() {
33 calcRotSpeed();
34 _98 = 0;
35}
36
37void CrystalSwitch::attackSensor(HitSensor *a1, HitSensor *a2) {
38 if (MR::isSensorPlayer(a2)) {
39 a2->receiveMessage(41, a1);
40 }
41}
42
43bool CrystalSwitch::receiveMsgPlayerAttack(u32, HitSensor *, HitSensor *) {
44 _98 = 1;
45 return 1;
46}
47
48bool CrystalSwitch::trySwitchDown() {
49 if (_98) {
50 setNerve(&NrvCrystalSwitch::CrystalSwitchNrvSwitchDown::sInstance);
51 return true;
52 }
53
54 return false;
55}
56
57bool CrystalSwitch::tryOn() {
58 if (getNerveStep() > 10) {
59 setNerve(&NrvCrystalSwitch::CrystalSwitchNrvOn::sInstance);
60 return true;
61 }
62
63 return false;
64}
65
66bool CrystalSwitch::tryOff() {
67 if (mRotateSpeed < 8.0f) {
68 setNerve(&NrvCrystalSwitch::CrystalSwitchNrvOff::sInstance);
69 return true;
70 }
71
72 return false;
73}
74
75void CrystalSwitch::exeOff() {
76 if (MR::isFirstStep(this)) {
77 MR::validateClipping(this);
78 MR::offSwitchA(this);
79 }
80
81 trySwitchDown();
82}
83
84void CrystalSwitch::exeSwitchDown() {
85 if (MR::isFirstStep(this)) {
86 MR::startBpk(this, "On");
87 MR::invalidateClipping(this);
88 }
89
90 tryOn();
91}
92
93void CrystalSwitch::exeOn() {
94 if (MR::isFirstStep(this)) {
95 MR::onSwitchA(this);
96 MR::shakeCameraNormal();
97 MR::startSound(this, "SE_OJ_CRYSTAL_SWITCH_ON", -1, -1);
98 mRotateSpeed = 10.0f;
99 MR::setBckRate(this, 10.0f);
100 }
101}
102
103void CrystalSwitch::calcRotSpeed() {
104 if (isNerve(&NrvCrystalSwitch::CrystalSwitchNrvOn::sInstance)) {
105 if (mRotateSpeed < 10.0f) {
106 mRotateSpeed += 1.5f;
107 }
108
109 if (mRotateSpeed > 10.0f) {
110 mRotateSpeed = 10.0f;
111 }
112 }
113 else {
114 if (mRotateSpeed > 10.0f) {
115 mRotateSpeed = 10.0f;
116 }
117
118 MR::setBckRate(this, mRotateSpeed);
119 mRotateSpeed *= 0.99000001f;
120
121 if (mRotateSpeed < 0.0f) {
122 mRotateSpeed = 0.0f;
123 }
124 }
125}
126
127CrystalSwitch::~CrystalSwitch() {
128
129}
130
131namespace NrvCrystalSwitch {
132 INIT_NERVE(CrystalSwitchNrvOff);
133 INIT_NERVE(CrystalSwitchNrvSwitchDown);
134 INIT_NERVE(CrystalSwitchNrvOn);
135 INIT_NERVE(CrystalSwitchNrvSwitchUp);
136
137 void CrystalSwitchNrvSwitchUp::execute(Spine *pSpine) const {
138 CrystalSwitch* crystal = reinterpret_cast<CrystalSwitch*>(pSpine->mExecutor);
139
140 if (MR::isFirstStep(crystal)) {
141 MR::startBpk(crystal, "Off");
142 }
143
144 crystal->tryOff();
145 }
146
147 void CrystalSwitchNrvOn::execute(Spine *pSpine) const {
148 CrystalSwitch* crystal = reinterpret_cast<CrystalSwitch*>(pSpine->mExecutor);
149 crystal->exeOn();
150 }
151
152 void CrystalSwitchNrvSwitchDown::execute(Spine *pSpine) const {
153 CrystalSwitch* crystal = reinterpret_cast<CrystalSwitch*>(pSpine->mExecutor);
154 crystal->exeSwitchDown();
155 }
156
157 void CrystalSwitchNrvOff::execute(Spine *pSpine) const {
158 CrystalSwitch* crystal = reinterpret_cast<CrystalSwitch*>(pSpine->mExecutor);
159 crystal->exeOff();
160 }
161};
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
Definition Spine.hpp:9