SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
PressureBase.cpp
1#include "Game/MapObj/PressureBase.hpp"
2
3PressureMessenger::PressureMessenger(MsgSharedGroup *pGroup, const char *pName) : LiveActor(pName) {
4 mSharedGroup = pGroup;
5 _90 = 0;
6}
7
9 MR::connectToSceneMapObjMovement(this);
10 initHitSensor(1);
11 MR::addBodyMessageSensorMapObj(this);
12 MR::invalidateClipping(this);
13 initNerve(&NrvPressureMessenger::PressureMessengerNrvSync::sInstance);
14 makeActorAppeared();
15}
16
17void PressureMessenger::exeSync() {
18 if (MR::isStep(this, _90)) {
19 mSharedGroup->sendMsgToGroupMember(0x68, getSensor("body"), "body");
20 setNerve(&NrvPressureMessenger::PressureMessengerNrvSync::sInstance);
21 }
22}
23
24PressureBase::PressureBase(const char *pName) : LiveActor(pName) {
25 mJointController = nullptr;
26 mFront.x = 0.0f;
27 mFront.y = 0.0f;
28 mFront.z = 1.0f;
29 _9C = 0.0f;
30 mNozzleRotation = 0.0f;
31 mWaitTime = 300;
32 mBallSpeed = 30.0f;
33 mShotType = 0;
34 _B0 = 0;
35 mMessenger = nullptr;
36 mGroup = nullptr;
37 _BC = 0;
38}
39
40void PressureBase::init(const JMapInfoIter &rIter) {
41 MR::initDefaultPos(this, rIter);
42 const char* objName;
43 MR::getObjectName(&objName, rIter);
44 initModelManagerWithAnm(objName, nullptr, false);
45 MR::calcFrontVec(&mFront, this);
46 MR::connectToSceneNoShadowedMapObjStrongLight(this);
47 initHitSensor(2);
48 MR::addHitSensorMapObj(this, "body", 8, 70.0f, TVec3f(0.0f, 30.0f, 0.0f));
49 MR::addHitSensorAtJointMapObjSimple(this, "cannon", "Cannon1", 8, 70.0f, TVec3f(40.0f, 0.0f, 0.0f));
50 initEffectKeeper(0, nullptr, false);
51 initSound(6, false);
52 MR::initShadowVolumeSphere(this, 75.0f);
53 MR::invalidateShadow(this, nullptr);
54 mJointController = MR::createJointDelegatorWithNullChildFunc<PressureBase>(this, &PressureBase::calcJointCannonV, "Cannon1");
55 MR::initJointTransform(this);
56 MR::getJMapInfoArg0NoInit(rIter, &mNozzleRotation);
57 MR::getJMapInfoArg1NoInit(rIter, &mWaitTime);
58 s16 frame = MR::getBckFrameMax(this, "ShotStart");
59 _B0 = (mWaitTime < frame);
60 //_B0 = ((frame ^ mWaitTime >> 1) - (frame ^ mWaitTime) < 0;
61 initBullet(rIter);
62 MR::getJMapInfoArg2NoInit(rIter, &mBallSpeed);
63 MR::getJMapInfoArg3NoInit(rIter, &mShotType);
64 MR::calcGravity(this);
65 MR::setGroupClipping(this, rIter, 32);
66 mGroup = MR::joinToGroupArray(this, rIter, "プレッシャー軍団", 0x20);
67
68 if (mGroup != nullptr) {
69 PressureBase* actor = (PressureBase*)mGroup->getActor(0);
70
71 if (this == actor) {
72 mMessenger = new PressureMessenger(mGroup, "プレッシャー同期メッセンジャー");
73 mMessenger->initWithoutIter();
74 }
75
76 }
77
78 MR::tryRegisterDemoCast(this, rIter);
79 MR::useStageSwitchSleep(this, rIter);
80
81 if (MR::useStageSwitchReadA(this, rIter)) {
82 void (PressureBase::*relaxFunc)(void) = &PressureBase::startRelax;
83 void (PressureBase::*waitFunc)(void) = &PressureBase::startWait;
84 MR::listenStageSwitchOnOffA(this, MR::Functor(this, relaxFunc), MR::Functor(this, waitFunc));
85 initNerve(&NrvPressureBase::PressureBaseNrvRelax::sInstance);
86 }
87 else {
88 initNerve(&NrvPressureBase::PressureBaseNrvFirstWait::sInstance);
89 }
90
91 if (MR::useStageSwitchReadAppear(this, rIter)) {
92 MR::syncStageSwitchAppear(this);
93 makeActorDead();
94 }
95 else {
96 makeActorAppeared();
97 }
98}
99
100#ifdef NON_MATCHING
101// regswap
102void PressureBase::initAfterPlacement() {
103 if (mMessenger != nullptr) {
104 s32 waitTime = -1;
105
106 for (u16 i = 0; i < MR::getGroupFromArray(this)->mObjectCount; ++i) {
107 PressureBase* actor = (PressureBase*)MR::getGroupFromArray(this)->getActor(i);
108
109 if (actor->mWaitTime > waitTime) {
110 waitTime = actor->mWaitTime;
111 }
112 }
113
114 mMessenger->_90 = waitTime + 60;
115 }
116}
117#endif
118
121 mJointController->registerCallBack();
122}
123
124void PressureBase::control() {
125 if (mWaitTime == 3) {
126 MR::turnDirectionToTargetDegree(this, &mFront, *MR::getPlayerPos(), 5.0f);
127 }
128}
129
130void PressureBase::exeBound() {
131 if (MR::isFirstStep(this)) {
132 if (isNerve(&NrvPressureBase::PressureBaseNrvRelaxStart::sInstance)) {
133 MR::startBck(this, "SwitchOff", nullptr);
134 }
135 else {
136 MR::startBck(this, "SwitchOn", nullptr);
137 }
138 }
139
140 f32 rate = MR::calcNerveRate(this, 0x14);
141 f32 scale = MR::getScaleWithReactionValueZeroToOne(rate, 1.0f, -2.0f);
142 scale *= (-45.0f - mNozzleRotation);
143
144 if (isNerve(&NrvPressureBase::PressureBaseNrvRelaxStart::sInstance)) {
145 _9C = mNozzleRotation + scale;
146 }
147 else {
148 _9C = -45.0f - scale;
149 }
150
151 if (MR::isStep(this, 0x14)) {
152 if (isNerve(&NrvPressureBase::PressureBaseNrvRelaxStart::sInstance)) {
153 setNerve(&NrvPressureBase::PressureBaseNrvRelax::sInstance);
154 }
155 else {
156 setNerve(&NrvPressureBase::PressureBaseNrvWait::sInstance);
157 }
158 }
159}
160
161void PressureBase::exeWait() {
162 if (mWaitTime == MR::getBckFrameMax(this, "ShotStart") + getNerveStep()) {
163 setNerve(&NrvPressureBase::PressureBaseNrvPrepareToShot::sInstance);
164 }
165 else if (MR::isStep(this, mWaitTime)) {
166 setNerve(&NrvPressureBase::PressureBaseNrvShot::sInstance);
167 }
168}
169
170void PressureBase::exePrepareToShot() {
171 if (MR::isFirstStep(this)) {
172 MR::startBck(this, "ShotStart", nullptr);
173 }
174
175 if (MR::isBckStopped(this)) {
176 setNerve(&NrvPressureBase::PressureBaseNrvShot::sInstance);
177 }
178}
179
180void PressureBase::exeShot() {
181 if (MR::isFirstStep(this)) {
182 if (_B0) {
183 MR::startBck(this, "ShortShot", nullptr);
184 }
185 else {
186 MR::startBck(this, "Shot", nullptr);
187 }
188 }
189
190 if (_B0) {
191 if (MR::isStep(this, 0x36)) {
192 shotBullet(mBallSpeed);
193 }
194 }
195 else {
196 if (MR::isStep(this, 0x10)) {
197 shotBullet(mBallSpeed);
198 }
199 }
200
201 if (MR::isBckStopped(this)) {
202 if (mGroup != nullptr) {
203 setNerve(&NrvPressureBase::PressureBaseNrvSyncWait::sInstance);
204 }
205 else {
206 setNerve(&NrvPressureBase::PressureBaseNrvWait::sInstance);
207 }
208 }
209}
210
211void PressureBase::attackSensor(HitSensor *a1, HitSensor *a2) {
212 if (MR::isSensorPlayer(a2) || MR::isSensorEnemy(a2)) {
213 MR::sendMsgPush(a2, a1);
214 }
215}
216
217bool PressureBase::receiveMsgPlayerAttack(u32 msg, HitSensor *, HitSensor *) {
218 return MR::isMsgStarPieceReflect(msg);
219}
220
221bool PressureBase::receiveOtherMsg(u32 msg, HitSensor *, HitSensor *) {
222 if (msg == 0x68) {
223 bool v5 = false;
224 if (isNerve(&NrvPressureBase::PressureBaseNrvRelaxStart::sInstance) || isNerve(&NrvPressureBase::PressureBaseNrvRelax::sInstance)) {
225 v5 = true;
226 }
227
228 if (v5) {
229 return false;
230 }
231
232 setNerve(&NrvPressureBase::PressureBaseNrvWait::sInstance);
233 return true;
234 }
235
236 return false;
237}
238
239void PressureBase::startWait() {
240 if (isNerve(&NrvPressureBase::PressureBaseNrvRelax::sInstance)) {
241 setNerve(&NrvPressureBase::PressureBaseNrvWaitStart::sInstance);
242 }
243}
244
245void PressureBase::startRelax() {
246 bool dontStartRelax = false;
247
248 if (isNerve(&NrvPressureBase::PressureBaseNrvRelaxStart::sInstance) || isNerve(&NrvPressureBase::PressureBaseNrvRelax::sInstance)) {
249 dontStartRelax = true;
250 }
251
252 if (!dontStartRelax) {
253 MR::startSound(this, "SE_OJ_W_PRESS_HEAD_OFF", -1, -1);
254 setNerve(&NrvPressureBase::PressureBaseNrvRelaxStart::sInstance);
255 }
256}
257
258void PressureBase::initBullet(const JMapInfoIter &) {
259
260}
261
262bool PressureBase::shotBullet(f32) {
263 return false;
264}
265
266// PressureBase::calcJointCannonV
267
268bool PressureBase::isShotTypeOnGravity() const {
269 return mShotType == 0;
270}
271
272bool PressureBase::isShotTypeFollow() const {
273 return mShotType == 2;
274}
275
276namespace NrvPressureMessenger {
277 INIT_NERVE(PressureMessengerNrvSync);
278};
279
280namespace NrvPressureBase {
281 INIT_NERVE(PressureBaseNrvRelaxStart);
282 INIT_NERVE(PressureBaseNrvWaitStart);
283 INIT_NERVE(PressureBaseNrvRelax);
284 INIT_NERVE(PressureBaseNrvSyncWait);
285 INIT_NERVE(PressureBaseNrvFirstWait);
286 INIT_NERVE(PressureBaseNrvWait);
287 INIT_NERVE(PressureBaseNrvPrepareToShot);
288 INIT_NERVE(PressureBaseNrvShot);
289
290 void PressureBaseNrvShot::execute(Spine *pSpine) const {
291 PressureBase* pressure = reinterpret_cast<PressureBase*>(pSpine->mExecutor);
292 pressure->exeShot();
293 }
294
295 void PressureBaseNrvPrepareToShot::execute(Spine *pSpine) const {
296 PressureBase* pressure = reinterpret_cast<PressureBase*>(pSpine->mExecutor);
297 pressure->exePrepareToShot();
298 }
299
300 void PressureBaseNrvWait::execute(Spine *pSpine) const {
301 PressureBase* pressure = reinterpret_cast<PressureBase*>(pSpine->mExecutor);
302 pressure->exeWait();
303 }
304
305 void PressureBaseNrvFirstWait::execute(Spine *pSpine) const {
306 PressureBase* pressure = reinterpret_cast<PressureBase*>(pSpine->mExecutor);
307
308 if (MR::isStep(pressure, pressure->mWaitTime)) {
309 pressure->setNerve(&NrvPressureBase::PressureBaseNrvPrepareToShot::sInstance);
310 }
311 }
312
313 void PressureBaseNrvSyncWait::execute(Spine *pSpine) const {
314
315 }
316
317 void PressureBaseNrvRelax::execute(Spine *pSpine) const {
318 PressureBase* pressure = reinterpret_cast<PressureBase*>(pSpine->mExecutor);
319
320 if (MR::isFirstStep(pressure)) {
321 pressure->_9C = -45.0f;
322 }
323 }
324
325 void PressureBaseNrvWaitStart::execute(Spine *pSpine) const {
326 PressureBase* pressure = reinterpret_cast<PressureBase*>(pSpine->mExecutor);
327 pressure->exeBound();
328 }
329
330 void PressureBaseNrvRelaxStart::execute(Spine *pSpine) const {
331 PressureBase* pressure = reinterpret_cast<PressureBase*>(pSpine->mExecutor);
332 pressure->exeBound();
333 }
334};
335
336namespace NrvPressureMessenger {
337 void PressureMessengerNrvSync::execute(Spine *pSpine) const {
338 PressureMessenger* mess = reinterpret_cast<PressureMessenger*>(pSpine->mExecutor);
339 mess->exeSync();
340 }
341};
342
343PressureMessenger::~PressureMessenger() {
344
345}
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.
void initWithoutIter()
Initializes a NameObj without a JMapInfoIter instance.
Definition NameObj.cpp:41
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.
Definition Spine.hpp:9