Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
HiddenPanel.c
Go to the documentation of this file.
1#include "common.h"
2#include "vars_access.h"
3#include "ld_addrs.h"
4#include "entity.h"
5
6#if VERSION_JP // TODO remove once segments are split
7extern Addr entity_model_HiddenPanel_ROM_END;
8extern Addr entity_model_HiddenPanel_ROM_START;
9#endif
10
13
14void mdl_project_tex_coords(s32 modelID, Gfx* destGfx, Matrix4f destMtx, void* destVertices);
15s32 npc_find_standing_on_entity(s32 entityIndex);
16
17extern s32 ERS_AltHiddenPanel[];
18
19extern Gfx Gfx_HiddenPanel_RenderTop[];
22extern Gfx Gfx_HiddenPanel_Render[];
23extern Gfx Gfx_HiddenPanel_Render2[];
24
25void entity_HiddenPanel_setupGfx(s32 entityIndex) {
26 Entity* entity = get_entity_by_index(entityIndex);
27 HiddenPanelData* data = entity->dataBuf.hiddenPanel;
28 Matrix4f rotMtx;
29 Matrix4f tempMtx;
30
31 if (entity->pos.y != data->initialY) {
32 guMtxIdentF(rotMtx);
33 guTranslateF(tempMtx, entity->pos.x, data->initialY + 1.0f, entity->pos.z);
34 guMtxCatF(tempMtx, rotMtx, tempMtx);
36 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
37 gSPDisplayList(gMainGfxPos++, ENTITY_ADDR(entity, Gfx*, Gfx_HiddenPanel_RenderHole));
38 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
39 }
42}
43
51
53 entity->flags &= ~ENTITY_FLAG_DISABLE_COLLISION;
54 entity->flags |= ENTITY_FLAG_HIDDEN;
55}
56
58 HiddenPanelData* data = entity->dataBuf.hiddenPanel;
59 s32 distToPlayer;
60
62 if (!data->unk_04) {
63 data->unk_04 = TRUE;
65 }
66 } else {
67 data->unk_04 = FALSE;
68 }
69
70 data->standingNpcIndex = -1;
71 data->npcFlags = 0;
72
74 data->state = 10;
75 distToPlayer = get_xz_dist_to_player(entity->pos.x, entity->pos.z);
76 if (distToPlayer <= 100) {
78 data->riseVel = 0.5f;
80 } else if (entity_HiddenPanel_is_item_on_top(entity)) {
81 data->riseVel = 0.5f;
83 } else {
84 s32 npcIndex = npc_find_standing_on_entity(entity->listIndex);
85 if (npcIndex >= 0) {
86 Npc* npc = get_npc_by_index(npcIndex);
87 dist2D(entity->pos.x, entity->pos.z, npc->pos.x, npc->pos.z);
88 data->standingNpcIndex = npcIndex;
90 npc->flags &= ~NPC_FLAG_FLYING;
91 npc->flags |= NPC_FLAG_GRAVITY;
92 data->riseVel = 0.5f;
94 } else {
96 if (distToPlayer > 60) {
97 data->riseVel = 0.5f;
99 } else {
100 data->state = 0;
101 data->riseVel = 10.0f;
103 }
104 }
105 }
106 }
107 }
108}
109
111 HiddenPanelData* data = entity->dataBuf.hiddenPanel;
112 f32 yaw;
113 f32 rotAngle;
114 s32 flipAxis;
115
116 yaw = clamp_angle(gCameras[CAM_DEFAULT].curYaw + 45.0f);
117 if (yaw < 90.0f || yaw >= 180.0f && yaw < 270.0f) {
118 rotAngle = entity->rot.z;
119 flipAxis = 1;
120 } else {
121 rotAngle = entity->rot.x;
122 flipAxis = 0;
123 }
124
125 switch (data->state) {
126 case 0:
128 data->state = 1;
129 data->unk_02 = TRUE;
130 data->riseInterpPhase = 90.0f;
131 data->rotSpeed = 65.0f;
135 if (data->needSpawnItem) {
136 data->needSpawnItem = FALSE;
138 entity->pos.x, entity->pos.y + 2.0, entity->pos.z,
140 }
141 entity->flags &= ~ENTITY_FLAG_HIDDEN;
142 break;
143 case 1:
144 entity->pos.y += data->riseVel * sin_rad(DEG_TO_RAD(data->riseInterpPhase));
145 if (entity->pos.y <= data->initialY) {
146 entity->pos.y = data->initialY;
147 entity->rot.x = 0.0f;
148 entity->rot.z = 0.0f;
149 rotAngle = 0.0f;
150 data->timer = 10;
151 }
152
153 data->riseInterpPhase += 10.0f;
154 if (data->riseInterpPhase >= 180.0f) {
155 data->riseInterpPhase = 180.0f;
156 data->timer = 7;
157 data->state++;
158 }
159
160 if (data->riseInterpPhase > 110.0f) {
161 rotAngle += data->rotSpeed;
162 if (rotAngle >= 360.0f) {
163 rotAngle -= 360.0f;
164 }
165 }
166 break;
167 case 2:
168 data->rotSpeed -= 2.0f;
169 if (data->rotSpeed <= 0.0f) {
170 data->rotSpeed = 0.0f;
171 }
172
173 rotAngle += data->rotSpeed;
174 if (rotAngle >= 360.0f) {
175 rotAngle -= 360.0f;
176 }
177
178 if (--data->timer <= 0) {
179 data->state++;
180 }
181 break;
182 case 3:
183 data->rotSpeed -= 5.0f;
184 if (data->rotSpeed <= 0.0f) {
185 data->rotSpeed = 0.0f;
186 }
187
188 rotAngle += data->rotSpeed;
189 if (rotAngle >= 360.0f) {
190 rotAngle = 360.0f;
191 }
192
193 entity->pos.y += data->riseVel * sin_rad(DEG_TO_RAD(data->riseInterpPhase));
194 data->riseInterpPhase += 10.0f;
195 if (data->riseInterpPhase > 270.0f) {
196 data->riseInterpPhase = 270.0f;
197 }
198
199 if (entity->pos.y <= data->initialY) {
200 data->state++;
201
202 entity->pos.y = data->initialY;
203 entity->rot.x = 0.0f;
204 entity->rot.z = 0.0f;
205 rotAngle = 0.0f;
206 data->timer = 10;
209 }
210 break;
211 case 4:
212 data->state++;
213 break;
214 case 5:
215 data->state = 11;
216 entity->pos.y += 2.0f;
217 break;
218 case 10:
219 entity->flags &= ~ENTITY_FLAG_HIDDEN;
220 data->unk_02 = FALSE;
221 data->state++;
222 entity->pos.y += 6.0f;
223 break;
224 case 11:
225 entity->pos.y -= 1.0f;
226 if (entity->pos.y <= data->initialY) {
227 entity->pos.y = data->initialY;
228 data->timer = 1;
229 data->state++;
231 if (data->unk_02) {
233 }
234 }
235 break;
236 case 12:
237 data->timer--;
238 if (data->timer < 0) {
239 data->state = 0;
241 if (data->unk_02) {
243 gPlayerStatusPtr->animFlags &= ~PA_FLAG_OPENED_HIDDEN_PANEL;
244 }
245 entity->flags &= ~ENTITY_FLAG_DISABLE_COLLISION;
246 if (data->standingNpcIndex >= 0) {
249 npc->flags |= data->npcFlags;
250 }
251 }
252 break;
253 }
254
255 if (flipAxis == 0) {
256 entity->rot.x = rotAngle;
257 } else {
258 entity->rot.z = rotAngle;
259 }
260
261 if (data->spawnedItemIndex >= 0) {
262 ItemEntity* itemEntity = get_item_entity(data->spawnedItemIndex);
263 if (itemEntity != NULL) {
264 if (itemEntity->flags & ITEM_ENTITY_FLAG_10) {
265 data->spawnedItemPos.x = itemEntity->pos.x;
266 data->spawnedItemPos.y = itemEntity->pos.y;
267 data->spawnedItemPos.z = itemEntity->pos.z;
268 } else {
269 data->spawnedItemPos.x = 0x8000;
270 data->spawnedItemPos.y = 0x8000;
271 data->spawnedItemPos.z = 0x8000;
272 }
273 } else {
274 data->spawnedItemIndex = -1;
275 }
276 }
277}
278
280 HiddenPanelData* data = entity->dataBuf.hiddenPanel;
281
282 if (data->spawnedItemIndex >= 0) {
283 ItemEntity* itemEntity = get_item_entity(data->spawnedItemIndex);
284 if (itemEntity != NULL) {
285 if (itemEntity->flags & ITEM_ENTITY_FLAG_10) {
286 if (fabs(entity->pos.x - data->spawnedItemPos.x) <= 34.0) {
287 if (fabs(entity->pos.z - data->spawnedItemPos.z) <= 34.0) {
288 return TRUE;
289 }
290 }
291 }
292 }
293 }
294
295 return FALSE;
296}
297
299 HiddenPanelData* data = entity->dataBuf.hiddenPanel;
300 Matrix4f sp18;
301 Matrix4f sp58;
302 Gfx* dlist;
303
306 data->pickupVar = 0xFFFF;
307 data->initialY = entity->pos.y;
310 data->needSpawnItem = TRUE;
311 data->spawnedItemIndex = -1;
312
313 if (data->itemID == 0) {
314 data->itemID = ITEM_STAR_PIECE;
315 }
316
317 guMtxIdentF(data->entityMatrix);
318 guTranslateF(sp18, entity->pos.x, entity->pos.y, entity->pos.z);
319 guRotateF(sp58, entity->rot.y, 0.0f, 1.0f, 0.0f);
320 guMtxCatF(sp58, sp18, sp18);
321 guRotateF(sp58, entity->rot.x, 1.0f, 0.0f, 0.0f);
322 guMtxCatF(sp58, sp18, sp18);
323 guRotateF(sp58, entity->rot.z, 0.0f, 0.0f, 1.0f);
324 guMtxCatF(sp58, sp18, sp18);
325 guScaleF(sp58, entity->scale.x, entity->scale.y, entity->scale.z);
326 guMtxCatF(sp58, sp18, data->entityMatrix);
327
331 } else {
333 }
334 data->renderDList = ENTITY_ADDR(entity, Gfx*, dlist);
335
338}
339
349
357
365
368 .typeDataSize = sizeof(HiddenPanelData),
369 .renderCommandList = ERS_HiddenPanel,
370 .modelAnimationNodes = 0,
371 .fpInit = entity_HiddenPanel_init,
372 .updateEntityScript = Entity_HiddenPanel_Script,
373 .fpHandleCollision = NULL,
374 { .dma = ENTITY_ROM(HiddenPanel) },
375 .entityType = ENTITY_TYPE_HIDDEN_PANEL,
376 .aabbSize = { 60, 0, 60 }
377};
378
379//TODO remove this
380static const f32 rodata_alignment[] = {0.0f, 0.0f};
EntityModelScript ERS_HiddenPanel
void entity_HiddenPanel_setupGfx(s32 entityIndex)
Definition HiddenPanel.c:25
Gfx Gfx_HiddenPanel_RenderHole[]
Definition HiddenPanel.c:71
void entity_HiddenPanel_set_ispy_notification(Entity *entity)
Definition HiddenPanel.c:44
void entity_HiddenPanel_flip_over(Entity *)
void entity_HiddenPanel_idle(Entity *entity)
Definition HiddenPanel.c:57
Gfx Gfx_HiddenPanel_RenderTop[]
Definition HiddenPanel.c:40
s32 npc_find_standing_on_entity(s32 entityIndex)
Definition npc.c:2021
Gfx Gfx_HiddenPanel_Render[]
Definition HiddenPanel.c:84
s32 entity_HiddenPanel_is_item_on_top(Entity *)
EntityBlueprint Entity_HiddenPanel
void mdl_project_tex_coords(s32 modelID, Gfx *destGfx, Matrix4f destMtx, void *destVertices)
s32 ERS_AltHiddenPanel[]
Gfx Gfx_HiddenPanel_Render2[]
Definition HiddenPanel.c:91
EntityScript Entity_HiddenPanel_Script
void entity_HiddenPanel_init(Entity *entity)
void entity_HiddenPanel_hide(Entity *entity)
Definition HiddenPanel.c:52
Gfx Gfx_AltHiddenPanel_RenderTop[]
Definition HiddenPanel.c:49
Mtx matrixStack[0x200]
struct HiddenPanelData * hiddenPanel
f32 Matrix4f[4][4]
#define guRotateF
#define guMtxF2L
#define guTranslateF
#define guMtxCatF
#define mdl_draw_hidden_panel_surface
#define clamp_angle
#define mem_clear
#define guScaleF
s32 CreateEntityVarArgBuffer[]
Definition entity.c:35
s32 EntityModelScript[]
Definition entity.h:7
f32 riseInterpPhase
Definition entity.h:241
#define es_Call(func)
Definition entity.h:37
#define ems_Restart
Definition entity.h:49
#define ENTITY_ADDR(entity, type, data)
Definition entity.h:64
#define es_SetCallback(func, time)
Definition entity.h:38
s32 spawnedItemIndex
Definition entity.h:237
Gfx * renderDList
Definition entity.h:246
#define ENTITY_ROM(name)
Definition entity.h:65
#define ems_SetRenderMode(mode)
Definition entity.h:51
#define es_Label(labelId)
Definition entity.h:41
#define es_Goto(labelId)
Definition entity.h:39
s32 EntityScript[]
Definition entity.h:6
#define ems_SetFlags(flags)
Definition entity.h:52
#define es_End
Definition entity.h:35
Vec3i spawnedItemPos
Definition entity.h:238
#define ems_End
Definition entity.h:47
Matrix4f entityMatrix
Definition entity.h:243
s32 standingNpcIndex
Definition entity.h:234
void entity_set_render_script(Entity *entity, EntityModelScript *cmdList)
Definition entity.c:761
#define ems_Draw(dlist, holdTime)
Definition entity.h:48
@ ENTITY_MODEL_FLAG_10000
Definition enums.h:5026
@ CAM_SHAKE_DECAYING_VERTICAL
Definition enums.h:1809
@ ITEM_ENTITY_FLAG_10
Definition enums.h:2699
@ ITEM_SPAWN_MODE_TOSS_NEVER_VANISH
Definition enums.h:2296
@ ENTITY_TYPE_HIDDEN_PANEL
Definition enums.h:2585
@ PA_FLAG_OPENED_HIDDEN_PANEL
Definition enums.h:3102
@ TIME_FREEZE_PARTIAL
Definition enums.h:3465
@ TIME_FREEZE_NONE
Definition enums.h:3464
@ ENTITY_COLLISION_PLAYER_TOUCH_FLOOR
Definition enums.h:2648
@ ABILITY_I_SPY
Definition enums.h:477
@ SOUND_FLIP_PANEL
Definition enums.h:1460
@ SOUND_CLOSE_PANEL
Definition enums.h:1461
@ RENDER_MODE_SURFACE_OPA
Definition enums.h:3264
@ ENTITY_FLAG_HIDDEN
Definition enums.h:2613
@ ENTITY_FLAG_DISABLE_COLLISION
Definition enums.h:2618
@ CAM_DEFAULT
Definition enums.h:1800
@ NPC_FLAG_FLYING
Definition enums.h:3001
@ NPC_FLAG_GRAVITY
Definition enums.h:3007
Entity * get_entity_by_index(s32 index)
Definition entity.c:530
s32 is_ability_active(s32 arg0)
Definition inventory.c:1725
f64 fabs(f64 f)
void func_800EF3D4(s32)
Definition partners.c:2414
ItemEntity * get_item_entity(s32 itemEntityIndex)
s32 disable_player_static_collisions(void)
Definition 77480.c:972
s32 make_item_entity_nodelay(s32 itemID, f32 x, f32 y, f32 z, s32 itemSpawnMode, s32 pickupVar)
f32 dist2D(f32 ax, f32 ay, f32 bx, f32 by)
Definition 43F0.c:670
void exec_entity_commandlist(Entity *entity)
Definition entity.c:313
void exec_ShakeCamX(s32 arg0, s32 arg1, s32 arg2, f32 arg3)
Definition cam_api.c:374
f32 sin_rad(f32 x)
Definition 43F0.c:713
void set_time_freeze_mode(s32)
Time freeze modes: 0: none 1: NPCs move, can't be interacted with 2: NPCs don't move,...
Definition main_loop.c:358
s32 enable_player_static_collisions(void)
Definition 77480.c:980
f32 get_xz_dist_to_player(f32, f32)
Definition 77480.c:960
Npc * get_npc_by_index(s32 listIndex)
Definition npc.c:271
void sfx_play_sound(s32 soundID)
Definition sfx.c:517
#define DEG_TO_RAD(deg)
Definition macros.h:134
void(* renderSetupFunc)(s32)
EntityData dataBuf
void * gfxBaseAddr
Vec3f scale
u8 collisionFlags
s32 flags
Vec3f pos
u8 Addr[]
Linker symbol address, as in ld_addrs.h.
Definition types.h:16
PlayerStatus * gPlayerStatusPtr
Camera gCameras[4]
Definition cam_main.c:17
Gfx * gMainGfxPos
Definition cam_main.c:15
u16 gMatrixListPos
Definition main_loop.c:45
DisplayContext * gDisplayContext
Definition cam_main.c:16
HiddenPanelsData gCurrentHiddenPanels
Definition entity.c:36
s32 get_global_flag(s32 index)
Definition vars_access.c:89