SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
BigFan.cpp
1#include "Game/MapObj/BigFan.hpp"
2#include "Game/MapObj/BigFanHolder.hpp"
3#include "Game/LiveActor/ModelObj.hpp"
4#include "JSystem/JMath/JMath.hpp"
5
6BigFan::BigFan(const char *pName) : LiveActor(pName) {
7 mWindModel = 0;
8 _90.x = 0.0f;
9 _90.y = 0.0f;
10 _90.z = 0.0f;
11 mWindLength = 4000.0f;
12 _A0 = 100.0f;
13 mIsTeresaGalaxy = false;
14 BigFanFunction::createBigFanHolder();
15 BigFanFunction::registerBigFan(this);
16}
17
18void BigFan::init(const JMapInfoIter &rIter) {
19 MR::initDefaultPos(this, rIter);
20 const char* object_name;
21 MR::getObjectName(&object_name, rIter);
22 initModelManagerWithAnm(object_name, 0, false);
23 MR::connectToSceneNoSilhouettedMapObj(this);
24
25 if (MR::isExistCollisionResource(this, object_name)) {
26 initHitSensor(1);
27 MR::addBodyMessageSensorReceiver(this);
28 MR::initCollisionParts(this, object_name, getSensor(0), 0);
29 }
30
31 MR::getJMapInfoArg0NoInit(rIter, &mWindLength);
32 MR::getJMapInfoArg1NoInit(rIter, &_A0);
33 initWindModel();
34 TVec3f front;
35 MR::calcFrontVec(&front, this);
36 JMAVECScaleAdd(front.toCVec(), mPosition.toCVec(), _90.toVec(), 0.5f * mWindLength);
37 MR::setClippingTypeSphere(this, 400.0f + mWindLength, &_90);
38 initSound(4, false);
39
40 if (MR::isEqualStageName("TeresaMario2DGalaxy")) {
41 mIsTeresaGalaxy = true;
42 }
43 else {
44 mIsTeresaGalaxy = false;
45 }
46
47 initNerve(&NrvBigFan::BigFanNrvWait::sInstance);
48 if (MR::useStageSwitchReadAppear(this, rIter)) {
49 void (BigFan::*startFunc)(void) = &BigFan::start;
50 MR::listenStageSwitchOnAppear(this, MR::Functor(this, startFunc));
51 setNerve(&NrvBigFan::BigFanNrvStop::sInstance);
52 mWindModel->kill();
53 }
54
55 MR::registerDemoSimpleCastAll(this);
56 makeActorAppeared();
57}
58
59void BigFan::initWindModel() {
60 mWindModel = MR::createModelObjMapObj("風モデル", "BigFanWind", getBaseMtx());
61 mWindModel->initWithoutIter();
62 MR::invalidateClipping(mWindModel);
63 MR::startBtk(mWindModel, "BigFanWind");
64 MR::registerDemoSimpleCastAll(mWindModel);
65 mWindModel->mScale.z = mWindLength / 2000.0f;
66}
67
68void BigFan::calcWindInfo(TVec3f *pWindInfo, const TVec3f &a2) {
69 if (MR::isDead(this) || isStartOrWait()) {
70 pWindInfo->zero();
71 }
72 else {
73 if (mWindLength <= 0.0f) {
74 pWindInfo->zero();
75 return;
76 }
77
78 TVec3f front_vec;
79 MR::calcFrontVec(&front_vec, this);
80 MR::normalize(&front_vec);
81 TVec3f stack_38 = a2 - mPosition;
82 f32 dot = front_vec.dot(stack_38);
83
84 if (dot < 0.0f) {
85 pWindInfo->zero();
86 return;
87 }
88
89 TVec3f stack_2C;
90 stack_2C.setInlinePS(stack_38 - (front_vec * dot));
91 f32 mag = PSVECMag(stack_2C.toCVec());
92
93 if (mag >= 400.0f * mScale.x) {
94 pWindInfo->zero();
95 return;
96 }
97
98 f32 scalar = (1.0f - (dot / mWindLength));
99 if (scalar < 0.0f) {
100 pWindInfo->zero();
101 return;
102 }
103
104 front_vec.multAndSet(pWindInfo, scalar);
105 return;
106 }
107}
108
109void BigFan::control() {
110
111}
112
113void BigFan::start() {
114 if (isNerve(&NrvBigFan::BigFanNrvStop::sInstance)) {
115 setNerve(&NrvBigFan::BigFanNrvStart::sInstance);
116 }
117}
118
119void BigFan::exeStart() {
120 if (MR::isFirstStep(this)) {
121 mWindModel->appear();
122 MR::startAction(this, "Appear");
123 MR::startAction(mWindModel, "Appear");
124
125 if (mIsTeresaGalaxy) {
126 MR::startSound(this, "SE_OJ_BIG_FAN_START_FAR", -1, -1);
127 }
128 else {
129 MR::startSound(this, "SE_OJ_BIG_FAN_START", -1, -1);
130 }
131 }
132
133 if (MR::isActionEnd(this)) {
134 setNerve(&NrvBigFan::BigFanNrvWait::sInstance);
135 }
136}
137
138void BigFan::exeWait() {
139 if (MR::isFirstStep(this)) {
140 MR::startAction(this, "Wait");
141 MR::startAction(mWindModel, "Wait");
142 }
143
144 if (mIsTeresaGalaxy) {
145 MR::startLevelSound(this, "SE_OJ_LV_BIG_FAN_FAR", -1, -1, -1);
146 }
147 else {
148 MR::startLevelSound(this, "SE_OJ_LV_BIG_FAN", -1, -1, -1);
149 }
150}
151
152namespace NrvBigFan {
153 INIT_NERVE(BigFanNrvStop);
154 INIT_NERVE(BigFanNrvStart);
155 INIT_NERVE(BigFanNrvWait);
156
157 void BigFanNrvWait::execute(Spine *pSpine) const {
158 BigFan* fan = reinterpret_cast<BigFan*>(pSpine->mExecutor);
159 fan->exeWait();
160 }
161
162 void BigFanNrvStart::execute(Spine *pSpine) const {
163 BigFan* fan = reinterpret_cast<BigFan*>(pSpine->mExecutor);
164 fan->exeStart();
165 }
166
167 void BigFanNrvStop::execute(Spine *pSpine) const {
168 BigFan* fan = reinterpret_cast<BigFan*>(pSpine->mExecutor);
169
170 if (MR::isFirstStep(fan)) {
171 MR::startAction(fan, "Appear");
172 MR::stopBck(fan);
173 }
174 }
175};
176
177BigFan::~BigFan() {
178
179}
virtual void init(const JMapInfoIter &)
Intializes the NameObj and can set various settings and construct necessary classes.
Definition BigFan.cpp:18
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
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.
HitSensor * getSensor(const char *pSensorName) const
Gets a sensor.
void initWithoutIter()
Initializes a NameObj without a JMapInfoIter instance.
Definition NameObj.cpp:41
Definition Spine.hpp:9