SMG-Decomp
A decompilation of Super Mario Galaxy 1
Loading...
Searching...
No Matches
SeaGull.cpp
1#include "Game/Map/SeaGull.hpp"
2#include "Game/Util.hpp"
3
4NrvSeaGull::SeaGullNrvHoverFront NrvSeaGull::SeaGullNrvHoverFront::sInstance;
5NrvSeaGull::SeaGullNrvHoverLeft NrvSeaGull::SeaGullNrvHoverLeft::sInstance;
6NrvSeaGull::SeaGullNrvHoverRight NrvSeaGull::SeaGullNrvHoverRight::sInstance;
7
8SeaGull::SeaGull(SeaGullGroup *pGroup) : LiveActor("カモメ") {
9 mSeaGullGroup = pGroup;
10 _90 = 0;
11 _94 = false;
12 _98 = MR::getRandom((s32)0, (s32)0xB4);
13 _9C = 0;
14 _A0.x = 0.0f;
15 _A0.y = 1.0f;
16 _A0.z = 0.0f;
17 _AC.x = 0.0f;
18 _AC.y = 0.0f;
19 _AC.z = 1.0f;
20 _B8.x = 0.0f;
21 _B8.y = 1.0f;
22 _B8.z = 0.0f;
23 _C4.x = 1.0f;
24 _C4.y = 0.0f;
25 _C4.z = 0.0f;
26 _D0 = 0;
27 _D4 = 0.0f;
28 _D8 = 0;
29 _DC = 0;
30 _E0 = 0;
31}
32
33#ifdef NON_MATCHING
34void SeaGull::init(const JMapInfoIter &rIter) {
35 MR::initDefaultPos(this, rIter);
36 MR::calcActorAxis(&_C4, &_B8, &_AC, this);
37 MR::calcActorAxisY(&_A0, this);
38 initModelManagerWithAnm("SeaGull", 0, false);
39 MR::startBck(this, "Fly", 0);
40 MR::setBckFrameAtRandom(this);
41 MR::connectToSceneEnvironment(this);
42 f32 railLength = MR::getRailTotalLength(mSeaGullGroup);
43 f32 diff = railLength - 1.0f;
44 f32 rnd = MR::getRandom(1.0f, diff);
45 f64 val = rnd / 500.0f;
46 _90 = val;
47 MR::calcRailPosAtCoord(&mPosition, mSeaGullGroup, rnd);
48 u8 a = MR::isHalfProbability();
49 _94 = a;
50 _9C = mSeaGullGroup->updatePosInfo(&_90, a);
51
52 TVec3f stack_14(_C4);
53 TVec3f stack_8(_AC);
54 f32 scale = MR::getRandom(-1.0f, 1.0f);
55 stack_14.scale(scale);
56 scale = MR::getRandom(-1.0f, 1.0f);
57 stack_8.scale(scale);
58 _AC.set(stack_14);
59 _AC.add(stack_8);
60
61 if (MR::isNearZero(_AC, 0.001f)) {
62 _AC.x = 0.0f;
63 _AC.y = 0.0f;
64 _AC.z = 1.0f;
65 }
66 else {
67 MR::normalize(&_AC);
68 }
69
70 initNerve(&NrvSeaGull::SeaGullNrvHoverFront::sInstance);
71 initSound(4, false);
72 _E0 = MR::getRandom((s32)0x3C, (s32)0x1E0);
73 MR::invalidateClipping(this);
74 makeActorAppeared();
75}
76#endif
77
78void SeaGull::exeHoverFront() {
79 if (MR::isFirstStep(this)) {
80 _D0 = MR::getRandom((s32)0, (s32)0x3C);
81 }
82
83 _D4 *= 0.995f;
84
85 if (_D0 >= 0) {
86 _D0 = _D0 - 1;
87 }
88 else {
89 TVec3f stack_8(*_9C);
90 stack_8.sub(mPosition);
91 f32 dist = PSVECDistance((const Vec*)&mPosition, (const Vec*)_9C);
92
93 if (dist > 500.0f) {
94 f32 prod = _C4.dot(stack_8);
95
96 if (prod > 0.0f) {
97 setNerve(&NrvSeaGull::SeaGullNrvHoverLeft::sInstance);
98 }
99 else {
100 setNerve(&NrvSeaGull::SeaGullNrvHoverRight::sInstance);
101 }
102 }
103 }
104}
105
106void SeaGull::exeHoverLeft() {
107 if (MR::isFirstStep(this)) {
108 _D0 = MR::getRandom((s32)0x3C, (s32)0x78);
109 }
110
111 _D4 -= 0.1f;
112
113 if (MR::isStep(this, _D0)) {
114 setNerve(&NrvSeaGull::SeaGullNrvHoverFront::sInstance);
115 }
116}
117
118void SeaGull::exeHoverRight() {
119 if (MR::isFirstStep(this)) {
120 _D0 = MR::getRandom((s32)0x3C, (s32)0x78);
121 }
122
123 _D4 += 0.1f;
124
125 if (MR::isStep(this, _D0)) {
126 setNerve(&NrvSeaGull::SeaGullNrvHoverFront::sInstance);
127 }
128}
129
130void SeaGull::control() {
131 updateHover();
132
133 mVelocity.x *= 0.99000001f;
134 mVelocity.y *= 0.99000001f;
135 mVelocity.z *= 0.99000001f;
136
137 f32 mag = PSVECMag((const Vec*)&mVelocity);
138
139 if (mag > 0.0f) {
140 MR::normalize(&mVelocity);
141 mVelocity.x *= 10.0f;
142 mVelocity.y *= 10.0f;
143 mVelocity.z *= 10.0f;
144 }
145
146 PSVECCrossProduct((const Vec*)&_B8, (const Vec*)&_AC, (Vec*)&_C4);
147 MR::normalize(&_C4);
148 PSVECCrossProduct((const Vec*)&_AC, (const Vec*)&_C4, (Vec*)&_B8);
149 MR::normalize(&_B8);
150 _98 -= 1;
151
152 if (_98 <= 0) {
153 _9C = mSeaGullGroup->updatePosInfo(&_90, _94);
154 _98 = 0xB4;
155 }
156
157 if (_E0 <= 0) {
158 MR::startSound(this, "SE_OJ_SEAGULL_CHIRP", -1, -1);
159 _E0 = MR::getRandom((s32)0x3C, (s32)0x1E0);
160 }
161 else {
162 _E0--;
163 }
164
165 if (MR::isJudgedToClipFrustum300m(mPosition, 200.0f)) {
166 if (!MR::isHiddenModel(this)) {
167 MR::hideModel(this);
168 }
169 }
170 else {
171 if (MR::isHiddenModel(this)) {
172 MR::showModel(this);
173 }
174 }
175}
176
178 TPos3f mtx;
179 mtx.identity();
180 mtx.mMtx[0][0] = _C4.x;
181 mtx.mMtx[1][0] = _C4.y;
182 mtx.mMtx[2][0] = _C4.z;
183 mtx.mMtx[0][1] = _B8.x;
184 mtx.mMtx[1][1] = _B8.y;
185 mtx.mMtx[2][1] = _B8.z;
186 mtx.mMtx[0][2] = _AC.x;
187 mtx.mMtx[1][2] = _AC.y;
188 mtx.mMtx[2][2] = _AC.z;
189 mtx.mMtx[0][3] = mPosition.x;
190 mtx.mMtx[1][3] = mPosition.y;
191 mtx.mMtx[2][3] = mPosition.z;
192 MR::setBaseTRMtx(this, mtx);
193}
194
195SeaGullGroup::SeaGullGroup(const char *pName) : LiveActor(pName) {
196 _8C = 0;
197 _90 = 0;
198}
199
200TVec3f* SeaGullGroup::updatePosInfo(s32 *a1, bool a2) const {
201 if (a2) {
202 if (--*a1 <= 0) {
203 *a1 = _8C - 1;
204 }
205 }
206 else {
207 s32 val = _8C;
208 s32 next = *a1 + 1;
209 *a1 = next;
210
211 if (next >= val) {
212 *a1 = 0;
213 }
214 }
215
216 return &_90[*a1];
217}
218
219SeaGull::~SeaGull() {
220
221}
222
223SeaGullGroup::~SeaGullGroup() {
224
225}
226
227namespace NrvSeaGull {
228 void SeaGullNrvHoverRight::execute(Spine *pSpine) const {
229 SeaGull* gull = reinterpret_cast<SeaGull*>(pSpine->mExecutor);
230 gull->exeHoverRight();
231 }
232
233 void SeaGullNrvHoverLeft::execute(Spine *pSpine) const {
234 SeaGull* gull = reinterpret_cast<SeaGull*>(pSpine->mExecutor);
235 gull->exeHoverLeft();
236 }
237
238 void SeaGullNrvHoverFront::execute(Spine *pSpine) const {
239 SeaGull* gull = reinterpret_cast<SeaGull*>(pSpine->mExecutor);
240 gull->exeHoverFront();
241 }
242};
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 mVelocity
3D vector of the actor's velocity.
Definition LiveActor.hpp:98
virtual void calcAndSetBaseMtx()
Calculates and sets the base matrix of the actor.
Definition SeaGull.cpp:177
virtual void init(const JMapInfoIter &)
Intializes the NameObj and can set various settings and construct necessary classes.
Definition Spine.hpp:9