NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
d_a_wm_sand_pillar.cpp
1#include <game/sLib/s_GlobalData.hpp>
2#include <game/bases/d_a_wm_sand_pillar.hpp>
3#include <game/bases/d_wm_lib.hpp>
4#include <game/bases/d_cs_seq_manager.hpp>
6#include <game/bases/d_a_wm_map.hpp>
7
14STATE_DEFINE(daWmSandPillar_c, BottomWaitForever);
15STATE_DEFINE(daWmSandPillar_c, TopWaitForever);
16STATE_DEFINE(daWmSandPillar_c, TopWaitFromTheStart);
17
18ACTOR_PROFILE(WM_SANDPILLAR, daWmSandPillar_c, 0);
19
20template <>
22 .mStepInitialScale = { 0.01f, 0.01f, 0.01f },
23 .mStepAccel = { 0.001f, 0.003f, 0.003f },
24 .mStepMaxScale = { 0.03f, 0.05f, 0.05f },
25 .mPosY = { -320.0f, -200.0f, -200.0f },
26 .mBottomHeight = { 0.5f, 0.2f, 0.2f },
27 .mTopHeight = { 2.0f, 1.4f, 1.6f },
28 .mPulseBottomHeight = { 0.4f, 0.1f, 0.1f },
29 .mPulseTopHeight = { 1.1f, 1.8f, 1.8f },
30 .mPulseCount = { 3, 1, 1 },
31 .mBottomWaitTime = { 100, 10, 40 },
32 .mTopWaitTime = { 100, 100, 100 }
33};
34
37
40
41 mClipSphere.set(mPos, 350.0f);
42 calcModel();
43
44 mPos.y = GLOBAL_DATA.mPosY[getNodeIdx()];
46
47 return SUCCEEDED;
48}
49
51 dCsSeqMng_c *csSeqMng = dCsSeqMng_c::ms_instance;
52 mPos.y = GLOBAL_DATA.mPosY[getNodeIdx()];
53
54 mStateMgr.executeState();
55 if (csSeqMng->FUN_80915600()) {
56 processCutsceneCommand(csSeqMng->GetCutName(), csSeqMng->m_164);
57 }
58
59 mSrtAnim.play();
60 mModel.play();
61 calcModel();
63
64 return SUCCEEDED;
65}
66
68 mVec3_c pos = mPos;
69 mAng3_c angle = mAngle;
70 mMatrix.trans(pos);
71 mMatrix.ZXYrotM(angle);
72 mModel.setLocalMtx(&mMatrix);
73 mModel.setScale(mScale);
74 mModel.calc(false);
75}
76
78
80 mModel.entry();
81 return SUCCEEDED;
82}
83
85 mAllocator.createFrmHeap(-1, mHeap::g_gameHeaps[mHeap::GAME_HEAP_DEFAULT], nullptr, 0x20);
86 mResFile = dResMng_c::m_instance->getRes("cobSandpillar", "g3d/model.brres");
87
88 nw4r::g3d::ResMdl resMdl = mResFile.GetResMdl("cobSandpillar");
89 mModel.create(resMdl, &mAllocator,
90 nw4r::g3d::ScnMdl::BUFFER_RESMATMISC | nw4r::g3d::ScnMdl::BUFFER_RESTEXSRT | nw4r::g3d::ScnMdl::ANM_TEXPAT);
91
92 nw4r::g3d::ResAnmChr resAnmChr = mResFile.GetResAnmChr("cobSandpillar");
93 mChrAnim.create(resMdl, resAnmChr, &mAllocator);
94
95 mResAnmTexSrt = mResFile.GetResAnmTexSrt("cobSandpillar");
96 mSrtAnim.create(resMdl, mResAnmTexSrt, &mAllocator);
98 mModel.setAnm(mSrtAnim, 1.0f);
99
100 mAllocator.adjustFrmHeap();
101}
102
116
117// -------------
118// StateID_Ready
119// -------------
120
121void daWmSandPillar_c::initializeState_Ready() {
122 if (getNodeIdx() == NODE_1 || getNodeIdx() == NODE_2) {
123 mHasCourseCond = TRUE;
124 } else {
125 mHasCourseCond = FALSE;
126 }
127}
128
129void daWmSandPillar_c::executeState_Ready() {
130 if (mHasCourseCond) {
131 int world = daWmMap_c::GetCurrentWorld();
132 int course = dWmLib::GetCourseNoFromPointName("W205");
133 if (dWmLib::IsCourseClear(world, course)) {
134 if (dWmLib::IsCourseFirstClear(world, course)) {
135 mStateMgr.changeState(StateID_BottomWait);
136 } else {
138 }
139 } else {
141 }
142 } else {
143 mStateMgr.changeState(StateID_BottomWait);
144 }
145}
146
147void daWmSandPillar_c::finalizeState_Ready() {}
148
149// ------------------
150// StateID_BottomWait
151// ------------------
152
153void daWmSandPillar_c::initializeState_BottomWait() {
154 mWaitTimer = GLOBAL_DATA.mBottomWaitTime[getNodeIdx()];
155 mScale.y = GLOBAL_DATA.mBottomHeight[getNodeIdx()];
156
157 nw4r::g3d::ResAnmChr resAnmChr = mResFile.GetResAnmChr("cobSandpillar");
158 mChrAnim.setAnm(mModel, resAnmChr, m3d::FORWARD_LOOP);
159 mChrAnim.setRate(1.0f);
160 mModel.setAnm(mChrAnim, 1.0f);
161
162 mIsPulsing = false;
163}
164
165void daWmSandPillar_c::executeState_BottomWait() {
166 if (mIsPulsing) {
167 return;
168 }
169
170 mWaitTimer--;
171 if (mWaitTimer <= 0) {
172 mStateMgr.changeState(StateID_MoveReady);
173 }
174}
175
176void daWmSandPillar_c::finalizeState_BottomWait() {}
177
178// -------------------------
179// StateID_BottomWaitForever
180// -------------------------
181
182void daWmSandPillar_c::initializeState_BottomWaitForever() {
183 mScale.y = GLOBAL_DATA.mBottomHeight[getNodeIdx()];
184
185 nw4r::g3d::ResAnmChr resAnmChr = mResFile.GetResAnmChr("cobSandpillar");
186 mChrAnim.setAnm(mModel, resAnmChr, m3d::FORWARD_LOOP);
187 mChrAnim.setRate(1.0f);
188 mModel.setAnm(mChrAnim, 1.0f);
189
190 mIsPulsing = false;
191}
192
193void daWmSandPillar_c::executeState_BottomWaitForever() {}
194
195void daWmSandPillar_c::finalizeState_BottomWaitForever() {}
196
197// -----------------
198// StateID_MoveReady
199// -----------------
200
201void daWmSandPillar_c::initializeState_MoveReady() {
202 mRemainingPulses = GLOBAL_DATA.mPulseCount[getNodeIdx()];
203 mScaleStep = -GLOBAL_DATA.mStepInitialScale[getNodeIdx()];
204 mScale.y = GLOBAL_DATA.mBottomHeight[getNodeIdx()];
205 mStepAccel = GLOBAL_DATA.mStepAccel[getNodeIdx()];
206 mTargetScaleStep = -GLOBAL_DATA.mStepMaxScale[getNodeIdx()];
207 mIsPulsing = true;
208 mChrAnim.setRate(0.0f);
209}
210
211void daWmSandPillar_c::executeState_MoveReady() {
212 float pulseBottomHeight = GLOBAL_DATA.mPulseBottomHeight[getNodeIdx()];
213 float pulseTopHeight = GLOBAL_DATA.mPulseTopHeight[getNodeIdx()];
214
215 if (mIsPulsing == true) {
216 float prevScaleY = mScale.y;
217 float prevStep = mScaleStep;
219 mScale.y += mScaleStep;
220
221 // Once the scale step is zero, reverse direction for the next pulse
222 if (mScaleStep == 0.0f) {
223 if (prevStep > 0.0f) {
224 mTargetScaleStep = -GLOBAL_DATA.mStepMaxScale[getNodeIdx()];
225 } else if (prevStep < 0.0f) {
226 mTargetScaleStep = GLOBAL_DATA.mStepMaxScale[getNodeIdx()];
227 }
228 }
229
230 if (prevScaleY < pulseTopHeight && mScale.y >= pulseTopHeight) {
231 // Reached top pulse height, brake and count one completed pulse
232 mTargetScaleStep = 0.0f;
234 } else if (prevScaleY > pulseBottomHeight && mScale.y <= pulseBottomHeight) {
235 // Reached bottom pulse height: brake before rising again
236 mTargetScaleStep = 0.0f;
237 }
238
239 if (mRemainingPulses <= 0) {
240 mStateMgr.changeState(StateID_MoveUp);
241 }
242 }
243}
244
245void daWmSandPillar_c::finalizeState_MoveReady() {}
246
247// --------------
248// StateID_MoveUp
249// --------------
250
251void daWmSandPillar_c::initializeState_MoveUp() {
252 mTargetScaleStep = GLOBAL_DATA.mStepMaxScale[getNodeIdx()];
253 mStepAccel = GLOBAL_DATA.mStepAccel[getNodeIdx()];
254 if (mHasCourseCond) {
255 mStepAccel = GLOBAL_DATA.mStepAccel[getNodeIdx()];
256 mTargetScaleStep = -GLOBAL_DATA.mStepMaxScale[getNodeIdx()];
257 }
258
259 mChrAnim.setRate(0.0f);
260}
261
262void daWmSandPillar_c::executeState_MoveUp() {
263 float topHeight = GLOBAL_DATA.mTopHeight[getNodeIdx()];
264 float pulseTopHeight = GLOBAL_DATA.mPulseTopHeight[getNodeIdx()];
265
267 mScale.y += mScaleStep;
268
269 if (mHasCourseCond) {
270 if (mScaleStep <= 0.0f && mScale.y <= topHeight) {
271 mScale.y = topHeight;
273 }
274 } else {
275 if (topHeight >= pulseTopHeight) {
276 if (mScale.y >= topHeight) {
277 mScale.y = topHeight;
278 mStateMgr.changeState(StateID_TopWait);
279 }
280 } else {
281 if (mScale.y <= topHeight) {
282 mScale.y = topHeight;
283 mStateMgr.changeState(StateID_TopWait);
284 }
285 }
286 }
287}
288
289void daWmSandPillar_c::finalizeState_MoveUp() {}
290
291// ---------------
292// StateID_TopWait
293// ---------------
294
295void daWmSandPillar_c::initializeState_TopWait() {
296 mChrAnim.setRate(1.0f);
297 mWaitTimer = GLOBAL_DATA.mTopWaitTime[getNodeIdx()];
298}
299
300void daWmSandPillar_c::executeState_TopWait() {
301 mWaitTimer--;
302 if (mWaitTimer <= 0) {
303 mStateMgr.changeState(StateID_MoveDown);
304 }
305}
306
307void daWmSandPillar_c::finalizeState_TopWait() {}
308
309// ----------------------
310// StateID_TopWaitForever
311// ----------------------
312
313void daWmSandPillar_c::initializeState_TopWaitForever() {
314 mChrAnim.setRate(1.0f);
315 mScaleStep = 0.0f;
316 mWaitTimer = GLOBAL_DATA.mTopWaitTime[getNodeIdx()];
317}
318
319void daWmSandPillar_c::executeState_TopWaitForever() {}
320
321void daWmSandPillar_c::finalizeState_TopWaitForever() {}
322
323// ----------------
324// StateID_MoveDown
325// ----------------
326
327void daWmSandPillar_c::initializeState_MoveDown() {
328 mChrAnim.setRate(0.0f);
329 mScaleStep = 0.0f;
330 mTargetScaleStep = -GLOBAL_DATA.mStepMaxScale[getNodeIdx()];
331}
332
333void daWmSandPillar_c::executeState_MoveDown() {
334 float bottomHeight = GLOBAL_DATA.mBottomHeight[getNodeIdx()];
336 mScale.y += mScaleStep;
337 if (mScale.y <= bottomHeight) {
338 mScale.y = bottomHeight;
339 mStateMgr.changeState(StateID_BottomWait);
340 }
341}
342
343void daWmSandPillar_c::finalizeState_MoveDown() {}
344
345// ---------------------------
346// StateID_TopWaitFromTheStart
347// ---------------------------
348
349void daWmSandPillar_c::initializeState_TopWaitFromTheStart() {
350 nw4r::g3d::ResAnmChr resAnmChr = mResFile.GetResAnmChr("cobSandpillar");
351 mChrAnim.setAnm(mModel, resAnmChr, m3d::FORWARD_LOOP);
352 mChrAnim.setRate(1.0f);
353 mModel.setAnm(mChrAnim, 1.0f);
354 mScale.y = GLOBAL_DATA.mTopHeight[getNodeIdx()];
355}
356
357void daWmSandPillar_c::executeState_TopWaitFromTheStart() {
359}
360
361void daWmSandPillar_c::finalizeState_TopWaitFromTheStart() {}
362
363void daWmSandPillar_c::processCutsceneCommand(int cutsceneCommandId, bool isFirstFrame) {
364 if (cutsceneCommandId != dCsSeqMng_c::CUTSCENE_CMD_NONE && !isStaff()) {
365 mIsCutEnd = true;
366 }
367}
368
370 mVec3_c efPos;
371 ulong nodeId = m3d::getNodeID(mModel.getResMdl(), "ef_cobSandpillar");
372 mModel.getNodeWorldMtxMultVecZero(nodeId, efPos);
373
374 mEffect1.createEffect("Wm_cs_sandpillar01", 0, &efPos, nullptr, nullptr);
375 mEffect2.createEffect("Wm_cs_sandpillar02", 0, &efPos, nullptr, nullptr);
376}
mMtx_c mMatrix
The actor's partial transformation matrix. See makeMtx() for details.
mVec3_c mScale
The actor's scale (defaults to 1).
mVec3_c mPos
The actor's position.
mAng3_c mAngle
The actor's rotation (for 2D actors).
bool FUN_80915600()
static dResMng_c * m_instance
The instance of this class.
Definition d_res_mng.hpp:71
mSphere_c mClipSphere
A sphere representing the actor's visible area.
static u8 GetCurrentWorld()
The sand pillar world map actor.
dHeapAllocator_c mAllocator
The allocator.
static sFStateID_c< daWmSandPillar_c > StateID_MoveDown
Retracting back to the bottom scale.
static sFStateID_c< daWmSandPillar_c > StateID_TopWaitFromTheStart
Initializing directly at the top before waiting indefinitely.
virtual void finalUpdate()
Code to be executed after all actors' execute operation has run.
void calcModel()
Updates the model's transformation matrix.
int mWaitTimer
The countdown timer for the Wait states.
sFStateMgr_c< daWmSandPillar_c, sStateMethodUsr_FI_c > mStateMgr
The state manager.
void createEffect()
Creates the sand effects.
m3d::mdl_c mModel
The model.
nw4r::g3d::ResAnmTexSrt mResAnmTexSrt
The texture animation resource.
static sFStateID_c< daWmSandPillar_c > StateID_BottomWait
Waiting at the bottom before pulsing.
virtual void processCutsceneCommand(int cutsceneCommandId, bool isFirstFrame)
Contains the actor-specific logic for processing the current world map cutscene.
static sFStateID_c< daWmSandPillar_c > StateID_Ready
Initial state.
float mStepAccel
The rate at which the scale step approaches mTargetScaleStep.
m3d::anmChr_c mChrAnim
The model animation.
void calcScaleStep()
Updates the movement scale step.
~daWmSandPillar_c()
Destroys the object.
virtual int create()
do method for the create operation.
m3d::anmTexSrt_c mSrtAnim
The texture animation.
virtual int execute()
do method for the execute operation.
BOOL mIsPulsing
Whether the pillar is doing a regular pulse.
void createModel()
Initializes the resources for the actor.
static sFStateID_c< daWmSandPillar_c > StateID_MoveReady
Pulsing up and down before rising to full height.
BOOL mHasCourseCond
Whether the actor is linked to a specific course.
float mTargetScaleStep
The target scale step.
daWmSandPillar_c()
Constructs a new object.
mVec3_c mInitialPos
The actor's initial position.
nw4r::g3d::ResFile mResFile
The resource file.
float mScaleStep
The current scale step.
static sFStateID_c< daWmSandPillar_c > StateID_TopWait
Waiting at the top before retracting.
virtual int draw()
do method for the draw operation.
static sFStateID_c< daWmSandPillar_c > StateID_MoveUp
Rising to the top scale.
int mRemainingPulses
The remaining pulse cycles before the pillar moves all the way to the top.
static sFStateID_c< daWmSandPillar_c > StateID_TopWaitForever
Waiting indefinitely at the top.
static sFStateID_c< daWmSandPillar_c > StateID_BottomWaitForever
Waiting indefinitely at the bottom.
@ SUCCEEDED
The step was completed successfully.
Definition f_base.hpp:47
A three-dimensional short angle vector.
Definition m_angle.hpp:72
A three-dimensional floating point vector.
Definition m_vec.hpp:122
static const T::GlobalData_t mData
#define ACTOR_PROFILE(profName, className, properties)
Creates an actor profile, using the profile number as the execute and draw order value.
Definition f_profile.hpp:29
@ FORWARD_LOOP
Play the animation forward in a loop.
Definition banm.hpp:8
@ GAME_HEAP_DEFAULT
The default game heap (alias of MEM1 or MEM2).
Definition m_heap.hpp:38
EGG::ExpHeap * g_gameHeaps[GAME_HEAP_COUNT]
The game heaps.
Definition m_heap.cpp:13
#define STATE_DEFINE(class, name)
Defines a state.
Definition s_State.hpp:36
The global configuration for the actor.