NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
d_a_en_snake_block.hpp
1#pragma once
2#include <game/bases/d_enemy.hpp>
3#include <game/bases/d_bg_ctr.hpp>
4#include <game/bases/d_heap_allocator.hpp>
5#include <game/mLib/m_3d/anm_mat_clr.hpp>
6#include <game/mLib/m_3d/mdl.hpp>
7
8#define MAX_SNAKE_BLOCK_COUNT 20
9
10/// @brief A Snake Block which travels along a rail.
11/// @paramtable
12/// @statetable
13/// @ingroup bases
14class daEnSnakeBlock_c : public dEn_c {
15public:
16
17 /// @brief A single block segment within the Snake Block actor.
18 /// @details Manages its own 3D model, animations, collision, and physics.
19 class dBlock_c {
20 public:
21 /// @brief Creates a block.
22 dBlock_c() : mpOwner(nullptr), m_1b4(0) {}
23
24 /// @brief Destroys the block.
25 virtual ~dBlock_c() { mBgCtr.release(); }
26
27 /// @brief Initializes the 3D model, textures, and color animations.
28 /// @param allocator The allocator to use for the model and animation data.
29 void createMdl(mAllocator_c *allocator);
30
31 /// @brief Initializes the block's collision.
32 /// @param parent The parent Snake Block actor.
33 /// @param blockPos The block position.
34 /// @param icy Whether the surface must be icy.
35 void initCollision(daEnSnakeBlock_c *parent, mVec3_c &blockPos, bool icy);
36
37 /// @brief Sets the color animation for the block.
38 /// @param name The animation name.
39 void setAnmClr(const char *name);
40
41 /// @brief Renders the block model.
42 /// @param offset The offset from the block position, used for the shaking animation.
43 void draw(const mVec3_c &offset);
44
45 /// @brief Updates the block's position when in the @ref StateID_Collapse1 "Collapse1 state".
46 void calcCollapse1(s8 *moveSequence);
47 void calcCollision(); ///< Updates the block's collision based on its offset from the parent.
48 void calcFallSpeed(); ///< Updates the block's falling speed.
49 void calcAnm(); ///< Advances the animations for the block.
50
51 mVec3_c getPos() const { return mPos; }
52 void setPos(mVec3_c pos) { mPos = pos; }
53 void posMove() { mPos += mSpeed; } ///< Moves the block by its @ref mSpeed "speed".
54
55 void deleteBlock(); ///< Releases the model and associated animation resources.
56
57 /// @brief Releases the block's collision.
58 void releaseBgCtr() {
59 if (mBgCtr.m_dc) {
60 mBgCtr.release();
61 }
62 }
63
64 static dBg_ctr_c::CallbackF callBackF; ///< The floor collision callback.
65 static dBg_ctr_c::CallbackH callBackH; ///< The ceiling collision callback.
66 static dBg_ctr_c::CallbackW callBackW; ///< The side collision callback.
67
68 nw4r::g3d::ResFile mResFile; ///< The resource file.
69 m3d::mdl_c mModel; ///< The block model.
70 m3d::anmMatClr_c mAnmClr; ///< The color animation.
71 nw4r::g3d::ResAnmTexSrt mResTexSrt; ///< The texture animation resource.
72 m3d::anmTexSrt_c mAnmTexSrt; ///< The texture animation.
73
74 mVec3_c mPos; ///< The block's position (center of block).
75 mVec3_c mSpeed; ///< The block' speed.
76 mVec3_c mLastPos; ///< The block's position in the previous movement.
77
78 dBg_ctr_c mBgCtr; ///< The collision.
79 int mMoveSequenceIdx; ///< The block's current step in the movement sequence.
80 daEnSnakeBlock_c *mpOwner; ///< The parent Snake Block actor.
81
82 s16 m_1b4; ///< @unused
83 };
84
85 /// @brief Specialized block representing the head or tail of the Snake Block.
86 /// @details Contains logic for advancing the block along the precalculated path.
87 class dCtrlBlock_c : public dBlock_c {
88 public:
89 /// @brief The possible speed modes of a Snake Block.
91 SNAKE_SPEED_SLOW,
92 SNAKE_SPEED_MEDIUM,
93 SNAKE_SPEED_FAST,
94 SNAKE_SPEED_COUNT
95 };
96
97 dCtrlBlock_c() {} ///< @copydoc dBlock_c::dBlock_c
98 virtual ~dCtrlBlock_c() { mBgCtr.release(); } ///< @copydoc dBlock_c::~dBlock_c
99
100 /// @brief Moves the block in the direction specified by the current sequence step.
101 /// @param moveSequence The sequence of movement directions.
102 /// @return Whether the block is ready for the next move.
103 bool moveBlock(s8 *moveSequence);
104
105 /// @brief Snaps the block to the grid and advances the sequence index to the next step.
106 /// @param moveSequence The sequence of movement directions.
107 /// @return Whether the block has reached the end of the movement sequence.
108 bool nextTravelMove(s8 *moveSequence);
109
110 SnakeSpeed_e mSnakeSpeed; ///< The speed mode for this block.
111 };
112
113 enum MoveDir_e {
114 MOVE_DIR_NONE,
115 MOVE_DIR_UP,
116 MOVE_DIR_DOWN,
117 MOVE_DIR_LEFT,
118 MOVE_DIR_RIGHT,
119 MOVE_DIR_COUNT
120 };
121
122 /// @brief Creates a Snake Block.
124
125 /// @brief Destroys the Snake Block.
126 virtual ~daEnSnakeBlock_c() {}
127
128 virtual int create();
129 virtual int doDelete();
130 virtual int execute();
131 virtual int draw();
132 virtual void deleteReady();
133
134 /// @brief Rasterizes the rail path into the @ref mpMoveSequence "sequence of movements".
135 /// @details Diagonal steps are converted automatically to a staircase pattern.
136 void initMoveSequence();
137 void initBlocks(); ///< Initializes various components.
138 void initBlockCollision(); ///< Initializes the collision for the head, body, and tail segments.
139 void createMdl(); ///< Creates the model and animations for each block.
140 void setStopState(); ///< Sets the state to transition to after the Snake Block reaches the end of the rail.
141
142 void calcAnm(); ///< Advances the animations for all blocks in the Snake Block.
143 void calcCollision(); ///< Updates each block's collision.
144 void calcBlockPos(); ///< Updates each body block's position.
145 void calcActorPos(); ///< Updates the Snake Block's position to match the head block's.
146
147 /// @brief Checks whether the tail block is below the screen edge.
148 /// @details Used by the collapse states to check if the actor can be deleted.
149 bool chkCollapseDelete();
151 /// @brief Checks whether the Snake Block is far past the right edge of the screen.
152 /// @details Used to delete the actor if it goes off-screen.
153 bool chkOffScreen();
154
155 void deleteBlocks(); ///< Releases the resources for each block.
156
157 dCtrlBlock_c &getHeadBlock() { return mCtrlBlock[0]; }
158 dCtrlBlock_c &getTailBlock() { return mCtrlBlock[1]; }
159
160 dHeapAllocator_c mAllocator; ///< The allocator.
161 dCtrlBlock_c mCtrlBlock[2]; ///< The head and tail blocks.
162 dBlock_c mBlocks[MAX_SNAKE_BLOCK_COUNT]; ///< The blocks between the head and tail. Only the first #mBlockCount of these are used.
163 int mBlockCount; ///< The number of blocks between the head and tail.
165 /// @brief The precalculated sequence of movements each block has to perform to reach the end of the rail.
166 /// @details Each value is a MoveDir_e.
168 int mMoveSequenceIdx; ///< The current index into #mpMoveSequence.
169 s16 mShakeTimer; ///< Counts down frames for the shake animation at the end of the rail.
170 sStateID_c *mpStopState; ///< The state to transition to when the Snake Block stops.
171
172 /// @brief The snake type.
173 /// @decompnote{Has no effect in-game, but might have been intended for ice / no ice variants.}
175 int mCollapseTimer; ///< The timer used by the @ref StateID_Collapse2 "Collapse2 state" to delay the fall of each block.
176 int mGradientActiveBlocks; ///< The number of blocks currently displaying the gradient animation.
177 int mGradientMaxBlocks; ///< The maximum number of blocks the gradient animation can cover.
178 u8 mPad[4]; ///< @unused
179
180 ACTOR_PARAM_CONFIG(BlockCount, 0, 4); ///< The number of blocks between the head and tail.
181 ACTOR_PARAM_CONFIG(RailID, 4, 4); ///< The ID of the rail that the Snake Block travels along.
182 ACTOR_PARAM_CONFIG(SnakeSpeed, 8, 2); ///< The snake's speed. See dCtrlBlock_c::SnakeSpeed_e.
183 ACTOR_PARAM_CONFIG(RailStartIdx, 12, 8); ///< The rail node index where the snake spawns.
184 ACTOR_PARAM_CONFIG(SnakeType, 20, 1); ///< The snake type. See #mSnakeType.
185 ACTOR_PARAM_CONFIG(StopMode, 28, 4); ///< Determines how the Snake Block behaves after terminating.
186
187 static const float sc_FallAccel; ///< The gravity acceleration applied during a collapse.
188 static const float sc_FallMaxSpeed; ///< The terminal velocity applied during a collapse.
189 static const float sc_SnakeSpeeds[dCtrlBlock_c::SNAKE_SPEED_COUNT]; ///< The speed values corresponding to SnakeSpeed_e. @hideinitializer
190 static const float sc_SnakeSpeeds2[dCtrlBlock_c::SNAKE_SPEED_COUNT]; ///< Alternate array of speed values. @unused @hideinitializer
191 static const mVec2_c sc_TravelDirs[MOVE_DIR_COUNT]; ///< The unit vector for each movement direction. @hideinitializer
192 static const int scSnakeSoundID; ///< The sound effect ID played while the snake moves.
193 static int g_SnakeNum; ///< Global counter for the active Snake Blocks.
194
195 STATE_FUNC_DECLARE(daEnSnakeBlock_c, Wait); ///< Waiting for a player to land on the Snake Block to start moving.
196 STATE_FUNC_DECLARE(daEnSnakeBlock_c, Move); ///< Moving along the rail.
197 STATE_FUNC_DECLARE(daEnSnakeBlock_c, Shake); ///< Shaking before collapsing.
198 STATE_FUNC_DECLARE(daEnSnakeBlock_c, Stop); ///< Stopped at the end of the rail.
199 STATE_FUNC_DECLARE(daEnSnakeBlock_c, Collapse1); ///< Collapse mode 1: Blocks travel all the way to the final rail node and then fall.
200 STATE_FUNC_DECLARE(daEnSnakeBlock_c, Collapse2); ///< Collapse mode 2: Blocks fall one after another, with a delay between each.
201 STATE_FUNC_DECLARE(daEnSnakeBlock_c, Collapse3); ///< Collapse mode 3: Blocks fall all at once.
202};
mVec3_c mPos
The actor's position.
dEn_c()
Constructs a new enemy actor.
Definition d_enemy.cpp:28
A single block segment within the Snake Block actor.
void deleteBlock()
Releases the model and associated animation resources.
mVec3_c mLastPos
The block's position in the previous movement.
void releaseBgCtr()
Releases the block's collision.
static dBg_ctr_c::CallbackH callBackH
The ceiling collision callback.
void calcCollapse1(s8 *moveSequence)
Updates the block's position when in the Collapse1 state.
mVec3_c mSpeed
The block' speed.
daEnSnakeBlock_c * mpOwner
The parent Snake Block actor.
int mMoveSequenceIdx
The block's current step in the movement sequence.
m3d::anmMatClr_c mAnmClr
The color animation.
void calcAnm()
Advances the animations for the block.
void posMove()
Moves the block by its speed.
dBg_ctr_c mBgCtr
The collision.
mVec3_c mPos
The block's position (center of block).
nw4r::g3d::ResAnmTexSrt mResTexSrt
The texture animation resource.
nw4r::g3d::ResFile mResFile
The resource file.
void calcCollision()
Updates the block's collision based on its offset from the parent.
static dBg_ctr_c::CallbackW callBackW
The side collision callback.
void initCollision(daEnSnakeBlock_c *parent, mVec3_c &blockPos, bool icy)
Initializes the block's collision.
m3d::anmTexSrt_c mAnmTexSrt
The texture animation.
void calcFallSpeed()
Updates the block's falling speed.
void setAnmClr(const char *name)
Sets the color animation for the block.
virtual ~dBlock_c()
Destroys the block.
m3d::mdl_c mModel
The block model.
static dBg_ctr_c::CallbackF callBackF
The floor collision callback.
Specialized block representing the head or tail of the Snake Block.
SnakeSpeed_e
The possible speed modes of a Snake Block.
virtual ~dCtrlBlock_c()
Destroys the block.
bool moveBlock(s8 *moveSequence)
Moves the block in the direction specified by the current sequence step.
SnakeSpeed_e mSnakeSpeed
The speed mode for this block.
bool nextTravelMove(s8 *moveSequence)
Snaps the block to the grid and advances the sequence index to the next step.
int mBlockCount
The number of blocks between the head and tail.
sStateID_c * mpStopState
The state to transition to when the Snake Block stops.
virtual ~daEnSnakeBlock_c()
Destroys the Snake Block.
int mSnakeType
The snake type.
ACTOR_PARAM_CONFIG(SnakeSpeed, 8, 2)
The snake's speed. See dCtrlBlock_c::SnakeSpeed_e.
ACTOR_PARAM_CONFIG(BlockCount, 0, 4)
The number of blocks between the head and tail.
bool chkOffScreen()
Checks whether the Snake Block is far past the right edge of the screen.
static const mVec2_c sc_TravelDirs[MOVE_DIR_COUNT]
The unit vector for each movement direction.
void initMoveSequence()
Rasterizes the rail path into the sequence of movements.
static const float sc_FallMaxSpeed
The terminal velocity applied during a collapse.
dHeapAllocator_c mAllocator
The allocator.
static const int scSnakeSoundID
The sound effect ID played while the snake moves.
ACTOR_PARAM_CONFIG(StopMode, 28, 4)
Determines how the Snake Block behaves after terminating.
static const float sc_FallAccel
The gravity acceleration applied during a collapse.
int mGradientActiveBlocks
The number of blocks currently displaying the gradient animation.
void createMdl()
Creates the model and animations for each block.
ACTOR_PARAM_CONFIG(SnakeType, 20, 1)
The snake type. See mSnakeType.
dCtrlBlock_c mCtrlBlock[2]
The head and tail blocks.
void calcAnm()
Advances the animations for all blocks in the Snake Block.
void deleteBlocks()
Releases the resources for each block.
ACTOR_PARAM_CONFIG(RailStartIdx, 12, 8)
The rail node index where the snake spawns.
int mMoveSequenceIdx
The current index into mpMoveSequence.
dBlock_c mBlocks[20]
The blocks between the head and tail. Only the first mBlockCount of these are used.
bool chkCollapseDelete()
Checks whether the tail block is below the screen edge.
virtual int execute()
do method for the execute operation.
int mCollapseTimer
The timer used by the Collapse2 state to delay the fall of each block.
virtual int create()
do method for the create operation.
s8 * mpMoveSequence
The precalculated sequence of movements each block has to perform to reach the end of the rail.
void calcActorPos()
Updates the Snake Block's position to match the head block's.
void calcBlockPos()
Updates each body block's position.
void calcCollision()
Updates each block's collision.
s16 mShakeTimer
Counts down frames for the shake animation at the end of the rail.
virtual int doDelete()
do method for the delete operation.
static const float sc_SnakeSpeeds2[dCtrlBlock_c::SNAKE_SPEED_COUNT]
Alternate array of speed values.
ACTOR_PARAM_CONFIG(RailID, 4, 4)
The ID of the rail that the Snake Block travels along.
void initBlockCollision()
Initializes the collision for the head, body, and tail segments.
virtual void deleteReady()
Informs the base that it's about to be deleted.
void setStopState()
Sets the state to transition to after the Snake Block reaches the end of the rail.
daEnSnakeBlock_c()
Creates a Snake Block.
void initBlocks()
Initializes various components.
static const float sc_SnakeSpeeds[dCtrlBlock_c::SNAKE_SPEED_COUNT]
The speed values corresponding to SnakeSpeed_e.
int mGradientMaxBlocks
The maximum number of blocks the gradient animation can cover.
static int g_SnakeNum
Global counter for the active Snake Blocks.
virtual int draw()
do method for the draw operation.
An allocator class that wraps an EGG:Allocator .
A two-dimensional floating point vector.
Definition m_vec.hpp:26
A three-dimensional floating point vector.
Definition m_vec.hpp:122
A generic implementation of a state ID.
Definition s_StateID.hpp:7
#define STATE_FUNC_DECLARE(class, name)
Declares a state.
Definition s_State.hpp:12