SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
PTimerSwitch.cpp
1#include "Game/MapObj/PTimerSwitch.hpp"
2#include "Game/Map/CollisionParts.hpp"
3
4PTimerSwitch::PTimerSwitch(const char *pName) : LiveActor(pName) {
5 mSwitchCollision = nullptr;
6 mConnector = nullptr;
7 _94 = 0;
8 _98 = false;
9}
10
11void PTimerSwitch::reset() {
12 LiveActor::appear();
13 setNerve(&NrvPTimerSwitch::PTimerSwitchNrvOff::sInstance);
14 MR::validateCollisionParts(mSwitchCollision);
15 MR::startBck(this, "Wait", 0);
16 _94 = 0;
17 _98 = false;
18}
19
20void PTimerSwitch::init(const JMapInfoIter& rIter) {
21 MR::initDefaultPos(this, rIter);
22 initModelManagerWithAnm("PTimerSwitch", nullptr, false);
23 MR::connectToSceneMapObj(this);
24 initHitSensor(2);
25 MR::addHitSensorMapObj(this, "body", 0x10, 0.0f, TVec3f(0.0f, 0.0f, 0.0f));
26 MR::addHitSensor(this, "hit", 0x4f, 0x10, 120.0f, TVec3f(0.0f, 50.0f, 0.0f));
27 MR::initCollisionParts(this, "PTimerSwitch", getSensor("body"), 0);
28 mSwitchCollision = MR::createCollisionPartsFromLiveActor(this, "Move", getSensor("hit"), (MR::CollisionScaleType)2);
29 initSound(4, false);
30 MR::needStageSwitchWriteA(this, rIter);
31 initNerve(&NrvPTimerSwitch::PTimerSwitchNrvOff::sInstance);
32 initEffectKeeper(0, nullptr, false);
33 MR::startBck(this, "Move", 0);
34 mConnector = new MapObjConnector(this);
35 appear();
36}
37
38void PTimerSwitch::initAfterPlacement() {
39 mConnector->attachToUnder();
40}
41
42void PTimerSwitch::appear() {
43 reset();
44}
45
46void PTimerSwitch::kill() {
47 LiveActor::kill();
48 MR::emitEffect(this, "Delete");
49 MR::invalidateCollisionParts(mSwitchCollision);
50}
51
52void PTimerSwitch::calcAnim() {
53 LiveActor::calcAnim();
54 TPos3f mtx;
55 mtx.setInline(MR::getJointMtx(this, "Move"));
56 mSwitchCollision->setMtx(mtx);
57}
58
59void PTimerSwitch::control() {
60 if (_98) {
61 ++_94;
62 } else if (_94 > 0) {
63 --_94;
64 }
65
66 _98 = false;
67}
68
71 mConnector->connect();
72}
73
74bool PTimerSwitch::receiveOtherMsg(u32 msg, HitSensor *pSender, HitSensor *pReceiver) {
75 return false;
76}
77
78bool PTimerSwitch::receiveMsgPlayerAttack(u32 msg, HitSensor *pSender, HitSensor *pReceiver) {
79 if (!MR::isMsgPlayerTrample(msg)) {
80 return false;
81 }
82
83 if (pReceiver->mSensorType != 0x4f) {
84 return false;
85 }
86
87 if (!isNerve(&NrvPTimerSwitch::PTimerSwitchNrvOff::sInstance)) {
88 return false;
89 }
90
91 _98 = true;
92 return true;
93}
94
95bool PTimerSwitch::trySwitchDown() {
96 if (_94 > 0) {
97 setNerve(&NrvPTimerSwitch::PTimerSwitchNrvSwitchDown::sInstance);
98 return true;
99 }
100
101 return false;
102}
103
104bool PTimerSwitch::tryOn() {
105 if (MR::isBckStopped(this)) {
106 setNerve(&NrvPTimerSwitch::PTimerSwitchNrvOn::sInstance);
107 return true;
108 }
109
110 return false;
111}
112
113void PTimerSwitch::exeOff() {
114 if (MR::isFirstStep(this)) {
115 MR::validateClipping(this);
116 MR::offSwitchA(this);
117 }
118
119 if (!trySwitchDown()) {
120 return;
121 }
122}
123
124void PTimerSwitch::exeSwitchDown() {
125 if (MR::isFirstStep(this)) {
126 MR::startBck(this, "On", nullptr);
127 MR::invalidateClipping(this);
128 }
129
130 if (!tryOn()) {
131 return;
132 }
133}
134
135void PTimerSwitch::exeOn() {
136 if (MR::isFirstStep(this)) {
137 MR::onSwitchA(this);
138 MR::shakeCameraNormal();
139 MR::startSound(this, "SE_OJ_SWITCH_1", -1, -1);
140 }
141
142 if (MR::isGreaterStep(this, 25)) {
143 kill();
144 }
145}
146
147namespace NrvPTimerSwitch {
148 INIT_NERVE(PTimerSwitchNrvOn);
149 INIT_NERVE(PTimerSwitchNrvSwitchDown);
150 INIT_NERVE(PTimerSwitchNrvOff);
151
152 void PTimerSwitchNrvOn::execute(Spine *pSpine) const {
153 PTimerSwitch *actor = reinterpret_cast<PTimerSwitch *>(pSpine->mExecutor);
154 actor->exeOn();
155 }
156
157 void PTimerSwitchNrvSwitchDown::execute(Spine *pSpine) const {
158 PTimerSwitch *actor = reinterpret_cast<PTimerSwitch *>(pSpine->mExecutor);
159 actor->exeSwitchDown();
160 }
161
162 void PTimerSwitchNrvOff::execute(Spine *pSpine) const {
163 PTimerSwitch *actor = reinterpret_cast<PTimerSwitch *>(pSpine->mExecutor);
164 actor->exeOff();
165 }
166}
The basis of a drawable actor that can contain states (see: Nerve)
Definition LiveActor.hpp:24
virtual void calcAndSetBaseMtx()
Calculates and sets the base matrix of the actor.
HitSensor * getSensor(const char *pSensorName) const
Gets a sensor.
virtual void calcAndSetBaseMtx()
Calculates and sets the base matrix of the actor.
virtual void init(const JMapInfoIter &rIter)
Intializes the NameObj and can set various settings and construct necessary classes.
Definition Spine.hpp:9