NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
d_a_en_door.cpp
1#include <game/bases/d_a_en_door.hpp>
3#include <game/bases/d_actor_manager.hpp>
4#include <game/bases/d_a_player.hpp>
5#include <game/framework/f_profile_name.hpp>
6#include <game/mLib/m_effect.hpp>
7#include <game/mLib/m_allocator_dummy_heap.hpp>
9
15
17 daObjCenter_c *result = nullptr;
18
19 while ((result = (daObjCenter_c *) fManager_c::searchBaseByProfName(fProf::OBJ_CENTER, result))) {
20 if (rotationID == result->mRotationID) {
21 return result;
22 }
23 }
24
25 return nullptr;
26}
27
29 daObjCenter2_c *result = nullptr;
30
31 while ((result = (daObjCenter2_c *) fManager_c::searchBaseByProfName(fProf::OBJ_CENTER2, result))) {
32 if (rotationID == result->mRotationID) {
33 return result;
34 }
35 }
36
37 return nullptr;
38}
39
41 dActor_c *result = searchParent_centerA(rotationID);
42 if (result != nullptr) {
43 return result;
44 }
45
46 return searchParent_centerB(rotationID);
47}
48
50 mParentUniqueID = parent->mUniqueID;
51 mDistanceToParent = mPos - parent->mPos;
52}
53
55 mVec3_c parentPos = parent->mPos;
56
57 s16 parentAngle = parent->mAngle.z;
58 parentAngle += 0x4000;
59 mAngle.z = parentAngle + mOrientation;
60
61 // [using mAng::cos and mAng::sin breaks the match]
62 float parentAngleCos = nw4r::math::CosIdx(parentAngle);
63 float parentAngleSin = nw4r::math::SinIdx(parentAngle);
64
65 float distWithParentX = mDistanceToParent.x;
66 float distWithParentY = mDistanceToParent.y;
67
68 mPos.x = parentPos.x + ((distWithParentX * parentAngleCos) - (distWithParentY * parentAngleSin));
69 mPos.y = parentPos.y + ((distWithParentX * parentAngleSin) + (distWithParentY * parentAngleCos));
70}
71
74 if (result != nullptr) {
75 rotation_move(result);
76 }
77
78 return result;
79}
80
82 dActor_c *parent = searchParent(rotationID);
83 if (parent != nullptr) {
84 setParentInfo(parent);
85 rotation_move(parent);
86
88 }
89
90 return parent;
91}
92
94 allocate();
95
96 mScale.set(1.0f, 1.0f, 1.0f);
97 mCenterOffs.set(0.0f, 24.0f, 0.0f);
98 mVisibleAreaOffset.set(0.0f, 24.0f);
99 mVisibleAreaSize.set(32.0f, 48.0f);
101
102 initCcData();
103
104 mExecStopMask &= ~BIT_FLAG(STAGE_ACTOR_ENEMY);
105
106 initAnm();
107 initialize();
108
109 u32 isRotationControlled = ACTOR_PARAM(HasParent);
110 mPos.z = 32.0f;
112 mOrientation = ACTOR_PARAM(Orientation) * 0x4000;
113 mHasParent = isRotationControlled != 0;
114
115 if (isRotationControlled) {
116 mRotationID = ACTOR_PARAM(RotationID);
119 }
120 } else {
122 }
123
124 return SUCCEEDED;
125}
126
128 mAllocator.createFrmHeap(-1, mHeap::g_gameHeaps[mHeap::GAME_HEAP_DEFAULT], nullptr, 0x20);
129 createMdl();
130 mAllocator.adjustFrmHeap();
131}
132
134 if (mHasParent) {
136 if (!rotation_move()) {
137 deleteActor(FALSE);
138 return SUCCEEDED;
139 }
140 }
141 } else if (ActorScrOutCheck(SKIP_NONE)) {
142 return SUCCEEDED;
143 }
144
145 mStateMgr.executeState();
146 calcMdl();
147 return SUCCEEDED;
148}
149
151 mModel.entry();
152 return SUCCEEDED;
153}
154
156 if (mAllocator.mpHeap != mAllocatorDummyHeap_c::getInstance()) {
157 mAnim.remove();
158 mModel.remove();
159 }
160
161 return SUCCEEDED;
162}
163
165 mVec3_c pos = mPos;
166 mAng3_c angle = mAngle;
167 changePosAngle(&pos, &angle, 1);
168
169 mMatrix.trans(pos);
170 mMatrix.YrotM(angle.y);
171 mMatrix.XrotM(angle.x);
172 mMatrix.ZrotM(angle.z);
173
174 mModel.setLocalMtx(&mMatrix);
175 mModel.setScale(mScale);
176 mModel.calc(false);
177}
178
179void daEnDoor_c::ccCallback(dCc_c *self, dCc_c *other) {
180 dAcPy_c *otherActor = (dAcPy_c *) other->mpOwner;
181 if (otherActor->mKind != STAGE_ACTOR_PLAYER) {
182 return;
183 }
184
185 daEnDoor_c *door = (daEnDoor_c *) self->mpOwner;
186 if (door->isDummyOpen()) {
187 if (otherActor->isDoorDemoEnable()) {
188 if (door->isClosed()) {
190 }
191
192 self->mInfo |= CC_NO_HIT;
193 }
194 } else if (door->checkOpenOk() && otherActor->setDoorDemo(door)) {
195 door->mMayOpen = true;
196 self->mInfo |= CC_NO_HIT;
197 }
198}
199
201 if (isClosed()) {
202 return true;
203 }
204
206 return true;
207 }
208
209 return false;
210}
211
212void daEnDoor_c::initializeState_Search() {}
213
214void daEnDoor_c::finalizeState_Search() {}
215
216void daEnDoor_c::executeState_Search() {
218}
219
220void daEnDoor_c::initializeState_Open() {
221 setOpenAnm();
222 setOpenSE();
223}
224
225void daEnDoor_c::finalizeState_Open() {
226 mIsOpen = false;
227}
228
229void daEnDoor_c::executeState_Open() {
230 mModel.play();
231
232 if (!mAnim.isStop()) {
233 return;
234 }
235
236 mIsOpen = true;
238 return;
239 }
240
242}
243
244void daEnDoor_c::initializeState_Dummy() {
245 dAudio::g_pSndObjMap->startSound(SE_OBJ_DDOOR_OPEN, mPos, 0);
246
247 mVec3_c effPos = getCenterPos();
248 effPos.z = 2800.0f;
249
250 mEf::createEffect("Wm_en_obakedoor", 0, &effPos, nullptr, nullptr);
251 dActorMng_c::m_instance->createUpCoin(getCenterPos(), 0, 1, 0);
252}
253
254void daEnDoor_c::finalizeState_Dummy() {}
255
256void daEnDoor_c::executeState_Dummy() {
257 deleteActor(TRUE);
258}
259
260void daEnDoor_c::initializeState_Close() {
261 setCloseAnm();
262}
263
264void daEnDoor_c::finalizeState_Close() {}
265
266void daEnDoor_c::executeState_Close() {
267 mModel.play();
269
270 if (!mAnim.isStop()) {
271 return;
272 }
273
274 setCloseSE();
276}
277
278void daEnDoor_c::initializeState_Wait() {
280 mMayOpen = false;
281 setWaitAnm();
282}
283
284void daEnDoor_c::finalizeState_Wait() {}
285
286void daEnDoor_c::executeState_Wait() {
287 mModel.play();
288 waitProc();
289
290 if (!mMayOpen) {
291 return;
292 }
293
296 }
297}
The player class for Mario, Luigi and the Toads.
bool isState(const sStateIDIf_c &other) const
Checks if the actor is currently in the given state.
sFStateStateMgr_c< dActorMultiState_c, sStateMethodUsr_FI_c, sStateMethodUsr_FI_c > mStateMgr
The state manager.
void deleteActor(u8 deleteForever)
Deletes the actor and optionally disables respawn.
Definition d_actor.cpp:355
u8 mExecStopMask
The mask required to disable the execute operation for the actor.
Definition d_actor.hpp:379
@ SKIP_NONE
No checks are skipped.
Definition d_actor.hpp:78
static const float smc_CULL_YLIMIT
The default max bound Y offset.
Definition d_actor.hpp:408
u8 mKind
The actor's kind. Value is a STAGE_ACTOR_KIND_e.
Definition d_actor.hpp:377
static void changePosAngle(mVec3_c *pos, mAng3_c *ang, int param3)
Adjusts the actor's position to account for looping stages.
Definition d_actor.cpp:297
mVec2_c mVisibleAreaSize
The size of the area inside which the actor is visible.
Definition d_actor.hpp:350
bool ActorScrOutCheck(u16 flags)
Checks if the actor is out of gameplay and optionally deletes it.
Definition d_actor.cpp:413
dActor_c()
Constructs a new actor.
Definition d_actor.cpp:46
sRangeDataF mMaxBound
Definition d_actor.hpp:352
@ STAGE_ACTOR_ENEMY
An enemy actor.
Definition d_actor.hpp:52
@ STAGE_ACTOR_PLAYER
The player actor.
Definition d_actor.hpp:50
static const float smc_CULL_XLIMIT
The default max bound X offset.
Definition d_actor.hpp:407
mVec2_c mVisibleAreaOffset
The offset applied to the area size.
Definition d_actor.hpp:351
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.
mVec3_c mCenterOffs
The offset from the position to the center of the actor (defaults to 0).
mVec3_c getCenterPos() const
Gets the actor's centered position.
mAng3_c mAngle
The actor's rotation (for 2D actors).
Collider ("Collision Check") class - handles collisions between actors.
Definition d_cc.hpp:134
dActor_c * mpOwner
The actor this collider belongs to.
Definition d_cc.hpp:280
u8 mInfo
Info flags for this collider. See CC_INFO_e.
Definition d_cc.hpp:339
virtual void changeState(const sStateIDIf_c &newState)
Changes the actor's state to the given state.
The base class for door actors.
virtual int execute() override
do method for the execute operation.
virtual void setWaitAnm()
Stops all animations for the door.
void calcMdl()
Updates mMatrix and mModel.
void allocate()
Wraps createMdl to allocate memory for the door's assets.
dActor_c * setParentInfo(u32 rotationID)
Links the door to its parent.
fBaseID_e mParentUniqueID
The unique ID of the parent actor if linked (daObjCenter_c or daObjCenter2_c).
DoorStatus_e mDoorStatus
The current status of the door.
static sFStateID_c< daEnDoor_c > StateID_Dummy
Acting as a fake Ghost House door.
virtual void setCloseMoveSE()
Plays the door closing SFX.
dActor_c * rotation_move()
Moves the door along its parent's Z angle.
virtual void setOpenAnm()
Sets up the door open animation.
m3d::mdl_c mModel
The door model.
virtual void initAnm()
Initializes the animation for the door.
virtual int doDelete() override
do method for the delete operation.
mAng mOrientation
The orientation of the door.
@ DOOR_STATUS_WAIT
The door is ready to be opened.
@ DOOR_STATUS_OPEN_IN
The door must open for players to exit it.
@ DOOR_STATUS_CLOSED
The door must close.
@ DOOR_STATUS_OPEN_OUT
The door must open for players to enter it.
virtual bool isClosed()
Checks whether the door is closed.
virtual int draw() override
do method for the draw operation.
static sFStateID_c< daEnDoor_c > StateID_Wait
Waiting for players to interact with the door.
virtual void setOpenSE()
Plays the door opening SFX.
virtual bool isDummyOpen()
Returns whether the door must act like fake Ghost House Doors.
BOOL mMayOpen
Whether the door may open.
virtual void initialize()
Initializes other elements, called by create().
u8 mRotationID
The rotation ID that links the door to the corresponding controller.
BOOL mIsOpen
Whether the door finished opening or not.
virtual void setCloseAnm()
Sets up the door close animation.
dHeapAllocator_c mAllocator
The allocator.
virtual void createMdl()
Creates the model and animation for the door.
static sFStateID_c< daEnDoor_c > StateID_Search
Searching for the parent controller actor.
virtual int create() override
do method for the create operation.
static daObjCenter2_c * searchParent_centerB(u32 rotationID)
Searches for a daObjCenter2_c with the given Rotation ID.
static sFStateID_c< daEnDoor_c > StateID_Open
Playing the open animation.
mVec3_c mDistanceToParent
The distance between the parent controller's position and the door when it spawned.
m3d::anmChr_c mAnim
The door model animation.
virtual void initCcData()
Initializes collision data for the door.
static sFStateID_c< daEnDoor_c > StateID_Close
Playing the close animation.
static daObjCenter_c * searchParent_centerA(u32 rotationID)
Searches for a daObjCenter_c with the given Rotation ID.
virtual void waitProc()
Executed every frame during the Wait state.
u8 mHasParent
Whether the door is controlled by a parent actor.
static dActor_c * searchParent(u32 rotationID)
Searches for a daObjCenter_c or daObjCenter2_c with the given Rotation ID.
bool checkOpenOk()
Checks if the door is opening for players to enter it.
virtual void setCloseSE()
Plays the door closed SFX.
static void ccCallback(dCc_c *self, dCc_c *other)
Collision callback for the door.
A controller for rotating objects around a center point.
u8 mRotationID
The rotation ID to be set on the affected objects.
A controller for swaying objects around a center point.
u8 mRotationID
The rotation ID to be set on the affected objects.
@ SUCCEEDED
The step was completed successfully.
Definition f_base.hpp:47
fBaseID_e mUniqueID
The base's unique identifier.
Definition f_base.hpp:62
static fBase_c * searchBaseByID(fBaseID_e id)
Searches for a base with the given ID.
Definition f_manager.cpp:18
static fBase_c * searchBaseByProfName(ProfileName profID, const fBase_c *parent)
Searches for a base with a given profile name, optionally under a given parent.
Definition f_manager.cpp:26
A three-dimensional short angle vector.
Definition m_angle.hpp:72
mAng y
The rotation on the Y axis.
Definition m_angle.hpp:130
mAng z
The rotation on the Z axis.
Definition m_angle.hpp:131
mAng x
The rotation on the X axis.
Definition m_angle.hpp:129
A three-dimensional floating point vector.
Definition m_vec.hpp:122
@ BASE_ID_NULL
Represents the null base.
Definition f_base_id.hpp:7
@ 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